Skip to content

Commit 055a19d

Browse files
maleadtjohanmon
authored andcommitted
Fixes for overlay tables (JuliaLang#41174)
* Add support for at-overlay with parametric function definitions. * Fix error message with at-MethodTable. * Fix function signature to avoid compiler warning.
1 parent fcd8d18 commit 055a19d

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

base/experimental.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,21 @@ method tables (e.g., using [`Core.Compiler.OverlayMethodTable`](@ref)).
268268
"""
269269
macro overlay(mt, def)
270270
def = macroexpand(__module__, def) # to expand @inline, @generated, etc
271-
if !isexpr(def, [:function, :(=)]) || !isexpr(def.args[1], :call)
271+
if !isexpr(def, [:function, :(=)])
272+
error("@overlay requires a function Expr")
273+
end
274+
if isexpr(def.args[1], :call)
275+
def.args[1].args[1] = Expr(:overlay, mt, def.args[1].args[1])
276+
elseif isexpr(def.args[1], :where)
277+
def.args[1].args[1].args[1] = Expr(:overlay, mt, def.args[1].args[1].args[1])
278+
else
272279
error("@overlay requires a function Expr")
273280
end
274-
def.args[1].args[1] = Expr(:overlay, mt, def.args[1].args[1])
275281
esc(def)
276282
end
277283

278284
let new_mt(name::Symbol, mod::Module) = begin
279-
ccall(:jl_check_top_level_effect, Cvoid, (Any, Cstring), mod, name)
285+
ccall(:jl_check_top_level_effect, Cvoid, (Any, Cstring), mod, "@MethodTable")
280286
ccall(:jl_new_method_table, Any, (Any, Any), name, mod)
281287
end
282288
@eval macro MethodTable(name::Symbol)

src/toplevel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ static void jl_check_open_for(jl_module_t *m, const char* funcname)
922922
}
923923
}
924924

925-
JL_DLLEXPORT void jl_check_top_level_effect(jl_value_t *m, char *fname)
925+
JL_DLLEXPORT void jl_check_top_level_effect(jl_module_t *m, char *fname)
926926
{
927927
if (jl_current_task->ptls->in_pure_callback)
928928
jl_errorf("%s cannot be used in a generated function", fname);

test/compiler/contextual.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ end
153153
# short function def
154154
@overlay mt cos(x::Float64) = 2
155155

156+
# parametric function def
157+
@overlay mt tan(x::T) where {T} = 3
158+
156159
end
157160

158161
methods = Base._methods_by_ftype(Tuple{typeof(sin), Float64}, nothing, 1, typemax(UInt))

0 commit comments

Comments
 (0)