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

Fails to build on 1.6: type piracy? #24

Closed
timholy opened this issue Oct 14, 2020 · 6 comments
Closed

Fails to build on 1.6: type piracy? #24

timholy opened this issue Oct 14, 2020 · 6 comments

Comments

@timholy
Copy link

timholy commented Oct 14, 2020

Hyperscript doesn't build on nightly. The reason is https://github.com/yurivish/Hyperscript.jl/blob/7731aecafd06e9366020ebee0d6674527fe3d7d6/src/Hyperscript.jl#L117

Here's why: 1.6 has a new TOML parser that includes this line. The issue is that Union{} <: Hyperscript.AbstractNode, because Union{} is a subtype of every other type, and hence instead of creating an array with eltype Union{} it tries (during package loading!) to call Union{}(xs...), which obviously fails. CC @KristofferC.

I am pretty sure this method counts as type-piracy (even if you own YourType, you do not own Vector{YourType}), so I guess the question is, can it be eliminated?

@KristofferC
Copy link

I guess it could be written as Vector{Union}() but changing the result of Union{}[] is probably not ideal anyway.

@timholy
Copy link
Author

timholy commented Oct 14, 2020

In case someone asks:

julia> using SnoopCompileCore

julia> abstract type AbstractNode{T} end

julia> invs = @snoopr Base.getindex(node::Type{<:AbstractNode}, xs::Any...) = node(xs...);

julia> using SnoopCompile

julia> length(uinvalidated(invs))
358

All the invalidated methods are callers of parse_array. But if you load Revise it goes up to 590.

@timholy
Copy link
Author

timholy commented Oct 14, 2020

Hmm, tests pass just fine with

diff --git a/src/Hyperscript.jl b/src/Hyperscript.jl
index 10ca312..8608159 100644
--- a/src/Hyperscript.jl
+++ b/src/Hyperscript.jl
@@ -114,7 +114,8 @@ function Base.typed_hvcat(node::AbstractNode, rows::Tuple{Vararg{Int64}}, xs::An
 end
 Base.typed_hcat(node::AbstractNode, xs::Any...) = node(xs...)
 Base.typed_vcat(node::AbstractNode, xs::Any...) = node(xs...)
-Base.getindex(node::Union{AbstractNode, Type{<:AbstractNode}}, xs::Any...) = node(xs...)
+Base.getindex(node::AbstractNode, xs::Any...) = node(xs...)
+# Base.getindex(node::Union{AbstractNode, Type{<:AbstractNode}}, xs::Any...) = node(xs...)
 
 function Base.:(==)(x::Node, y::Node)
     context(x)  == context(y)  && tag(x)   == tag(y) &&

yurivish added a commit that referenced this issue Oct 15, 2020
This change should fix issue #24. 

The original idea was to make using Hyperscript more concise, so one leave out commas between arguments when constructing nodes.
@SimonDanisch
Copy link
Collaborator

@yurivish does anything speak against tagging a new version with your fix?

@timholy
Copy link
Author

timholy commented Nov 9, 2020

Meanwhile I think this can be closed. Thanks @yurivish, sorry I didn't notice the fix when it came in.

@timholy timholy closed this as completed Nov 9, 2020
@yurivish
Copy link
Collaborator

yurivish commented Nov 9, 2020

@SimonDanisch Not at all, feel free to tag a new version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants