Skip to content

Commit

Permalink
Try type class synthesis as a fallback in type class specialization
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusrossel committed Apr 12, 2024
1 parent e78fe93 commit fe6d991
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Lean/Egg/Core/Gen/TcSpecs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ private partial def genSpecialization (rw : Rewrite) (dir : Direction) (missing
while changed do
changed := false
for var in missing do
if let some inst ← findLocalDeclWithType? (← var.getType) then
var.assign (.fvar inst)
if let some inst ← instanceForType? (← var.getType) then
var.assign inst
missing := missing.erase var
changed := true
let rw ← rw.instantiateMVars
return if rw.validDirs.contains dir then rw else none
where
instanceForType? (type : Expr) : MetaM (Option Expr) := do
if let some inst ← findLocalDeclWithType? type
then return (Expr.fvar inst)
else optional (synthInstance type)

private def genTcSpecializationsForRw (rw : Rewrite) : MetaM Rewrites := do
let missingOnLhs := rw.rhsMVars.tc.subtract rw.lhsMVars.tc
Expand Down
6 changes: 6 additions & 0 deletions Lean/Egg/Tests/WIP.lean
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ example : True := by
-- TODO: If we have a theorem like `(fun a b => a) x y = x`, it's only applicable in the forward
-- direction. But once we β-reduce it, it's applicable in both directions. I think that can
-- cause problems during reconstruction as we cannot reconstruct the assignment of `y`.



-- TODO: Something about tc-specialization isn'T quite working yet.
-- The first calc step in inv_eq_of_mul_eq_one_left should be doable with egg, but no tc-spec
-- is generated.

0 comments on commit fe6d991

Please sign in to comment.