Skip to content

Commit 9ceed3a

Browse files
authored
Avoid setting the store during module precompilation (#136)
Co-authored-by: Cédric Belmant <cedric.belmant@juliahub.com>
1 parent ec78563 commit 9ceed3a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Infiltrator"
22
uuid = "5903a43b-9cc3-4c30-8d17-598619ec4e9b"
3-
version = "1.8.6"
3+
version = "1.8.7"
44

55
[deps]
66
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

src/Infiltrator.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const REPL_HOOKED = Ref{Bool}(false)
1616
const INFILTRATION_LOCK = Ref{ReentrantLock}()
1717

1818
function __init__()
19-
clear_store!(store)
19+
ccall(:jl_generating_output, Cint, ()) == 0 && clear_store!(store)
2020
INFILTRATION_LOCK[] = ReentrantLock()
2121
if VERSION >= v"1.5.0-DEV.282"
2222
if isdefined(Base, :active_repl_backend) && !isnothing(Base.active_repl_backend)
@@ -104,7 +104,7 @@ macro exfiltrate()
104104
quote
105105
for (k, v) in Base.@locals
106106
try
107-
Core.eval(getfield(getfield($(@__MODULE__), :store), :store), Expr(:(=), k, QuoteNode(v)))
107+
Core.eval(get_store(getfield($(@__MODULE__), :store)), Expr(:(=), k, QuoteNode(v)))
108108
catch err
109109
println(stderr, "Assignment to store variable failed.")
110110
Base.display_error(stderr, err, catch_backtrace())
@@ -216,7 +216,7 @@ function Base.show(io::IO, ::MIME"text/plain", s::Session)
216216
end
217217
end
218218
function Base.getproperty(sp::Session, s::Symbol)
219-
m = getfield(sp, :store)
219+
m = get_store(sp)
220220
if isdefined(m, s)
221221
getproperty(m, s)
222222
else
@@ -294,6 +294,12 @@ function end_session!(s::Session = store)
294294
return nothing
295295
end
296296

297+
function get_store(s::Session = store)
298+
isdefined(s, :store) && return getfield(s, :store)
299+
ccall(:jl_generating_output, Cint, ()) == 1 && error("Functionality provided by this package should not be used during precompilation or other compilation modes")
300+
error("The provided session does not have a module")
301+
end
302+
297303
"""
298304
clear_store!(s = safehouse)
299305
@@ -499,7 +505,7 @@ function exfiltrate_locals(io, evalmod, locals, sline::AbstractString)
499505
v = getfield(evalmod, k)
500506
end
501507
try
502-
Core.eval(getfield(store, :store), Expr(:(=), k, QuoteNode(v)))
508+
Core.eval(get_store(store), Expr(:(=), k, QuoteNode(v)))
503509
catch err
504510
println(io, "Assignment to store variable failed.")
505511
Base.display_error(io, err, catch_backtrace())
@@ -758,7 +764,7 @@ function debugprompt(mod, locals, trace, terminal, repl, ex, bt; nostack = false
758764
end
759765
end
760766

761-
get_store_names(s = store) = get_module_names(getfield(s, :store), m -> names(m, all = true))
767+
get_store_names(s = store) = get_module_names(get_store(s), m -> names(m, all = true))
762768

763769
function get_module_names(m::Module, get_names = all_names)
764770
ns = get_names(m)
@@ -948,7 +954,7 @@ function completions(c::InfiltratorCompletionProvider, full, partial)
948954
prepend!(ret, map(REPL.REPLCompletions.completion_text, comps))
949955

950956
# completions for safehouse variables
951-
comps, range, should_complete = REPL.REPLCompletions.completions(full, lastindex(partial), getfield(store, :store))
957+
comps, range, should_complete = REPL.REPLCompletions.completions(full, lastindex(partial), get_store(store))
952958
prepend!(ret, map(REPL.REPLCompletions.completion_text, comps))
953959

954960
# Infiltrator commands completions

0 commit comments

Comments
 (0)