From fd8710414abbd8e6b52bf015f687decc09224109 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Sat, 2 Nov 2024 22:32:25 +0000 Subject: [PATCH] Fix various test issues --- base/opaque_closure.jl | 3 +- base/reflection.jl | 8 ++-- stdlib/Compiler/src/Compiler.jl | 3 +- stdlib/InteractiveUtils/src/codeview.jl | 4 +- test/compiler/inference.jl | 63 +++++++++++++------------ 5 files changed, 42 insertions(+), 39 deletions(-) diff --git a/base/opaque_closure.jl b/base/opaque_closure.jl index 5d067f7bcd174e..d7a91cff7d6026 100644 --- a/base/opaque_closure.jl +++ b/base/opaque_closure.jl @@ -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{} diff --git a/base/reflection.jl b/base/reflection.jl index 078bee60ef8a97..1e8f03468d35f1 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -534,7 +534,7 @@ 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) @@ -542,7 +542,7 @@ 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) @@ -550,7 +550,7 @@ 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 @@ -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)] diff --git a/stdlib/Compiler/src/Compiler.jl b/stdlib/Compiler/src/Compiler.jl index df948835b9725b..60a693c2b7ad7e 100644 --- a/stdlib/Compiler/src/Compiler.jl +++ b/stdlib/Compiler/src/Compiler.jl @@ -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, diff --git a/stdlib/InteractiveUtils/src/codeview.jl b/stdlib/InteractiveUtils/src/codeview.jl index f7304919f8ea9a..d1b5f2e43a44ad 100644 --- a/stdlib/InteractiveUtils/src/codeview.jl +++ b/stdlib/InteractiveUtils/src/codeview.jl @@ -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) @@ -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) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 33660ecac5965c..8a14774e2404fc 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -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) @@ -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) @@ -4635,18 +4635,18 @@ 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 @@ -4654,14 +4654,14 @@ end 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 @@ -4669,8 +4669,8 @@ end @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 @@ -4678,8 +4678,8 @@ end @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 @@ -4687,7 +4687,7 @@ end @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 @@ -4695,7 +4695,7 @@ end 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 @@ -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) @@ -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)