Skip to content

Refactorings and fixes to erased definition handling #23404

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 3 commits into from
Jun 24, 2025

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 23, 2025

These are cleanups and bug-fixes. They don't change the semantics of erasedDefinitions

odersky added 2 commits June 23, 2025 13:41
The motivation for the phase was always unclear to me. No tests broke after the change.

Piggybacked on the phase was the unrelated "anonymous class in inline method" warning.
I moved it in changed form to FirstTransform. It is more efficient now since it does
not need an auxiliary tree traversal.
We assumed all type applications were pure, which is claerly false.

E.g.

    def fn[T] = println("hi")
    fn[Int]

This triggered a problem in coverage tests which now assumes a use of an erased
function is not erased (probably because it now shows up in the coverage info).
The problem was fixed by mapping the erased defs to inline defs.

I found out the problem with coverage: If an argument is not a pure expression, it gets lifted
into a prefix val. And the prefix val is not erased even if the parameter is erased. So that way
things escape an erased context. I believe this is a fundamental problem that would also affect
lifting due to other reasons (e.g. eta expansion or handling default arguments). We either
have to fix the lifting to mainain erased status, or restrict erased arguments to pure expressions
that don't need lifting.
If one of the methods is an inline method that is not retained, no need
to report a double definition.
Copy link
Contributor

@natsukagami natsukagami left a comment

Choose a reason for hiding this comment

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

LGTM aside from the comments. Also, this removes erased defs right? Do we reject them while parsing now? I didn't notice any such changes.

Comment on lines +21 to +37
0
macro-late-suspend/UsesTest.scala
example
UsesTest$package
Object
example.UsesTest$package
<init>
22
22
3
<none>
Literal
true
0
false


Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what this test does. Is it important that the output changes?

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 am not sure. It might have to do with the fact that we don't delete code in PruneErasedDefs anymore. But if anything this hshould be more precise now.

@@ -56,6 +56,6 @@ object ccConfig:

/** Not used currently. Handy for trying out new features */
def newScheme(using ctx: Context): Boolean =
ctx.settings.XdropComments.value
Feature.sourceVersion.stable.isAtLeast(SourceVersion.`3.7`)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be a random change

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, it's not needed elsewhere though.

@odersky
Copy link
Contributor Author

odersky commented Jun 24, 2025

erased defs are not yet removed. That comes later.

@odersky odersky merged commit 8f0d12b into scala:main Jun 24, 2025
30 checks passed
@odersky odersky deleted the change-erased branch June 24, 2025 21:54
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.

2 participants