Skip to content
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

Mutable semantic analysis (data) for eclass #250

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions src/EGraphs/egraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ The children and parent nodes are stored as [`VecExpr`](@ref)s for performance,
means that without a reference to the [`EGraph`](@ref) object we cannot re-build human-readable terms
they represent. The [`EGraph`](@ref) itself comes with pretty printing for human-readable terms.
"""
struct EClass{D}
id::Id
nodes::Vector{VecExpr}
parents::Vector{Pair{VecExpr,Id}}
mutable struct EClass{D}
const id::Id
const nodes::Vector{VecExpr}
const parents::Vector{Pair{VecExpr,Id}}
data::Union{D,Nothing}
end

Expand Down Expand Up @@ -353,15 +353,12 @@ function Base.union!(
merged_2 && append!(g.analysis_pending, eclass_2.parents)


new_eclass = EClass{AnalysisType}(
id_1.val,
append!(eclass_1.nodes, eclass_2.nodes),
append!(eclass_1.parents, eclass_2.parents),
new_data,
)
# update eclass_1
append!(eclass_1.nodes, eclass_2.nodes)
append!(eclass_1.parents, eclass_2.parents)
eclass_1.data = new_data

g.classes[id_1] = new_eclass
modify!(g, new_eclass)
modify!(g, eclass_1)

return true
end
Expand Down Expand Up @@ -431,14 +428,12 @@ function process_unions!(g::EGraph{ExpressionType,AnalysisType})::Int where {Exp
joined_data = join(eclass.data, node_data)

if joined_data != eclass.data
g.classes[eclass_id_key] = EClass{AnalysisType}(eclass_id, eclass.nodes, eclass.parents, joined_data)
# eclass.data = joined_data
eclass.data = joined_data
modify!(g, eclass)
append!(g.analysis_pending, eclass.parents)
end
else
g.classes[eclass_id_key] = EClass{AnalysisType}(eclass_id, eclass.nodes, eclass.parents, node_data)
# eclass.data = node_data
eclass.data = node_data
modify!(g, eclass)
append!(g.analysis_pending, eclass.parents)
end
Expand Down
Loading