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: Don't resolve type bindings earlier than necessary #54999

Merged
merged 1 commit into from
Jul 6, 2024

Conversation

Keno
Copy link
Member

@Keno Keno commented Jul 2, 2024

This is a follow up to resolve a TODO left in #54773 as part of preparatory work for #54654. Currently, our lowering for type definition contains an early isdefined that forces a decision on binding resolution before the assignment of the actual binding. In the current implementation, this doesn't matter much, but with #54654, this would incur a binding invalidation we would like to avoid.

To get around this, we extend the (internal) isdefined form to take an extra argument specifying whether or not to permit looking at imported bindings. If not, resolving the binding is not required semantically, but for the purposes of type definition (where assigning to an imported binding would error anyway), this is all we need.

@Keno Keno force-pushed the kf/isdefinedimplicit branch 4 times, most recently from 8d24794 to 9615722 Compare July 4, 2024 15:52
This is a follow up to resolve a TODO left in #54773 as part of
preparatory work for #54654. Currently, our lowering for type
definition contains an early `isdefined` that forces a decision
on binding resolution before the assignment of the actual binding.
In the current implementation, this doesn't matter much, but
with #54654, this would incur a binding invalidation we would like
to avoid.

To get around this, we extend the (internal) `isdefined` form to take
an extra argument specifying whether or not to permit looking at
imported bindings. If not, resolving the binding is not required
semantically, but for the purposes of type definition (where assigning
to an imported binding would error anyway), this is all we need.
@Keno Keno force-pushed the kf/isdefinedimplicit branch from 9615722 to 2b11378 Compare July 5, 2024 14:49
@Keno Keno merged commit aa07585 into master Jul 6, 2024
7 checks passed
@Keno Keno deleted the kf/isdefinedimplicit branch July 6, 2024 22:18
@@ -681,10 +681,10 @@ JL_DLLEXPORT void jl_module_public(jl_module_t *from, jl_sym_t *s, int exported)
b->exportp |= exported;
}

JL_DLLEXPORT int jl_boundp(jl_module_t *m, jl_sym_t *var) // unlike most queries here, this is currently seq_cst
JL_DLLEXPORT int jl_boundp(jl_module_t *m, jl_sym_t *var, int allow_import) // unlike most queries here, this is currently seq_cst
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment appears to be inaccurate now:

Suggested change
JL_DLLEXPORT int jl_boundp(jl_module_t *m, jl_sym_t *var, int allow_import) // unlike most queries here, this is currently seq_cst
JL_DLLEXPORT int jl_boundp(jl_module_t *m, jl_sym_t *var, int allow_import) // unlike most queries here, this is currently seq_cst if `allow_import` is true.

Keno added a commit that referenced this pull request Jan 8, 2025
In #54999 I extended `:isdefined` with the ability to specify whether
or not to consider imported bindings defined. As a result, we now have
two mechanisms for querying `isdefined` on globals (the other being
`Core.isdefined`) with incompatible feature sets (`Core.isdefined`
supports an atomic ordering argument, but not `allow_import`).
Additionally, only one of them had proper codegen support.
I also don't like to have IR forms for things that could be
perfectly well handled by builtin calls (along the lines of #56713).
So this tries to clean that all up by:
1. Adding a new builtin `isdefinedglobal` that has the full feature set
2. Dropping `:isdefined` on globals as an IR form (the frontend form gets
   lowered to the intrinsic if called on globals)
3. Wiring up codegen and correcting inference for that new builtin

An additional motivation is that `isdefined` on globals needs support
for partition edges (like other builtins), and having to have a special
case for :isdefined was marginally annoying. Just using an intrinsic
for this is much cleaner.

Lastly, the reason for a new intrinsic over extending the existing
`isdefined`, is that over time we've moved away from conflating
fields and globals for Module (e.g. introducing `getglobal`/`setglobal!`),
so this is a natural extension of that. Of course, the existing
behavior is retained for ordinary `isdefined`.
Keno added a commit that referenced this pull request Jan 8, 2025
In #54999 I extended `:isdefined` with the ability to specify whether
or not to consider imported bindings defined. As a result, we now have
two mechanisms for querying `isdefined` on globals (the other being
`Core.isdefined`) with incompatible feature sets (`Core.isdefined`
supports an atomic ordering argument, but not `allow_import`).
Additionally, only one of them had proper codegen support.
I also don't like to have IR forms for things that could be
perfectly well handled by builtin calls (along the lines of #56713).
So this tries to clean that all up by:
1. Adding a new builtin `isdefinedglobal` that has the full feature set
2. Dropping `:isdefined` on globals as an IR form (the frontend form gets
   lowered to the intrinsic if called on globals)
3. Wiring up codegen and correcting inference for that new builtin

An additional motivation is that `isdefined` on globals needs support
for partition edges (like other builtins), and having to have a special
case for :isdefined was marginally annoying. Just using an intrinsic
for this is much cleaner.

Lastly, the reason for a new intrinsic over extending the existing
`isdefined`, is that over time we've moved away from conflating
fields and globals for Module (e.g. introducing `getglobal`/`setglobal!`),
so this is a natural extension of that. Of course, the existing
behavior is retained for ordinary `isdefined`.
Keno added a commit that referenced this pull request Jan 8, 2025
In #54999 I extended `:isdefined` with the ability to specify whether
or not to consider imported bindings defined. As a result, we now have
two mechanisms for querying `isdefined` on globals (the other being
`Core.isdefined`) with incompatible feature sets (`Core.isdefined`
supports an atomic ordering argument, but not `allow_import`).
Additionally, only one of them had proper codegen support.
I also don't like to have IR forms for things that could be
perfectly well handled by builtin calls (along the lines of #56713).
So this tries to clean that all up by:
1. Adding a new builtin `isdefinedglobal` that has the full feature set
2. Dropping `:isdefined` on globals as an IR form (the frontend form gets
   lowered to the intrinsic if called on globals)
3. Wiring up codegen and correcting inference for that new builtin

An additional motivation is that `isdefined` on globals needs support
for partition edges (like other builtins), and having to have a special
case for :isdefined was marginally annoying. Just using an intrinsic
for this is much cleaner.

Lastly, the reason for a new intrinsic over extending the existing
`isdefined`, is that over time we've moved away from conflating
fields and globals for Module (e.g. introducing `getglobal`/`setglobal!`),
so this is a natural extension of that. Of course, the existing
behavior is retained for ordinary `isdefined`.
Keno added a commit that referenced this pull request Jan 9, 2025
In #54999 I extended `:isdefined` with the ability to specify whether or
not to consider imported bindings defined. As a result, we now have two
mechanisms for querying `isdefined` on globals (the other being
`Core.isdefined`) with incompatible feature sets (`Core.isdefined`
supports an atomic ordering argument, but not `allow_import`).
Additionally, only one of them had proper codegen support. I also don't
like to have IR forms for things that could be perfectly well handled by
builtin calls (along the lines of #56713). So this tries to clean that
all up by:
1. Adding a new builtin `isdefinedglobal` that has the full feature set
2. Dropping `:isdefined` on globals as an IR form (the frontend form
gets lowered to the intrinsic if called on globals)
3. Wiring up codegen and correcting inference for that new builtin

An additional motivation is that `isdefined` on globals needs support
for partition edges (like other builtins), and having to have a special
case for :isdefined was marginally annoying. Just using an intrinsic for
this is much cleaner.

Lastly, the reason for a new intrinsic over extending the existing
`isdefined`, is that over time we've moved away from conflating fields
and globals for Module (e.g. introducing `getglobal`/`setglobal!`), so
this is a natural extension of that. Of course, the existing behavior is
retained for ordinary `isdefined`.
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