Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/ir/possible-contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,11 @@ struct Flower {
// For a non-full cone, we also reduce the depth as much as possible, so it is
// equal to the maximum depth of an existing subtype.
Index getNormalizedConeDepth(Type type, Index depth) {
return std::min(depth, maxDepths[type.getHeapType()]);
auto iter = maxDepths.find(type.getHeapType());
// A max depth must be in the map (otherwise we would use the default 0,
// making it exact, almost certainly incorrectly).
assert(iter != maxDepths.end());
return std::min(depth, iter->second);
}

void normalizeConeType(PossibleContents& cone) {
Expand Down Expand Up @@ -2639,6 +2643,12 @@ bool Flower::updateContents(LocationIndex locationIndex,
// more later (we compute that at the end), so use a temp out var for that.
bool worthSendingMoreTemp = true;
filterExpressionContents(newContents, *exprLoc, worthSendingMoreTemp);

#if defined(POSSIBLE_CONTENTS_DEBUG) && POSSIBLE_CONTENTS_DEBUG >= 2
std::cout << " post-filtered exprLoc:\n";
newContents.dump(std::cout, &wasm);
std::cout << '\n';
#endif
} else if (auto* globalLoc = std::get_if<GlobalLocation>(&location)) {
// Generic filtering. We do this both before and after.
filterGlobalContents(newContents, *globalLoc);
Expand Down
14 changes: 14 additions & 0 deletions src/ir/subtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,27 @@ struct SubTypes {
basicDepth = std::max(basicDepth, depths[type] + 1);
}

// Fill in the other basic types.
for (auto share : {Unshared, Shared}) {
depths[HeapTypes::eq.getBasic(share)] =
std::max(depths[HeapTypes::struct_.getBasic(share)],
depths[HeapTypes::array.getBasic(share)]) +
1;
depths[HeapTypes::any.getBasic(share)] =
depths[HeapTypes::eq.getBasic(share)] + 1;

depths[HeapTypes::i31.getBasic(share)] = 0;
depths[HeapTypes::exn.getBasic(share)] = 0;

// Extern has string as a subtype.
depths[HeapTypes::ext.getBasic(share)] = 1;
depths[HeapTypes::string.getBasic(share)] = 0;

depths[HeapTypes::none.getBasic(share)] = 0;
depths[HeapTypes::noext.getBasic(share)] = 0;
depths[HeapTypes::nofunc.getBasic(share)] = 0;
depths[HeapTypes::nocont.getBasic(share)] = 0;
depths[HeapTypes::noexn.getBasic(share)] = 0;
}

return depths;
Expand Down
9 changes: 9 additions & 0 deletions test/gtest/type-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,15 @@ TEST_F(TypeTest, TestMaxStructDepths) {
EXPECT_EQ(maxDepths[HeapType::struct_], Index(2));
EXPECT_EQ(maxDepths[HeapType::eq], Index(3));
EXPECT_EQ(maxDepths[HeapType::any], Index(4));
EXPECT_EQ(maxDepths[HeapType::i31], Index(0));
EXPECT_EQ(maxDepths[HeapType::exn], Index(0));
EXPECT_EQ(maxDepths[HeapType::ext], Index(1));
EXPECT_EQ(maxDepths[HeapType::string], Index(0));
EXPECT_EQ(maxDepths[HeapType::none], Index(0));
EXPECT_EQ(maxDepths[HeapType::noext], Index(0));
EXPECT_EQ(maxDepths[HeapType::nofunc], Index(0));
EXPECT_EQ(maxDepths[HeapType::nocont], Index(0));
EXPECT_EQ(maxDepths[HeapType::noexn], Index(0));
}

TEST_F(TypeTest, TestMaxArrayDepths) {
Expand Down
Loading