Skip to content
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 2 commits into from
Jul 21, 2023
Merged

Numeric type inference #4829

merged 2 commits into from
Jul 21, 2023

Conversation

IGI-111
Copy link
Contributor

@IGI-111 IGI-111 commented Jul 19, 2023

Description

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.

Fixes #3470

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@IGI-111 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 IGI-111 self-assigned this Jul 19, 2023
@IGI-111 IGI-111 force-pushed the IGI-111/numeric-inference branch 3 times, most recently from 9156842 to 8143ce9 Compare July 20, 2023 07:29
@IGI-111 IGI-111 marked this pull request as ready for review July 20, 2023 07:29
@IGI-111 IGI-111 requested a review from a team July 20, 2023 07:29
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 IGI-111 force-pushed the IGI-111/numeric-inference branch from 8143ce9 to 69e8154 Compare July 20, 2023 13:07
@IGI-111 IGI-111 requested review from anton-trunov and a team July 20, 2023 13:11
@IGI-111 IGI-111 requested a review from a team July 20, 2023 14:54
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Removing implicit casting between integer types
3 participants