Skip to content

Commit 6a84531

Browse files
committed
experiment @noinfer on Core.Compiler
1 parent e5e33d4 commit 6a84531

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

base/compiler/abstractlattice.jl

Lines changed: 3 additions & 3 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

base/compiler/typelattice.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ ignorelimited(typ::LimitedAccuracy) = typ.typ
401401
# lattice order
402402
# =============
403403

404-
function (lattice::InferenceLattice, @nospecialize(a), @nospecialize(b))
404+
@noinfer function (lattice::InferenceLattice, @nospecialize(a), @nospecialize(b))
405405
r = (widenlattice(lattice), ignorelimited(a), ignorelimited(b))
406406
r || return false
407407
isa(b, LimitedAccuracy) || return true
@@ -420,7 +420,7 @@ function ⊑(lattice::InferenceLattice, @nospecialize(a), @nospecialize(b))
420420
return b.causes a.causes
421421
end
422422

423-
function (lattice::OptimizerLattice, @nospecialize(a), @nospecialize(b))
423+
@noinfer function (lattice::OptimizerLattice, @nospecialize(a), @nospecialize(b))
424424
if isa(a, MaybeUndef)
425425
isa(b, MaybeUndef) || return false
426426
a, b = a.typ, b.typ
@@ -430,7 +430,7 @@ function ⊑(lattice::OptimizerLattice, @nospecialize(a), @nospecialize(b))
430430
return (widenlattice(lattice), a, b)
431431
end
432432

433-
function (lattice::AnyConditionalsLattice, @nospecialize(a), @nospecialize(b))
433+
@noinfer function (lattice::AnyConditionalsLattice, @nospecialize(a), @nospecialize(b))
434434
# Fast paths for common cases
435435
b === Any && return true
436436
a === Any && return false
@@ -450,7 +450,7 @@ function ⊑(lattice::AnyConditionalsLattice, @nospecialize(a), @nospecialize(b)
450450
return (widenlattice(lattice), a, b)
451451
end
452452

453-
function (𝕃::AnyMustAliasesLattice, @nospecialize(a), @nospecialize(b))
453+
@noinfer function (𝕃::AnyMustAliasesLattice, @nospecialize(a), @nospecialize(b))
454454
MustAliasT = isa(𝕃, MustAliasesLattice) ? MustAlias : InterMustAlias
455455
if isa(a, MustAliasT)
456456
if isa(b, MustAliasT)
@@ -463,7 +463,7 @@ function ⊑(𝕃::AnyMustAliasesLattice, @nospecialize(a), @nospecialize(b))
463463
return (widenlattice(𝕃), a, b)
464464
end
465465

466-
function (lattice::PartialsLattice, @nospecialize(a), @nospecialize(b))
466+
@noinfer function (lattice::PartialsLattice, @nospecialize(a), @nospecialize(b))
467467
if isa(a, PartialStruct)
468468
if isa(b, PartialStruct)
469469
if !(length(a.fields) == length(b.fields) && a.typ <: b.typ)
@@ -526,7 +526,7 @@ function ⊑(lattice::PartialsLattice, @nospecialize(a), @nospecialize(b))
526526
return (widenlattice(lattice), a, b)
527527
end
528528

529-
function (lattice::ConstsLattice, @nospecialize(a), @nospecialize(b))
529+
@noinfer function (lattice::ConstsLattice, @nospecialize(a), @nospecialize(b))
530530
if isa(a, Const)
531531
if isa(b, Const)
532532
return a.val === b.val

base/compiler/typelimits.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ end
303303

304304
# A simplified type_more_complex query over the extended lattice
305305
# (assumes typeb ⊑ typea)
306-
function issimplertype(𝕃::AbstractLattice, @nospecialize(typea), @nospecialize(typeb))
306+
@noinfer function issimplertype(𝕃::AbstractLattice, @nospecialize(typea), @nospecialize(typeb))
307307
typea isa MaybeUndef && (typea = typea.typ) # n.b. does not appear in inference
308308
typeb isa MaybeUndef && (typeb = typeb.typ) # n.b. does not appear in inference
309309
@assert !isa(typea, LimitedAccuracy) && !isa(typeb, LimitedAccuracy) "LimitedAccuracy not supported by simplertype lattice" # n.b. the caller was supposed to handle these
@@ -413,7 +413,7 @@ function merge_causes(causesa::IdSet{InferenceState}, causesb::IdSet{InferenceSt
413413
end
414414
end
415415

416-
@noinline function tmerge_limited(lattice::InferenceLattice, @nospecialize(typea), @nospecialize(typeb))
416+
@noinfer @noinline function tmerge_limited(lattice::InferenceLattice, @nospecialize(typea), @nospecialize(typeb))
417417
typea === Union{} && return typeb
418418
typeb === Union{} && return typea
419419

@@ -464,7 +464,7 @@ end
464464
return LimitedAccuracy(tmerge(widenlattice(lattice), typea, typeb), causes)
465465
end
466466

467-
function tmerge(lattice::InferenceLattice, @nospecialize(typea), @nospecialize(typeb))
467+
@noinfer function tmerge(lattice::InferenceLattice, @nospecialize(typea), @nospecialize(typeb))
468468
if isa(typea, LimitedAccuracy) || isa(typeb, LimitedAccuracy)
469469
return tmerge_limited(lattice, typea, typeb)
470470
end
@@ -474,7 +474,7 @@ function tmerge(lattice::InferenceLattice, @nospecialize(typea), @nospecialize(t
474474
return tmerge(widenlattice(lattice), typea, typeb)
475475
end
476476

477-
function tmerge(lattice::ConditionalsLattice, @nospecialize(typea), @nospecialize(typeb))
477+
@noinfer function tmerge(lattice::ConditionalsLattice, @nospecialize(typea), @nospecialize(typeb))
478478
# type-lattice for Conditional wrapper (NOTE never be merged with InterConditional)
479479
if isa(typea, Conditional) && isa(typeb, Const)
480480
if typeb.val === true
@@ -509,7 +509,7 @@ function tmerge(lattice::ConditionalsLattice, @nospecialize(typea), @nospecializ
509509
return tmerge(widenlattice(lattice), typea, typeb)
510510
end
511511

512-
function tmerge(lattice::InterConditionalsLattice, @nospecialize(typea), @nospecialize(typeb))
512+
@noinfer function tmerge(lattice::InterConditionalsLattice, @nospecialize(typea), @nospecialize(typeb))
513513
# type-lattice for InterConditional wrapper (NOTE never be merged with Conditional)
514514
if isa(typea, InterConditional) && isa(typeb, Const)
515515
if typeb.val === true
@@ -544,15 +544,15 @@ function tmerge(lattice::InterConditionalsLattice, @nospecialize(typea), @nospec
544544
return tmerge(widenlattice(lattice), typea, typeb)
545545
end
546546

547-
function tmerge(𝕃::AnyMustAliasesLattice, @nospecialize(typea), @nospecialize(typeb))
547+
@noinfer function tmerge(𝕃::AnyMustAliasesLattice, @nospecialize(typea), @nospecialize(typeb))
548548
typea = widenmustalias(typea)
549549
typeb = widenmustalias(typeb)
550550
return tmerge(widenlattice(𝕃), typea, typeb)
551551
end
552552

553553
# N.B. This can also be called with both typea::Const and typeb::Const to
554554
# to recover PartialStruct from `Const`s with overlapping fields.
555-
function tmerge_partial_struct(lattice::PartialsLattice, @nospecialize(typea), @nospecialize(typeb))
555+
@noinfer function tmerge_partial_struct(lattice::PartialsLattice, @nospecialize(typea), @nospecialize(typeb))
556556
aty = widenconst(typea)
557557
bty = widenconst(typeb)
558558
if aty === bty
@@ -610,7 +610,7 @@ function tmerge_partial_struct(lattice::PartialsLattice, @nospecialize(typea), @
610610
return nothing
611611
end
612612

613-
function tmerge(lattice::PartialsLattice, @nospecialize(typea), @nospecialize(typeb))
613+
@noinfer function tmerge(lattice::PartialsLattice, @nospecialize(typea), @nospecialize(typeb))
614614
# type-lattice for Const and PartialStruct wrappers
615615
aps = isa(typea, PartialStruct)
616616
bps = isa(typeb, PartialStruct)
@@ -653,8 +653,7 @@ function tmerge(lattice::PartialsLattice, @nospecialize(typea), @nospecialize(ty
653653
return tmerge(wl, typea, typeb)
654654
end
655655

656-
657-
function tmerge(lattice::ConstsLattice, @nospecialize(typea), @nospecialize(typeb))
656+
@noinfer function tmerge(lattice::ConstsLattice, @nospecialize(typea), @nospecialize(typeb))
658657
acp = isa(typea, Const) || isa(typea, PartialTypeVar)
659658
bcp = isa(typeb, Const) || isa(typeb, PartialTypeVar)
660659
if acp && bcp
@@ -666,7 +665,7 @@ function tmerge(lattice::ConstsLattice, @nospecialize(typea), @nospecialize(type
666665
return tmerge(wl, typea, typeb)
667666
end
668667

669-
function tmerge(::JLTypeLattice, @nospecialize(typea::Type), @nospecialize(typeb::Type))
668+
@noinfer function tmerge(::JLTypeLattice, @nospecialize(typea::Type), @nospecialize(typeb::Type))
670669
# it's always ok to form a Union of two concrete types
671670
act = isconcretetype(typea)
672671
bct = isconcretetype(typeb)
@@ -682,7 +681,7 @@ function tmerge(::JLTypeLattice, @nospecialize(typea::Type), @nospecialize(typeb
682681
return tmerge_types_slow(typea, typeb)
683682
end
684683

685-
@noinline function tmerge_types_slow(@nospecialize(typea::Type), @nospecialize(typeb::Type))
684+
@noinfer @noinline function tmerge_types_slow(@nospecialize(typea::Type), @nospecialize(typeb::Type))
686685
# collect the list of types from past tmerge calls returning Union
687686
# and then reduce over that list
688687
types = Any[]

0 commit comments

Comments
 (0)