Skip to content

Commit e176da8

Browse files
authored
Improve inference and add precompiles in ExprSplitter (#428)
These make a substantial contribution to reducing latency for Revise 3, specifically in the area of handling atsign-require blocks.
1 parent 7aef26f commit e176da8

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/construct.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ mutable struct ExprSplitter
437437
lnn::Union{LineNumberNode,Nothing}
438438
end
439439
function ExprSplitter(mod::Module, ex::Expr; lnn=nothing)
440-
index = []
440+
index = Int[]
441441
if ex.head === :block || ex.head === :toplevel
442442
push!(index, 1)
443443
end
@@ -474,14 +474,15 @@ function queuenext!(iter::ExprSplitter)
474474
# Find or create the module
475475
newname = ex.args[2]::Symbol
476476
if isdefined(mod, newname)
477-
mod = getfield(mod, newname)
478-
mod isa Module || throw(ErrorException("invalid redefinition of constant $(newname)"))
477+
newmod = getfield(mod, newname)
478+
newmod isa Module || throw(ErrorException("invalid redefinition of constant $(newname)"))
479+
mod = newmod
479480
else
480481
if (id = Base.identify_package(mod, String(newname))) !== nothing && haskey(Base.loaded_modules, id)
481-
mod = Base.root_module(id)
482+
mod = Base.root_module(id)::Module
482483
else
483484
loc = firstline(ex)
484-
mod = Core.eval(mod, Expr(:module, ex.args[1], ex.args[2], Expr(:block, loc, loc)))
485+
mod = Core.eval(mod, Expr(:module, ex.args[1], ex.args[2], Expr(:block, loc, loc)))::Module
485486
end
486487
end
487488
# We've handled the module declaration, remove it and queue the body

src/precompile.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function _precompile_()
2323
@assert precompile(Tuple{Type{Frame}, Module, Expr})
2424
@assert precompile(Tuple{Type{ExprSplitter}, Module, Expr})
2525
# @assert precompile(Tuple{typeof(Core.kwfunc(ExprSplitter)), NamedTuple{(:lnn,),Tuple{LineNumberNode}}, typeof(ExprSplitter), Module, Expr})
26+
@assert precompile(Tuple{typeof(queuenext!), ExprSplitter})
27+
@assert precompile(Tuple{typeof(Base.iterate), ExprSplitter}) # won't entirely work, but any dependents might help
2628
@assert precompile(Tuple{typeof(prepare_framedata), FrameCode, Vector{Any}, SimpleVector, Bool})
2729
@assert precompile(Tuple{typeof(prepare_args), Any, Vector{Any}, Vector{Any}})
2830
@assert precompile(Tuple{typeof(prepare_call), Any, Vector{Any}})

src/utils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,13 @@ Test whether expression `ex` is a `@doc` expression.
233233
function is_doc_expr(@nospecialize(ex))
234234
docsym = Symbol("@doc")
235235
if isexpr(ex, :macrocall)
236+
ex::Expr
236237
a = ex.args[1]
237238
is_global_ref(a, Core, docsym) && return true
238239
isa(a, Symbol) && a == docsym && return true
239240
if isexpr(a, :.)
240241
mod, name = (a::Expr).args[1], (a::Expr).args[2]
241-
return mod === :Core && isa(name, QuoteNode) && name.value == docsym
242+
return mod === :Core && isa(name, QuoteNode) && name.value === docsym
242243
end
243244
end
244245
return false

0 commit comments

Comments
 (0)