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

try to recover alias in help> #55119

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Moelf
Copy link
Contributor

@Moelf Moelf commented Jul 13, 2024

Before:

julia> using Base: isvisible as iv

help?> iv
search: div divrem DivideError inv invoke invmod isvalid invperm invpermute! invokelatest InvalidStateException @invoke BitVector @invokelatest code_native

  No documentation found.

  Binding Base.iv does not exist.

this PR:

julia> using Base: isvisible as iv

help?> iv
search: div inv im in if mv

  Base.isvisible is a Function.

  # 1 method for generic function "isvisible" from Base:
   [1] isvisible(sym::Symbol, parent::Module, from::Module)
       @ show.jl:1023

The problem is that it currently tries too hard to recover:

help?> Base.iv
  Base.isvisible is a Function.

  # 1 method for generic function "isvisible" from Base:
   [1] isvisible(sym::Symbol, parent::Module, from::Module)
       @ show.jl:1023

The underlying reason is that by the time REPL doc functions gets the Binding object, it's already in the form of Base.iv -- regardless of help?> iv or help?> Base.iv

cc. @JeffBezanson for pointing to the internal function

@giordano giordano added docs This change adds or pertains to documentation REPL Julia's REPL (Read Eval Print Loop) needs tests Unit tests are required for this change labels Jul 14, 2024
@JeffBezanson
Copy link
Member

Here's a patch that should work:

--- a/base/docs/bindings.jl
+++ b/base/docs/bindings.jl
@@ -10,7 +10,12 @@ struct Binding
         # Normalise the binding module for module symbols so that:
         #   Binding(Base, :Base) === Binding(Main, :Base)
         m = nameof(m) === v ? parentmodule(m) : m
-        new(Base.binding_module(m, v), v)
+        if ccall(:jl_binding_owner, Ptr{Cvoid}, (Any,Any), m, v) == C_NULL
+            new(Base.binding_module(m, v), v)
+        else
+            b = ccall(:jl_binding_owner, Any, (Any,Any), m, v)::Core.Binding
+            new(b.globalref.mod, b.globalref.name)
+        end
     end
 end

The basic problem is that this code assumed "resolving" a symbol can only change the module and not the name, so this fixes that. We can probably go ahead with this since it's at least an improvement, but we could try to get fancier and preserve the original name so we can print something useful like iv is a renamed import of isvisible.

@JeffBezanson JeffBezanson added docsystem The documentation building system and removed docs This change adds or pertains to documentation labels Jul 18, 2024
@Moelf
Copy link
Contributor Author

Moelf commented Jul 21, 2024

Tests have been added

@fatteneder fatteneder removed the needs tests Unit tests are required for this change label Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docsystem The documentation building system REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants