Skip to content

Commit 3efba74

Browse files
committed
experiment @noinfer on Core.Compiler
This commit adds `@noinfer` macro on various `Core.Compiler` functions and achieves the following sysimage size reduction: | | this commit | master | % | | --------------------------------- | ----------- | ----------- | ------- | | `Core.Compiler` compilation (sec) | `66.4551` | `71.0846` | `0.935` | | `corecompiler.jl` (KB) | `17638080` | `18407248` | `0.958` | | `sys.jl` (KB) | `88736432` | `89361280` | `0.993` | | `sys-o.a` (KB) | `189484400` | `189907096` | `0.998` |
1 parent 5fbefbd commit 3efba74

File tree

5 files changed

+86
-87
lines changed

5 files changed

+86
-87
lines changed

β€Žbase/compiler/abstractinterpretation.jlβ€Ž

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,18 +2663,18 @@ struct BestguessInfo{Interp<:AbstractInterpreter}
26632663
end
26642664
end
26652665

2666-
function widenreturn(@nospecialize(rt), info::BestguessInfo)
2666+
@noinfer function widenreturn(@nospecialize(rt), info::BestguessInfo)
26672667
return widenreturn(typeinf_lattice(info.interp), rt, info)
26682668
end
26692669

2670-
function widenreturn(𝕃ᡒ::AbstractLattice, @nospecialize(rt), info::BestguessInfo)
2670+
@noinfer function widenreturn(𝕃ᡒ::AbstractLattice, @nospecialize(rt), info::BestguessInfo)
26712671
return widenreturn(widenlattice(𝕃ᡒ), rt, info)
26722672
end
2673-
function widenreturn_noslotwrapper(𝕃ᡒ::AbstractLattice, @nospecialize(rt), info::BestguessInfo)
2673+
@noinfer function widenreturn_noslotwrapper(𝕃ᡒ::AbstractLattice, @nospecialize(rt), info::BestguessInfo)
26742674
return widenreturn_noslotwrapper(widenlattice(𝕃ᡒ), rt, info)
26752675
end
26762676

