Skip to content

Commit

Permalink
Allow sysimage build without the doc system (JuliaLang#53533)
Browse files Browse the repository at this point in the history
The earliest bootstrapping code has a definition of `atdoc` that is just
supposed to ignore the doc string and pass the defining code through.
This function is then replaced by the actual docsystem once that is
available. For testing, I wanted to build the whole system image without
the doc system using this boostrap definition. However, this turns out
not to be possible, because there's a few doc syntax semantics that do
not actually just ignore the doc string.

In particular:
```
"""
I am a doc for a particular signature
"""
foo(x::Int, y::Float64)
```

Does not acutally result in a call to `foo`.

And similarly

```
"""
I am a doc for a global binding
"""
MyModule.foo
```

Does not require `MyModule.foo` to actually have a value, since it only
documents the binding.

This PR allows both of those cases in the boostrap version of `atdoc` so
that we can bootstrap without the doc system if we wanted to.
  • Loading branch information
Keno committed Mar 1, 2024
1 parent 136f018 commit 0918cf1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,17 @@ end
macro __doc__(x)
return Expr(:escape, Expr(:block, Expr(:meta, :doc), x))
end
atdoc = (source, mod, str, expr) -> Expr(:escape, expr)
atdoc!(λ) = global atdoc = λ

isbasicdoc(@nospecialize x) = (isa(x, Expr) && x.head === :.) || isa(x, Union{QuoteNode, Symbol})
iscallexpr(ex::Expr) = (isa(ex, Expr) && ex.head === :where) ? iscallexpr(ex.args[1]) : (isa(ex, Expr) && ex.head === :call)
iscallexpr(ex) = false
function ignoredoc(source, mod, str, expr)
(isbasicdoc(expr) || iscallexpr(expr)) && return Expr(:escape, nothing)
Expr(:escape, expr)
end

global atdoc = ignoredoc
atdoc!(λ) = global atdoc = λ

# macros for big integer syntax
macro int128_str end
Expand Down
6 changes: 3 additions & 3 deletions base/shell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const shell_special = "#{}()[]<>|&*?~;"

@doc raw"""
(@doc raw"""
rstrip_shell(s::AbstractString)
Strip trailing whitespace from a shell command string, while respecting a trailing backslash followed by a space ("\\ ").
Expand All @@ -16,7 +16,7 @@ julia> Base.rstrip_shell("echo 'Hello World' \\ ")
julia> Base.rstrip_shell("echo 'Hello World' ")
"echo 'Hello World'"
```
""" ->
"""
function rstrip_shell(s::AbstractString)
c_old = nothing
for (i, c) in Iterators.reverse(pairs(s))
Expand All @@ -26,7 +26,7 @@ function rstrip_shell(s::AbstractString)
c_old = c
end
SubString(s, 1, 0)
end
end)

function shell_parse(str::AbstractString, interpolate::Bool=true;
special::AbstractString="", filename="none")
Expand Down

0 comments on commit 0918cf1

Please sign in to comment.