mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-10 22:00:54 +01:00
Add part of definition 2.2.
This commit is contained in:
parent
dd65db40ee
commit
00a15a9e8c
3 changed files with 22 additions and 0 deletions
|
@ -34,6 +34,16 @@ struct EGraph final
|
||||||
// TODO: static_assert L <: Language
|
// TODO: static_assert L <: Language
|
||||||
// TODO: static_assert N <: Analysis<L>
|
// TODO: static_assert N <: Analysis<L>
|
||||||
|
|
||||||
|
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:
|
private:
|
||||||
/// A union-find data structure 𝑈 stores an equivalence relation over e-class ids.
|
/// A union-find data structure 𝑈 stores an equivalence relation over e-class ids.
|
||||||
UnionFind unionfind;
|
UnionFind unionfind;
|
||||||
|
|
11
EqSat/src/EGraph.cpp
Normal file
11
EqSat/src/EGraph.cpp
Normal file
|
@ -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<typename L, typename N>
|
||||||
|
Id EGraph<L, N>::find(Id id) const {
|
||||||
|
return unionfind.find(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -302,6 +302,7 @@ target_sources(Luau.EqSat PRIVATE
|
||||||
EqSat/include/Luau/Language.h
|
EqSat/include/Luau/Language.h
|
||||||
EqSat/include/Luau/UnionFind.h
|
EqSat/include/Luau/UnionFind.h
|
||||||
|
|
||||||
|
EqSat/src/EGraph.cpp
|
||||||
EqSat/src/Id.cpp
|
EqSat/src/Id.cpp
|
||||||
EqSat/src/UnionFind.cpp
|
EqSat/src/UnionFind.cpp
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue