Skip to content

Commit

Permalink
inference: fix infinite recursion of nested Generators (#51845)
Browse files Browse the repository at this point in the history
It seems this case has already been fixed by other improvements, so we
no longer need this hack, which is now causing problems.

Fixes #51694
  • Loading branch information
vtjnash authored and aviatesk committed Oct 25, 2023
1 parent a599ed4 commit ac2593a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
13 changes: 0 additions & 13 deletions base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,9 @@ function type_more_complex(@nospecialize(t), @nospecialize(c), sources::SimpleVe
else
tupledepth = 0
end
isgenerator = (t.name.name === :Generator && t.name.module === _topmod(t.name.module))
for i = 1:length(tP)
tPi = tP[i]
cPi = cP[i + ntail]
if isgenerator
let tPi = unwrap_unionall(tPi),
cPi = unwrap_unionall(cPi)
if isa(tPi, DataType) && isa(cPi, DataType) &&
!isabstracttype(tPi) && !isabstracttype(cPi) &&
sym_isless(cPi.name.name, tPi.name.name)
# allow collect on (anonymous) Generators to nest, provided that their functions are appropriately ordered
# TODO: is there a better way?
continue
end
end
end
type_more_complex(tPi, cPi, sources, depth + 1, tupledepth, 0) && return true
end
return false
Expand Down
2 changes: 0 additions & 2 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ end
is_meta_expr_head(head::Symbol) = head === :boundscheck || head === :meta || head === :loopinfo
is_meta_expr(@nospecialize x) = isa(x, Expr) && is_meta_expr_head(x.head)

sym_isless(a::Symbol, b::Symbol) = ccall(:strcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}), a, b) < 0

function is_self_quoting(@nospecialize(x))
return isa(x,Number) || isa(x,AbstractString) || isa(x,Tuple) || isa(x,Type) ||
isa(x,Char) || x === nothing || isa(x,Function)
Expand Down
10 changes: 10 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ end
@test !Core.Compiler.type_more_complex(Tuple{Vararg{Tuple{}}}, Tuple{Vararg{Tuple}}, Core.svec(), 0, 0, 0)
@test Core.Compiler.type_more_complex(Tuple{Vararg{Tuple}}, Tuple{Vararg{Tuple{}}}, Core.svec(), 0, 0, 0)

# issue #51694
@test Core.Compiler.type_more_complex(
Base.Generator{Base.Iterators.Flatten{Array{Bool, 1}}, typeof(identity)},
Base.Generator{Array{Bool, 1}, typeof(identity)},
Core.svec(), 0, 0, 0)
@test Core.Compiler.type_more_complex(
Base.Generator{Base.Iterators.Flatten{Base.Generator{Array{Bool, 1}, typeof(identity)}}, typeof(identity)},
Base.Generator{Array{Bool, 1}, typeof(identity)},
Core.svec(), 0, 0, 0)

let # 40336
t = Type{Type{Int}}
c = Type{Int}
Expand Down

0 comments on commit ac2593a

Please sign in to comment.