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

Presence of a docstring somehow messes up type parameter of function argument resolution #28044

Closed
quinnj opened this issue Jul 10, 2018 · 3 comments
Assignees
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) docsystem The documentation building system kind:bug Indicates an unexpected problem or unintended behavior

Comments

@quinnj
Copy link
Member

quinnj commented Jul 10, 2018

julia> module DataStreams

       code(::Nothing) = missing

       struct Query{code, T, E, L, O}
           columns::T
       end

       "Compute the Data.Schema of the resultset of executing Data.Query `q` against its source"
       function schema(source::S, q::Query{code, columns, e, limit, offset}, wk=true) where {code, S, columns, e, limit, offset}
           @show q
           @show typeof(code)
           return
       end

       function schema2(source::S, q::Query{code, columns, e, limit, offset}, wk=true) where {code, S, columns, e, limit, offset}
           @show q
           @show typeof(code)
           return
       end

       end # module DataStreams
WARNING: replacing module DataStreams.
Main.DataStreams

julia> q = Main.DataStreams.Query{0x01,Nothing,(),nothing,nothing}(nothing)
Main.DataStreams.Query{0x01,Nothing,(),nothing,nothing}(nothing)

julia> Main.DataStreams.schema(1, q)
q = Main.DataStreams.Query{0x01,Nothing,(),nothing,nothing}(nothing)
typeof(code) = typeof(Main.DataStreams.code)

julia> Main.DataStreams.schema2(1, q)
q = Main.DataStreams.Query{0x01,Nothing,(),nothing,nothing}(nothing)
typeof(code) = UInt8
@JeffBezanson
Copy link
Sponsor Member

Off topic, but can anybody explain this:

julia> module Foo 
       code(x) = 10x
       @show macroexpand(quote
       """ some docs """
       function f(::Array{code}) where code
       code(2)
       end end)
       end
... = quote
    #= REPL[26]:4 =#
    begin
        function f(::Array{code}) where code
            #= REPL[26]:6 =#
            code(2)
        end
        (Base.Docs.doc!)(Main.Foo, (Base.Docs.Binding)(Main.Foo, :f), (Base.Docs.docstr)((Core.svec)(" some docs "), (Dict)(:path => "REPL[26]", :linenumber => 4, :module => Main.Foo)), Union{Tuple{Array{code}}, Tuple{code}} where code <: Any)
    end
end

What is the significance of the type Union{Tuple{Array{code}}, Tuple{code}} where code <: Any? Why is that passed to doc!? I think it's supposed to be the method signature, but I don't understand where that Union type comes from.

@JeffBezanson JeffBezanson added the docsystem The documentation building system label Jul 10, 2018
@JeffBezanson JeffBezanson self-assigned this Jul 11, 2018
@JeffBezanson JeffBezanson added compiler:lowering Syntax lowering (compiler front end, 2nd stage) kind:bug Indicates an unexpected problem or unintended behavior labels Jul 11, 2018
@KristofferC
Copy link
Sponsor Member

I think it comes from

julia/base/docs/Docs.jl

Lines 85 to 116 in f104ea4

function signature!(tv, expr::Expr)
is_macrocall = isexpr(expr, :macrocall)
if is_macrocall || isexpr(expr, :call)
sig = :(Union{Tuple{}})
first_arg = is_macrocall ? 3 : 2 # skip function arguments
for arg in expr.args[first_arg:end]
isexpr(arg, :parameters) && continue
if isexpr(arg, :kw) # optional arg
push!(sig.args, :(Tuple{$(sig.args[end].args[2:end]...)}))
end
push!(sig.args[end].args, argtype(arg))
end
if isexpr(expr.args[1], :curly) && isempty(tv)
append!(tv, tvar.(expr.args[1].args[2:end]))
end
for i = length(tv):-1:1
push!(sig.args, :(Tuple{$(tv[i].args[1])}))
end
for i = length(tv):-1:1
sig = Expr(:where, sig, tv[i])
end
return sig
elseif isexpr(expr, :where)
append!(tv, tvar.(expr.args[2:end]))
return signature!(tv, expr.args[1])
else
return signature!(tv, expr.args[1])
end
end
signature!(tv, @nospecialize(other)) = :(Union{})
signature(expr::Expr) = signature!([], expr)
signature(@nospecialize other) = signature!([], other)

@JeffBezanson
Copy link
Sponsor Member

Yes it does, but I can't figure out why that code does that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) docsystem The documentation building system kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants