Skip to content

[Feature] Support more inference "corner cases" #28654

Description

@mohammadfawaz

#28642 and all the work that came before support a good amount of common cases. We can do better thought. Here are some example that I would like to support in the future:

  1. Implicit array indices. Maybe default to u32 since I think we cast to u32 anyways?
  2. In let x = 1u32 + (true ? 1 : 2), we should infer 1 and 2 to be u32.
  3. In let x = [1, 2u32, 3], we should infer 1, and 3 to be u32.
  4. In let x = 1; let y = x + 3u32, we should infer that x and 1 are both u32. This requires revisiting previously type checked statements.
  5. In let x = 1 + 1 + 1u32, we should infer that the 1s are both u32. The problem here is that 1 + 1 is visited first and we quickly give up.
  6. In for i in 0u32..4 { }, we should infer that the 4 is a u32
  7. In assert_eq(1u32, 1), we should infer that the 1 is a u32.
  8. Mapping function such as .set(0, 0) should work.
  9. More to come

I have some ideas around these but they require a bigger refactor of parts in the compiler. I think we need a way to visit a statement/expression and have the ability to visit it again when we gather more information. So, certainly a way to throw away collected errors and not always emit them in case we revisit an item again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🚀 featureA new feature.🧱 Core CompilerAnything related to the core compiler including parsing, analysis, transforms, codegen, etc.
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions