This PR changes how fields are elaborated in the `structure`/`class` commands and also makes default values respect the structure resolution order when there is diamond inheritance. Before, the details of subobjects were exposed during elaboration, and in the local context any fields that came from a subobject were defined to be projections of the subobject field. Now, every field is represented as a local variable. All parents (not just subobject parents) are now represented in the local context, and they are now local variables defined to be parent constructors applied to field variables (inverting the previous relationship). Other notes: - The entire collection of parents is processed, and all parent projection names are checked for consistency. Every parent appears in the local context now. - For classes, every parent now contributes an instance, not just the parents represented as subobjects. - Default values are now processed according to the parent resolution order. Default value definition/override auxiliary definitions are stored at `StructName.fieldName._default`, and inherited values are stored at `StructName.fieldName._inherited_default`. Metaprograms no longer need to look at parents when doing calculations on default values. - Default value omission for structure instance notation pretty printing has been updated in consideration of this. - Now the elaborator generates a `_flat_ctor` constructor that will be used for structure instance elaboration. All types in this constructor are put in "field normal form" (projections of parent constructors are reduced, and parent constructors are eta reduced), and all fields with autoParams are annotated as such. This is not meant for users, but it may be useful for metaprogramming. - While elaborating fields, any metavariables whose type is one of the parents is assigned to that parent. The hypothesis is that, for the purpose of elaborating structure fields, parents are fixed: there is only *one* instance of any given parent under consideration. See the `Magma` test for an example of this being necessary. The hypothesis may not be true when there are recursive structures, since different values of the structure might not agree on parent fields. Other notes: - The elaborator has been refactored, and it now uses a monad to keep track of the elaboration state. - This PR was motivation for #7100, since we need to be able to make all parents have consistent projection names when there is diamond inheritance. Still to do: - Handle autoParams like we do default values. Inheritance for these is not correct when there is diamond inheritance. - Avoid splitting apart parents if the overlap is only on proof fields. - Non-subobject parent projections do not have parameter binder kinds that are consistent with other projections (i.e., all implicit by default, no inst implicits). This needs to wait on adjustments to the synthOrder algorithm. - We could elide parents with no fields, letting their projections be constant functions. This causes some trouble for defeq checking however (maybe #2258 would address this).
33 lines
1.5 KiB
Text
33 lines
1.5 KiB
Text
struct1.lean:9:14-9:17: error: invalid resulting type, expecting 'Type _' or 'Prop'
|
|
struct1.lean:12:20-12:29: error: expected structure
|
|
|
|
This error is possibly due to a change in the 'structure' syntax. Now the syntax is 'structure S : Type extends P' rather than 'structure S extends P' : Type'.
|
|
|
|
The purpose of the change is to accommodate 'structure S extends toP : P' syntax for naming parent projections.
|
|
struct1.lean:15:28-15:33: warning: field 'x' from 'B' has already been declared
|
|
struct1.lean:16:1-16:2: error: field 'x' has been declared in parent structure
|
|
struct1.lean:17:30-17:35: warning: duplicate parent structure 'A', skipping
|
|
struct1.lean:19:27-19:33: error: field type mismatch, field 'x' from parent 'B' has type
|
|
Bool : Type
|
|
but is expected to have type
|
|
Nat : Type
|
|
struct1.lean:30:1-30:2: error: field 'x' has already been declared
|
|
struct1.lean:33:1-33:2: error: field 'x' has been declared in parent structure
|
|
struct1.lean:36:6-36:10: error: type mismatch
|
|
true
|
|
has type
|
|
Bool : Type
|
|
but is expected to have type
|
|
Nat : Type
|
|
struct1.lean:39:5-39:9: error: omit field 'x' type to set default value
|
|
struct1.lean:42:12-42:16: error: type mismatch
|
|
true
|
|
has type
|
|
Bool : Type
|
|
but is expected to have type
|
|
Nat : Type
|
|
struct1.lean:45:0-45:13: error: invalid 'private' constructor in a 'private' structure
|
|
struct1.lean:48:0-48:15: error: invalid 'protected' constructor in a 'private' structure
|
|
struct1.lean:51:0-51:19: error: invalid 'protected' field in a 'private' structure
|
|
S : Type
|
|
S.mk2 (x : Nat) : S
|