Skip to content
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

improvement: use heuristic to figure out nameSpan if pointDelta too big #22484

Merged
merged 2 commits into from
Feb 7, 2025

Conversation

kasiaMarek
Copy link
Contributor

This is a hacky workaround when pointDelta >= SyntheticPointDelta, see:

fromOffsets(start, end, if (pointDelta >= SyntheticPointDelta) 0 else pointDelta)

Fix for: scalameta/metals#3053

@kasiaMarek kasiaMarek marked this pull request as ready for review January 31, 2025 16:06
@kasiaMarek kasiaMarek requested a review from tgodzik February 3, 2025 10:47
| case Thicket2(_) => ???
| }
|
| /** Does `tree' look like a reference to AnyVal? Temporary test before we have
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we skip the scaladoc actually, or make them a bit shorter?

Copy link
Contributor Author

@kasiaMarek kasiaMarek Feb 3, 2025

Choose a reason for hiding this comment

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

The problem is that the span is too big, so all these comments to make the method extra long are needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ach, makes sense. Thanks for explaining!

Copy link
Contributor

Choose a reason for hiding this comment

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

It definitely falls under "things I would not have anticipated"!

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

LGTM, though since it touches the main parts of the compiler anyone else wants to take a look?

@tgodzik tgodzik requested a review from mbovel February 3, 2025 15:33
| // prefixed by type or val). `tparams` and `vparamss` are the type parameters that
| // go in `constr`, the constructor after desugaring.
| 1
|}.<<showing2>>("aaa")
Copy link
Contributor

Choose a reason for hiding this comment

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

The > 4K string could be generated "x" * 4096 instead of adding text to the repo.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kasiaMarek Let's maybe to that and then merge?

@@ -59,6 +59,9 @@ object Spans {
if (poff == SyntheticPointDelta) start else start + poff
}

def pointMayBeIncorrect =
pointDelta == 0 && end - start >= SyntheticPointDelta
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it dubious to make this API of span? Why this check on pointDelta if any large span may make it overflow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If pointDelta it too large, pointDelta will be set to 0, so only then it can be wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

I withdraw my objection to adding the method to Span. As a footnote, there is no range check on point, so "incorrect" code can attempt to assign a point "outside" the span. This was an ongoing issue in Scala 2. I haven't looked again yet at the "multiple vars" position issue, but that is the sort of incorrect code I mean.

val realName = name.stripModuleClassSuffix.lastPart
val probablyPoint = span.end - realName.length
Span(probablyPoint, span.end, probablyPoint)
else Span(point, span.end, point)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't even see where select gets its point; I see the span is set in typedSelectOnTerm for example. I haven't looked at the span computations there. But, it seems to me I can never trust the point of a huge span, and that counting back from the end is always correct in that case. Or, is there logic somewhere that overflowing point is reset to zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, overflowing is set to zero. The exact line is in the PR description.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, my eyes saw it but my brain did not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this particular case, the span is set in selectorOrMatch in Parsers.scala by atSpan method.

@kasiaMarek kasiaMarek changed the title improvement: use heuristic to figure out nameSpan if pointDelta to big improvement: use heuristic to figure out nameSpan if pointDelta too big Feb 4, 2025
@tgodzik tgodzik merged commit bb2aadb into scala:main Feb 7, 2025
29 checks passed
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.

3 participants