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
14 changes: 12 additions & 2 deletions src/ir/type-updating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,22 @@ Type GlobalTypeRewriter::getTempTupleType(Tuple tuple) {

namespace TypeUpdating {

void handleNonDefaultableLocals(Function* func, Module& wasm) {
void handleNonDefaultableLocals(Function* func,
Module& wasm,
const std::unordered_set<Index>* forced) {
if (!wasm.features.hasReferenceTypes()) {
// No references, so no non-nullable ones at all.
return;
}
std::unordered_set<Index> badIndexes;
if (forced) {
for (auto index : *forced) {
assert(!func->isParam(index));
if (!func->getLocalType(index).isDefaultable()) {
badIndexes.insert(index);
}
}
}
bool hasNonNullable = false;
for (auto varType : func->vars) {
for (auto type : varType) {
Expand All @@ -522,7 +533,6 @@ void handleNonDefaultableLocals(Function* func, Module& wasm) {
// the wasm spec. We do not need to modify such locals.
LocalStructuralDominance info(
func, wasm, LocalStructuralDominance::NonNullableOnly);
std::unordered_set<Index> badIndexes;
for (auto index : info.nonDominatingIndices) {
badIndexes.insert(index);

Expand Down
10 changes: 9 additions & 1 deletion src/ir/type-updating.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef wasm_ir_type_updating_h
#define wasm_ir_type_updating_h

#include <unordered_set>

#include "ir/branch-utils.h"
#include "ir/module-utils.h"
#include "support/insert_ordered.h"
Expand Down Expand Up @@ -564,7 +566,13 @@ namespace TypeUpdating {
// them. Atm this turns them into nullable ones, and adds ref.as_non_null on
// their uses (which keeps the type of the users identical).
// This may also handle other types of nondefaultable locals in the future.
void handleNonDefaultableLocals(Function* func, Module& wasm);
//
// If `forced` is provided, the locals at those indexes are made nullable as
// well, even if they validate as they are.
void handleNonDefaultableLocals(
Function* func,
Module& wasm,
const std::unordered_set<Index>* forced = nullptr);

// Returns the type that a local should be, after handling of non-
// defaultability.
Expand Down
Loading