Skip to content

Commit

Permalink
adjust to recent binding partition changes (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Feb 3, 2025
1 parent 4049c04 commit bb7023b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CassetteBase/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CassetteBase"
uuid = "6dd3e646-b1c5-42c7-94be-00277fa12e22"
authors = ["Shuhei Kadowaki <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[compat]
julia = "1.10"
Expand Down
8 changes: 5 additions & 3 deletions CassetteBase/src/CassetteBase.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module CassetteBase

export cassette_transform!, generate_internalerr_ex, generate_lambda_ex
export SourceType, cassette_transform!, generate_internalerr_ex, generate_lambda_ex

using Core.IR
using Core: SimpleVector

const SourceType = @static VERSION v"1.12.0-DEV.1968" ? Method : LineNumberNode

function cassette_transform!(src::CodeInfo, mi::MethodInstance, nargs::Int,
selfname::Symbol, fargsname::Symbol)
method = mi.def::Method
Expand Down Expand Up @@ -146,7 +148,7 @@ function Base.showerror(io::IO, err::CassetteInternalError)
end

function generate_internalerr_ex(err, bt::Vector, context::Symbol,
world::UInt, source::LineNumberNode,
world::UInt, source::SourceType,
argnames::SimpleVector, spnames::SimpleVector,
metadata=nothing)
@nospecialize err metadata
Expand All @@ -155,7 +157,7 @@ function generate_internalerr_ex(err, bt::Vector, context::Symbol,
return generate_lambda_ex(world, source, argnames, spnames, throw_ex)
end

function generate_lambda_ex(world::UInt, source::LineNumberNode,
function generate_lambda_ex(world::UInt, source::SourceType,
argnames::SimpleVector, spnames::SimpleVector,
body::Expr)
stub = Core.GeneratedFunctionStub(identity, argnames, spnames)
Expand Down
6 changes: 3 additions & 3 deletions CassetteBase/test/test_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module test_basic

using Test, CassetteBase

struct BasicGenerator
struct BasicGenerator <: (@static isdefined(Core, :CachedGenerator) ? Core.CachedGenerator : Any)
selfname::Symbol
fargsname::Symbol
raise::Bool
end
function (generator::BasicGenerator)(world::UInt, source::LineNumberNode, passtype, fargtypes)
function (generator::BasicGenerator)(world::UInt, source::SourceType, passtype, fargtypes)
@nospecialize passtype fargtypes
(; selfname, fargsname, raise) = generator
try
Expand All @@ -21,7 +21,7 @@ function (generator::BasicGenerator)(world::UInt, source::LineNumberNode, passty
#=metadata=#(; world, source, passtype, fargtypes))
end
end
function generate_basic_src(world::UInt, source::LineNumberNode, passtype, fargtypes,
function generate_basic_src(world::UInt, source::SourceType, passtype, fargtypes,
selfname::Symbol, fargsname::Symbol; raise::Bool)
@nospecialize passtype fargtypes
tt = Base.to_tuple_type(fargtypes)
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CassetteOverlay"
uuid = "d78b62d4-37fa-4a6f-acd8-2f19986eb9ee"
authors = ["JuliaHub, Inc. and other contributors"]
version = "0.2.1"
version = "0.2.2"

[deps]
CassetteBase = "6dd3e646-b1c5-42c7-94be-00277fa12e22"
Expand Down
20 changes: 13 additions & 7 deletions src/CassetteOverlay.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct CassetteOverlayGenerator <: (@static isdefined(Core, :CachedGenerator) ?
selfname::Symbol
fargsname::Symbol
end
function (generator::CassetteOverlayGenerator)(world::UInt, source::LineNumberNode, passtype, fargtypes)
function (generator::CassetteOverlayGenerator)(world::UInt, source::SourceType, passtype, fargtypes)
@nospecialize passtype fargtypes
(; selfname, fargsname) = generator
try
Expand All @@ -48,7 +48,7 @@ function (generator::CassetteOverlayGenerator)(world::UInt, source::LineNumberNo
end
end

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

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

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

abstract type AbstractBindingOverlay{M, S} <: OverlayPass; end
function methodtable(::Type{<:AbstractBindingOverlay{M, S}}) where {M, S}
if M === nothing
return nothing
end
@assert isconst(M, S)
return getglobal(M, S)::MethodTable
@assert @invokelatest isconst(M, S)
mt = @invokelatest getglobal(M, S)
return mt::MethodTable
end
@overlaypass AbstractBindingOverlay nothing

struct Overlay{M, S} <: AbstractBindingOverlay{M, S}; end
function Overlay(mt::MethodTable)
@assert isconst(mt.module, mt.name)
@assert getglobal(mt.module, mt.name) === mt
@assert @invokelatest isconst(mt.module, mt.name)
@assert mt === @invokelatest getglobal(mt.module, mt.name)
return Overlay{mt.module, mt.name}()
end

Expand Down

2 comments on commit bb7023b

@aviatesk
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register subdir=CassetteBase

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/124227

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a CassetteBase-v0.1.1 -m "<description of version>" bb7023bccbb9e2d6143e0acf48c50ca06f46ab1e
git push origin CassetteBase-v0.1.1

Please sign in to comment.