Skip to content

Commit 806025b

Browse files
committed
fix tests by passing md to EGraphs.make
1 parent 84cff61 commit 806025b

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

docs/src/egraphs.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ The `EGraph{E,A}` type is parametrized by the expression type `E` and the
269269

270270
The following functions define an interface for analyses based on multiple dispatch:
271271

272-
* [make(g::EGraph{ExprType, AnalysisType}, n)](@ref) should take an e-node `n::VecExpr` and return a value from the analysis domain.
272+
* [make(g::EGraph{ExprType, AnalysisType}, n, md)](@ref) should take an e-node `n::VecExpr`, and metadata `md` from an expression (possibly `noting`), and return a value from the analysis domain.
273273
* [join(x::AnalysisType, y::AnalysisType)](@ref) should return the semilattice join of `x` and `y` in the analysis domain (e.g. *given two analyses value from ENodes in the same EClass, which one should I choose?* or *how should they be merged?*).`Base.isless` must be defined.
274274
* [modify!(g::EGraph{ExprType, AnalysisType}, eclass::EClass{AnalysisType})](@ref) Can be optionally implemented. This can be used modify an EClass `egraph[eclass.id]` on-the-fly during an e-graph saturation iteration, given its analysis value, typically by adding an e-node.
275275

@@ -325,7 +325,9 @@ From the definition of an e-node, we know that children of e-nodes are always ID
325325
to e-classes in the `EGraph`.
326326

327327
```@example custom_analysis
328-
function EGraphs.make(g::EGraph{ExpressionType,OddEvenAnalysis}, op, n::VecExpr) where {ExpressionType}
328+
function EGraphs.make(g::EGraph{ExpressionType,OddEvenAnalysis}, op, n::VecExpr, md) where {ExpressionType}
329+
# metadata `md` is not used in this instance.
330+
329331
v_isexpr(n) || return odd_even_base_case(op)
330332
# The e-node is not a literal value,
331333
# Let's consider only binary function call terms.

src/EGraphs/egraph.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,9 @@ function process_unions!(g::EGraph{ExpressionType,AnalysisType})::Int where {Exp
425425
eclass_id = find(g, eclass_id)
426426
eclass_id_key = IdKey(eclass_id)
427427
eclass = g.classes[eclass_id_key]
428+
md = eclass.data
428429

429-
node_data = make(g, node)
430+
node_data = make(g, node, md)
430431
if !isnothing(node_data)
431432
if !isnothing(eclass.data)
432433
joined_data = join(eclass.data, node_data)
@@ -472,7 +473,7 @@ end
472473
function check_analysis(g)
473474
for (id, eclass) in g.classes
474475
isnothing(eclass.data) && continue
475-
pass = mapreduce(x -> make(g, x), (x, y) -> join(x, y), eclass)
476+
pass = mapreduce(x -> make(g, x, x.data), (x, y) -> join(x, y), eclass)
476477
@assert eclass.data == pass
477478
end
478479
true

test/egraphs/analysis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Base.:(*)(a::NumberFoldAnalysis, b::NumberFoldAnalysis) = NumberFoldAnalysis(a.n
1515
Base.:(+)(a::NumberFoldAnalysis, b::NumberFoldAnalysis) = NumberFoldAnalysis(a.n + b.n)
1616

1717
# This should be auto-generated by a macro
18-
function EGraphs.make(g::EGraph{ExpressionType,NumberFoldAnalysis}, n::VecExpr) where {ExpressionType}
18+
function EGraphs.make(g::EGraph{ExpressionType,NumberFoldAnalysis}, n::VecExpr, md) where {ExpressionType}
1919
h = get_constant(g, v_head(n))
2020
v_isexpr(n) || return h isa Number ? NumberFoldAnalysis(h) : nothing
2121
if v_iscall(n) && v_arity(n) == 2

test/integration/cas.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ end
215215
# ex = rewrite(ex, canonical_t; clean=false)
216216

217217

218-
function EGraphs.make(g::EGraph{Expr,Type}, n::VecExpr)
218+
function EGraphs.make(g::EGraph{Expr,Type}, n::VecExpr, md)
219219
h = get_constant(g, v_head(n))
220220
v_isexpr(n) || return (h in (:im, im) ? Complex : typeof(h))
221221
v_iscall(n) || return (Any)

test/tutorials/lambda_theory.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const LambdaAnalysis = Set{Symbol}
104104

105105
getdata(eclass) = eclass.data
106106

107-
function EGraphs.make(g::EGraph{ExprType,LambdaAnalysis}, n::VecExpr) where {ExprType}
107+
function EGraphs.make(g::EGraph{ExprType,LambdaAnalysis}, n::VecExpr, md) where {ExprType}
108108
v_isexpr(n) || return LambdaAnalysis()
109109
if v_iscall(n)
110110
h = v_head(n)

0 commit comments

Comments
 (0)