Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Oct 29, 2025

Path resolution needs to happen before variable resolution, because otherwise we cannot know whether an identifier pattern binds a new variable or whether it refers to a constructor or constant:

let x = ...; // `x` is only a variable if it does not resolve to a constructor/constant

Even though variable names typically start with a lowercase letter and constructors/constants with an uppercase letter, this is not enforced by the Rust language.

Variables may shadow declarations, so variable resolution also needs to affect path resolution:

fn foo() {}        // (1)

fn bar() {
    let f = foo;   // `foo` here refers to (1) via path resolution
    let foo = f(); // (2)
    foo            // `foo` here refers to (2) via variable resolution
}

So it may seem that path resolution and variable resolution must happen in mutual recursion, but we would like to keep the inherently global path resolution logic separate from the inherently local variable resolution logic. We acheive this by

  • First computing global path resolution, where variable shadowing is ignored, exposed as the internal predicate resolvePathIgnoreVariableShadowing.
  • resolvePathIgnoreVariableShadowing is sufficient to determine whether an identifier pattern resolves to a constructor/constant, since if it does, it cannot be shadowed by a variable. We expose this as the predicate identPatIsResolvable.
  • Variable resolution can then be computed as a local property, using only the global information from identPatIsResolvable.
  • Finally, path resolution can be computed by restricting resolvePathIgnoreVariableShadowing to paths that are not resolvable via variable resolution.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Oct 29, 2025
@hvitved hvitved force-pushed the rust/path-resolution-variable-impl branch 3 times, most recently from f41c74b to fa48969 Compare October 29, 2025 19:28
@hvitved hvitved force-pushed the rust/path-resolution-variable-impl branch 6 times, most recently from b74d8c6 to e845ff0 Compare November 10, 2025 10:02
@hvitved hvitved force-pushed the rust/path-resolution-variable-impl branch 3 times, most recently from 530a7a8 to 5410d17 Compare November 13, 2025 14:19
@hvitved hvitved force-pushed the rust/path-resolution-variable-impl branch 5 times, most recently from 07703ae to fbb1541 Compare November 17, 2025 13:12
@hvitved hvitved force-pushed the rust/path-resolution-variable-impl branch from fbb1541 to da174c3 Compare November 19, 2025 07:55
@hvitved hvitved force-pushed the rust/path-resolution-variable-impl branch from da174c3 to ec3b2c6 Compare November 19, 2025 08:07
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant