Skip to content

[NFC] Remove StringLowering::replaceNulls #7607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
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
58 changes: 0 additions & 58 deletions src/passes/StringLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ struct StringLowering : public StringGathering {
// Replace string.* etc. operations with imported ones.
replaceInstructions(module);

// Replace ref.null types as needed.
replaceNulls(module);

// ReFinalize to apply all the above changes.
ReFinalize().run(getPassRunner(), module);

Expand Down Expand Up @@ -495,61 +492,6 @@ struct StringLowering : public StringGathering {
replacer.run(getPassRunner(), module);
replacer.walkModuleCode(module);
}

// A ref.null of none needs to be noext if it is going to a location of type
// stringref.
void replaceNulls(Module* module) {
// Use SubtypingDiscoverer to find when a ref.null of none flows into a
// place that has been changed from stringref to externref.
struct NullFixer
: public WalkerPass<
ControlFlowWalker<NullFixer, SubtypingDiscoverer<NullFixer>>> {
// Hooks for SubtypingDiscoverer.
void noteSubtype(Type, Type) {
// Nothing to do for pure types.
}
void noteSubtype(HeapType, HeapType) {
// Nothing to do for pure types.
}
void noteSubtype(Type, Expression*) {
// Nothing to do for a subtype of an expression.
}
void noteSubtype(Expression* a, Type b) {
// This is the case we care about: if |a| is a null that must be a
// subtype of ext then we fix that up.
if (!b.isRef()) {
return;
}
HeapType top = b.getHeapType().getTop();
if (top.isMaybeShared(HeapType::ext)) {
if (auto* null = a->dynCast<RefNull>()) {
null->finalize(HeapTypes::noext.getBasic(top.getShared()));
}
}
}
void noteSubtype(Expression* a, Expression* b) {
// Only the type matters of the place we assign to.
noteSubtype(a, b->type);
}
void noteNonFlowSubtype(Expression* a, Type b) {
// Flow or non-flow is the same for us.
noteSubtype(a, b);
}
void noteCast(HeapType, HeapType) {
// Casts do not concern us.
}
void noteCast(Expression*, Type) {
// Casts do not concern us.
}
void noteCast(Expression*, Expression*) {
// Casts do not concern us.
}
};

NullFixer fixer;
fixer.run(getPassRunner(), module);
fixer.walkModuleCode(module);
}
};

Pass* createStringGatheringPass() { return new StringGathering(); }
Expand Down
Loading