From 00a15a9e8c9bf578f1feccec53584ba0a3686b57 Mon Sep 17 00:00:00 2001 From: Alexander McCord Date: Fri, 24 May 2024 13:24:48 -0700 Subject: [PATCH] Add part of definition 2.2. --- EqSat/include/Luau/EGraph.h | 10 ++++++++++ EqSat/src/EGraph.cpp | 11 +++++++++++ Sources.cmake | 1 + 3 files changed, 22 insertions(+) create mode 100644 EqSat/src/EGraph.cpp diff --git a/EqSat/include/Luau/EGraph.h b/EqSat/include/Luau/EGraph.h index 6d583142..e50cb3c4 100644 --- a/EqSat/include/Luau/EGraph.h +++ b/EqSat/include/Luau/EGraph.h @@ -34,6 +34,16 @@ struct EGraph final // TODO: static_assert L <: Language // TODO: static_assert N <: Analysis + Id find(Id id) const; + + // Per the egg paper, definition 2.2 (Canonicalization): + // + // An e-node 𝑛 is canonical iff 𝑛 = canonicalize(𝑛), where + // canonicalize(𝑓(𝑎1, 𝑎2, ...)) = 𝑓(find(𝑎1), find(𝑎2), ...). + // + // Doing so requires sketching out `Luau::EqSat::Language` which + // I want to do at a later time for the time being. Will revisit. + private: /// A union-find data structure 𝑈 stores an equivalence relation over e-class ids. UnionFind unionfind; diff --git a/EqSat/src/EGraph.cpp b/EqSat/src/EGraph.cpp new file mode 100644 index 00000000..4d5194bb --- /dev/null +++ b/EqSat/src/EGraph.cpp @@ -0,0 +1,11 @@ +// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details +#include "Luau/EGraph.h" + +namespace Luau::EqSat { + +template +Id EGraph::find(Id id) const { + return unionfind.find(id); +} + +} diff --git a/Sources.cmake b/Sources.cmake index 8601fa28..6419aef4 100644 --- a/Sources.cmake +++ b/Sources.cmake @@ -302,6 +302,7 @@ target_sources(Luau.EqSat PRIVATE EqSat/include/Luau/Language.h EqSat/include/Luau/UnionFind.h + EqSat/src/EGraph.cpp EqSat/src/Id.cpp EqSat/src/UnionFind.cpp )