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

docs: include summarized information in the extended documentation mode #57108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aviatesk
Copy link
Member

@aviatesk aviatesk commented Jan 20, 2025

When a binding does not have documentation, we return the result of summarize(::Binding) as fallback documentation. While this summary itself is often quite useful, it is not displayed when the binding does have documentation, e.g. help?> Base.Compiler.InferenceResult:

help?> Base.Compiler.InferenceResult
  ...

  result::InferenceResult

  A type that represents the result of running type inference on a chunk of code. There are two constructor available:InferenceResult(mi::MethodInstance, [𝕃::AbstractLattice]) for regular inference, without extended lattice information included in result.argtypes.
    •  InferenceResult(mi::MethodInstance, argtypes::Vector{Any}, overridden_by_const::BitVector) for constant inference, with extended lattice information included in
       result.argtypes.

I believe allowing summary information to be included someway could be useful, so this commit modifies the behavior in extended documentation mode to include the result of summarize at the end of the documentation. Now help?> ?Base.Compiler.InferenceResult would look like:

help?> ?Base.Compiler.InferenceResult
  ... # the same contents as what rendered in the regular documentation mode

  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  Extended information found for private binding Compiler.InferenceResult.

  Summary
  ≡≡≡≡≡≡≡

  mutable struct Compiler.InferenceResult

  Fields
  ≡≡≡≡≡≡

  linfo               :: Core.MethodInstance
  argtypes            :: Vector{Any}
  overridden_by_const :: Union{Nothing, BitVector}
  result              :: Any
  exc_result          :: Any
  src                 :: Any
  valid_worlds        :: Compiler.WorldRange
  ipo_effects         :: Compiler.Effects
  effects             :: Compiler.Effects
  analysis_results    :: Compiler.AnalysisResults
  is_src_volatile     :: Bool
  ci                  :: Core.CodeInstance
  ci_as_edge          :: Core.CodeInstance

Note that it only changes the behavior of the extended documentation mode within REPL, and the existing behavior of @doc outside of REPL doesn't change at all.

Additionally, this commit refactors the internal implementation of the help mode in REPL.jl to improve extensibility for future enhancements.

When a binding does not have documentation, we return the result of
`summarize(::Binding)` as fallback documentation. While this summary
itself is often quite useful, it is not displayed when the binding does
have documentation, e.g. `help?> Base.Compiler.InferenceResult`:
```julia
help?> Base.Compiler.InferenceResult
  ...

  result::InferenceResult

  A type that represents the result of running type inference on a chunk of code. There are two constructor available:

    •  InferenceResult(mi::MethodInstance, [𝕃::AbstractLattice]) for regular inference, without extended lattice information included in result.argtypes.
    •  InferenceResult(mi::MethodInstance, argtypes::Vector{Any}, overridden_by_const::BitVector) for constant inference, with extended lattice information included in
       result.argtypes.
```
I believe allowing summary information to be included someway could be
useful, so this commit modifies the behavior in extended documentation
mode to include the result of `summarize` at the end of the documentation.
Now ``help?> ?Base.Compiler.InferenceResult`` would look like:
```julia
help?> ?Base.Compiler.InferenceResult
  ... # the same contents as what rendered in the regular documentation mode

  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  Extended information found for private binding Compiler.InferenceResult.

  Summary
  ≡≡≡≡≡≡≡

  mutable struct Compiler.InferenceResult

  Fields
  ≡≡≡≡≡≡

  linfo               :: Core.MethodInstance
  argtypes            :: Vector{Any}
  overridden_by_const :: Union{Nothing, BitVector}
  result              :: Any
  exc_result          :: Any
  src                 :: Any
  valid_worlds        :: Compiler.WorldRange
  ipo_effects         :: Compiler.Effects
  effects             :: Compiler.Effects
  analysis_results    :: Compiler.AnalysisResults
  is_src_volatile     :: Bool
  ci                  :: Core.CodeInstance
  ci_as_edge          :: Core.CodeInstance
```

Additionally, this commit refactors the internal implementation of the
help mode in REPL.jl to improve extensibility for future enhancements.
@aviatesk aviatesk added docs This change adds or pertains to documentation REPL Julia's REPL (Read Eval Print Loop) labels Jan 20, 2025
@aviatesk aviatesk requested a review from JeffBezanson January 20, 2025 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant