Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #31663, long inference time printing large tree structure #31680

Merged
merged 1 commit into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ function is_derived_type(@nospecialize(t), @nospecialize(c), mindepth::Int)
# it cannot have a reference cycle in the type graph
cF = c.types
for f in cF
is_derived_type(t, f, mindepth) && return true
# often a parameter is also a field type; avoid searching twice
if !contains_is(c.parameters, f)
is_derived_type(t, f, mindepth) && return true
end
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,9 @@ function invokelatest(@nospecialize(f), @nospecialize args...; kwargs...)
Core._apply_latest(inner)
end

# TODO: possibly make this an intrinsic
inferencebarrier(@nospecialize(x)) = Ref{Any}(x)[]

"""
isempty(collection) -> Bool

Expand Down
5 changes: 4 additions & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ show(x) = show(stdout::IO, x)

show(io::IO, @nospecialize(x)) = show_default(io, x)

function show_default(io::IO, @nospecialize(x))
# avoid inferring show_default on the type of `x`
show_default(io::IO, @nospecialize(x)) = _show_default(io, inferencebarrier(x))

function _show_default(io::IO, @nospecialize(x))
t = typeof(x)::DataType
show(io, t)
print(io, '(')
Expand Down
1 change: 1 addition & 0 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ static int obviously_egal(jl_value_t *a, jl_value_t *b)
if (jl_is_datatype(a)) {
jl_datatype_t *ad = (jl_datatype_t*)a, *bd = (jl_datatype_t*)b;
if (ad->name != bd->name) return 0;
if (ad->isconcretetype || bd->isconcretetype) return 0;
size_t i, np = jl_nparams(ad);
if (np != jl_nparams(bd)) return 0;
for(i=0; i < np; i++) {
Expand Down
23 changes: 23 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2325,3 +2325,26 @@ h28762(::Type{X}) where {X} = Array{f28762(X)}(undef, 0)
@inferred g28762(Array)
@inferred h28762(Array)
end

# issue #31663
module I31663
abstract type AbstractNode end

struct Node{N1<:AbstractNode, N2<:AbstractNode} <: AbstractNode
a::N1
b::N2
end

struct Leaf <: AbstractNode
end

function gen_nodes(qty::Integer) :: AbstractNode
@assert qty > 0
result = Leaf()
for i in 1:qty
result = Node(result, Leaf())
end
return result
end
end
@test count(==('}'), string(I31663.gen_nodes(50))) == 1275