Skip to content

Commit e87c852

Browse files
chore: update to nightly-2025-03-24 (#390)
1 parent 4ef44ca commit e87c852

File tree

8 files changed

+175
-31
lines changed

8 files changed

+175
-31
lines changed

.vale/styles/config/ignore/terms.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ iterator
7979
iterator's
8080
iterators
8181
letterlike
82+
linearize
83+
linearizing
84+
linearization
8285
lookup
8386
lookups
8487
macro_rules

Manual/BasicTypes/Array.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ tag := "array-api"
189189

190190
{docstring Array.ofFn}
191191

192-
{docstring Array.mkArray}
192+
{docstring Array.replicate}
193193

194194
{docstring Array.append}
195195

Manual/BuildTools/Lake/Config.lean

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ name = "example-package"
155155
nativeLibDir := FilePath.mk "lib",
156156
binDir := FilePath.mk "bin",
157157
irDir := FilePath.mk "ir",
158-
releaseRepo? := none,
159158
releaseRepo := none,
160-
buildArchive? := none,
161159
buildArchive := ELIDED,
162160
preferReleaseBuild := false,
163161
testDriver := "",
@@ -184,6 +182,7 @@ name = "example-package"
184182
scripts := {},
185183
defaultScripts := #[],
186184
postUpdateHooks := #[],
185+
buildArchive := ELIDED,
187186
testDriver := "",
188187
lintDriver := ""}
189188
```
@@ -230,9 +229,7 @@ name = "Sorting"
230229
nativeLibDir := FilePath.mk "lib",
231230
binDir := FilePath.mk "bin",
232231
irDir := FilePath.mk "ir",
233-
releaseRepo? := none,
234232
releaseRepo := none,
235-
buildArchive? := none,
236233
buildArchive := ELIDED,
237234
preferReleaseBuild := false,
238235
testDriver := "",
@@ -310,6 +307,7 @@ name = "Sorting"
310307
scripts := {},
311308
defaultScripts := #[],
312309
postUpdateHooks := #[],
310+
buildArchive := ELIDED,
313311
testDriver := "",
314312
lintDriver := ""}
315313
```

Manual/Elaboration.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Manual.Papers
1111
open Verso.Genre Manual
1212

1313
set_option pp.rawOnError true
14+
set_option guard_msgs.diff true
1415

1516
open Lean (Syntax SourceInfo)
1617

@@ -183,7 +184,7 @@ example (b : B) : ⟨b.1, b.2⟩ = b := rfl
183184
error: type mismatch
184185
rfl
185186
has type
186-
?m.714 = ?m.714 : Prop
187+
?m.724 = ?m.724 : Prop
187188
but is expected to have type
188189
e1 = e2 : Prop
189190
-/

Manual/Language/InductiveTypes/Structures.lean

Lines changed: 150 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ open Verso.Genre Manual
1212

1313
open Lean.Parser.Command («inductive» «structure» declValEqns computedField)
1414

