Skip to content

Conversation

@timsueberkrueb
Copy link
Contributor

Fixes #1153.

case Stmt.Match(scrutinee, clauses, default) => !freeInExpr(scrutinee) && clauses.forall {
case (_, BlockLit(tparams, cparams, vparams, bparams, body)) => tailResumptive(k, body)
} && default.forall { stmt => tailResumptive(k, stmt) }
case Stmt.Region(BlockLit(tparams, cparams, vparams, bparams, body)) => tailResumptive(k, body)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this also be false then?

Copy link
Contributor

Choose a reason for hiding this comment

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

If/when we change this, could we add an example where this fires / doesn't fire?

@b-studios
Copy link
Collaborator

Nice that you apparently didn't have to change the VMTests!

Copy link
Collaborator

@b-studios b-studios left a comment

Choose a reason for hiding this comment

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

I pre-approve :) Once you fixed / commented out the Scheme tests this is ready to go.

Comment on lines 38 to 40
case Stmt.Var(ref, init, capture, body) => tailResumptive(k, body) && !freeInExpr(init)
// Conceptually, a mutable variable definition can be seen as a handler for get and put operations.
// Treating this as tail-resumptive leads to a failure of semantics preservation
case Stmt.Var(ref, init, capture, body) => false
Copy link
Contributor

Choose a reason for hiding this comment

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

Not too relevant for the current PR, but would a use-mention distinction help here?
If we have variables/prompts that are merely mentioned, can we still consider the function to be tail-res?

As a very trivial example, is it safe to do something similar to the example, but not use x at all after declaring it? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there an example that isn't just dead code (and would be handled by dead code elimination)?

@timsueberkrueb timsueberkrueb marked this pull request as ready for review October 21, 2025 20:09
Copy link

@batenwi batenwi left a comment

Choose a reason for hiding this comment

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

LGTM

@b-studios b-studios merged commit 6648978 into master Oct 27, 2025
2 checks passed
@b-studios b-studios deleted the fix-tail-resumptive-analysis branch October 27, 2025 15:36
danielflat pushed a commit that referenced this pull request Oct 31, 2025
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.

Incorrectly applies tail resumption optimization under var scope

5 participants