-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic analysis #293
Generic analysis #293
Conversation
…and `analysis_pending`
Just so I understand; this is not a user facing change? The goal is to implement various egg internals using a more flexible analysis API, right? |
Unfortunately, the old |
I see. I think this is a cool idea, and could be the right thing going forward. I would hope that it would result in code reduction rather and growth, but maybe that's asking for too much. In general, I'm pretty hesitant (but not totally unwilling) to break the user-facing API at this point unless there is some demonstrable need. Most of the egg maintainers (including me) are spending more time on other projects at the moment. But don't let that stop you from experimenting or working on a fork! |
@robert-chiniquy I heard that you were working on a fork of |
Oh, heh, sorry, I'm absolutely not going to work on a fork, I'm just going to use my own hacked fork until something equivalent to my latest PR lands (this is how I avoid waiting). |
Note this assumes #291
I've noticed that
EGraph
andEClass
struct's can be broken down into various parts that serve different purposes:Core egraph: (
EGraph.{unionfind, nodes, memo, pending, classes}, EClass.{id, parents}
)process_unions
)EGraph.parents
could potentially be de-duplicated but this is never requiredBacktracking e-matching:
EGraph.classes_by_op, EClass.nodes
EClass.nodes
is maintained partially incrementallyrebuild_classes
before e-matchingCustom Lattice Analysis:
EGraph.{analysis, analysis_pending}, EClass.data
N=()
EGraph.analysis_pending
whenAnalysis::merge
always returnsDidMerge(false, false)
Explanations:
EGraph.explain
Option
causing slight overheadId
Symbol
sI've started experimenting with trying to factor out the core egraph and use a new
Analysis
trait (I renamed the old one toLatticeAnalysis
) to handle everything else though so far the core egraph still includes explanations. ThisAnalysis
trait is implemented for pairs ofAnalysis
s to allow composing multiple together. I created to implementation of thisAnalysis
, traitEMatchingAnalysis
which containsclasses_by_op
and hasEClass.nodes
as its data field, andWrapLatticeAnalysis
that wraps aLatticeAnalysis
to handleanalysis_pending
.To handle methods that relied on a specific analysis like
set_analysis_data
orsearch_eclass
I implemented them for egraphs with specific analysis instantiations, egEGraph<L, (WrapAnalysisData<N>, N2)>
forset_analysis_data
orEGraph<L, (N, EMatchingAnalysis<L>)>
forsearch_eclass
, and I created the aliaslegacy::EGraph<L, N> = EGraph<L, (WrapAnalysisData<N>, EMatchingAnalysis<L>)>
. While this has worked fine, for now, it seems like it will break down if users want to use these types of methods for multiple analyses at once, for example, if theexplain_equivalence
required something likeEGraph<L, (ExplainAnalysis, N2)>
then a user could call it andset_analysis_data
on the sameEGraph
. I could have something like implementset_analysis_data
forEGraph<L, ((WrapAnalysisData<N> N2), N3)>
and implementexplain_equivalence
forEGraph<L, ((N2, ExplainAnalysis), N3)>
but this doesn't seem scalable.Other side effects of this change
EGraph::dot
,EGraph::intersect
, andExtractor::new
are more expensive since they need to calculate the nodes in each eclass, andAnalysis
s can't access the nodes of an eclass. This second change prevented the constant folding analysis from themath
test from removing nodes from eclasses representing constants which caused 4 of the tests to fail.I'm making this a draft PR so that you can view the exact changes I made but I am mostly interested in discussion