From 614b740409859147725d4fe8e9ad2549b060dae5 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Fri, 1 Mar 2024 00:34:00 -0600 Subject: [PATCH] Allow sysimage build without the doc system (#53533) 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. --- base/boot.jl | 13 +++++++++++-- base/shell.jl | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/base/boot.jl b/base/boot.jl index f8ed86b0fb6b7c..e041488cdb74c8 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -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 diff --git a/base/shell.jl b/base/shell.jl index 9f15550a1aa59f..137150b585d863 100644 --- a/base/shell.jl +++ b/base/shell.jl @@ -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 ("\\ "). @@ -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)) @@ -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")