Repository navigation
fix(vm): keep int64 arithmetic when int is 32 bits - #1043
Open
tonycoder-hub wants to merge 1 commit into
Open
tonycoder-hub wants to merge 1 commit into
tonycoder-hub wants to merge 1 commit into
Conversation
Signed operations that include an int64 were evaluated as int, so on GOARCH=386 values above MaxInt32 wrapped. The generated helpers take an int64 path only when strconv.IntSize == 32; on amd64 that arm compiles out and the result stays int. Comparisons of those pairs use int64 with no arch branch, which matches int comparison when int is 64 bits. The checker uses the same result rule. On 386, a real Go func invoked by reflection or OpCallTyped rejects an int64 argument where it would assert .(int). Builtins and expr.Function still take ...any and convert with ToInt. runtime.Modulo still returns int. The new runtime.ModuloWide handles only the int64 cases and falls back to Modulo; the VM calls it only when int is 32 bits. uniq's wider index is used only on 386. uint64 arithmetic is unchanged. Fixes expr-lang#804 Signed-off-by: Tony Coder <407243179@qq.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Signed arithmetic that includes an int64 was evaluated as int, so on GOARCH=386
I64 + 0withI64 = int64(MaxInt32+1)returned-2147483648.The helper generator uses an int64 operation only inside
if strconv.IntSize == 32for+,-,*, and%. On amd64 that arm compiles out and the result stays int, so results and types on 64-bit match master. Comparisons of those signed pairs areint64(x) op int64(y)with no arch branch; when int is 64 bits that is the same boolean as comparing as int. The checker uses the same result rule.On 386, the compile error for an int64 argument applies only to a real Go function invoked by reflection or OpCallTyped, where the VM would assert
.(int). Builtins andexpr.Functionstill receive...anyand convert withruntime.ToInt, sorepeat,bitand,bitshl,split, and adoublefunction declared asfunc(int) intwith a ToInt body keep working.runtime.Modulostill returns int. New exportedruntime.ModuloWidehandles only the signed int64 cases and falls back toModulo. The VM calls it only when int is 32 bits.uniqkeeps the original int-keyed index on amd64. On 386 it uses a separate index, so signed int64 values that do not fit in int are not collapsed. An amd64 bench ofuniqstayed within noise (78.49µ vs 78.45µ, same 58 allocs/op).Behavior changes on 386:
func(int)parameter, or used as amap[int]key, is now a compile error (it used to truncate silently). Wrap it inint(...).FnInt(Any + 1)andMI[Any + 1]fail at runtime when Any's dynamic value is an int64, because the static type is any.Still limited on 386:
a..brange bounds are int.sum([]uint64)andsum([]int32)accumulate in int.A fully green
GOARCH=386 go test ./...still depends on #1039. With those three test edits applied locally, that command passed. #1039 and this branch both add an import to the sameexpr_test.goblock, so whichever lands second needs a trivial rebase.Fixes #804