15+
set_option guard_msgs.diff true
16+
1517
#doc (Manual) "Structure Declarations" =>
1618
%%%
1719
tag := "structures"
@@ -316,11 +318,21 @@ tag := "structure-inheritance"
316318
Structures may be declared as extending other structures using the optional {keywordOf Lean.Parser.Command.declaration (parser:=«structure»)}`extends` clause.
317319
The resulting structure type has all of the fields of all of the parent structure types.
318320
If the parent structure types have overlapping field names, then all overlapping field names must have the same type.
319-
If the overlapping fields have different default values, then the default value from the last parent structure that includes the field is used.
320-
New default values in the child structure take precedence over default values from the parent structures.
321+
322+
The resulting structure has a {deftech}_field resolution order_ that affects the values of fields.
323+
When possible, this resolution order is the [C3 linearization](https://en.wikipedia.org/wiki/C3_linearization) of the structure's parents.
324+
Essentially, the field resolution order should be a total ordering of the entire set of parents such that every {keywordOf Lean.Parser.Command.declaration (parser:=«structure»)}`extends` list is in order.
325+
When there is no C3 linearization, a heuristic is used to find an order nonetheless.
326+
Every structure type is first in its own field resolution order.
327+
328+
The field resolution order is used to compute the default values of optional fields.
329+
When the value of a field is not specified, the first default value defined in the resolution order is used.
330+
References to fields in the default value use the field resolution order as well; this means that child structures that override default fields of parent constructors may also change the computed default values of parent fields.
331+
Because the child structure is the first element of its own resolution order, default values in the child structure take precedence over default values from the parent structures.
321332

322333
```lean (show := false) (keep := false)
323-
-- If the overlapping fields have different default values, then the default value from the last parent structure that includes the field is used.
334+
-- If the overlapping fields have different default values, then the default value from the first
335+
-- parent structure in the resolution order that includes the field is used.
324336
structure Q where
325337
x : Nat := 0
326338
deriving Repr
@@ -332,24 +344,83 @@ deriving Repr
332344
structure Q''' extends Q', Q
333345
deriving Repr
334346

335-
/-- info: 3 -/
347+
/--
348+
info: structure Q'' : Type
349+
number of parameters: 0
350+
parents:
351+
Q''.toQ : Q
352+
Q''.toQ' : Q'
353+
fields:
354+
Q.x : Nat :=
355+
0
356+
constructor:
357+
Q''.mk (toQ : Q) : Q''
358+
field notation resolution order:
359+
Q'', Q, Q'
360+
-/
336361
#guard_msgs in
337-
#eval ({} : Q'').x
362+
#print Q''
363+
338364
/-- info: 0 -/
339365
#guard_msgs in
366+
#eval ({} : Q'').x
367+
368+
/--
369+
info: structure Q''' : Type
370+
number of parameters: 0
371+
parents:
372+
Q'''.toQ' : Q'
373+
Q'''.toQ : Q
374+
fields:
375+
Q'.x : Nat :=
376+
3
377+
constructor:
378+
Q'''.mk (toQ' : Q') : Q'''
379+
field notation resolution order:
380+
Q''', Q', Q
381+
-/
382+
#guard_msgs in
383+
#print Q'''
384+
385+
/-- info: 3 -/
386+
#guard_msgs in
340387
#eval ({} : Q''').x
388+
389+
-- Defaults use local values
390+
structure A where
391+
n : Nat := 0
392+
deriving Repr
393+
structure B extends A where
394+
k : Nat := n
395+
deriving Repr
396+
structure C extends A where
397+
n := 5
398+
deriving Repr
399+
structure C' extends A where
400+
n := 3
401+
deriving Repr
402+
403+
structure D extends B, C, C'
404+
deriving Repr
405+
structure D' extends B, C', C
406+
deriving Repr
407+
408+
#eval ({} : D).k
409+
410+
#eval ({} : D').k
411+
341412
```
342413

343414
When the new structure extends existing structures, the new structure's constructor takes the existing structure's information as additional arguments.
344415
Typically, this is in the form of a constructor parameter for each parent structure type.
345416
This parent value contains all of the parent's fields.
346417
If the parents' fields overlap, however, then the subset of non-overlapping fields from one or more of the parents is included instead of an entire value of the parent structure to prevent duplicating field information.
347418

348-
349419
There is no subtyping relation between a parent structure type and its children.
350420
Even if structure `B` extends structure `A`, a function expecting an `A` will not accept a `B`.
351421
However, conversion functions are generated that convert a structure into each of its parents.
352-
These conversion functions are in the child structure's namespace, and their name is the parent structure's name preceded by `to`.
422+
These conversion functions are called {deftech}_parent projections_.
423+
Parent projections are in the child structure's namespace, and their name is the parent structure's name preceded by `to`.
353424

354425
::: example "Structure type inheritance with overlapping fields"
355426
In this example, a {lean}`Textbook` is a {lean}`Book` that is also an {lean}`AcademicWork`:
@@ -518,14 +589,85 @@ structure E extends A, B where
518589
#guard_msgs in
519590
#check E.mk
520591
/--
521-
error: parent field type mismatch, field 'x' from parent 'A'' has type
592+
error: field type mismatch, field 'x' from parent 'A'' has type
522593
Int : Type
523594
but is expected to have type
524595
Nat : Type
525596
-/
526597
#guard_msgs in
527598
structure F extends A, A' where
528599

600+
```
601+
602+
603+
The {keywordOf Lean.Parser.Command.print}`#print` command displays the most important information about structure types, including the {tech}[parent projections], all the fields with their default values, the constructor, and the {tech}[field resolution order].
604+
When working with deep hierarchies that contain inheritance diamonds, this information can be very useful.
529605

606+
::: example "{keyword}`#print` and Structure Types"
530607

608+
This collection of structure types models a variety of bicycles, both electric and non-electric and both ordinary-sized and large family bicycles.
609+
The final structure type, {lean}`ElectricFamilyBike`, contains a diamond in its inheritance graph, because both {lean}`FamilyBike` and {lean}`ElectricBike` extend {lean}`Bicycle`.
610+
611+
```lean
612+
structure Vehicle where
613+
wheels : Nat
614+
615+
structure Bicycle extends Vehicle where
616+
wheels := 2
617+
618+
structure ElectricVehicle extends Vehicle where
619+
batteries : Nat := 1
620+
621+
structure FamilyBike extends Bicycle where
622+
wheels := 3
623+
624+
structure ElectricBike extends Bicycle, ElectricVehicle
625+
626+
structure ElectricFamilyBike
627+
extends FamilyBike, ElectricBike where
628+
batteries := 2
629+
```
630+
631+
The {keywordOf Lean.Parser.Command.print}`#print` command displays the important information about each structure type:
632+
```lean (name := el)
633+
#print ElectricBike
634+
```
635+
```leanOutput el
636+
structure ElectricBike : Type
637+
number of parameters: 0
638+
parents:
639+
ElectricBike.toBicycle : Bicycle
640+
ElectricBike.toElectricVehicle : ElectricVehicle
641+
fields:
642+
Vehicle.wheels : Nat :=
643+
2
644+
ElectricVehicle.batteries : Nat :=
645+
1
646+
constructor:
647+
ElectricBike.mk (toBicycle : Bicycle) (batteries : Nat) : ElectricBike
648+
field notation resolution order:
649+
ElectricBike, Bicycle, ElectricVehicle, Vehicle
650+
```
651+
652+
An {lean}`ElectricFamilyBike` has three wheels by default because {lean}`FamilyBike` precedes {lean}`Bicycle` in its resolution order:
653+
```lean (name := elFam)
654+
#print ElectricFamilyBike
655+
```
656+
```leanOutput elFam
657+
structure ElectricFamilyBike : Type
658+
number of parameters: 0
659+
parents:
660+
ElectricFamilyBike.toFamilyBike : FamilyBike
661+
ElectricFamilyBike.toElectricBike : ElectricBike
662+
fields:
663+
Vehicle.wheels : Nat :=
664+
3
665+
ElectricVehicle.batteries : Nat :=
666+
2
667+
constructor:
668+
ElectricFamilyBike.mk (toFamilyBike : FamilyBike) (batteries : Nat) : ElectricFamilyBike
669+
field notation resolution order:
670+
ElectricFamilyBike, FamilyBike, ElectricBike, Bicycle, ElectricVehicle, Vehicle
531671
```
672+
673+
:::

0 commit comments

Comments
 (0)