From b23b47d54a2fb02b048e7eb8de8043358599ec8b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 26 Sep 2022 13:49:50 -0700 Subject: [GUFA] Infer a RefEq value of 0 when possible (#5081) If the PossibleContents for the two sides have no possible intersection then the result must be 0. --- src/ir/possible-contents.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/ir/possible-contents.h') diff --git a/src/ir/possible-contents.h b/src/ir/possible-contents.h index 38bc263e9..f3ad37d92 100644 --- a/src/ir/possible-contents.h +++ b/src/ir/possible-contents.h @@ -167,6 +167,13 @@ public: // This returns false for None and Many, for whom it is not well-defined. bool hasExactType() const { return isExactType() || isLiteral(); } + // Returns whether the given contents have any intersection, that is, whether + // some value exists that can appear in both |a| and |b|. For example, if + // either is None, or if they are both ExactTypes but of different types, then + // they have no intersection. + static bool haveIntersection(const PossibleContents& a, + const PossibleContents& b); + // Whether we can make an Expression* for this containing the proper contents. // We can do that for a Literal (emitting a Const or RefFunc etc.) or a // Global (emitting a GlobalGet), but not for anything else yet. @@ -529,6 +536,13 @@ public: return iter->second; } + // Helper for the common case of an expression location that is not a + // multivalue. + PossibleContents getContents(Expression* curr) { + assert(curr->type.size() == 1); + return getContents(ExpressionLocation{curr, 0}); + } + private: std::unordered_map locationContents; }; -- cgit v1.2.3