summaryrefslogtreecommitdiff
path: root/src/ir/stack-utils.cpp
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2021-03-11 13:53:19 -0800
committerGitHub <noreply@github.com>2021-03-11 21:53:19 +0000
commit484563771dbca78e5323cc3f5129890aea03aed5 (patch)
tree50c869eb9ebd43cba0c5a7bd11c57129ccf61e6e /src/ir/stack-utils.cpp
parentd369cd6474364e5797e40af94676339af03723a9 (diff)
downloadbinaryen-484563771dbca78e5323cc3f5129890aea03aed5.tar.gz
binaryen-484563771dbca78e5323cc3f5129890aea03aed5.tar.bz2
binaryen-484563771dbca78e5323cc3f5129890aea03aed5.zip
Remove LUB calculation (#3669)
Since correct LUB calculation for recursive types is complicated, stop depending on LUBs throughout the code base. This also fixes a validation bug in which the validator required blocks to be typed with the LUB of all the branch types, when in fact any upper bound should have been valid. In addition to fixing that bug, this PR simplifies the code for break handling by not storing redundant information about the arity of types.
Diffstat (limited to 'src/ir/stack-utils.cpp')
-rw-r--r--src/ir/stack-utils.cpp89
1 files changed, 0 insertions, 89 deletions
diff --git a/src/ir/stack-utils.cpp b/src/ir/stack-utils.cpp
index bc20dfe91..aa6da22d9 100644
--- a/src/ir/stack-utils.cpp
+++ b/src/ir/stack-utils.cpp
@@ -164,95 +164,6 @@ bool StackSignature::isSubType(StackSignature a, StackSignature b) {
});
}
-bool StackSignature::haveLeastUpperBound(StackSignature a, StackSignature b) {
- // If a signature is polymorphic, the LUB could extend its params and results
- // arbitrarily. Otherwise, the LUB must extend its params and results
- // uniformly so that each additional param is a subtype of the corresponding
- // additional result.
- auto extensionCompatible = [](auto self, auto other) -> bool {
- if (self.kind == Polymorphic) {
- return true;
- }
- // If no extension, then no problem.
- if (self.params.size() >= other.params.size() &&
- self.results.size() >= other.results.size()) {
- return true;
- }
- auto extSize = other.params.size() - self.params.size();
- if (extSize != other.results.size() - self.results.size()) {
- return false;
- }
- return std::equal(other.params.begin(),
- other.params.begin() + extSize,
- other.results.begin(),
- other.results.begin() + extSize,
- [](const Type& param, const Type& result) {
- return Type::isSubType(param, result);
- });
- };
- if (!extensionCompatible(a, b) || !extensionCompatible(b, a)) {
- return false;
- }
-
- auto valsCompatible = [](auto as, auto bs, auto compatible) -> bool {
- // Canonicalize so the as are shorter and any unshared prefix is on bs.
- if (bs.size() < as.size()) {
- std::swap(as, bs);
- }
- // Check that shared values after the unshared prefix have are compatible.
- size_t diff = bs.size() - as.size();
- for (size_t i = 0, shared = as.size(); i < shared; ++i) {
- if (!compatible(as[i], bs[i + diff])) {
- return false;
- }
- }
- return true;
- };
-
- bool paramsOk = valsCompatible(a.params, b.params, [](Type a, Type b) {
- assert(a == b && "TODO: calculate greatest lower bound to handle "
- "contravariance correctly");
- return true;
- });
- bool resultsOk = valsCompatible(a.results, b.results, [](Type a, Type b) {
- return Type::getLeastUpperBound(a, b) != Type::none;
- });
- return paramsOk && resultsOk;
-}
-
-StackSignature StackSignature::getLeastUpperBound(StackSignature a,
- StackSignature b) {
- assert(haveLeastUpperBound(a, b));
-
- auto combineVals = [](auto as, auto bs, auto combine) -> std::vector<Type> {
- // Canonicalize so the as are shorter and any unshared prefix is on bs.
- if (bs.size() < as.size()) {
- std::swap(as, bs);
- }
- // Combine shared values after the unshared prefix.
- size_t diff = bs.size() - as.size();
- std::vector<Type> vals(bs.begin(), bs.begin() + diff);
- for (size_t i = 0, shared = as.size(); i < shared; ++i) {
- vals.push_back(combine(as[i], bs[i + diff]));
- }
- return vals;
- };
-
- auto params = combineVals(a.params, b.params, [&](Type a, Type b) {
- assert(a == b && "TODO: calculate greatest lower bound to handle "
- "contravariance correctly");
- return a;
- });
-
- auto results = combineVals(a.results, b.results, [&](Type a, Type b) {
- return Type::getLeastUpperBound(a, b);
- });
-
- Kind kind =
- a.kind == Polymorphic && b.kind == Polymorphic ? Polymorphic : Fixed;
- return StackSignature{Type(params), Type(results), kind};
-}
-
StackFlow::StackFlow(Block* block) {
// Encapsulates the logic for treating the block and its children
// uniformly. The end of the block is treated as if it consumed values