-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
Closes #20518 and improves inference when splatting genetal iterables.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1421,13 +1421,32 @@ function precise_container_type(arg, typ, vtypes::VarTable, sv) | |
else | ||
return tti.parameters | ||
end | ||
elseif tti <: AbstractArray | ||
return Any[Vararg{eltype(tti)}] | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
martinholters
Author
Member
|
||
else | ||
return Any[Vararg{Any}] | ||
return Any[Vararg{abstract_iteration(tti, vtypes, sv)}] | ||
end | ||
end | ||
|
||
# simulate iteration protocol on container type up to fixpoint | ||
function abstract_iteration(itertype, vtypes::VarTable, sv) | ||
if !isdefined(Main, :Base) || !isdefined(Main.Base, :start) || !isdefined(Main.Base, :next) | ||
return Any | ||
end | ||
statetype = abstract_call(Main.Base.start, (), Any[Const(Main.Base.start), itertype], vtypes, sv) | ||
valtype = Bottom | ||
while valtype !== Any | ||
nt = abstract_call(Main.Base.next, (), Any[Const(Main.Base.next), itertype, statetype], vtypes, sv) | ||
if !isa(nt, DataType) || !(nt <: Tuple) || isvatuple(nt) || length(nt.parameters) != 2 | ||
return Any | ||
end | ||
if nt.parameters[1] <: valtype && nt.parameters[2] <: statetype | ||
break | ||
end | ||
valtype = tmerge(valtype, nt.parameters[1]) | ||
statetype = tmerge(statetype, nt.parameters[2]) | ||
end | ||
return valtype | ||
end | ||
|
||
# do apply(af, fargs...), where af is a function value | ||
function abstract_apply(af::ANY, fargs, aargtypes::Vector{Any}, vtypes::VarTable, sv) | ||
res = Union{} | ||
|
3 comments
on commit 12d6eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great example of how to add stuff to inference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We also need to somehow tell people that you can do cd("base"); include("coreimg.jl")
to test any changes to inference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, knowing that a bit earlier would have been quite helpful.
Maybe worth keeping this case for
<: Array{T}
, as a performance optimization in inference?