@@ -655,18 +655,28 @@ function _collect_indices(indsA, A)
655
655
copy! (B, CartesianRange (indices (B)), A, CartesianRange (indsA))
656
656
end
657
657
658
+ # define this as a macro so that the call to Inference
659
+ # gets inlined into the caller before recursion detection
660
+ # gets a chance to see it, so that recursive calls to the caller
661
+ # don't trigger the inference limiter
658
662
if isdefined (Core, :Inference )
659
- _default_eltype (@nospecialize itrt) = Core. Inference. return_type (first, Tuple{itrt})
663
+ macro default_eltype (itrt)
664
+ return quote
665
+ Core. Inference. return_type (first, Tuple{$ (esc (itrt))})
666
+ end
667
+ end
660
668
else
661
- _default_eltype (@nospecialize itr) = Any
669
+ macro default_eltype (itrt)
670
+ return :(Any)
671
+ end
662
672
end
663
673
664
674
_array_for (:: Type{T} , itr, :: HasLength ) where {T} = Array {T,1} (Int (length (itr):: Integer ))
665
675
_array_for (:: Type{T} , itr, :: HasShape ) where {T} = similar (Array{T}, indices (itr))
666
676
667
677
function collect (itr:: Generator )
668
678
isz = iteratorsize (itr. iter)
669
- et = _default_eltype (typeof (itr))
679
+ et = @default_eltype (typeof (itr))
670
680
if isa (isz, SizeUnknown)
671
681
return grow_to! (Array {et,1} (0 ), itr)
672
682
else
@@ -680,12 +690,12 @@ function collect(itr::Generator)
680
690
end
681
691
682
692
_collect (c, itr, :: EltypeUnknown , isz:: SizeUnknown ) =
683
- grow_to! (_similar_for (c, _default_eltype (typeof (itr)), itr, isz), itr)
693
+ grow_to! (_similar_for (c, @default_eltype (typeof (itr)), itr, isz), itr)
684
694
685
695
function _collect (c, itr, :: EltypeUnknown , isz:: Union{HasLength,HasShape} )
686
696
st = start (itr)
687
697
if done (itr,st)
688
- return _similar_for (c, _default_eltype (typeof (itr)), itr, isz)
698
+ return _similar_for (c, @default_eltype (typeof (itr)), itr, isz)
689
699
end
690
700
v1, st = next (itr, st)
691
701
collect_to_with_first! (_similar_for (c, typeof (v1), itr, isz), v1, itr, st)
0 commit comments