Skip to content

Commit 3770051

Browse files
authored
EA: remove _TOP_MOD and just use Base (JuliaLang#56581)
The reason we originally used `_TOP_MOD` was to make it possible to load `EscapeAnalysis.jl` from the `Main` context while developing EA. However, now that the Compiler stdlib allows the same thing to be done for the entire `Compiler` module including `EscapeAnalysis`, the trick on the EA side is no longer necessary.
1 parent e1cfa73 commit 3770051

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

Compiler/src/ssair/EscapeAnalysis.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ export
1010
has_thrown_escape,
1111
has_all_escape
1212

13-
const _TOP_MOD = ccall(:jl_base_relative_to, Any, (Any,), EscapeAnalysis)::Module
13+
using Base: Base
1414

1515
# imports
16-
import ._TOP_MOD: ==, getindex, setindex!
16+
import Base: ==, getindex, setindex!
1717
# usings
1818
using Core: MethodMatch, SimpleVector, ifelse, sizeof
1919
using Core.IR
20-
using ._TOP_MOD: # Base definitions
21-
@__MODULE__, @assert, @eval, @goto, @inbounds, @inline, @label, @noinline, @show,
20+
using Base: # Base definitions
21+
@__MODULE__, @assert, @eval, @goto, @inbounds, @inline, @label, @noinline,
2222
@nospecialize, @specialize, BitSet, Callable, Csize_t, IdDict, IdSet, UnitRange, Vector,
2323
copy, delete!, empty!, enumerate, error, first, get, get!, haskey, in, isassigned,
2424
isempty, ismutabletype, keys, last, length, max, min, missing, pop!, push!, pushfirst!,
2525
unwrap_unionall, !, !=, !==, &, *, +, -, :, <, <<, =>, >, |, , , , , , , , ,
2626
hasintersect
27-
using ..Compiler: # Core.Compiler specific definitions
27+
using ..Compiler: # Compiler specific definitions
2828
AbstractLattice, Bottom, IRCode, IR_FLAG_NOTHROW, InferenceResult, SimpleInferenceLattice,
2929
argextype, fieldcount_noerror, hasintersect, has_flag, intrinsic_nothrow,
3030
is_meta_expr_head, is_identity_free_argtype, isexpr, println, setfield!_nothrow,
3131
singleton_type, try_compute_field, try_compute_fieldidx, widenconst, , Compiler
3232

33-
function include(x)
34-
if !isdefined(_TOP_MOD.Base, :end_base_include)
33+
function include(x::String)
34+
if !isdefined(Base, :end_base_include)
3535
# During bootstrap, all includes are relative to `base/`
3636
x = ccall(:jl_prepend_string, Ref{String}, (Any, Any), "ssair/", x)
3737
end
38-
_TOP_MOD.include(@__MODULE__, x)
38+
Compiler.include(@__MODULE__, x)
3939
end
4040

4141
include("disjoint_set.jl")

Compiler/src/ssair/disjoint_set.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
# under the MIT license: https://github.com/JuliaCollections/DataStructures.jl/blob/master/License.md
44

55
# imports
6-
import ._TOP_MOD:
7-
length,
8-
eltype,
9-
union!,
10-
push!
6+
import Base: length, eltype, union!, push!
117
# usings
12-
import ._TOP_MOD:
13-
OneTo, collect, zero, zeros, one, typemax
8+
import Base: OneTo, collect, zero, zeros, one, typemax
149

1510
# Disjoint-Set
1611

@@ -27,7 +22,8 @@ import ._TOP_MOD:
2722
#
2823
############################################################
2924

30-
_intdisjointset_bounds_err_msg(T) = "the maximum number of elements in IntDisjointSet{$T} is $(typemax(T))"
25+
_intdisjointset_bounds_err_msg(@nospecialize T) =
26+
"the maximum number of elements in IntDisjointSet{$T} is $(typemax(T))"
3127

3228
"""
3329
IntDisjointSet{T<:Integer}(n::Integer)

doc/src/devdocs/EscapeAnalysis.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ This escape analysis aims to:
2020
You can give a try to the escape analysis by loading the `EAUtils.jl` utility script that
2121
defines the convenience entries `code_escapes` and `@code_escapes` for testing and debugging purposes:
2222
```@repl EAUtils
23+
using Base.Compiler: EscapeAnalysis # or `using Compiler: EscapeAnalysis` to use the stdlib version
2324
let JULIA_DIR = normpath(Sys.BINDIR, "..", "share", "julia")
24-
# load `EscapeAnalysis` module to define the core analysis code
25-
include(normpath(JULIA_DIR, "Compiler", "src", "ssair", "EscapeAnalysis.jl"))
26-
using .EscapeAnalysis
27-
# load `EAUtils` module to define the utilities
2825
include(normpath(JULIA_DIR, "Compiler", "test", "EAUtils.jl"))
2926
using .EAUtils
3027
end
@@ -37,19 +34,17 @@ Base.setindex!(x::SafeRef, v) = x.x = v;
3734
Base.isassigned(x::SafeRef) = true;
3835
get′(x) = isassigned(x) ? x[] : throw(x);
3936
40-
result = code_escapes((String,String,String,String)) do s1, s2, s3, s4
41-
r1 = Ref(s1)
37+
result = code_escapes((Base.RefValue{String},String,String,)) do r1, s2, s3
4238
r2 = Ref(s2)
4339
r3 = SafeRef(s3)
4440
try
4541
s1 = get′(r1)
4642
ret = sizeof(s1)
4743
catch err
48-
global GV = err # will definitely escape `r1`
44+
global GV = err # `r1` may escape
4945
end
50-
s2 = get′(r2) # still `r2` doesn't escape fully
51-
s3 = get′(r3) # still `r3` doesn't escape fully
52-
s4 = sizeof(s4) # the argument `s4` doesn't escape here
46+
s2 = get′(r2) # `r2` doesn't escape
47+
s3 = get′(r3) # `r3` doesn't escape
5348
return s2, s3, s4
5449
end
5550
```
@@ -105,10 +100,10 @@ One distinctive design of this escape analysis is that it is fully _backward_,
105100
i.e. escape information flows _from usages to definitions_.
106101
For example, in the code snippet below, EA first analyzes the statement `return %1` and
107102
imposes `ReturnEscape` on `%1` (corresponding to `obj`), and then it analyzes
108-
`%1 = %new(Base.RefValue{String, _2}))` and propagates the `ReturnEscape` imposed on `%1`
109-
to the call argument `_2` (corresponding to `s`):
103+
`%1 = %new(Base.RefValue{Base.RefValue{String}, _2}))` and propagates the `ReturnEscape`
104+
imposed on `%1` to the call argument `_2` (corresponding to `s`):
110105
```@repl EAUtils
111-
code_escapes((String,)) do s
106+
code_escapes((Base.RefValue{String},)) do s
112107
obj = Ref(s)
113108
return obj
114109
end
@@ -120,7 +115,7 @@ As a result this scheme enables a simple implementation of escape analysis,
120115
e.g. `PhiNode` for example can be handled simply by propagating escape information
121116
imposed on a `PhiNode` to its predecessor values:
122117
```@repl EAUtils
123-
code_escapes((Bool, String, String)) do cnd, s, t
118+
code_escapes((Bool, Base.RefValue{String}, Base.RefValue{String})) do cnd, s, t
124119
if cnd
125120
obj = Ref(s)
126121
else

0 commit comments

Comments
 (0)