Skip to content

Commit

Permalink
Fix various test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Nov 2, 2024
1 parent ba34a49 commit fd87104
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 39 deletions.
3 changes: 2 additions & 1 deletion base/opaque_closure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ end

# OpaqueClosure construction from pre-inferred CodeInfo/IRCode
using Core: CodeInfo, SSAValue
using Base.Compiler: IRCode
using Base: Compiler
using .Compiler: IRCode

function compute_ir_rettype(ir::IRCode)
rt = Union{}
Expand Down
8 changes: 4 additions & 4 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -534,23 +534,23 @@ end

function _builtin_return_type(interp,
@nospecialize(f::Core.Builtin), @nospecialize(types))
Compiler = typename(typeof(interp))
Compiler = typename(typeof(interp)).module
argtypes = Any[to_tuple_type(types).parameters...]
rt = Compiler.builtin_tfunction(interp, f, argtypes, nothing)
return Compiler.widenconst(rt)
end

function _builtin_effects(interp,
@nospecialize(f::Core.Builtin), @nospecialize(types))
Compiler = typename(typeof(interp))
Compiler = typename(typeof(interp)).module
argtypes = Any[to_tuple_type(types).parameters...]
rt = Compiler.builtin_tfunction(interp, f, argtypes, nothing)
return Compiler.builtin_effects(Compiler.typeinf_lattice(interp), f, argtypes, rt)
end

