Skip to content

Commit 99779db

Browse files
jrevelsvchuravy
andcommitted
fix to allow at-pure optimization for generated thunks that have the pure field set
Co-authored-by: Valentin Churavy <[email protected]>
1 parent 8d4f6d2 commit 99779db

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,17 @@ function pure_eval_call(@nospecialize(f), argtypes::Vector{Any}, @nospecialize(a
605605
return false
606606
end
607607
meth = meth[1]::SimpleVector
608+
sig = meth[1]::DataType
609+
sparams = meth[2]::SimpleVector
608610
method = meth[3]::Method
609-
# TODO: check pure on the inferred thunk
610-
if isdefined(method, :generator) || !method.pure
611+
612+
if isdefined(method, :generator)
613+
method.generator.expand_early || return false
614+
mi = specialize_method(method, sig, sparams, false)
615+
isa(mi, MethodInstance) || return false
616+
staged = get_staged(mi)
617+
(staged isa CodeInfo && (staged::CodeInfo).pure) || return false
618+
elseif !method.pure
611619
return false
612620
end
613621

test/compiler/contextual.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,9 @@ f() = 2
108108

109109
# Test that MiniCassette is at least somewhat capable by overdubbing gcd
110110
@test overdub(Ctx(), gcd, 10, 20) === gcd(10, 20)
111+
112+
# Test that pure propagates for Cassette
113+
Base.@pure isbitstype(T) = T.isbitstype
114+
f31012(T) = Val(isbitstype(T))
115+
@test @inferred overdub(Ctx(), f31012, Int64) == Val(true)
116+

0 commit comments

Comments
 (0)