From 5dc5b7e03f8d90699bb68133845a1a783b003a71 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Tue, 9 Mar 2021 21:18:33 -0500 Subject: [PATCH 1/6] Check issimpleenoughtype before stripping off type parameters --- base/compiler/typelimits.jl | 4 ++++ test/compiler/inference.jl | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/base/compiler/typelimits.jl b/base/compiler/typelimits.jl index 3de2627f42569..788063c302baf 100644 --- a/base/compiler/typelimits.jl +++ b/base/compiler/typelimits.jl @@ -432,6 +432,10 @@ function tmerge(@nospecialize(typea), @nospecialize(typeb)) (uw isa DataType && ti <: uw.name.wrapper) || return Any typenames[i] = uw.name end + u = Union{types...} + if issimpleenoughtype(u) + return u + end # see if any of the union elements have the same TypeName # in which case, simplify this tmerge by replacing it with # the widest possible version of itself (the wrapper) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 1a5ac13684c29..132ec6d641257 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -3202,3 +3202,13 @@ end return y end == Any[Union{Nothing, Tuple{String, Union{Nothing, String}}}] end + +@test Base.return_types((Int,)) do x + if x === 0 + Some(0.0) + elseif x == 1 + Some(1) + else + Some(0x2) + end +end == [Union{Some{Float64}, Some{Int64}, Some{UInt8}}] From 4bcd69525f3063145a2662fc1cb15467ff5ec485 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 10 Mar 2021 17:57:18 -0500 Subject: [PATCH 2/6] Fix inference tests --- test/compiler/inference.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 132ec6d641257..14dd6df313758 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -103,10 +103,16 @@ tmerge_test(Tuple{ComplexF64, ComplexF64, ComplexF32}, Tuple{Vararg{Union{Comple tmerge_test(Tuple{}, Tuple{Complex, Vararg{Union{ComplexF32, ComplexF64}}}, Tuple{Vararg{Complex}}) @test Core.Compiler.tmerge(Tuple{}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) == + Union{Nothing, Tuple{}, Tuple{ComplexF32, ComplexF32}} +@test Core.Compiler.tmerge(Tuple{}, Union{Nothing, Tuple{ComplexF32}, Tuple{ComplexF32, ComplexF32}}) == Union{Nothing, Tuple{Vararg{ComplexF32}}} @test Core.Compiler.tmerge(Union{Nothing, Tuple{ComplexF32}}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) == + Union{Nothing, Tuple{ComplexF32}, Tuple{ComplexF32, ComplexF32}} +@test Core.Compiler.tmerge(Union{Nothing, Tuple{}, Tuple{ComplexF32}}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) == Union{Nothing, Tuple{Vararg{ComplexF32}}} -@test Core.Compiler.tmerge(Vector{Int}, Core.Compiler.tmerge(Vector{String}, Vector{Bool})) == Vector +@test Core.Compiler.tmerge(Vector{Int}, Core.Compiler.tmerge(Vector{String}, Vector{Bool})) == + Union{Vector{Bool}, Vector{Int64}, Vector{String}} +@test Core.Compiler.tmerge(Vector{Int}, Core.Compiler.tmerge(Vector{String}, Union{Vector{Bool}, Vector{Symbol}})) == Vector @test Core.Compiler.tmerge(Base.BitIntegerType, Union{}) === Base.BitIntegerType @test Core.Compiler.tmerge(Union{}, Base.BitIntegerType) === Base.BitIntegerType @test Core.Compiler.tmerge(Core.Compiler.InterConditional(1, Int, Union{}), Core.Compiler.InterConditional(2, String, Union{})) === Core.Compiler.Const(true) From 72fb012e8346ada8505f9bdc10757a3772f07917 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 10 Mar 2021 18:50:46 -0500 Subject: [PATCH 3/6] Avoid finalizer to be compiled during test_jl_dump_compiles_toplevel_thunks --- test/compiler/codegen.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/compiler/codegen.jl b/test/compiler/codegen.jl index 2b7b266751a08..47f419d9937a2 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -73,11 +73,13 @@ function test_jl_dump_compiles_toplevel_thunks() # Make sure to cause compilation of the eval function # before calling it below. Core.eval(Main, Any[:(nothing)][1]) + GC.enable(false) # avoid finalizers to be compiled topthunk = Meta.lower(Main, :(for i in 1:10; end)) ccall(:jl_dump_compiles, Cvoid, (Ptr{Cvoid},), io.handle) Core.eval(Main, topthunk) ccall(:jl_dump_compiles, Cvoid, (Ptr{Cvoid},), C_NULL) close(io) + GC.enable(true) tstats = stat(tfile) tempty = tstats.size == 0 rm(tfile) From e05cc5b4ca84c3cbd7a55e0d9e2fe152da8dec48 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 10 Mar 2021 21:45:09 -0500 Subject: [PATCH 4/6] Fix test/worlds.jl --- test/worlds.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/worlds.jl b/test/worlds.jl index deec2489de11c..692f4febd91cd 100644 --- a/test/worlds.jl +++ b/test/worlds.jl @@ -89,8 +89,8 @@ B265(x::Any, dummy::Nothing) = B265{UInt8}(x, dummy) @test (B265_(2)::B265{Float64}).field1 === 2.0e0 @test (B265_(3)::B265{UInt8}).field1 === 0x03 -@test Base.return_types(B265_, (Int,)) == Any[B265] -@test Core.Compiler.return_type(B265_, (Int,)) == B265 +@test B265{UInt8} <: only(Base.return_types(B265_, (Int,))) <: B265 +@test B265{UInt8} <: Core.Compiler.return_type(B265_, (Int,)) <: B265 # test oldworld call / inference From 58742ebb1de80af3245018cd222c94fddbb0b1e8 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 11 Mar 2021 00:26:39 -0500 Subject: [PATCH 5/6] Fix test/broadcast.jl --- test/broadcast.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/broadcast.jl b/test/broadcast.jl index bebb072c5732c..ae68494c4e361 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -955,18 +955,18 @@ p0 = copy(p) @test isequal([1, 2] .+ [3.0, missing], [4.0, missing]) @test Core.Compiler.return_type(broadcast, Tuple{typeof(+), Vector{Int}, Vector{Union{Float64, Missing}}}) == - Vector{<:Union{Float64, Missing}} + Union{Vector{Missing}, Vector{Union{Missing, Float64}}, Vector{Float64}} @test isequal([1, 2] + [3.0, missing], [4.0, missing]) @test Core.Compiler.return_type(+, Tuple{Vector{Int}, Vector{Union{Float64, Missing}}}) == - Vector{<:Union{Float64, Missing}} + Union{Vector{Missing}, Vector{Union{Missing, Float64}}, Vector{Float64}} @test Core.Compiler.return_type(+, Tuple{Vector{Int}, Vector{Union{Float64, Missing}}}) == - Vector{<:Union{Float64, Missing}} + Union{Vector{Missing}, Vector{Union{Missing, Float64}}, Vector{Float64}} @test isequal(tuple.([1, 2], [3.0, missing]), [(1, 3.0), (2, missing)]) @test Core.Compiler.return_type(broadcast, Tuple{typeof(tuple), Vector{Int}, Vector{Union{Float64, Missing}}}) == - Vector{<:Tuple{Int, Any}} + Union{Vector{Tuple{Int64, Missing}}, Vector{Tuple{Int64, Any}}, Vector{Tuple{Int64, Float64}}} # Check that corner cases do not throw an error @test isequal(broadcast(x -> x === 1 ? nothing : x, [1, 2, missing]), [nothing, 2, missing]) From 5239b25382077e5ed15d7c7678d7eaaf27627dc0 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 11 Mar 2021 02:01:01 -0500 Subject: [PATCH 6/6] Fix tests for 32bit machines --- test/broadcast.jl | 2 +- test/compiler/inference.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/broadcast.jl b/test/broadcast.jl index ae68494c4e361..6e97d609a42b0 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -966,7 +966,7 @@ p0 = copy(p) @test isequal(tuple.([1, 2], [3.0, missing]), [(1, 3.0), (2, missing)]) @test Core.Compiler.return_type(broadcast, Tuple{typeof(tuple), Vector{Int}, Vector{Union{Float64, Missing}}}) == - Union{Vector{Tuple{Int64, Missing}}, Vector{Tuple{Int64, Any}}, Vector{Tuple{Int64, Float64}}} + Union{Vector{Tuple{Int, Missing}}, Vector{Tuple{Int, Any}}, Vector{Tuple{Int, Float64}}} # Check that corner cases do not throw an error @test isequal(broadcast(x -> x === 1 ? nothing : x, [1, 2, missing]), [nothing, 2, missing]) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 14dd6df313758..6f1d25c3d3d1d 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -111,7 +111,7 @@ tmerge_test(Tuple{}, Tuple{Complex, Vararg{Union{ComplexF32, ComplexF64}}}, @test Core.Compiler.tmerge(Union{Nothing, Tuple{}, Tuple{ComplexF32}}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) == Union{Nothing, Tuple{Vararg{ComplexF32}}} @test Core.Compiler.tmerge(Vector{Int}, Core.Compiler.tmerge(Vector{String}, Vector{Bool})) == - Union{Vector{Bool}, Vector{Int64}, Vector{String}} + Union{Vector{Bool}, Vector{Int}, Vector{String}} @test Core.Compiler.tmerge(Vector{Int}, Core.Compiler.tmerge(Vector{String}, Union{Vector{Bool}, Vector{Symbol}})) == Vector @test Core.Compiler.tmerge(Base.BitIntegerType, Union{}) === Base.BitIntegerType @test Core.Compiler.tmerge(Union{}, Base.BitIntegerType) === Base.BitIntegerType @@ -3217,4 +3217,4 @@ end else Some(0x2) end -end == [Union{Some{Float64}, Some{Int64}, Some{UInt8}}] +end == [Union{Some{Float64}, Some{Int}, Some{UInt8}}]