Compare commits

...

19 Commits

Author SHA1 Message Date
Paul Reichert
b146691f09 approach 1 *seems* to work 2025-12-04 09:48:06 +01:00
Paul Reichert
145fc0df8f approach 1 2025-12-04 09:27:07 +01:00
Paul Reichert
39ae5c56ca minimize test 2025-12-02 21:00:23 +01:00
Paul Reichert
e040d800c2 minimize 2025-12-02 20:48:17 +01:00
Paul Reichert
9d038a0fa7 minimized problem 2025-12-02 20:43:05 +01:00
Paul Reichert
dd3b827dad Revert "debugging"
This reverts commit 3f82bdf176.
2025-12-02 20:40:20 +01:00
Paul Reichert
3f82bdf176 debugging 2025-12-02 20:40:14 +01:00
Paul Reichert
c33a6ef44b minimize 2025-12-02 20:39:47 +01:00
Paul Reichert
6c5afe9025 fixes and cleanups 2025-12-02 18:08:15 +01:00
Paul Reichert
4dc5544f70 revert the changes in src/Lean 2025-12-02 18:04:22 +01:00
Paul Reichert
81602b87b8 Revert "revert the changes in src/Lean"
This reverts commit 75c70823b5.
2025-12-02 17:44:05 +01:00
Paul Reichert
4a34913e45 why doesn't this work? 2025-12-02 17:36:54 +01:00
Paul Reichert
75c70823b5 revert the changes in src/Lean 2025-12-02 17:11:21 +01:00
Paul Reichert
8d71d99539 make sure stage0 is updated after merging 2025-12-02 17:01:01 +01:00
Paul Reichert
725778780f make the linter more defensive to avoid panics 2025-12-02 16:59:25 +01:00
Paul Reichert
8493245e37 add backticks 2025-12-02 15:58:08 +01:00
Paul Reichert
a9f5920823 write linter 2025-12-02 15:26:42 +01:00
Paul Reichert
c5c159536f fix test and simp 'copy' to 'toArray' 2025-12-02 10:22:59 +01:00
Paul Reichert
191a51674c introduce copy, remove coercion 2025-12-02 10:22:57 +01:00
3 changed files with 48 additions and 4 deletions

View File

@@ -36,17 +36,33 @@ private def resumePostponed (savedContext : SavedContext) (stx : Syntax) (mvarId
withSavedContext savedContext do
let mvarDecl getMVarDecl mvarId
let expectedType instantiateMVars mvarDecl.type
withInfoHole mvarId do
let ret withInfoHole mvarId do
let result resumeElabTerm stx expectedType (!postponeOnError)
/- We must ensure `result` has the expected type because it is the one expected by the method that postponed stx.
That is, the method does not have an opportunity to check whether `result` has the expected type or not. -/
let result withRef stx <| ensureHasType expectedType result
let result do
if ( getInfoState).enabled then
let savedInfoTrees getResetInfoTrees
-- withRef stx <| ensureHasType expectedType result
Prod.fst <$> MonadFinally.tryFinally' (withRef stx <| ensureHasType expectedType result) fun _ => do
modifyInfoState fun state =>
if savedInfoTrees.size > 0 then
let mod (t : InfoTree) : InfoTree :=
match t with
| .node i ts => .node i (ts.append state.trees)
| _ => t -- TODO?
{ state with trees := savedInfoTrees.modify (savedInfoTrees.size - 1) mod }
else
{ state with trees := savedInfoTrees }
else
withRef stx <| ensureHasType expectedType result
/- We must perform `occursCheck` here since `result` may contain `mvarId` when it has synthetic `sorry`s. -/
if ( occursCheck mvarId result) then
mvarId.assign result
return true
else
return false
pure ret
catch
| ex@(.internal id _) =>
if id == postponeExceptionId then

View File

@@ -1183,6 +1183,23 @@ def synthesizeInstMVarCore (instMVar : MVarId) (maxResultSize? : Option Nat := n
else
throwNamedError lean.synthInstanceFailed "failed to synthesize instance of type class{indentExpr type}{extraErrorMsg}{useTraceSynthMsg}"
structure CoeExpansionTrace where
expandedCoeDecls : List Name
deriving TypeName
partial def _root_.Lean.Elab.InfoTree.format' (tree : InfoTree) (ctx? : Option ContextInfo := none) : TermElabM Format := do
match tree with
| .hole id => return .nestD f!"• ?{toString id.name}"
| .context i t => t.format' <| i.mergeIntoOuter? ctx?
| .node i cs =>
let ctx := ctx?.getD { env := ( getEnv), fileMap := ( getFileMap), ngen := NameGenerator.mk `dummy 0 }
let fmt i.format ctx
if cs.size == 0 then
return .nestD f!"• {fmt}"
else
let ctx? := i.updateContext? ctx?
return .nestD f!"• {fmt}{Std.Format.prefixJoin .line (← cs.toList.mapM fun c => c.format' ctx?)}"
def mkCoe (expectedType : Expr) (e : Expr) (f? : Option Expr := none) (errorMsgHeader? : Option String := none)
(mkErrorMsg? : Option (MVarId (expectedType e : Expr) MetaM MessageData) := none)
(mkImmedErrorMsg? : Option ((errorMsg? : Option MessageData) (expectedType e : Expr) MetaM MessageData) := none) : TermElabM Expr := do
@@ -1190,7 +1207,12 @@ def mkCoe (expectedType : Expr) (e : Expr) (f? : Option Expr := none) (errorMsgH
try
withoutMacroStackAtErr do
match coerce? e expectedType with
| .some eNew => return eNew
| .some eNew =>
pushInfoLeaf (.ofCustomInfo {
stx := getRef
value := Dynamic.mk <| CoeExpansionTrace.mk []
})
return eNew
| .none => failure
| .undef =>
let mvarAux mkFreshExprMVar expectedType MetavarKind.syntheticOpaque
@@ -1500,7 +1522,7 @@ private def elabUsingElabFnsAux (s : SavedState) (stx : Syntax) (expectedType? :
| (elabFn::elabFns) =>
try
-- record elaborator in info tree, but only when not backtracking to other elaborators (outer `try`)
withTermInfoContext' elabFn.declName stx (expectedType? := expectedType?)
let ret withTermInfoContext' elabFn.declName stx (expectedType? := expectedType?)
(try
elabFn.value stx expectedType?
catch ex => match ex with
@@ -1533,6 +1555,7 @@ private def elabUsingElabFnsAux (s : SavedState) (stx : Syntax) (expectedType? :
postponeElabTermCore stx expectedType?
else
throw ex)
pure ret
catch ex => match ex with
| .internal id _ =>
if id == unsupportedSyntaxExceptionId then

5
tests/lean/run/test.lean Normal file
View File

@@ -0,0 +1,5 @@
structure X
def X.x (_ : X) : BaseIO Bool := sorry
def f : IO Unit := do
let _ ([] : List X).findM? fun p => p.x