Skip to content

Commit 11f5d81

Browse files
vtjnashaviatesk
authored andcommitted
Revert "inference: implement an opt-in interface to cache generated sources (…"
This reverts commit b5d0b90.
1 parent 00c700e commit 11f5d81

File tree

3 files changed

+1
-47
lines changed

3 files changed

+1
-47
lines changed

base/boot.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,6 @@ function (g::GeneratedFunctionStub)(world::UInt, source::LineNumberNode, @nospec
750750
end
751751
end
752752

753-
# If the generator is a subtype of this trait, inference caches the generated unoptimized
754-
# code, sacrificing memory space to improve the performance of subsequent inferences.
755-
# This tradeoff is not appropriate in general cases (e.g., for `GeneratedFunctionStub`s
756-
# generated from the front end), but it can be justified for generators involving complex
757-
# code transformations, such as a Cassette-like system.
758-
abstract type CachedGenerator end
759-
760753
NamedTuple() = NamedTuple{(),Tuple{}}(())
761754

762755
eval(Core, :(NamedTuple{names}(args::Tuple) where {names} =

base/compiler/utilities.jl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,27 +138,13 @@ use_const_api(li::CodeInstance) = invoke_api(li) == 2
138138

139139
function get_staged(mi::MethodInstance, world::UInt)
140140
may_invoke_generator(mi) || return nothing
141-
cache_ci = (mi.def::Method).generator isa Core.CachedGenerator ?
142-
RefValue{CodeInstance}() : nothing
143141
try
144-
return call_get_staged(mi, world, cache_ci)
142+
return ccall(:jl_code_for_staged, Ref{CodeInfo}, (Any, UInt, Ptr{Cvoid}), mi, world, C_NULL)
145143
catch # user code might throw errors – ignore them
146144
return nothing
147145
end
148146
end
149147

150-
# enable caching of unoptimized generated code if the generator is `CachedGenerator`
151-
function call_get_staged(mi::MethodInstance, world::UInt, cache_ci::RefValue{CodeInstance})
152-
token = @_gc_preserve_begin cache_ci
153-
cache_ci_ptr = pointer_from_objref(cache_ci)
154-
src = ccall(:jl_code_for_staged, Ref{CodeInfo}, (Any, UInt, Ptr{CodeInstance}), mi, world, cache_ci_ptr)
155-
@_gc_preserve_end token
156-
return src
157-
end
158-
function call_get_staged(mi::MethodInstance, world::UInt, ::Nothing)
159-
return ccall(:jl_code_for_staged, Ref{CodeInfo}, (Any, UInt, Ptr{Cvoid}), mi, world, C_NULL)
160-
end
161-
162148
function get_cached_uninferred(mi::MethodInstance, world::UInt)
163149
ccall(:jl_cached_uninferred, Any, (Any, UInt), mi.cache, world)::CodeInstance
164150
end

test/staged.jl

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -381,31 +381,6 @@ let
381381
@test length(ir.cfg.blocks) == 1
382382
end
383383

384-
# Test that `Core.CachedGenerator` works as expected
385-
struct Generator54916 <: Core.CachedGenerator end
386-
function (::Generator54916)(world::UInt, source::LineNumberNode, args...)
387-
stub = Core.GeneratedFunctionStub(identity, Core.svec(:doit54916, :func, :arg), Core.svec())
388-
return stub(world, source, :(func(arg)))
389-
end
390-
@eval function doit54916(func, arg)
391-
$(Expr(:meta, :generated, Generator54916()))
392-
$(Expr(:meta, :generated_only))
393-
end
394-
@test doit54916(sin, 1) == sin(1)
395-
let mi = only(methods(doit54916)).specializations
396-
ci = mi.cache::Core.CodeInstance
397-
found = false
398-
while true
399-
if ci.owner === :uninferred && ci.inferred isa Core.CodeInfo
400-
found = true
401-
break
402-
end
403-
isdefined(ci, :next) || break
404-
ci = ci.next
405-
end
406-
@test found
407-
end
408-
409384
# Test that writing a bad cassette-style pass gives the expected error (#49715)
410385
function generator49715(world, source, self, f, tt)
411386
tt = tt.parameters[1]

0 commit comments

Comments
 (0)