diff --git a/EqSat/include/Luau/EGraph.h b/EqSat/include/Luau/EGraph.h new file mode 100644 index 00000000..88c0f01e --- /dev/null +++ b/EqSat/include/Luau/EGraph.h @@ -0,0 +1,52 @@ +// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details +#pragma once + +#include "Luau/DenseHash.h" +#include "Luau/Id.h" +#include "Luau/UnionFind.h" + +#include +#include + +namespace Luau::EqSat +{ + +/// Each e-class is a set of e-nodes representing equivalent terms from a given language, +/// and an e-node is a function symbol paired with a list of children e-classes. +template +struct EClass { + Id id; + std::vector nodes; + D data; + std::vector> parents; +}; + +/// In Definition 2.1, an EGraph is composed with a tuple (U, M, H) where +/// - U: [`EGraph::u`] +/// - M: [`EGraph::m`] +/// - H: [`EGraph::h`] +/// +/// See . +template +struct EGraph +{ + // TODO: static_assert L <: Language + // TODO: static_assert N <: Analysis + +private: + /// A union-find data structure 𝑈 stores an equivalence relation over e-class ids. + UnionFind u; + + /// The e-class map 𝑀 maps e-class ids to e-classes. All equivalent e-class ids map to the same + /// e-class, i.e., 𝑎 ≡id 𝑏 iff 𝑀[𝑎] is the same set as 𝑀[𝑏]. An e-class id 𝑎 is said to refer to the + /// e-class 𝑀[find(𝑎)]. + DenseHashMap> m; + + /// The hashcons 𝐻 is a map from e-nodes to e-node ids. + /// + /// Author note: the paper says this maps from e-nodes to e-class ids, but the + /// corresponding map in the egg crate called `memo`, they map it to e-node ids? + DenseHashMap, Id> h; +}; + +} // namespace Luau::EqSat diff --git a/EqSat/include/Luau/Language.h b/EqSat/include/Luau/Language.h new file mode 100644 index 00000000..f86f8375 --- /dev/null +++ b/EqSat/include/Luau/Language.h @@ -0,0 +1,15 @@ +// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details +#pragma once + +#include "Luau/Id.h" + +namespace Luau::EqSat +{ + +template +struct Language +{ + +}; + +} // namespace Luau::EqSat diff --git a/EqSat/include/Luau/UnionFind.h b/EqSat/include/Luau/UnionFind.h new file mode 100644 index 00000000..bd8bdaaf --- /dev/null +++ b/EqSat/include/Luau/UnionFind.h @@ -0,0 +1,12 @@ +// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details +#pragma once + +namespace Luau::EqSat +{ + +/// See . +struct UnionFind +{ +}; + +} // namespace Luau::EqSat diff --git a/EqSat/src/UnionFind.cpp b/EqSat/src/UnionFind.cpp new file mode 100644 index 00000000..0bf171b5 --- /dev/null +++ b/EqSat/src/UnionFind.cpp @@ -0,0 +1,9 @@ +// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details +#include "Luau/UnionFind.h" + +namespace Luau::EqSat +{ + + + +} // namespace Luau::EqSat diff --git a/Sources.cmake b/Sources.cmake index 1b87a328..8601fa28 100644 --- a/Sources.cmake +++ b/Sources.cmake @@ -297,9 +297,13 @@ target_sources(Luau.Analysis PRIVATE # Luau.Analysis Sources target_sources(Luau.EqSat PRIVATE + EqSat/include/Luau/EGraph.h EqSat/include/Luau/Id.h + EqSat/include/Luau/Language.h + EqSat/include/Luau/UnionFind.h EqSat/src/Id.cpp + EqSat/src/UnionFind.cpp ) # Luau.VM Sources