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

cleanup: Remove fallback post-lowering global resolution #57051

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

Keno
Copy link
Member

@Keno Keno commented Jan 15, 2025

After recent changes, essentially all global symbol scopes are resolved by lowering, so the code in method.c that replaces symbols by globalrefs is no longer necessary. The one small exception to this were symbols resulting from closure conversion, because these get inserted after the point at which lowering converts symbols to globalrefs. However, in the current design, I think that's basically a bug (and easily addressed by inserting globalrefs where appropriate). Removing this extra resolution step is not particularly necessary, but for the upcoming binding partition backedges, it removes an ambiguity as to which version of the lowered code to scan. It also partially resolves a very old todo about not performing post-hoc mutation of lowered code (although we still do this for ccall).

@Keno Keno requested a review from JeffBezanson January 15, 2025 00:41
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

LGTM. Particularly the rename so this function finally is named after what its actual purpose is for 😅

src/method.c Outdated
Comment on lines 174 to 175
if (e->head == jl_call_sym && jl_expr_nargs(e) == 3 &&
jl_is_globalref(jl_exprarg(e, 0)) &&
Copy link
Member

Choose a reason for hiding this comment

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

Do we still care about this hack (replacing the syntax a.b with GlobalRef(a, :b) if a appears to be a module?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that hack has been broken for a long time.

Copy link
Member

Choose a reason for hiding this comment

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

okay, yeah, do we just clean this up by deleting it too?

julia> @eval Base f() = Base.x
f (generic function with 1 method)

julia> @code_lowered Base.f()
CodeInfo(
    @ REPL[10]:1 within `unknown scope`
1 ─ %1 = Base.Base
│   %2 =   dynamic Base.getproperty(%1, :x)
└──      return %2
)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fine by me. We could consider putting it into lowering though.

Copy link
Member

Choose a reason for hiding this comment

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

Lowering doesn't know the symbol will refers to a module constant, so it had to be when we evaluate the expression here

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, fair enough. In that case, I don't think we can really do this at all. With binding redefinition, our semantics do not allow us to make that decision here.

After recent changes, essentially all global symbol scopes are
resolved by lowering, so the code in method.c that replaces
symbols by globalrefs is no longer necessary. The one small
exception to this were symbols resulting from closure conversion,
because these get inserted after the point at which lowering converts
symbols to globalrefs. However, in the current design, I think
that's basically a bug (and easily addressed by inserting
`globalref`s where appropriate). Removing this extra resolution
step is not particularly necessary, but for the upcoming
binding partition backedges, it removes an ambiguity as to
which version of the lowered code to scan. It also partially
resolves a very old todo about not performing post-hoc mutation
of lowered code (although we still do this for ccall).
@Keno Keno force-pushed the kf/nopostlowerresolve branch from 6ab8ffd to f52bdb9 Compare January 15, 2025 17:26
@Keno Keno merged commit 30177d0 into master Jan 15, 2025
5 of 7 checks passed
@Keno Keno deleted the kf/nopostlowerresolve branch January 15, 2025 21:49
@oscardssmith oscardssmith added the compiler:codegen Generation of LLVM IR and native code label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants