Skip to content

Commit bb7023b

Browse files
authored
adjust to recent binding partition changes (#61)
1 parent 4049c04 commit bb7023b

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

CassetteBase/Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CassetteBase"
22
uuid = "6dd3e646-b1c5-42c7-94be-00277fa12e22"
33
authors = ["Shuhei Kadowaki <[email protected]>"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[compat]
77
julia = "1.10"

CassetteBase/src/CassetteBase.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
module CassetteBase
22

3-
export cassette_transform!, generate_internalerr_ex, generate_lambda_ex
3+
export SourceType, cassette_transform!, generate_internalerr_ex, generate_lambda_ex
44

55
using Core.IR
66
using Core: SimpleVector
77

8+
const SourceType = @static VERSION v"1.12.0-DEV.1968" ? Method : LineNumberNode
9+
810
function cassette_transform!(src::CodeInfo, mi::MethodInstance, nargs::Int,
911
selfname::Symbol, fargsname::Symbol)
1012
method = mi.def::Method
@@ -146,7 +148,7 @@ function Base.showerror(io::IO, err::CassetteInternalError)
146148
end
147149

148150
function generate_internalerr_ex(err, bt::Vector, context::Symbol,
149-
world::UInt, source::LineNumberNode,
151+
world::UInt, source::SourceType,
150152
argnames::SimpleVector, spnames::SimpleVector,
151153
metadata=nothing)
152154
@nospecialize err metadata
@@ -155,7 +157,7 @@ function generate_internalerr_ex(err, bt::Vector, context::Symbol,
155157
return generate_lambda_ex(world, source, argnames, spnames, throw_ex)
156158
end
157159

158-
function generate_lambda_ex(world::UInt, source::LineNumberNode,
160+
function generate_lambda_ex(world::UInt, source::SourceType,
159161
argnames::SimpleVector, spnames::SimpleVector,
160162
body::Expr)
161163
stub = Core.GeneratedFunctionStub(identity, argnames, spnames)

CassetteBase/test/test_basic.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ module test_basic
22

33
using Test, CassetteBase
44

5-
struct BasicGenerator
5+
struct BasicGenerator <: (@static isdefined(Core, :CachedGenerator) ? Core.CachedGenerator : Any)
66
selfname::Symbol
77
fargsname::Symbol
88
raise::Bool
99
end
10-
function (generator::BasicGenerator)(world::UInt, source::LineNumberNode, passtype, fargtypes)
10+
function (generator::BasicGenerator)(world::UInt, source::SourceType, passtype, fargtypes)
1111
@nospecialize passtype fargtypes
1212
(; selfname, fargsname, raise) = generator
1313
try
@@ -21,7 +21,7 @@ function (generator::BasicGenerator)(world::UInt, source::LineNumberNode, passty
2121
#=metadata=#(; world, source, passtype, fargtypes))
2222
end
2323
end
24-
function generate_basic_src(world::UInt, source::LineNumberNode, passtype, fargtypes,
24+
function generate_basic_src(world::UInt, source::SourceType, passtype, fargtypes,
2525
selfname::Symbol, fargsname::Symbol; raise::Bool)
2626
@nospecialize passtype fargtypes
2727
tt = Base.to_tuple_type(fargtypes)

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CassetteOverlay"
22
uuid = "d78b62d4-37fa-4a6f-acd8-2f19986eb9ee"
33
authors = ["JuliaHub, Inc. and other contributors"]
4-
version = "0.2.1"
4+
version = "0.2.2"
55

66
[deps]
77
CassetteBase = "6dd3e646-b1c5-42c7-94be-00277fa12e22"

src/CassetteOverlay.jl

+13-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct CassetteOverlayGenerator <: (@static isdefined(Core, :CachedGenerator) ?
3434
selfname::Symbol
3535
fargsname::Symbol
3636
end
37-
function (generator::CassetteOverlayGenerator)(world::UInt, source::LineNumberNode, passtype, fargtypes)
37+
function (generator::CassetteOverlayGenerator)(world::UInt, source::SourceType, passtype, fargtypes)
3838
@nospecialize passtype fargtypes
3939
(; selfname, fargsname) = generator
4040
try
@@ -48,7 +48,7 @@ function (generator::CassetteOverlayGenerator)(world::UInt, source::LineNumberNo
4848
end
4949
end
5050

51-
function generate_overlay_src(world::UInt, #=source=#::LineNumberNode, passtype, fargtypes,
51+
function generate_overlay_src(world::UInt, #=source=#::SourceType, passtype, fargtypes,
5252
selfname::Symbol, fargsname::Symbol)
5353
@nospecialize passtype fargtypes
5454
tt = Base.to_tuple_type(fargtypes)
@@ -135,23 +135,29 @@ macro overlaypass(args...)
135135

136136
push!(topblk.args, :(return $retval))
137137

138-
return topblk
138+
# attach :latestworld if necessary (N.B. adding it the :toplevel block doesn't work)
139+
@static if VERSION v"1.12.0-DEV.1662"
140+
return Expr(:block, Expr(:(=), :pass, topblk), Expr(:latestworld), :pass)
141+
else
142+
return topblk
143+
end
139144
end
140145

141146
abstract type AbstractBindingOverlay{M, S} <: OverlayPass; end
142147
function methodtable(::Type{<:AbstractBindingOverlay{M, S}}) where {M, S}
143148
if M === nothing
144149
return nothing
145150
end
146-
@assert isconst(M, S)
147-
return getglobal(M, S)::MethodTable
151+
@assert @invokelatest isconst(M, S)
152+
mt = @invokelatest getglobal(M, S)
153+
return mt::MethodTable
148154
end
149155
@overlaypass AbstractBindingOverlay nothing
150156

151157
struct Overlay{M, S} <: AbstractBindingOverlay{M, S}; end
152158
function Overlay(mt::MethodTable)
153-
@assert isconst(mt.module, mt.name)
154-
@assert getglobal(mt.module, mt.name) === mt
159+
@assert @invokelatest isconst(mt.module, mt.name)
160+
@assert mt === @invokelatest getglobal(mt.module, mt.name)
155161
return Overlay{mt.module, mt.name}()
156162
end
157163

0 commit comments

Comments
 (0)