Equations
- Lean.Elab.Term.StructInst.expandStructInstExpectedType stx = let expectedArg := Lean.Syntax.getOp stx 4; if Lean.Syntax.isNone expectedArg = true then Lean.Macro.throwUnsupported else let expected := Lean.Syntax.getOp expectedArg 1; let stxNew := Lean.Syntax.setArg stx 4 Lean.mkNullNode; do let info ← Lean.MonadRef.mkInfoFromRefPos let _ ← Lean.getCurrMacroScope let _ ← Lean.getMainModule pure (Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.paren #[Lean.Syntax.atom info "(", Lean.Syntax.node Lean.SourceInfo.none `null #[stxNew, Lean.Syntax.node Lean.SourceInfo.none `null #[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.typeAscription #[Lean.Syntax.atom info ":", expected]]], Lean.Syntax.atom info ")"])
Equations
- Lean.Elab.Term.StructInst.expandStructInstFieldAbbrev stx = if Array.any (Lean.Syntax.getArgs (Lean.Syntax.getOp stx 2)) (fun arg => Lean.Syntax.getKind (Lean.Syntax.getOp arg 0) == `Lean.Parser.Term.structInstFieldAbbrev) 0 (Array.size (Lean.Syntax.getArgs (Lean.Syntax.getOp stx 2))) = true then do let fieldsNew ← Array.mapM (fun stx => let field := Lean.Syntax.getOp stx 0; if (Lean.Syntax.getKind field == `Lean.Parser.Term.structInstFieldAbbrev) = true then let id := Lean.Syntax.getOp field 0; do let fieldNew ← do let info ← Lean.MonadRef.mkInfoFromRefPos let _ ← Lean.getCurrMacroScope let _ ← Lean.getMainModule pure (Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.structInstField #[Lean.Syntax.node Lean.SourceInfo.none `Lean.Parser.Term.structInstLVal #[id, Lean.Syntax.node Lean.SourceInfo.none `null #[]], Lean.Syntax.atom info ":=", id]) pure (Lean.Syntax.setArg stx 0 fieldNew) else pure stx) (Lean.Syntax.getArgs (Lean.Syntax.getOp stx 2)) pure (Lean.Syntax.setArg stx 2 (Lean.mkNullNode fieldsNew)) else Lean.Macro.throwUnsupported
- stx : Lean.Syntax
- structName : Lean.Name
Equations
- Lean.Elab.Term.StructInst.instInhabitedExplicitSourceInfo = { default := { stx := default, structName := default } }
Equations
- Lean.Elab.Term.StructInst.Source.isNone x = match x with | Lean.Elab.Term.StructInst.Source.none => true | x => false
- fieldName: Lean.Syntax → Lean.Name → Lean.Elab.Term.StructInst.FieldLHS
- fieldIndex: Lean.Syntax → Nat → Lean.Elab.Term.StructInst.FieldLHS
- modifyOp: Lean.Syntax → Lean.Syntax → Lean.Elab.Term.StructInst.FieldLHS
Equations
- Lean.Elab.Term.StructInst.instInhabitedFieldLHS = { default := Lean.Elab.Term.StructInst.FieldLHS.fieldName default default }
Equations
- Lean.Elab.Term.StructInst.instToFormatFieldLHS = { format := fun lhs => match lhs with | Lean.Elab.Term.StructInst.FieldLHS.fieldName x n => Lean.format n | Lean.Elab.Term.StructInst.FieldLHS.fieldIndex x i => Lean.format i | Lean.Elab.Term.StructInst.FieldLHS.modifyOp x i => Std.Format.text "[" ++ Lean.Syntax.prettyPrint i ++ Std.Format.text "]" }
- term: {σ : Type} → Lean.Syntax → Lean.Elab.Term.StructInst.FieldVal σ
- nested: {σ : Type} → σ → Lean.Elab.Term.StructInst.FieldVal σ
- default: {σ : Type} → Lean.Elab.Term.StructInst.FieldVal σ
instance
Lean.Elab.Term.StructInst.instInhabitedFieldVal
:
{a : Type} → Inhabited (Lean.Elab.Term.StructInst.FieldVal a)
Equations
- Lean.Elab.Term.StructInst.instInhabitedFieldVal = { default := Lean.Elab.Term.StructInst.FieldVal.term default }
- ref : Lean.Syntax
- lhs : List Lean.Elab.Term.StructInst.FieldLHS
- val : Lean.Elab.Term.StructInst.FieldVal σ
- expr? : Option Lean.Expr
instance
Lean.Elab.Term.StructInst.instInhabitedField
:
{a : Type} → Inhabited (Lean.Elab.Term.StructInst.Field a)
Equations
- Lean.Elab.Term.StructInst.instInhabitedField = { default := { ref := default, lhs := default, val := default, expr? := default } }
Equations
- Lean.Elab.Term.StructInst.Field.isSimple x = match x with | { ref := x_1, lhs := [x], val := x_2, expr? := x_3 } => true | x => false
Equations
- Lean.Elab.Term.StructInst.instInhabitedStruct = { default := Lean.Elab.Term.StructInst.Struct.mk default default default default }
@[inline]
Equations
- Lean.Elab.Term.StructInst.Struct.ref x = match x with | Lean.Elab.Term.StructInst.Struct.mk ref x x_1 x_2 => ref
Equations
- Lean.Elab.Term.StructInst.Struct.structName x = match x with | Lean.Elab.Term.StructInst.Struct.mk x structName x_1 x_2 => structName
Equations
- Lean.Elab.Term.StructInst.Struct.fields x = match x with | Lean.Elab.Term.StructInst.Struct.mk x x_1 fields x_2 => fields
Equations
- Lean.Elab.Term.StructInst.Struct.source x = match x with | Lean.Elab.Term.StructInst.Struct.mk x x_1 x_2 s => s
def
Lean.Elab.Term.StructInst.formatField
(formatStruct : Lean.Elab.Term.StructInst.Struct → Lean.Format)
(field : Lean.Elab.Term.StructInst.Field Lean.Elab.Term.StructInst.Struct)
:
Equations
-
Lean.Elab.Term.StructInst.formatField formatStruct field = Lean.Format.joinSep field.lhs (Std.Format.text " . ") ++ Std.Format.text " := " ++ match field.val with
| Lean.Elab.Term.StructInst.FieldVal.term v => Lean.Syntax.prettyPrint v
| Lean.Elab.Term.StructInst.FieldVal.nested s => formatStruct s
| Lean.Elab.Term.StructInst.FieldVal.default => Std.Format.text "
"
Equations
- Lean.Elab.Term.StructInst.instToStringStruct = { toString := toString ∘ Lean.format }
Equations
- Lean.Elab.Term.StructInst.instToStringFieldStruct = { toString := toString ∘ Lean.format }
Equations
- Lean.Elab.Term.StructInst.FieldLHS.toSyntax first x = match x with | Lean.Elab.Term.StructInst.FieldLHS.modifyOp stx x => stx | Lean.Elab.Term.StructInst.FieldLHS.fieldName stx name => if first = true then Lean.mkIdentFrom stx name else Lean.mkGroupNode #[Lean.mkAtomFrom stx ".", Lean.mkIdentFrom stx name] | Lean.Elab.Term.StructInst.FieldLHS.fieldIndex stx x => if first = true then stx else Lean.mkGroupNode #[Lean.mkAtomFrom stx ".", stx]
Equations
- Lean.Elab.Term.StructInst.FieldVal.toSyntax x = match x with | Lean.Elab.Term.StructInst.FieldVal.term stx => stx | x => panicWithPosWithDecl "Lean.Elab.StructInst" "Lean.Elab.Term.StructInst.FieldVal.toSyntax" 319 25 "unreachable code has been reached"
Equations
- Lean.Elab.Term.StructInst.Field.toSyntax x = let field := x; let stx := field.ref; let stx := Lean.Syntax.setArg stx 2 (Lean.Elab.Term.StructInst.FieldVal.toSyntax field.val); match field.lhs with | first :: rest => Lean.Syntax.setArg stx 0 (Lean.mkNullNode #[Lean.Elab.Term.StructInst.FieldLHS.toSyntax true first, Lean.mkNullNode (Array.map (Lean.Elab.Term.StructInst.FieldLHS.toSyntax false) (List.toArray rest))]) | x => panicWithPosWithDecl "Lean.Elab.StructInst" "Lean.Elab.Term.StructInst.Field.toSyntax" 327 11 "unreachable code has been reached"
def
Lean.Elab.Term.StructInst.Struct.modifyFieldsM
{m : Type → Type}
[inst : Monad m]
(s : Lean.Elab.Term.StructInst.Struct)
(f : Lean.Elab.Term.StructInst.Fields → m Lean.Elab.Term.StructInst.Fields)
:
Equations
- Lean.Elab.Term.StructInst.Struct.modifyFieldsM s f = match s with | Lean.Elab.Term.StructInst.Struct.mk ref structName fields source => do let a ← f fields pure (Lean.Elab.Term.StructInst.Struct.mk ref structName a source)
def
Lean.Elab.Term.StructInst.Struct.setFields
(s : Lean.Elab.Term.StructInst.Struct)
(fields : Lean.Elab.Term.StructInst.Fields)
:
Equations
- Lean.Elab.Term.StructInst.Struct.setFields s fields = Lean.Elab.Term.StructInst.Struct.modifyFields s fun x => fields
def
Lean.Elab.Term.StructInst.mkProjStx?
(s : Lean.Syntax)
(structName : Lean.Name)
(fieldName : Lean.Name)
:
Equations
- Lean.Elab.Term.StructInst.mkProjStx? s structName fieldName = do let a ← Lean.getEnv let a ← pure (Lean.findField? a structName fieldName) let _do_jp : PUnit → Lean.Elab.TermElabM (Option Lean.Syntax) := fun y => pure (some (Lean.mkNode `Lean.Parser.Term.proj #[s, Lean.mkAtomFrom s ".", Lean.mkIdentFrom s fieldName])) if Option.isNone a = true then pure none else do let y ← pure PUnit.unit _do_jp y
def
Lean.Elab.Term.StructInst.findField?
(fields : Lean.Elab.Term.StructInst.Fields)
(fieldName : Lean.Name)
:
Equations
- Lean.Elab.Term.StructInst.findField? fields fieldName = List.find? (fun field => match field.lhs with | [Lean.Elab.Term.StructInst.FieldLHS.fieldName x n] => n == fieldName | x => false) fields
- ctorFn : Lean.Expr
- ctorFnType : Lean.Expr
- instMVars : Array Lean.MVarId
Equations
- Lean.Elab.Term.StructInst.markDefaultMissing e = Lean.mkAnnotation `structInstDefault e
Equations
- Lean.Elab.Term.StructInst.defaultMissing? e = Lean.annotation? `structInstDefault e
def
Lean.Elab.Term.StructInst.throwFailedToElabField
{α : Type}
(fieldName : Lean.Name)
(structName : Lean.Name)
(msgData : Lean.MessageData)
:
Equations
- Lean.Elab.Term.StructInst.throwFailedToElabField fieldName structName msgData = Lean.throwError (Lean.toMessageData "failed to elaborate field '" ++ Lean.toMessageData fieldName ++ Lean.toMessageData "' of '" ++ Lean.toMessageData structName ++ Lean.toMessageData ", " ++ Lean.toMessageData msgData ++ Lean.toMessageData "")
def
Lean.Elab.Term.StructInst.trySynthStructInstance?
(s : Lean.Elab.Term.StructInst.Struct)
(expectedType : Lean.Expr)
:
Equations
- Lean.Elab.Term.StructInst.trySynthStructInstance? s expectedType = if (!Lean.Elab.Term.StructInst.Struct.allDefault s) = true then pure none else tryCatch (liftM (Lean.Meta.synthInstance? expectedType none)) fun x => pure none
- structs : Array Lean.Elab.Term.StructInst.Struct
- allStructNames : Array Lean.Name
- maxDistance : Nat
partial def
Lean.Elab.Term.StructInst.DefaultFields.collectStructNames
(struct : Lean.Elab.Term.StructInst.Struct)
(names : Array Lean.Name)
:
partial def
Lean.Elab.Term.StructInst.DefaultFields.getHierarchyDepth
(struct : Lean.Elab.Term.StructInst.Struct)
:
def
Lean.Elab.Term.StructInst.DefaultFields.getFieldName
(field : Lean.Elab.Term.StructInst.Field Lean.Elab.Term.StructInst.Struct)
:
Equations
- Lean.Elab.Term.StructInst.DefaultFields.getFieldName field = match field.lhs with | [Lean.Elab.Term.StructInst.FieldLHS.fieldName x fieldName] => fieldName | x => panicWithPosWithDecl "Lean.Elab.StructInst" "Lean.Elab.Term.StructInst.DefaultFields.getFieldName" 708 9 "unreachable code has been reached"
def
Lean.Elab.Term.StructInst.DefaultFields.getFieldValue?
(struct : Lean.Elab.Term.StructInst.Struct)
(fieldName : Lean.Name)
:
Equations
- Lean.Elab.Term.StructInst.DefaultFields.getFieldValue? struct fieldName = List.findSome? (fun field => if (Lean.Elab.Term.StructInst.DefaultFields.getFieldName field == fieldName) = true then field.expr? else none) (Lean.Elab.Term.StructInst.Struct.fields struct)
partial def
Lean.Elab.Term.StructInst.DefaultFields.mkDefaultValueAux?
(struct : Lean.Elab.Term.StructInst.Struct)
:
def
Lean.Elab.Term.StructInst.DefaultFields.mkDefaultValue?
(struct : Lean.Elab.Term.StructInst.Struct)
(cinfo : Lean.ConstantInfo)
:
Equations
- Lean.Elab.Term.StructInst.DefaultFields.mkDefaultValue? struct cinfo = Lean.withRef (Lean.Elab.Term.StructInst.Struct.ref struct) do let us ← liftM (Lean.Meta.mkFreshLevelMVarsFor cinfo) Lean.Elab.Term.StructInst.DefaultFields.mkDefaultValueAux? struct (Lean.ConstantInfo.instantiateValueLevelParams cinfo us)
partial def
Lean.Elab.Term.StructInst.DefaultFields.reduce
(structNames : Array Lean.Name)
(e : Lean.Expr)
:
def
Lean.Elab.Term.StructInst.DefaultFields.tryToSynthesizeDefault
(structs : Array Lean.Elab.Term.StructInst.Struct)
(allStructNames : Array Lean.Name)
(maxDistance : Nat)
(fieldName : Lean.Name)
(mvarId : Lean.MVarId)
:
Equations
- Lean.Elab.Term.StructInst.DefaultFields.tryToSynthesizeDefault structs allStructNames maxDistance fieldName mvarId = (fun loop => loop 0 0) (Lean.Elab.Term.StructInst.DefaultFields.tryToSynthesizeDefault.loop structs allStructNames maxDistance fieldName mvarId)
partial def
Lean.Elab.Term.StructInst.DefaultFields.tryToSynthesizeDefault.loop
(structs : Array Lean.Elab.Term.StructInst.Struct)
(allStructNames : Array Lean.Name)
(maxDistance : Nat)
(fieldName : Lean.Name)
(mvarId : Lean.MVarId)
(i : Nat)
(dist : Nat)
:
partial def
Lean.Elab.Term.StructInst.DefaultFields.propagateLoop
(hierarchyDepth : Nat)
(d : Nat)
(struct : Lean.Elab.Term.StructInst.Struct)
:
Equations
- Lean.Elab.Term.StructInst.DefaultFields.propagate struct = let hierarchyDepth := Lean.Elab.Term.StructInst.DefaultFields.getHierarchyDepth struct; let structNames := Lean.Elab.Term.StructInst.DefaultFields.collectStructNames struct #[]; StateRefT'.run' (Lean.Elab.Term.StructInst.DefaultFields.propagateLoop hierarchyDepth 0 struct { structs := #[], allStructNames := structNames, maxDistance := 0 }) { progress := false }
Equations
-
Lean.Elab.Term.StructInst.elabStructInst stx expectedType? = do
let a ← Lean.Elab.Term.StructInst.expandNonAtomicExplicitSources stx
match a with
| some stxNew =>
Lean.Elab.Term.withMacroExpansion stx stxNew (Lean.Elab.Term.elabTerm stxNew expectedType? true true)
| none => do
let sourceView ← Lean.Elab.Term.StructInst.getStructSource stx
let a ← Lean.Elab.Term.StructInst.isModifyOp? stx
match a, sourceView with
| some modifyOp, Lean.Elab.Term.StructInst.Source.explicit sources =>
Lean.Elab.Term.StructInst.elabModifyOp stx modifyOp sources expectedType?
| some x, x_1 =>
Lean.throwError
(Lean.toMessageData "invalid {...} notation, explicit source is required when using '[
] := ) | x, x_1 => Lean.Elab.Term.StructInst.elabStructInstAux stx expectedType? sourceView'"