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

Base.@doc in macro doesn't work on master #52986

Closed
Tortar opened this issue Jan 20, 2024 · 10 comments · Fixed by #54499
Closed

Base.@doc in macro doesn't work on master #52986

Tortar opened this issue Jan 20, 2024 · 10 comments · Fixed by #54499
Assignees
Labels
domain:docs This change adds or pertains to documentation kind:regression Regression in behavior compared to a previous version
Milestone

Comments

@Tortar
Copy link
Contributor

Tortar commented Jan 20, 2024

As the title says this seems to be the case because in a PR on SumTypes.jl (https://github.com/MasonProtter/SumTypes.jl/pull/63/files) the doctest failing is only on nightly, while all the other works well, as you can see at https://github.com/MasonProtter/SumTypes.jl/actions/runs/7595253256/job/20687608559 the test fails with

Basics  : Test Failed at /home/runner/work/SumTypes.jl/SumTypes.jl/test/runtests.jl:40
  Expression: string(#= /home/runner/work/SumTypes.jl/SumTypes.jl/test/runtests.jl:40 =# @doc(Foo)) == "This is a Foo.\n"
   Evaluated: "nothing" == "This is a Foo.\n"

while for all other Julia versions it returns "This is a Foo.\n". Same is happening also on the CI of ProtoStructs.jl e.g. here https://github.com/BeastyBlacksmith/ProtoStructs.jl/actions/runs/7500520539/job/20419369109

Unfortunately I wasn't able to find a MWE when I searched for it

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 20, 2024

This is a REPL-only feature. Packages should normally be using @ref links, not copying the text from elsewhere. E.g.:

$ ./julia -E '@doc Base'
nothing
$ ./julia -E 'using REPL; @doc Base'
```
Base
```

The base library of Julia. `Base` is a module that contains basic functionality (the contents of `base/`). All modules implicitly contain `using Base`, since this is needed in the vast majority of cases.

@KristofferC
Copy link
Sponsor Member

KristofferC commented Jan 20, 2024

This doesn't make sense to me... Why would the docsystem work differently if the REPL is loaded? Seems something should be moved back to Base.

@jmert
Copy link
Contributor

jmert commented Jan 23, 2024

See also #52141.

@KristofferC KristofferC added this to the 1.11 milestone Mar 4, 2024
@KristofferC KristofferC added domain:docs This change adds or pertains to documentation kind:regression Regression in behavior compared to a previous version labels Mar 4, 2024
JamesWrigley added a commit to JamesWrigley/Clang.jl that referenced this issue Mar 6, 2024
@JamesWrigley
Copy link
Contributor

JamesWrigley commented Mar 6, 2024

This also hit the Clang.jl tests. Here's a MWE:

doc_expr = (@macroexpand @doc throw)
docstring = string(@doc throw)

@show Base.hasdoc(Main, :throw)
@show doc_expr
@show docstring

And the output on v1.11 alpha

$ julia +1.11 --startup-file=no mwe.jl
Base.hasdoc(Main, :throw) = true
doc_expr = nothing
docstring = "nothing"

Vs 1.10.2 (without Base.hasdoc()):

$ julia --startup-file=no mwe.jl
doc_expr = :((Base.Docs.doc)((Base.Docs.Binding)(Main, :throw)))
docstring = "```\nthrow(e)\n```\n\nThrow an object as an exception.\n\nSee also: [`rethrow`](@ref), [`error`](@ref).\n"

It looks like the macro is returning a nothing value instead of an Expr?

JamesWrigley added a commit to JamesWrigley/Clang.jl that referenced this issue Mar 6, 2024
JamesWrigley added a commit to JamesWrigley/Clang.jl that referenced this issue Mar 6, 2024
@KristofferC
Copy link
Sponsor Member

One issue with this is that @doc gives you are markdown object, which is defined in another stdlib.

Gnimuc pushed a commit to JuliaInterop/Clang.jl that referenced this issue Mar 7, 2024
@JeffBezanson
Copy link
Sponsor Member

I think we should have @doc x return the un-rendered doc object, so it can still be used to duplicate doc strings without the REPL being loaded. It doesn't really matter what @doc x does in the REPL since most people use ? to look up docs anyway.

@JeffBezanson JeffBezanson changed the title Base.@__doc__ in macro doesn't work on master Base.@doc in macro doesn't work on master Mar 8, 2024
@ztangent
Copy link

Noticed this a while back as well! See JuliaLang/Pkg.jl#3650.

@ztangent
Copy link

Could I ask what the intended return value of @doc x is before the REPL module is loaded, and whether it should be equal to the value of @doc x after REPL is loaded? After testing out the nightly, I'm seeing that different values get returned. Here's a MWE:

using Test

"my function"
function foo()
    return 0
end

io = IOBuffer()
print(io, @doc foo)
docstr1 = String(take!(io))

using REPL

io = IOBuffer()
print(io, @doc foo)
docstr2 = String(take!(io))

println("docstr1 = ")
println(docstr1)

println("docstr2 = ")
println(docstr2)

@test docstr1 == docstr2

The resulting output is below:

docstr1 =
Base.Docs.DocStr(svec("my function"), nothing, Dict{Symbol, Any}(:typesig => Tuple{}, :module => Main, :linenumber => 3, :binding => foo, :path => "C:\\Users\\...\\test.jl"))
docstr2 =
my function

Test Failed at C:\Users\...\test.jl:24
  Expression: docstr1 == docstr2
   Evaluated: "Base.Docs.DocStr(svec(\"my function\"), nothing, Dict{Symbol, Any}(:typesig => Tuple{}, :module => Main, :linenumber => 3, :binding => foo, :path => \"C:\\\\Users\\\\...\\\\test.jl\"))" == "my function\n"

As a result, docstring tests like the one in Gen.jl#3 are still failing, and will behave differently depending on whether the test suite is run in the REPL vs. during CI (when REPL isn't loaded).

@KristofferC
Copy link
Sponsor Member

Having the return type change like this just because REPL is loaded or not doesn't seem great. Couldn't @doc always return the raw string form?

DilumAluthge pushed a commit that referenced this issue Jun 3, 2024
@lgoettgens
Copy link
Contributor

Having the return type change like this just because REPL is loaded or not doesn't seem great. Couldn't @doc always return the raw string form?

I agree and thus created #54664 to discuss further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation kind:regression Regression in behavior compared to a previous version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants