feat: link docstrings for diamond inheritance (#11122)
This PR fixes a problem for structures with diamond inheritance: rather than copying doc-strings (which are not available unless `.server.olean` is loaded), we link to them. Adds tests.
This commit is contained in:
parent
08d0ae1e8a
commit
c7652413db
8 changed files with 55 additions and 2 deletions
|
|
@ -10,6 +10,7 @@ public import Lean.Meta.Structure
|
|||
public import Lean.Elab.MutualInductive
|
||||
import Lean.Linter.Basic
|
||||
import Lean.DocString
|
||||
import Lean.DocString.Extension
|
||||
|
||||
public section
|
||||
|
||||
|
|
@ -661,8 +662,8 @@ private partial def withStructField (view : StructView) (sourceStructNames : Lis
|
|||
let mut declName := view.declName ++ fieldName
|
||||
if inSubobject?.isNone then
|
||||
declName ← applyVisibility (← toModifiers fieldInfo) declName
|
||||
-- No need to validate links because this docstring was already added to the environment previously
|
||||
addDocStringCore' declName (← findDocString? (← getEnv) fieldInfo.projFn)
|
||||
-- Create a link to the parent field's docstring
|
||||
addInheritedDocString declName fieldInfo.projFn
|
||||
addDeclarationRangesFromSyntax declName (← getRef)
|
||||
checkNotAlreadyDeclared declName
|
||||
withLocalDecl fieldName fieldInfo.binderInfo (← reduceFieldProjs fieldType) fun fieldFVar => do
|
||||
|
|
|
|||
2
tests/pkg/structure_docstrings/StructureDocstrings.lean
Normal file
2
tests/pkg/structure_docstrings/StructureDocstrings.lean
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import StructureDocstrings.A
|
||||
import StructureDocstrings.B
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
module
|
||||
|
||||
public section
|
||||
|
||||
class Monoid (M : Type) extends Mul M where
|
||||
|
||||
class DivInvMonoid (G : Type) extends Mul G where
|
||||
/-- The power operation: `a ^ n = a * ··· * a`; `a ^ (-n) = a⁻¹ * ··· a⁻¹` (`n` times) -/
|
||||
protected zpow : Int → G → G
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
module
|
||||
|
||||
public import StructureDocstrings.A
|
||||
|
||||
public section
|
||||
|
||||
class GroupWithZero (G : Type) extends Monoid G, DivInvMonoid G where
|
||||
15
tests/pkg/structure_docstrings/StructureDocstrings/C.lean
Normal file
15
tests/pkg/structure_docstrings/StructureDocstrings/C.lean
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
module
|
||||
|
||||
import Lean.DocString
|
||||
import Lean.Meta.Basic
|
||||
public import StructureDocstrings.B
|
||||
|
||||
public section
|
||||
|
||||
/-- info: The power operation: `a ^ n = a * ··· * a`; `a ^ (-n) = a⁻¹ * ··· a⁻¹` (`n` times) -/
|
||||
#guard_msgs in
|
||||
open Lean in
|
||||
run_meta do
|
||||
let env ← getEnv
|
||||
let some r ← Lean.findDocString? env `GroupWithZero.zpow | failure
|
||||
logInfo r
|
||||
13
tests/pkg/structure_docstrings/lakefile.toml
Normal file
13
tests/pkg/structure_docstrings/lakefile.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
name = "structure_docstrings"
|
||||
defaultTargets = ["StructureDocstrings", "StructureDocstringsTest"]
|
||||
|
||||
[[lean_lib]]
|
||||
name = "StructureDocstrings"
|
||||
leanOptions = { experimental.module = true }
|
||||
roots = ["StructureDocstrings.A", "StructureDocstrings.B"]
|
||||
|
||||
[[lean_lib]]
|
||||
name = "StructureDocstringsTest"
|
||||
# Elab.inServer to allow docstring tests to access .server level data
|
||||
leanOptions = { experimental.module = true, Elab.inServer = true }
|
||||
roots = ["StructureDocstrings.C"]
|
||||
1
tests/pkg/structure_docstrings/lean-toolchain
Normal file
1
tests/pkg/structure_docstrings/lean-toolchain
Normal file
|
|
@ -0,0 +1 @@
|
|||
lean4-2
|
||||
5
tests/pkg/structure_docstrings/test.sh
Executable file
5
tests/pkg/structure_docstrings/test.sh
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
rm -rf .lake/build
|
||||
LEAN_ABORT_ON_PANIC=1 lake build
|
||||
Loading…
Add table
Reference in a new issue