Skip to content

Commit 063c75e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into special-form-builtins
2 parents 8e7a847 + 9d00b57 commit 063c75e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1036
-488
lines changed

Compiler/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Manifest.toml

Compiler/extras/CompilerDevTools/src/CompilerDevTools.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function lookup_method_instance(f, args...)
4545
@ccall jl_method_lookup(Any[f, args...]::Ptr{Any}, (1+length(args))::Csize_t, Base.tls_world_age()::Csize_t)::Ref{Core.MethodInstance}
4646
end
4747

48-
function Compiler.optimize(interp::SplitCacheInterp, opt::Compiler.OptimizationState, caller::Compiler.InferenceResult)
49-
@invoke Compiler.optimize(interp::Compiler.AbstractInterpreter, opt::Compiler.OptimizationState, caller::Compiler.InferenceResult)
48+
function Compiler.transform_result_for_cache(interp::SplitCacheInterp, result::Compiler.InferenceResult, edges::Compiler.SimpleVector)
49+
opt = result.src::Compiler.OptimizationState
5050
ir = opt.result.ir::Compiler.IRCode
5151
override = GlobalRef(@__MODULE__(), :with_new_compiler)
5252
for inst in ir.stmts
@@ -61,6 +61,7 @@ function Compiler.optimize(interp::SplitCacheInterp, opt::Compiler.OptimizationS
6161
insert!(stmt.args, 1, override)
6262
insert!(stmt.args, 3, interp.owner)
6363
end
64+
@invoke Compiler.transform_result_for_cache(interp::Compiler.AbstractInterpreter, result::Compiler.InferenceResult, edges::Compiler.SimpleVector)
6465
end
6566

6667
with_new_compiler(f, args...; owner::SplitCacheOwner = SplitCacheOwner()) = with_new_compiler(f, owner, args...)

Compiler/src/tfuncs.jl

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,16 @@ end
573573
add_tfunc(nfields, 1, 1, nfields_tfunc, 1)
574574
add_tfunc(Core._expr, 1, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->Expr), 100)
575575
add_tfunc(svec, 0, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->SimpleVector), 20)
576+
@nospecs function _svec_ref_tfunc(𝕃::AbstractLattice, s, i)
577+
if isa(s, Const) && isa(i, Const)
578+
s, i = s.val, i.val
579+
if isa(s, SimpleVector) && isa(i, Int)
580+
return 1 i length(s) ? Const(s[i]) : Bottom
581+
end
582+
end
583+
return Any
584+
end
585+
add_tfunc(Core._svec_ref, 2, 2, _svec_ref_tfunc, 1)
576586
@nospecs function typevar_tfunc(𝕃::AbstractLattice, n, lb_arg, ub_arg)
577587
lb = Union{}
578588
ub = Any
@@ -2316,6 +2326,9 @@ function _builtin_nothrow(𝕃::AbstractLattice, @nospecialize(f::Builtin), argt
23162326
elseif f === Core.compilerbarrier
23172327
na == 2 || return false
23182328
return compilerbarrier_nothrow(argtypes[1], nothing)
2329+
elseif f === Core._svec_ref
2330+
na == 2 || return false
2331+
return _svec_ref_tfunc(𝕃, argtypes[1], argtypes[2]) isa Const
23192332
end
23202333
return false
23212334
end
@@ -2346,7 +2359,9 @@ const _CONSISTENT_BUILTINS = Any[
23462359
throw,
23472360
Core.throw_methoderror,
23482361
setfield!,
2349-
donotdelete
2362+
donotdelete,
2363+
memoryrefnew,
2364+
memoryrefoffset,
23502365
]
23512366

23522367
# known to be effect-free (but not necessarily nothrow)
@@ -2371,6 +2386,7 @@ const _EFFECT_FREE_BUILTINS = [
23712386
Core.throw_methoderror,
23722387
getglobal,
23732388
compilerbarrier,
2389+
Core._svec_ref,
23742390
]
23752391

23762392
const _INACCESSIBLEMEM_BUILTINS = Any[
@@ -2404,6 +2420,7 @@ const _ARGMEM_BUILTINS = Any[
24042420
replacefield!,
24052421
setfield!,
24062422
swapfield!,
2423+
Core._svec_ref,
24072424
]
24082425

24092426
const _INCONSISTENT_INTRINSICS = Any[
@@ -2546,7 +2563,7 @@ const _EFFECTS_KNOWN_BUILTINS = Any[
25462563
# Core._primitivetype,
25472564
# Core._setsuper!,
25482565
# Core._structtype,
2549-
# Core._svec_ref,
2566+
Core._svec_ref,
25502567
# Core._typebody!,
25512568
Core._typevar,
25522569
apply_type,
@@ -2650,9 +2667,7 @@ function builtin_effects(𝕃::AbstractLattice, @nospecialize(f::Builtin), argty
26502667
else
26512668
if contains_is(_CONSISTENT_BUILTINS, f)
26522669
consistent = ALWAYS_TRUE
2653-
elseif f === memoryrefnew || f === memoryrefoffset
2654-
consistent = ALWAYS_TRUE
2655-
elseif f === memoryrefget || f === memoryrefset! || f === memoryref_isassigned
2670+
elseif f === memoryrefget || f === memoryrefset! || f === memoryref_isassigned || f === Core._svec_ref
26562671
consistent = CONSISTENT_IF_INACCESSIBLEMEMONLY
26572672
elseif f === Core._typevar || f === Core.memorynew
26582673
consistent = CONSISTENT_IF_NOTRETURNED
@@ -2838,6 +2853,8 @@ _istypemin(@nospecialize x) = !_iszero(x) && Intrinsics.neg_int(x) === x
28382853
function builtin_exct(𝕃::AbstractLattice, @nospecialize(f::Builtin), argtypes::Vector{Any}, @nospecialize(rt))
28392854
if isa(f, IntrinsicFunction)
28402855
return intrinsic_exct(𝕃, f, argtypes)
2856+
elseif f === Core._svec_ref
2857+
return BoundsError
28412858
end
28422859
return Any
28432860
end

Compiler/test/AbstractInterpreter.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using Test
44

5+
include("setup_Compiler.jl")
56
include("irutils.jl")
67
include("newinterp.jl")
78

Compiler/test/EscapeAnalysis.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module test_EA
22

3+
include("setup_Compiler.jl")
34
include("irutils.jl")
45

56
const EscapeAnalysis = Compiler.EscapeAnalysis

Compiler/test/compact.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using Test
44

5+
include("setup_Compiler.jl")
56
include("irutils.jl")
67

78
using .Compiler: IncrementalCompact, insert_node_here!, finish,

Compiler/test/contextual.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# N.B.: This file is also run from interpreter.jl, so needs to be standalone-executable
44
using Test
5+
56
include("setup_Compiler.jl")
67

78
# Cassette

Compiler/test/effects.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
using Test
4+
5+
include("setup_Compiler.jl")
46
include("irutils.jl")
57

68
# Test that the Core._apply_iterate bail path taints effects
@@ -1467,3 +1469,13 @@ end
14671469
@test Base.infer_effects(Core.invoke_in_world, Tuple{Vararg{Any}}) == Compiler.Effects()
14681470
@test Base.infer_effects(invokelatest, Tuple{Vararg{Any}}) == Compiler.Effects()
14691471
@test Base.infer_effects(invoke, Tuple{Vararg{Any}}) == Compiler.Effects()
1472+
1473+
# Core._svec_ref effects modeling (required for external abstract interpreter that doesn't run optimization)
1474+
let effects = Base.infer_effects((Core.SimpleVector,Int); optimize=false) do svec, i
1475+
Core._svec_ref(svec, i)
1476+
end
1477+
@test !Compiler.is_consistent(effects)
1478+
@test Compiler.is_effect_free(effects)
1479+
@test !Compiler.is_nothrow(effects)
1480+
@test Compiler.is_terminates(effects)
1481+
end

Compiler/test/inference.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module inference
44

55
using Test
66

7+
include("setup_Compiler.jl")
78
include("irutils.jl")
89

910
# tests for Compiler correctness and precision

Compiler/test/inline.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Test
44
using Base.Meta
55
using Core: ReturnNode
66

7+
include("setup_Compiler.jl")
78
include("irutils.jl")
89
include("newinterp.jl")
910

0 commit comments

Comments
 (0)