Skip to content

Core.Compiler.sort! is broken #47065

@Keno

Description

@Keno
ERROR: UndefVarError: sizeof not defined
Stacktrace:
  [1] sort!(v::Vector{Int64}, lo::Int64, hi::Int64, a::Core.Compiler.Sort.AdaptiveSort{Core.Compiler.Sort.QuickSortAlg}, o::Core.Compiler.Order.ForwardOrdering, t::Nothing)
    @ Core.Compiler.Sort ./sort.jl:804
  [2] sort!
    @ ./sort.jl:895 [inlined]
  [3] #sort!#8
    @ ./sort.jl:950 [inlined]
  [4] sort!
    @ ./sort.jl:943 [inlined]
  [5] compute_live_ins(cfg::Core.Compiler.CFG, du::Core.Compiler.SSADefUse)
    @ Core.Compiler base/compiler/ssair/passes.jl:46
  [6] sroa_mutables!(ir::Core.Compiler.IRCode, defuses::Core.Compiler.IdDict{Int64, Tuple{Core.Compiler.IdSet{Int64}, Core.Compiler.SSADefUse}}, used_ssas::Vector{Int64}, lazydomtree::Core.Compiler.LazyGenericDomtree{false}, inlining::Core.Compiler.InliningState{Core.Compiler.EdgeTracker, Core.Compiler.WorldView{DAECompiler.DAEGlobalCache}, DAECompiler.DAEInterpreter})
    @ Core.Compiler base/compiler/ssair/passes.jl:1314
  [7] sroa_pass!(ir::Core.Compiler.IRCode, inlining::Core.Compiler.InliningState{Core.Compiler.EdgeTracker, Core.Compiler.WorldView{DAECompiler.DAEGlobalCache}, DAECompiler.DAEInterpreter})
    @ Core.Compiler base/compiler/ssair/passes.jl:1041
  [8] run_passes(ci::Core.CodeInfo, sv::Core.Compiler.OptimizationState, caller::Core.Compiler.InferenceResult, optimize_until::Nothing)

This is the first issue, but fixing this shows a bunch more. Here's a start at fixing it, but there's more issues:

diff --git a/base/sort.jl b/base/sort.jl
index f6f737ac20..12ce7c79fc 100644
--- a/base/sort.jl
+++ b/base/sort.jl
@@ -12,7 +12,7 @@ using .Base: copymutable, LinearIndices, length, (:), iterate, OneTo,
     extrema, sub_with_overflow, add_with_overflow, oneunit, div, getindex, setindex!,
     length, resize!, fill, Missing, require_one_based_indexing, keytype, UnitRange,
     min, max, reinterpret, signed, unsigned, Signed, Unsigned, typemin, xor, Type, BitSigned, Val,
-    midpoint, @boundscheck, checkbounds
+    midpoint, @boundscheck, checkbounds, sizeof, leading_zeros

 using .Base: >>>, !==, !=

@@ -881,6 +881,8 @@ function sort!(v::AbstractVector{T}, lo::Integer, hi::Integer, a::AdaptiveSort,
         u2 = radix_sort!(u, lo, hi, bits, similar(u))
         uint_unmap!(v, u2, lo, hi, o, u_min)
     end
+
+    return nothing
 end

 ## generic sorting methods ##
@@ -1412,7 +1414,7 @@ uint_map(x::Unsigned, ::ForwardOrdering) = x
 uint_unmap(::Type{T}, u::T, ::ForwardOrdering) where T <: Unsigned = u

 uint_map(x::Signed, ::ForwardOrdering) =
-    unsigned(xor(x, typemin(x)))
+    unsigned(xor(x, typemin(typeof(x))))
 uint_unmap(::Type{T}, u::Unsigned, ::ForwardOrdering) where T <: Signed =
     xor(signed(u), typemin(T))

Metadata

Metadata

Labels

bugIndicates an unexpected problem or unintended behaviorregressionRegression in behavior compared to a previous version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions