Skip to content

Relax bodies of functions when their signature can't be changed - #9380

Draft
stevenfontanella wants to merge 1 commit into
mainfrom
relax-nullability-bodies
Draft

stevenfontanella wants to merge 1 commit into
mainfrom
relax-nullability-bodies

Conversation

@stevenfontanella

@stevenfontanella stevenfontanella commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Part of #9352. Resolves some TODOs in the code. For exported and possibly-indirectly-called functions, we can't change their signature. However we can still relax locals in their bodies.

As a drive-by fix, make runsOnFunction const so that subclasses aren't tempted to set class state in this method (as I was in this PR). It isn't guaranteed to be called on the particular instance that optimizes the function and in practice is not in our code (link, this is not the instance that we created with create() link).

Base automatically changed from relax-nullability3 to main November 11, 2026 01:08

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Google Antigravity Code Review

I have reviewed the changes in this Pull Request and left inline feedback.

bool isFunctionParallel() override { return true; }

bool runsOnFunction(Function* func) const override {
return func->vars.size() > 0 || isRelaxable(func, referencedFuncs);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM | Confidence: 5/5 | PERFORMANCE]

Checking func->vars.size() > 0 causes runsOnFunction to return true for every unrelaxable function (e.g. exported or referenced functions) that declares any local variables, even if all declared locals are primitive types (i32, i64, f32, f64) or already nullable.

For these functions, PassRunner instantiates the pass and performs a full AST traversal in Super::doWalkFunction(func). Because signatureWasUpdated is false and none of func->vars are non-nullable references, makeNullable does nothing and changed remains false, making the entire AST walk a redundant no-op.

To avoid traversing functions with only primitive or nullable locals, check whether any variable in func->vars is a non-nullable reference:

Suggested change
return func->vars.size() > 0 || isRelaxable(func, referencedFuncs);
bool runsOnFunction(Function* func) const override {
return isRelaxable(func, referencedFuncs) ||
std::any_of(func->vars.begin(), func->vars.end(), [](Type t) {
return t.isNonNullableRef();
});
}

@stevenfontanella
stevenfontanella force-pushed the relax-nullability-bodies branch 2 times, most recently from 26be07b to 3a51486 Compare November 11, 2026 02:04

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Google Antigravity Code Review

I have reviewed the changes in this Pull Request and left inline feedback.

;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.get $l)
;; CHECK-NEXT: )

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH | Confidence: 5/5 | BUG]

The lit test assertions for $exported-not-relaxed will fail under FileCheck. Line 231 adds (drop (local.tee $l (local.get $ref))) to the test input, but lines 222-223 in the CHECK directives expect CHECK-NEXT: (local.get $l) immediately after the local.set, omitting the dropped tee.

Because CHECK-NEXT enforces contiguous lines, FileCheck will fail when encountering (drop ...) in the output. Please update the test assertions using scripts/update_lit_checks.py -a (or include the expected (drop (local.tee ...)) checks before (local.get $l)).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant