-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13ffcb8
commit 39a1128
Showing
23 changed files
with
230 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Egg.Core.Rewrites.Basic | ||
import Std.Tactic.Exact | ||
import Lean | ||
open Lean Meta | ||
|
||
namespace Egg | ||
|
||
private partial def genSpecialization (rw : Rewrite) (dir : Direction) (missing : MVarIdSet) : | ||
MetaM (Option Rewrite) := do | ||
let (rw, subst) ← rw.freshWithSubst (src := .tcSpec rw.src dir) | ||
let mut missing := missing.map subst.expr.fwd.find! | ||
let mut changed := true | ||
while changed do | ||
changed := false | ||
for var in missing do | ||
if let some inst ← findLocalDeclWithType? (← var.getType) then | ||
var.assign (.fvar inst) | ||
missing := missing.erase var | ||
changed := true | ||
let rw ← rw.instantiateMVars | ||
return if rw.validDirs.contains dir then rw else none | ||
|
||
private def genTcSpecializationsForRw (rw : Rewrite) : MetaM Rewrites := do | ||
let missingOnLhs := rw.rhsMVars.tc.subtract rw.lhsMVars.tc | ||
let missingOnRhs := rw.lhsMVars.tc.subtract rw.rhsMVars.tc | ||
let mut specs : Rewrites := #[] | ||
if !missingOnLhs.isEmpty then | ||
if let some spec ← genSpecialization rw .forward missingOnLhs then | ||
specs := specs.push spec | ||
if !missingOnRhs.isEmpty then | ||
if let some spec ← genSpecialization rw .backward missingOnRhs then | ||
specs := specs.push spec | ||
return specs | ||
|
||
def genTcSpecializations (targets : Rewrites) : MetaM Rewrites := | ||
targets.foldlM (init := #[]) fun acc rw => return acc ++ (← genTcSpecializationsForRw rw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.