# Question about how method signatures are encoded in \`Docs.Meta\`

**URL:** <https://discourse.julialang.org/t/question-about-how-method-signatures-are-encoded-in-docs-meta/32666>\
**Category:** Internals & Design\
**Created:** [December 24, 2019, 7:54pm UTC](https://discourse.julialang.org/t/question-about-how-method-signatures-are-encoded-in-docs-meta/32666 "2019-12-24T19:54:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan-laurent](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@jonathan-laurent](https://discourse.julialang.org/u/jonathan-laurent)\
**Post date:** [December 24, 2019, 7:54pm UTC](https://discourse.julialang.org/t/question-about-how-method-signatures-are-encoded-in-docs-meta/32666/1 "2019-12-24T19:54:39Z")

</div>

Hi,  
I am trying to debug a surprising behavior in `Documenter.jl` and had to look at how docstrings are stored and represented internally. I am confused by the encoding that is used to represent method signatures that involve generic type variables.

For example, the following code

```julia
module Meta

    "Function"
    function f end

    "Method 1"
    function f(x::Int, y::Int=3) end

    "Method 2"
    function f(x::T, xs::Vector{T}) where T end

end

Docs.meta(Meta)[Docs.Binding(Meta, :f)].docs |> keys

```

yields this output using Julia 1.30:

```julia
Base.KeySet for a IdDict{Any,Any} with 3 entries. Keys:
  Union{}
  Union{Tuple{Int64}, Tuple{Int64,Int64}}
  Union{Tuple{T}, Tuple{T,Array{T,1}}} where T

```

The encoding for the signature of _Method 1_ is pretty natural: as the optional argument is desugarized into two methods, we have a union of two tuples with one and two elements respectively.

The encoding for the signature of _Method 2_ is less natural, as it seems that the union has a different and unusual semantics here. In fact, I would have expected the given encoding to encode  
the following signature:

```julia
"Method 2 bis"
function f(x::T, xs::Vector{T}=[]) where T end

```

Instead, the signature of _Method 2 bis_ above is encoded as:

```julia
Union{Tuple{T}, Tuple{T}, Tuple{T,Array{T,1}}} where T

```

* * *

Playing with this a bit, it seems that the signature of a method involving n variables is represented as a union whose n first elements are singletons containing those type variables.

**Am I correct here and can anyone justify such a convention?**

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [December 28, 2019, 2:00pm UTC](https://discourse.julialang.org/t/question-about-how-method-signatures-are-encoded-in-docs-meta/32666/2 "2019-12-28T14:00:29Z")

</div>

I was not involved in the design of this code, but if I had to guess it would be to support doc retrieval when, e.g., tab-completing in an editor. Again, this is just a guess.

---

<div class="post-metadata">

**Author:** ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)\
**Post date:** [December 28, 2019, 5:06pm UTC](https://discourse.julialang.org/t/question-about-how-method-signatures-are-encoded-in-docs-meta/32666/3 "2019-12-28T17:06:35Z")

</div>

The docsystem still has problems with the `where` syntax. I think with your `Method 2` you are seeing [https://github.com/JuliaLang/julia/issues/29437](https://github.com/JuliaLang/julia/issues/29437).
