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

lowering: Canonicalize to builtins for global assignment #56713

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

Keno
Copy link
Member

@Keno Keno commented Nov 29, 2024

This adjusts lowering to emit setglobal! for assignment to globals, thus making the = expr head used only for slots in CodeInfo and entirely absent in IRCode. The primary reason for this is just to reduce the number of special cases that compiler passes have to reason about. In IRCode, = was already essentially equivalent to setglobal!, so there's no good reason not to canonicalize.

Finally, the = syntax form for globals already gets recognized specially to insert convert calls to their declared binding type, so this doesn't impose any additional requirements on lowering to distinguish local from global assignments. In general, I'd also like to separate syntax and intermediate forms as much as possible where their semantics differ, which this accomplises by just using the builtin.

This change is mostly semantically invisible, except that spliced-in GlobalRefs now declare their binding because they are indistinguishable from ordinary assignments at the stage where I inserted the lowering. If we want to, we can preserve the difference, but it'd be a bit more annoying for not much benefit, because:

  1. The spliced in version was only recently made to work anyway, and
  2. The semantics of when exactly bindings are declared is still messy on master anyway and will get tweaked shortly in further binding partitions work.

Base automatically changed from kf/56711 to master December 2, 2024 23:02
This adjusts lowering to emit `setglobal!` for assignment to globals,
thus making the `=` expr head used only for slots in `CodeInfo` and
entirely absent in `IRCode`. The primary reason for this is just
to reduce the number of special cases that compiler passes have
to reason about. In IRCode, `=` was already essentially equivalent
to `setglobal!`, so there's no good reason not to canonicalize.

Finally, the `=` syntax form for globals already gets recognized
specially to insert `convert` calls to their declared binding
type, so this doesn't impose any additional requirements on
lowering to distinguish local from global assignments. In general,
I'd also like to separate syntax and intermediate forms as much
as possible where their semantics differ, which this accomplises
by just using the builtin.

This change is mostly semantically invisible, except that spliced-in
GlobalRefs now declare their binding because they are indistinguishable
from ordinary assignments at the stage where I inserted the lowering.
If we want to, we can preserve the difference, but it'd be a bit
more annoying for not much benefit, because:
1. The spliced in version was only recently made to work anyway, and
2. The semantics of when exactly bindings are declared is still messy
   on master anyway and will get tweaked shortly in further binding
   partitions work.
@Keno Keno force-pushed the kf/canonicalequal branch from 18205fb to 5de6d3b Compare December 3, 2024 00:57
@Keno Keno merged commit 2c87290 into master Dec 3, 2024
7 checks passed
@Keno Keno deleted the kf/canonicalequal branch December 3, 2024 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants