Skip to content

Commit

Permalink
make Core.OpaqueClosure(ir::IRCode) non-destructive (#49100)
Browse files Browse the repository at this point in the history
Currently the constructor is destructive because it calls
`replace_code_newstyle!(src, ir, ...)` etc.
This commit made it non-destructive by calling `Core.Compiler.copy(ir)`
beforehand. We can define a destructive version of this
`Core.OpaqueClosure!` later if we really want it.
  • Loading branch information
aviatesk committed Mar 23, 2023
1 parent e2c0be3 commit 0469154
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
1 change: 1 addition & 0 deletions base/opaque_closure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function Core.OpaqueClosure(ir::IRCode, env...;
if (isva && nargs > length(ir.argtypes)) || (!isva && nargs != length(ir.argtypes)-1)
throw(ArgumentError("invalid argument count"))
end
ir = Core.Compiler.copy(ir)
src = ccall(:jl_new_code_info_uninit, Ref{CodeInfo}, ())
src.slotflags = UInt8[]
src.slotnames = fill(:none, nargs+1)
Expand Down
3 changes: 1 addition & 2 deletions test/opaque_closure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ let src = first(only(code_typed(+, (Int, Int))))
@test oc(40, 2) == 42
@test isa(oc, OpaqueClosure{Tuple{Int,Int}, Int})
@test_throws TypeError oc("40", 2)
ir = Core.Compiler.inflate_ir(src)
@test OpaqueClosure(ir)(40, 2) == 42
@test OpaqueClosure(ir)(40, 2) == 42 # OpaqueClosure constructor should be non-destructive
end

# variadic arguments
Expand Down

0 comments on commit 0469154

Please sign in to comment.