Skip to content

Commit 3c21e32

Browse files
authored
inference: fix infinite recursion of nested Generators (#51845)
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
1 parent a43fcbc commit 3c21e32

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

base/compiler/typelimits.jl

-13
Original file line numberDiff line numberDiff line change
@@ -295,22 +295,9 @@ function type_more_complex(@nospecialize(t), @nospecialize(c), sources::SimpleVe
295295
else
296296
tupledepth = 0
297297
end
298-
isgenerator = (t.name.name === :Generator && t.name.module === _topmod(t.name.module))
299298
for i = 1:length(tP)
300299
tPi = tP[i]
301300
cPi = cP[i + ntail]
302-
if isgenerator
303-
let tPi = unwrap_unionall(tPi),
304-
cPi = unwrap_unionall(cPi)
305-
if isa(tPi, DataType) && isa(cPi, DataType) &&
306-
!isabstracttype(tPi) && !isabstracttype(cPi) &&
307-
sym_isless(cPi.name.name, tPi.name.name)
308-
# allow collect on (anonymous) Generators to nest, provided that their functions are appropriately ordered
309-
# TODO: is there a better way?
310-
continue
311-
end
312-
end
313-
end
314301
type_more_complex(tPi, cPi, sources, depth + 1, tupledepth, 0) && return true
315302
end
316303
return false

base/compiler/utilities.jl

-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ end
6666
is_meta_expr_head(head::Symbol) = head === :boundscheck || head === :meta || head === :loopinfo
6767
is_meta_expr(@nospecialize x) = isa(x, Expr) && is_meta_expr_head(x.head)
6868

69-
sym_isless(a::Symbol, b::Symbol) = ccall(:strcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}), a, b) < 0
70-
7169
function is_self_quoting(@nospecialize(x))
7270
return isa(x,Number) || isa(x,AbstractString) || isa(x,Tuple) || isa(x,Type) ||
7371
isa(x,Char) || x === nothing || isa(x,Function)

test/compiler/inference.jl

+10
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ end
9898
@test !Core.Compiler.type_more_complex(Tuple{Vararg{Tuple{}}}, Tuple{Vararg{Tuple}}, Core.svec(), 0, 0, 0)
9999
@test Core.Compiler.type_more_complex(Tuple{Vararg{Tuple}}, Tuple{Vararg{Tuple{}}}, Core.svec(), 0, 0, 0)
100100

101+
# issue #51694
102+
@test Core.Compiler.type_more_complex(
103+
Base.Generator{Base.Iterators.Flatten{Array{Bool, 1}}, typeof(identity)},
104+
Base.Generator{Array{Bool, 1}, typeof(identity)},
105+
Core.svec(), 0, 0, 0)
106+
@test Core.Compiler.type_more_complex(
107+
Base.Generator{Base.Iterators.Flatten{Base.Generator{Array{Bool, 1}, typeof(identity)}}, typeof(identity)},
108+
Base.Generator{Array{Bool, 1}, typeof(identity)},
109+
Core.svec(), 0, 0, 0)
110+
101111
let # 40336
102112
t = Type{Type{Type{Int}}}
103113
c = Type{Type{Int}}

0 commit comments

Comments
 (0)