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

Consolidate various isdefined functionality into a new builtin #56985

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

Keno
Copy link
Member

@Keno Keno commented 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.

Copy link
Member

@aviatesk aviatesk left a comment

Choose a reason for hiding this comment

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

Since we dropped the :isdefined for globals, do we now need to update some files modified in #54999, like verify.jl, validation.jl and ast.md?

@Keno Keno force-pushed the kf/isdefinedglobal branch from 31f2278 to 6d957c3 Compare January 8, 2025 18:44
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 Keno force-pushed the kf/isdefinedglobal branch from 6d957c3 to 47bcb34 Compare January 8, 2025 21:56
@Keno Keno merged commit 3d85309 into master Jan 9, 2025
4 of 7 checks passed
@Keno Keno deleted the kf/isdefinedglobal branch January 9, 2025 16:29
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.

3 participants