function _builtin_exception_type(interp,
@nospecialize(f::Core.Builtin), @nospecialize(types))
Compiler = typename(typeof(interp))
Compiler = typename(typeof(interp)).module
effects = _builtin_effects(interp, f, types)
return Compiler.is_nothrow(effects) ? Union{} : Any
end
Expand Down Expand Up @@ -612,7 +612,7 @@ function return_types(@nospecialize(f), @nospecialize(types=default_tt(f));
interp=Compiler.NativeInterpreter(world))
check_generated_context(world)
if isa(f, Core.OpaqueClosure)
_, rt = only(code_typed_opaque_closure(Compiler, f, types))
_, rt = only(code_typed_opaque_closure(f, types; Compiler))
return Any[rt]
elseif isa(f, Core.Builtin)
return Any[_builtin_return_type(interp, f, types)]
Expand Down
3 changes: 2 additions & 1 deletion stdlib/Compiler/src/Compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ using Base: Ordering, vect, EffectsOverride, BitVector, @_gc_preserve_begin, @_g
specialize_method, hasintersect, is_nospecializeinfer, is_nospecialized,
get_nospecializeinfer_sig, tls_world_age, uniontype_layout, kwerr,
moduleroot, is_file_tracked, decode_effects_override, lookup_binding_partition,
is_some_imported, binding_kind, is_some_guard, is_some_const_binding, partition_restriction
is_some_imported, binding_kind, is_some_guard, is_some_const_binding, partition_restriction,
BINDING_KIND_GLOBAL
using Base.Order
import Base: getindex, setindex!, length, iterate, push!, isempty, first, convert, ==,
copy, popfirst!, in, haskey, resize!, copy!, append!, last, get!, size,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/InteractiveUtils/src/codeview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function _dump_function(@nospecialize(f), @nospecialize(t), native::Bool, wrappe
if !isa(f, Core.OpaqueClosure)
src = Base.Compiler.typeinf_code(Base.Compiler.NativeInterpreter(world), mi, true)
else
src, rt = Base.get_oc_code_rt(f, tt, true)
src, rt = Base.get_oc_code_rt(Base.Compiler, f, tt, true)
end
src isa Core.CodeInfo || error("failed to infer source for $mi")
str = _dump_function_native_assembly(mi, src, wrapper, syntax, debuginfo, binary, raw, params)
Expand All @@ -248,7 +248,7 @@ function _dump_function(@nospecialize(f), @nospecialize(t), native::Bool, wrappe
if !isa(f, Core.OpaqueClosure)
src = Base.Compiler.typeinf_code(Base.Compiler.NativeInterpreter(world), mi, true)
else
src, rt = Base.get_oc_code_rt(f, tt, true)
src, rt = Base.get_oc_code_rt(Base.Compiler, f, tt, true)
end
src isa Core.CodeInfo || error("failed to infer source for $mi")
str = _dump_function_llvm(mi, src, wrapper, !raw, dump_module, optimize, debuginfo, params)
Expand Down
63 changes: 32 additions & 31 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ let nfields_tfunc(@nospecialize xs...) =
@test sizeof_nothrow(String)
@test !sizeof_nothrow(Type{String})
@test sizeof_tfunc(Type{Union{Int64, Int32}}) == Const(Core.sizeof(Union{Int64, Int32}))
let PT = Core.PartialStruct(Cpre.Compiler.fallback_lattice, Tuple{Int64,UInt64}, Any[Const(10), UInt64])
let PT = Core.PartialStruct(Base.Compiler.fallback_lattice, Tuple{Int64,UInt64}, Any[Const(10), UInt64])
@test sizeof_tfunc(PT) === Const(16)
@test nfields_tfunc(PT) === Const(2)
@test sizeof_nothrow(PT)
Expand Down Expand Up @@ -3381,9 +3381,9 @@ struct FooPartial
b::Int
c::Int
end
let PT1 = PartialStruct(FooPartial, Any[Const(1), Const(2), Int]),
PT2 = PartialStruct(FooPartial, Any[Const(1), Int, Int]),
PT3 = PartialStruct(FooPartial, Any[Const(1), Int, Const(3)])
let PT1 = PartialStruct(Base.Compiler.fallback_lattice, FooPartial, Any[Const(1), Const(2), Int]),
PT2 = PartialStruct(Base.Compiler.fallback_lattice, FooPartial, Any[Const(1), Int, Int]),
PT3 = PartialStruct(Base.Compiler.fallback_lattice, FooPartial, Any[Const(1), Int, Const(3)])

@test PT1 βŠ‘ PT2
@test !(PT1 βŠ‘ PT3) && !(PT2 βŠ‘ PT1)
Expand Down Expand Up @@ -4635,67 +4635,67 @@ end
@testset "issue #43784" begin
βŠ‘ = Core.Compiler.partialorder(Core.Compiler.fallback_lattice)
βŠ” = Core.Compiler.join(Core.Compiler.fallback_lattice)
𝕃 = Core.Compiler.fallback_lattice
Const, PartialStruct = Core.Const, Core.PartialStruct

let init = Base.ImmutableDict{Any,Any}()
a = Const(init)
b = PartialStruct(typeof(init), Any[Const(init), Any, Any])
b = PartialStruct(𝕃, typeof(init), Any[Const(init), Any, Any])
c = a βŠ” b
@test a βŠ‘ c && b βŠ‘ c
@test c === typeof(init)
end
let init = Base.ImmutableDict{Any,Any}(1,2)
a = Const(init)
b = PartialStruct(typeof(init), Any[Const(getfield(init,1)), Any, Any])
b = PartialStruct(𝕃, typeof(init), Any[Const(getfield(init,1)), Any, Any])
c = a βŠ” b
@test a βŠ‘ c && b βŠ‘ c
@test c isa PartialStruct
@test length(c.fields) == 3
end
let init = Base.ImmutableDict{Number,Number}()
a = Const(init)
b = PartialStruct(typeof(init), Any[Const(init), Number, ComplexF64])
b = PartialStruct(𝕃, typeof(init), Any[Const(init), Number, ComplexF64])
c = a βŠ” b
@test a βŠ‘ c && b βŠ‘ c
@test c === typeof(init)
end
let init = Base.ImmutableDict{Number,Number}()
a = PartialStruct(typeof(init), Any[Const(init), ComplexF64, ComplexF64])
b = PartialStruct(typeof(init), Any[Const(init), Number, ComplexF64])
a = PartialStruct(𝕃, typeof(init), Any[Const(init), ComplexF64, ComplexF64])
b = PartialStruct(𝕃, typeof(init), Any[Const(init), Number, ComplexF64])
c = a βŠ” b
@test a βŠ‘ c && b βŠ‘ c
@test c isa PartialStruct
@test c.fields[2] === Number
@test c.fields[3] === ComplexF64
end
let init = Base.ImmutableDict{Number,Number}()
a = PartialStruct(typeof(init), Any[Const(init), ComplexF64, ComplexF64])
b = PartialStruct(typeof(init), Any[Const(init), ComplexF32, Union{ComplexF32,ComplexF64}])
a = PartialStruct(𝕃, typeof(init), Any[Const(init), ComplexF64, ComplexF64])
b = PartialStruct(𝕃, typeof(init), Any[Const(init), ComplexF32, Union{ComplexF32,ComplexF64}])
c = a βŠ” b
@test a βŠ‘ c && b βŠ‘ c
@test c isa PartialStruct
@test c.fields[2] === Complex
@test c.fields[3] === Complex
end
let T = Base.ImmutableDict{Number,Number}
a = PartialStruct(T, Any[T])
b = PartialStruct(T, Any[T, Number, Number])
a = PartialStruct(𝕃, T, Any[T])
b = PartialStruct(𝕃, T, Any[T, Number, Number])
@test b βŠ‘ a
c = a βŠ” b
@test a βŠ‘ c && b βŠ‘ c
@test c isa PartialStruct
@test length(c.fields) == 1
end
let T = Base.ImmutableDict{Number,Number}
a = PartialStruct(T, Any[T])
a = PartialStruct(𝕃, T, Any[T])
b = Const(T())
c = a βŠ” b
@test a βŠ‘ c && b βŠ‘ c
@test c === T
end
let T = Base.ImmutableDict{Number,Number}
a = Const(T())
b = PartialStruct(T, Any[T])
b = PartialStruct(𝕃, T, Any[T])
c = a βŠ” b
@test a βŠ‘ c && b βŠ‘ c
@test c === T
Expand Down Expand Up @@ -4742,22 +4742,23 @@ end

let βŠ‘ = Core.Compiler.partialorder(Core.Compiler.fallback_lattice)
βŠ” = Core.Compiler.join(Core.Compiler.fallback_lattice)
𝕃 = Core.Compiler.fallback_lattice
Const, PartialStruct = Core.Const, Core.PartialStruct

@test (Const((1,2)) βŠ‘ PartialStruct(Tuple{Int,Int}, Any[Const(1),Int]))
@test !(Const((1,2)) βŠ‘ PartialStruct(Tuple{Int,Int,Int}, Any[Const(1),Int,Int]))
@test !(Const((1,2,3)) βŠ‘ PartialStruct(Tuple{Int,Int}, Any[Const(1),Int]))
@test (Const((1,2,3)) βŠ‘ PartialStruct(Tuple{Int,Int,Int}, Any[Const(1),Int,Int]))
@test (Const((1,2)) βŠ‘ PartialStruct(Tuple{Int,Vararg{Int}}, Any[Const(1),Vararg{Int}]))
@test (Const((1,2)) βŠ‘ PartialStruct(Tuple{Int,Int,Vararg{Int}}, Any[Const(1),Int,Vararg{Int}])) broken=true
@test (Const((1,2,3)) βŠ‘ PartialStruct(Tuple{Int,Int,Vararg{Int}}, Any[Const(1),Int,Vararg{Int}]))
@test !(PartialStruct(Tuple{Int,Int}, Any[Const(1),Int]) βŠ‘ Const((1,2)))
@test !(PartialStruct(Tuple{Int,Int,Int}, Any[Const(1),Int,Int]) βŠ‘ Const((1,2)))
@test !(PartialStruct(Tuple{Int,Int}, Any[Const(1),Int]) βŠ‘ Const((1,2,3)))
@test !(PartialStruct(Tuple{Int,Int,Int}, Any[Const(1),Int,Int]) βŠ‘ Const((1,2,3)))
@test !(PartialStruct(Tuple{Int,Vararg{Int}}, Any[Const(1),Vararg{Int}]) βŠ‘ Const((1,2)))
@test !(PartialStruct(Tuple{Int,Int,Vararg{Int}}, Any[Const(1),Int,Vararg{Int}]) βŠ‘ Const((1,2)))
@test !(PartialStruct(Tuple{Int,Int,Vararg{Int}}, Any[Const(1),Int,Vararg{Int}]) βŠ‘ Const((1,2,3)))
@test (Const((1,2)) βŠ‘ PartialStruct(𝕃, Tuple{Int,Int}, Any[Const(1),Int]))
@test !(Const((1,2)) βŠ‘ PartialStruct(𝕃, Tuple{Int,Int,Int}, Any[Const(1),Int,Int]))
@test !(Const((1,2,3)) βŠ‘ PartialStruct(𝕃, Tuple{Int,Int}, Any[Const(1),Int]))
@test (Const((1,2,3)) βŠ‘ PartialStruct(𝕃, Tuple{Int,Int,Int}, Any[Const(1),Int,Int]))
@test (Const((1,2)) βŠ‘ PartialStruct(𝕃, Tuple{Int,Vararg{Int}}, Any[Const(1),Vararg{Int}]))
@test (Const((1,2)) βŠ‘ PartialStruct(𝕃, Tuple{Int,Int,Vararg{Int}}, Any[Const(1),Int,Vararg{Int}])) broken=true
@test (Const((1,2,3)) βŠ‘ PartialStruct(𝕃, Tuple{Int,Int,Vararg{Int}}, Any[Const(1),Int,Vararg{Int}]))
@test !(PartialStruct(𝕃, Tuple{Int,Int}, Any[Const(1),Int]) βŠ‘ Const((1,2)))
@test !(PartialStruct(𝕃, Tuple{Int,Int,Int}, Any[Const(1),Int,Int]) βŠ‘ Const((1,2)))
@test !(PartialStruct(𝕃, Tuple{Int,Int}, Any[Const(1),Int]) βŠ‘ Const((1,2,3)))
@test !(PartialStruct(𝕃, Tuple{Int,Int,Int}, Any[Const(1),Int,Int]) βŠ‘ Const((1,2,3)))
@test !(PartialStruct(𝕃, Tuple{Int,Vararg{Int}}, Any[Const(1),Vararg{Int}]) βŠ‘ Const((1,2)))
@test !(PartialStruct(𝕃, Tuple{Int,Int,Vararg{Int}}, Any[Const(1),Int,Vararg{Int}]) βŠ‘ Const((1,2)))
@test !(PartialStruct(𝕃, Tuple{Int,Int,Vararg{Int}}, Any[Const(1),Int,Vararg{Int}]) βŠ‘ Const((1,2,3)))

t = Const((false, false)) βŠ” Const((false, true))
@test t isa PartialStruct && length(t.fields) == 2 && t.fields[1] === Const(false)
Expand Down Expand Up @@ -4899,7 +4900,7 @@ let src = code_typed1() do
end

# Test that Const βŠ‘ PartialStruct respects vararg
@test Const((1,2)) βŠ‘ PartialStruct(Tuple{Vararg{Int}}, [Const(1), Vararg{Int}])
@test Const((1,2)) βŠ‘ PartialStruct(Core.Compiler.fallback_lattice, Tuple{Vararg{Int}}, [Const(1), Vararg{Int}])

# Test that semi-concrete interpretation doesn't break on functions with while loops in them.
Base.@assume_effects :consistent :effect_free :terminates_globally function pure_annotated_loop(x::Int, y::Int)
Expand Down

0 comments on commit fd87104

Please sign in to comment.