2677-
function widenreturn(𝕃ᡒ::MustAliasesLattice, @nospecialize(rt), info::BestguessInfo)
2677+
@noinfer function widenreturn(𝕃ᡒ::MustAliasesLattice, @nospecialize(rt), info::BestguessInfo)
26782678
if isa(rt, MustAlias)
26792679
if 1 ≀ rt.slot ≀ info.nargs
26802680
rt = InterMustAlias(rt)
@@ -2686,7 +2686,7 @@ function widenreturn(𝕃ᡒ::MustAliasesLattice, @nospecialize(rt), info::Bestg
26862686
return widenreturn(widenlattice(𝕃ᡒ), rt, info)
26872687
end
26882688

2689-
function widenreturn(𝕃ᡒ::ConditionalsLattice, @nospecialize(rt), info::BestguessInfo)
2689+
@noinfer function widenreturn(𝕃ᡒ::ConditionalsLattice, @nospecialize(rt), info::BestguessInfo)
26902690
βŠ‘α΅’ = βŠ‘(𝕃ᡒ)
26912691
if !(βŠ‘(ipo_lattice(info.interp), info.bestguess, Bool)) || info.bestguess === Bool
26922692
# give up inter-procedural constraint back-propagation
@@ -2723,7 +2723,7 @@ function widenreturn(𝕃ᡒ::ConditionalsLattice, @nospecialize(rt), info::Best
27232723
isa(rt, InterConditional) && return rt
27242724
return widenreturn(widenlattice(𝕃ᡒ), rt, info)
27252725
end
2726-
function bool_rt_to_conditional(@nospecialize(rt), info::BestguessInfo)
2726+
@noinfer function bool_rt_to_conditional(@nospecialize(rt), info::BestguessInfo)
27272727
bestguess = info.bestguess
27282728
if isa(bestguess, InterConditional)
27292729
# if the bestguess so far is already `Conditional`, try to convert
@@ -2741,7 +2741,7 @@ function bool_rt_to_conditional(@nospecialize(rt), info::BestguessInfo)
27412741
end
27422742
return rt
27432743
end
2744-
function bool_rt_to_conditional(@nospecialize(rt), slot_id::Int, info::BestguessInfo)
2744+
@noinfer function bool_rt_to_conditional(@nospecialize(rt), slot_id::Int, info::BestguessInfo)
27452745
βŠ‘α΅’ = βŠ‘(typeinf_lattice(info.interp))
27462746
old = info.slottypes[slot_id]
27472747
new = widenslotwrapper(info.changes[slot_id].typ) # avoid nested conditional
@@ -2760,13 +2760,13 @@ function bool_rt_to_conditional(@nospecialize(rt), slot_id::Int, info::Bestguess
27602760
return rt
27612761
end
27622762

2763-
function widenreturn(𝕃ᡒ::PartialsLattice, @nospecialize(rt), info::BestguessInfo)
2763+
@noinfer function widenreturn(𝕃ᡒ::PartialsLattice, @nospecialize(rt), info::BestguessInfo)
27642764
return widenreturn_partials(𝕃ᡒ, rt, info)
27652765
end
2766-
function widenreturn_noslotwrapper(𝕃ᡒ::PartialsLattice, @nospecialize(rt), info::BestguessInfo)
2766+
@noinfer function widenreturn_noslotwrapper(𝕃ᡒ::PartialsLattice, @nospecialize(rt), info::BestguessInfo)
27672767
return widenreturn_partials(𝕃ᡒ, rt, info)
27682768
end
2769-
function widenreturn_partials(𝕃ᡒ::PartialsLattice, @nospecialize(rt), info::BestguessInfo)
2769+
@noinfer function widenreturn_partials(𝕃ᡒ::PartialsLattice, @nospecialize(rt), info::BestguessInfo)
27702770
if isa(rt, PartialStruct)
27712771
fields = copy(rt.fields)
27722772
local anyrefine = false
@@ -2789,21 +2789,21 @@ function widenreturn_partials(𝕃ᡒ::PartialsLattice, @nospecialize(rt), info:
27892789
return widenreturn(widenlattice(𝕃ᡒ), rt, info)
27902790
end
27912791

2792-
function widenreturn(::ConstsLattice, @nospecialize(rt), ::BestguessInfo)
2792+
@noinfer function widenreturn(::ConstsLattice, @nospecialize(rt), ::BestguessInfo)
27932793
return widenreturn_consts(rt)
27942794
end
2795-
function widenreturn_noslotwrapper(::ConstsLattice, @nospecialize(rt), ::BestguessInfo)
2795+
@noinfer function widenreturn_noslotwrapper(::ConstsLattice, @nospecialize(rt), ::BestguessInfo)
27962796
return widenreturn_consts(rt)
27972797
end
2798-
function widenreturn_consts(@nospecialize(rt))
2798+
@noinfer function widenreturn_consts(@nospecialize(rt))
27992799
isa(rt, Const) && return rt
28002800
return widenconst(rt)
28012801
end
28022802

2803-
function widenreturn(::JLTypeLattice, @nospecialize(rt), ::BestguessInfo)
2803+
@noinfer function widenreturn(::JLTypeLattice, @nospecialize(rt), ::BestguessInfo)
28042804
return widenconst(rt)
28052805
end
2806-
function widenreturn_noslotwrapper(::JLTypeLattice, @nospecialize(rt), ::BestguessInfo)
2806+
@noinfer function widenreturn_noslotwrapper(::JLTypeLattice, @nospecialize(rt), ::BestguessInfo)
28072807
return widenconst(rt)
28082808
end
28092809

β€Žbase/compiler/abstractlattice.jlβ€Ž

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,23 @@ If `𝕃` is `JLTypeLattice`, this is equivalent to subtyping.
161161
"""
162162
function βŠ‘ end
163163

164-
βŠ‘(::JLTypeLattice, @nospecialize(a::Type), @nospecialize(b::Type)) = a <: b
164+
@noinfer βŠ‘(::JLTypeLattice, @nospecialize(a::Type), @nospecialize(b::Type)) = a <: b
165165

166166
"""
167167
⊏(𝕃::AbstractLattice, a, b) -> Bool
168168
169169
The strict partial order over the type inference lattice.
170170
This is defined as the irreflexive kernel of `βŠ‘`.
171171
"""
172-
⊏(𝕃::AbstractLattice, @nospecialize(a), @nospecialize(b)) = βŠ‘(𝕃, a, b) && !βŠ‘(𝕃, b, a)
172+
@noinfer ⊏(𝕃::AbstractLattice, @nospecialize(a), @nospecialize(b)) = βŠ‘(𝕃, a, b) && !βŠ‘(𝕃, b, a)
173173

174174
"""
175175
β‹€(𝕃::AbstractLattice, a, b) -> Bool
176176
177177
This order could be used as a slightly more efficient version of the strict order `⊏`,
178178
where we can safely assume `a βŠ‘ b` holds.
179179
"""
180-
β‹€(𝕃::AbstractLattice, @nospecialize(a), @nospecialize(b)) = !βŠ‘(𝕃, b, a)
180+
@noinfer β‹€(𝕃::AbstractLattice, @nospecialize(a), @nospecialize(b)) = !βŠ‘(𝕃, b, a)
181181

182182
"""
183183
is_lattice_equal(𝕃::AbstractLattice, a, b) -> Bool
@@ -186,7 +186,7 @@ Check if two lattice elements are partial order equivalent.
186186
This is basically `a βŠ‘ b && b βŠ‘ a` in the lattice of `𝕃`
187187
but (optionally) with extra performance optimizations.
188188
"""
189-
function is_lattice_equal(𝕃::AbstractLattice, @nospecialize(a), @nospecialize(b))
189+
@noinfer function is_lattice_equal(𝕃::AbstractLattice, @nospecialize(a), @nospecialize(b))
190190
a === b && return true
191191
return βŠ‘(𝕃, a, b) && βŠ‘(𝕃, b, a)
192192
end
@@ -197,32 +197,32 @@ end
197197
Determines whether the given lattice element `t` of `𝕃` has non-trivial extended lattice
198198
information that would not be available from the type itself.
199199
"""
200-
has_nontrivial_extended_info(𝕃::AbstractLattice, @nospecialize t) =
200+
@noinfer has_nontrivial_extended_info(𝕃::AbstractLattice, @nospecialize t) =
201201
has_nontrivial_extended_info(widenlattice(𝕃), t)
202-
function has_nontrivial_extended_info(𝕃::PartialsLattice, @nospecialize t)
202+
@noinfer function has_nontrivial_extended_info(𝕃::PartialsLattice, @nospecialize t)
203203
isa(t, PartialStruct) && return true
204204
isa(t, PartialOpaque) && return true
205205
return has_nontrivial_extended_info(widenlattice(𝕃), t)
206206
end
207-
function has_nontrivial_extended_info(𝕃::ConstsLattice, @nospecialize t)
207+
@noinfer function has_nontrivial_extended_info(𝕃::ConstsLattice, @nospecialize t)
208208
isa(t, PartialTypeVar) && return true
209209
if isa(t, Const)
210210
val = t.val
211211
return !issingletontype(typeof(val)) && !(isa(val, Type) && hasuniquerep(val))
212212
end
213213
return has_nontrivial_extended_info(widenlattice(𝕃), t)
214214
end
215-
has_nontrivial_extended_info(::JLTypeLattice, @nospecialize(t)) = false
215+
@noinfer has_nontrivial_extended_info(::JLTypeLattice, @nospecialize(t)) = false
216216

217217
"""
218218
is_const_prop_profitable_arg(𝕃::AbstractLattice, t) -> Bool
219219
220220
Determines whether the given lattice element `t` of `𝕃` has new extended lattice information
221221
that should be forwarded along with constant propagation.
222222
"""
223-
is_const_prop_profitable_arg(𝕃::AbstractLattice, @nospecialize t) =
223+
@noinfer is_const_prop_profitable_arg(𝕃::AbstractLattice, @nospecialize t) =
224224
is_const_prop_profitable_arg(widenlattice(𝕃), t)
225-
function is_const_prop_profitable_arg(𝕃::PartialsLattice, @nospecialize t)
225+
@noinfer function is_const_prop_profitable_arg(𝕃::PartialsLattice, @nospecialize t)
226226
if isa(t, PartialStruct)
227227
return true # might be a bit aggressive, may want to enable some check like follows:
228228
# for i = 1:length(t.fields)
@@ -236,7 +236,7 @@ function is_const_prop_profitable_arg(𝕃::PartialsLattice, @nospecialize t)
236236
isa(t, PartialOpaque) && return true
237237
return is_const_prop_profitable_arg(widenlattice(𝕃), t)
238238
end
239-
function is_const_prop_profitable_arg(𝕃::ConstsLattice, @nospecialize t)
239+
@noinfer function is_const_prop_profitable_arg(𝕃::ConstsLattice, @nospecialize t)
240240
if isa(t, Const)
241241
# don't consider mutable values useful constants
242242
val = t.val
@@ -245,24 +245,24 @@ function is_const_prop_profitable_arg(𝕃::ConstsLattice, @nospecialize t)
245245
isa(t, PartialTypeVar) && return false # this isn't forwardable
246246
return is_const_prop_profitable_arg(widenlattice(𝕃), t)
247247
end
248-
is_const_prop_profitable_arg(::JLTypeLattice, @nospecialize t) = false
248+
@noinfer is_const_prop_profitable_arg(::JLTypeLattice, @nospecialize t) = false
249249

250-
is_forwardable_argtype(𝕃::AbstractLattice, @nospecialize(x)) =
250+
@noinfer is_forwardable_argtype(𝕃::AbstractLattice, @nospecialize(x)) =
251251
is_forwardable_argtype(widenlattice(𝕃), x)
252-
function is_forwardable_argtype(𝕃::ConditionalsLattice, @nospecialize x)
252+
@noinfer function is_forwardable_argtype(𝕃::ConditionalsLattice, @nospecialize x)
253253
isa(x, Conditional) && return true
254254
return is_forwardable_argtype(widenlattice(𝕃), x)
255255
end
256-
function is_forwardable_argtype(𝕃::PartialsLattice, @nospecialize x)
256+
@noinfer function is_forwardable_argtype(𝕃::PartialsLattice, @nospecialize x)
257257
isa(x, PartialStruct) && return true
258258
isa(x, PartialOpaque) && return true
259259
return is_forwardable_argtype(widenlattice(𝕃), x)
260260
end
261-
function is_forwardable_argtype(𝕃::ConstsLattice, @nospecialize x)
261+
@noinfer function is_forwardable_argtype(𝕃::ConstsLattice, @nospecialize x)
262262
isa(x, Const) && return true
263263
return is_forwardable_argtype(widenlattice(𝕃), x)
264264
end
265-
function is_forwardable_argtype(::JLTypeLattice, @nospecialize x)
265+
@noinfer function is_forwardable_argtype(::JLTypeLattice, @nospecialize x)
266266
return false
267267
end
268268

@@ -281,9 +281,9 @@ External lattice `𝕃ᡒ::ExternalLattice` may overload:
281281
"""
282282
function widenreturn end, function widenreturn_noslotwrapper end
283283

284-
is_valid_lattice(𝕃::AbstractLattice, @nospecialize(elem)) =
284+
@noinfer is_valid_lattice(𝕃::AbstractLattice, @nospecialize(elem)) =
285285
is_valid_lattice_norec(𝕃, elem) && is_valid_lattice(widenlattice(𝕃), elem)
286-
is_valid_lattice(𝕃::JLTypeLattice, @nospecialize(elem)) = is_valid_lattice_norec(𝕃, elem)
286+
@noinfer is_valid_lattice(𝕃::JLTypeLattice, @nospecialize(elem)) = is_valid_lattice_norec(𝕃, elem)
287287

288288
has_conditional(𝕃::AbstractLattice) = has_conditional(widenlattice(𝕃))
289289
has_conditional(::AnyConditionalsLattice) = true
@@ -306,12 +306,12 @@ has_extended_unionsplit(::JLTypeLattice) = false
306306
const fallback_lattice = InferenceLattice(BaseInferenceLattice.instance)
307307
const fallback_ipo_lattice = InferenceLattice(IPOResultLattice.instance)
308308

309-
βŠ‘(@nospecialize(a), @nospecialize(b)) = βŠ‘(fallback_lattice, a, b)
310-
tmeet(@nospecialize(a), @nospecialize(b)) = tmeet(fallback_lattice, a, b)
311-
tmerge(@nospecialize(a), @nospecialize(b)) = tmerge(fallback_lattice, a, b)
312-
⊏(@nospecialize(a), @nospecialize(b)) = ⊏(fallback_lattice, a, b)
313-
β‹€(@nospecialize(a), @nospecialize(b)) = β‹€(fallback_lattice, a, b)
314-
is_lattice_equal(@nospecialize(a), @nospecialize(b)) = is_lattice_equal(fallback_lattice, a, b)
309+
@noinfer @nospecialize(a) βŠ‘ @nospecialize(b) = βŠ‘(fallback_lattice, a, b)
310+
@noinfer @nospecialize(a) ⊏ @nospecialize(b) = ⊏(fallback_lattice, a, b)
311+
@noinfer @nospecialize(a) β‹€ @nospecialize(b) = β‹€(fallback_lattice, a, b)
312+
@noinfer tmeet(@nospecialize(a), @nospecialize(b)) = tmeet(fallback_lattice, a, b)
313+
@noinfer tmerge(@nospecialize(a), @nospecialize(b)) = tmerge(fallback_lattice, a, b)
314+
@noinfer is_lattice_equal(@nospecialize(a), @nospecialize(b)) = is_lattice_equal(fallback_lattice, a, b)
315315

316316
# Widenlattice with argument
317317
widenlattice(::JLTypeLattice, @nospecialize(t)) = widenconst(t)

0 commit comments

Comments
Β (0)