Skip to content

Commit

Permalink
generated: Switch resolution module back to what it was before (#57419)
Browse files Browse the repository at this point in the history
This addresses post-commit review
#57230 (comment).
This change was left-over from before I decided to also change the type
of the `source` argument (at which point `source.module` was unavailable
in the function). This module was supposed to be the same, but it turns
out that both the julia tests and several packages use this code
manually and use different modules for the two places. Use the same one
we used before (which is probably more correct anyway) to fix #57417
  • Loading branch information
Keno authored Feb 15, 2025
1 parent 2364719 commit 0c5372f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,6 @@ function (g::Core.GeneratedFunctionStub)(world::UInt, source::Method, @nospecial
Expr(:meta, :pop_loc))))
spnames = g.spnames
return generated_body_to_codeinfo(spnames === Core.svec() ? lam : Expr(Symbol("with-static-parameters"), lam, spnames...),
typename(typeof(g.gen)).module,
source.module,
source.isva)
end
28 changes: 28 additions & 0 deletions test/staged.jl
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,31 @@ end
@test first(only(code_typed((Int,Int)) do x, y; @inline overdub54341(x, y); end)) isa Core.CodeInfo
@test first(only(code_typed((Int,)) do x; @inline overdub54341(x, 1); end)) isa Core.CodeInfo
@test_throws "Wrong number of arguments" overdub54341(1, 2, 3)

# Test the module resolution scope of generated methods that are type constructors
module GeneratedScope57417
using Test
import ..generate_lambda_ex
const x = 1
struct Generator; end
@generated (::Generator)() = :x
f(x::Int) = 1
module OtherModule
import ..f
const x = 2
@generated f(::Float64) = :x
end
import .OtherModule: f
@test Generator()() == 1
@test f(1.0) == 2

function g_generator(world::UInt, source::Method, _)
return generate_lambda_ex(world, source, (:g,), (), :(return x))
end

@eval function g()
$(Expr(:meta, :generated, g_generator))
$(Expr(:meta, :generated_only))
end
@test g() == 1
end

0 comments on commit 0c5372f

Please sign in to comment.