Skip to content

Improve position of tailcalls diagnostic #10723

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
Jun 16, 2025

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Mar 22, 2024

Fixes scala/bug#4649

The diagnostic is as intended, so the OP is wont-fix, but improve error position and also an incorrect message, and move the pos test to neg.

@scala-jenkins scala-jenkins added this to the 2.13.15 milestone Mar 22, 2024
@som-snytt som-snytt marked this pull request as draft March 22, 2024 21:30
@som-snytt som-snytt force-pushed the issue/4649-tailrec-byname branch 2 times, most recently from ece451c to 5ecfa88 Compare March 23, 2024 18:58
@som-snytt som-snytt marked this pull request as ready for review March 23, 2024 20:05
@som-snytt som-snytt force-pushed the issue/4649-tailrec-byname branch from 5ecfa88 to a914532 Compare March 26, 2024 02:47
@som-snytt

This comment was marked as resolved.

@som-snytt
Copy link
Contributor Author

Instead of a -W, how about @notailrec to indicate "I did not intend this expression as a tail call and I know what I'm doing."

Sentiment on the dotty ticket is against diluting @tailrec.

@som-snytt som-snytt marked this pull request as draft March 28, 2024 00:35
@som-snytt
Copy link
Contributor Author

I'll rework this to align with Dotty.

@SethTisue SethTisue modified the milestones: 2.13.15, 2.13.16 Aug 14, 2024
@som-snytt som-snytt closed this Sep 11, 2024
@som-snytt som-snytt reopened this Nov 9, 2024
@SethTisue SethTisue modified the milestones: 2.13.16, 2.13.17 Dec 12, 2024
@som-snytt som-snytt changed the title Tailcalls is more selective when reporting self-recursion Tailcalls is more selective when reporting self-recursion [ci: last-only] Jun 2, 2025
@som-snytt som-snytt force-pushed the issue/4649-tailrec-byname branch from a914532 to 52130d7 Compare June 2, 2025 17:39
@som-snytt
Copy link
Contributor Author

Drop the -W; but the title should be "improve position in tailrec diagnostic", which may be worthwhile.

@som-snytt som-snytt force-pushed the issue/4649-tailrec-byname branch from 52130d7 to 2a48f82 Compare June 3, 2025 20:51
@som-snytt som-snytt changed the title Tailcalls is more selective when reporting self-recursion [ci: last-only] Improve position of tailcalls diagnostic Jun 3, 2025
@som-snytt som-snytt marked this pull request as ready for review June 3, 2025 20:59
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

LGTM otherwise, nice improvements!

def recursiveCalls(t: Tree): List[Tree] = detectRecursion.recursiveCalls(t)
def isRecursiveCall(sym: Symbol): Boolean = (method eq sym) && tailPos

def containsRecursiveCallCandidate(t: Tree): Boolean = {
Copy link
Member

Choose a reason for hiding this comment

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

unused, can be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed code for -Wstrict mode; probably I didn't delete enough.

I should've asked copilot...

Copy link
Contributor Author

@som-snytt som-snytt Jun 15, 2025

Choose a reason for hiding this comment

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

I guess I had previously refactored that away but didn't delete it. It was still used in the original PR commit. I have a vague memory that 2.13.16 pre-checks for "candidates" (hence the name) but I thought why do that. (The Giants won yesterday but they are losing badly to the Dodgers already tonight. Should I just code instead of listening to the game?) (6-0 is a bad tennis score and a worse baseball score.)

Comment on lines 175 to 176
for ((p, a) <- fun.symbol.paramLists.head.lazyZip(args))
traverse(a)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for ((p, a) <- fun.symbol.paramLists.head.lazyZip(args))
traverse(a)
args.foreach(traverse)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saved the branch which previously said if strict || !p.isByNameParam...

@som-snytt som-snytt force-pushed the issue/4649-tailrec-byname branch from 2a48f82 to 3cebe3d Compare June 15, 2025 08:11
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

Thanks!

@lrytz lrytz merged commit 10d239b into scala:2.13.x Jun 16, 2025
3 checks passed
@som-snytt som-snytt deleted the issue/4649-tailrec-byname branch June 16, 2025 08:52
@som-snytt
Copy link
Contributor Author

I added -Yaudit-tailcalls for testing, just to warn about all self-recursions that are not tail-call, but I'll only push it if it alerts me to a problem while bootstrapping (i.e. it misdiagnoses a self-recursion).

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.

Possible regression in 2.9: @tailrec annotated method rejected by scalac
4 participants