-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Numeric type inference #4829
Merged
Merged
Numeric type inference #4829
Conversation
This file contains 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
IGI-111
added
lib: std
Standard library
compiler: ir
IRgen and sway-ir including optimization passes
breaking
May cause existing user code to break. Requires a minor or major release.
lib: core
Core library
compiler: frontend
Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
labels
Jul 19, 2023
IGI-111
force-pushed
the
IGI-111/numeric-inference
branch
3 times, most recently
from
July 20, 2023 07:29
9156842
to
8143ce9
Compare
test/src/e2e_vm_tests/test_programs/should_fail/binop_intrinsics/test.toml
Outdated
Show resolved
Hide resolved
test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/src/main.sw
Show resolved
Hide resolved
This does two things. 1. Integer types no longer automatically cast to each other. Methods such as `as_u64` and `try_as_u8` have been introduced to require the user to explicit the cast. Warnings about casts losing precision have been removed as they are no longer possible. 2. Numeric literals (such as `32` without further qualifications) no longer immediately decay to a `u64` and we instead attempt to type them as `TypeInfo::Numeric` as far as possible to allow their usage with any integer type. Numeric intrinsics unify arguments with the numeric type to enforce their constraints. Numeric values are forced to decay to `u64` when resolving methods or traits. This change is a prerequisite to move our representation of sub-byte-sized values to a different memory representation, as numeric types need to be distinct if we are ever to treat them differently.
IGI-111
force-pushed
the
IGI-111/numeric-inference
branch
from
July 20, 2023 13:07
8143ce9
to
69e8154
Compare
anton-trunov
approved these changes
Jul 20, 2023
JoshuaBatty
approved these changes
Jul 21, 2023
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
breaking
May cause existing user code to break. Requires a minor or major release.
compiler: frontend
Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
compiler: ir
IRgen and sway-ir including optimization passes
lib: core
Core library
lib: std
Standard library
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.
Description
This does two things.
Integer types no longer automatically cast to each other. Methods such as
as_u64
andtry_as_u8
have been introduced to require the user to explicit the cast.Warnings about casts losing precision have been removed as they are no longer possible.
Numeric literals (such as
32
without further qualifications) no longer immediately decay to au64
and we instead attempt to type them asTypeInfo::Numeric
as far as possible to allow their usage with any integer type.Numeric intrinsics unify arguments with the numeric type to enforce their constraints.
Numeric values are forced to decay to
u64
when resolving methods or traits.This change is a prerequisite to move our representation of sub-byte-sized values to a different memory representation, as numeric types need to be distinct if we are ever to treat them differently.
Fixes #3470
Checklist
Breaking*
orNew Feature
labels where relevant.