Skip to content

Commit 8fd5728

Browse files
committed
Minor cleanup to inference barrier in core_parser_hook
1 parent 3601357 commit 8fd5728

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/hooks.jl

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,17 @@ else
2626
end
2727

2828
# Use caller's world age.
29-
const _caller_world = typemax(UInt)
30-
const _parser_world_age = Ref{UInt}(_caller_world)
29+
const _latest_world = typemax(UInt)
30+
const _parser_world_age = Ref{UInt}(_latest_world)
3131

3232
function core_parser_hook(code, filename, lineno, offset, options)
33-
# `hook` is always _core_parser_hook, but that's hidden from the compiler
34-
# via a Ref to prevent invalidation / recompilation when other packages are
35-
# loaded. This wouldn't seem like it should be necessary given the use of
36-
# invoke_in_world, but it is in Julia-1.7.3. I'm not sure exactly which
37-
# latency it's removing.
38-
hook = _core_parser_hook_ref[]
39-
if _parser_world_age[] != _caller_world
40-
Base.invoke_in_world(_parser_world_age[], hook,
33+
# NB: We need an inference barrier of one type or another here to prevent
34+
# invalidations. The invokes provide this currently.
35+
if _parser_world_age[] != _latest_world
36+
Base.invoke_in_world(_parser_world_age[], _core_parser_hook,
4137
code, filename, lineno, offset, options)
4238
else
43-
hook(code, filename, lineno, offset, options)
39+
Base.invokelatest(_core_parser_hook, code, filename, lineno, offset, options)
4440
end
4541
end
4642

@@ -150,8 +146,6 @@ end
150146
Base.Meta.ParseError(e::JuliaSyntax.ParseError) = e
151147

152148
const _default_parser = Core._parse
153-
# NB: Never reassigned, but the compiler doesn't know this!
154-
const _core_parser_hook_ref = Ref{Function}(_core_parser_hook)
155149

156150
"""
157151
enable_in_core!([enable=true; freeze_world_age, debug_filename])
@@ -169,7 +163,7 @@ Keyword arguments:
169163
"""
170164
function enable_in_core!(enable=true; freeze_world_age = true,
171165
debug_filename = get(ENV, "JULIA_SYNTAX_DEBUG_FILE", nothing))
172-
_parser_world_age[] = freeze_world_age ? Base.get_world_counter() : _caller_world
166+
_parser_world_age[] = freeze_world_age ? Base.get_world_counter() : _latest_world
173167
if enable && !isnothing(debug_filename)
174168
_debug_log[] = open(debug_filename, "w")
175169
elseif !enable && !isnothing(_debug_log[])

0 commit comments

Comments
 (0)