Skip to content

Commit b44b0c3

Browse files
fix: enable substitute to precompile
1 parent 9d625d8 commit b44b0c3

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/SymbolicUtils.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,14 @@ PrecompileTools.@setup_workload begin
178178
ex = x + 2y + sin(x)
179179
rules1 = Dict(x => y)
180180
rules2 = Dict(x => 1)
181-
substitute(ex, rules1)
181+
# Running `fold = Val(true)` invalidates the precompiled statements
182+
# for `fold = Val(false)` and itself doesn't precompile anyway.
183+
# substitute(ex, rules1)
182184
substitute(ex, rules1; fold = fold1)
183185
substitute(ex, rules2; fold = fold1)
184-
substitute(ex, rules2)
185-
substitute(ex, rules1; fold = fold2)
186-
substitute(ex, rules2; fold = fold2)
186+
# substitute(ex, rules2)
187+
# substitute(ex, rules1; fold = fold2)
188+
# substitute(ex, rules2; fold = fold2)
187189
q[1]
188190
q'q
189191
end

src/types.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,9 @@ function TermInterface.maketerm(::Type{BasicSymbolic{T}}, f, args, metadata; @no
16211621
end
16221622
return res::BasicSymbolic{T}
16231623
elseif f === getindex
1624-
res = getindex(unwrap_const.(args)...)
1624+
# This can't call `getindex` because that goes through `@cache`, which is unstable
1625+
# and doesn't precompile.
1626+
res = _getindex(unwrap_const.(args)...)
16251627
if metadata !== nothing && iscall(res)
16261628
@set! res.metadata = metadata
16271629
end

test/precompilation.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ expr = x + sin(y) * z
1616
rules = Dict(x => y)
1717
fold = Val{false}()
1818
subs_inf = @snoop_inference substitute(expr, rules; fold)
19+
args_inf = @snoop_inference arguments(expr)
1920

2021
using SnoopCompile
2122

@@ -30,14 +31,10 @@ using SnoopCompile
3031
("const_div", const_div_inf),
3132
("pow", pow_inf),
3233
("const_pow", const_pow_inf),
33-
("substitute", subs_inf)
34+
("substitute", subs_inf),
35+
("arguments", args_inf)
3436
]
3537
@test isempty(staleinstances(inf))
36-
# `setindex!` on TaskLocalValue doesn't infer (COMPARE_FULL)
37-
if inf === subs_inf
38-
@test treesize(inf) == 21
39-
else
40-
@test isempty(children(inf))
41-
end
38+
@test isempty(children(inf))
4239
end
4340

0 commit comments

Comments
 (0)