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

Fixes for cleanup retains scheme #21350

Merged
merged 5 commits into from
Aug 10, 2024
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Aug 8, 2024

  • Cleanup all inferred types, not just result types of ValDefs and DefDefs.
  • To compensate, map overriding ValDefs and DefDefs to have declared result types.
  • Make type trees generated for varargs inferred.

Based on #21309.

odersky added 5 commits August 7, 2024 12:48
These arguments tell the whole truth; they cannot possibly be decorated with another capture set. So
we should not add a capture set variable.
These need to be handled like reach capabilities.

Fixes scala#21347
 - Cleanup all inferred types, not just result types of ValDefs and DefDefs.
 - To compensate, map overriding ValDefs and DefDefs to have declared result types.
 - Make type trees generated for varargs inferred.
This is now redundant since result types of overriding ValDefs and DefDefs
are now mapped to TypeTrees in PostTyper.
@odersky odersky force-pushed the fix-cleanupRetains branch from 11e2986 to a8cc133 Compare August 8, 2024 09:10
@odersky odersky requested review from Linyxus and mbovel August 8, 2024 09:50
@odersky
Copy link
Contributor Author

odersky commented Aug 8, 2024

This should solve the problems with varargs we were seeing recently.

Copy link
Member

@mbovel mbovel left a comment

Choose a reason for hiding this comment

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

This looks good to me. Cleaning up all types sounds safer.

On a more general note, it is however not clear to me that this is yet enough: can't non-sensical inferred types have escaped outside of trees before they are cleaned up, for example in symbol's denotations? Wouldn't there be even more to cleanup?

tree.withType:
tpe match
case AnnotatedType(parent, annot) =>
AnnotatedType(parent, transformAnnot(annot)) // TODO: Also map annotations embedded in type?
Copy link
Member

Choose a reason for hiding this comment

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

Also map annotations embedded in type?

Does that only transform outermost annotations? Shouldn't this be a TypeMap?

* retains annotations come from the explicitly declared parent types, so should
* be kept.
*/
private def makeOverrideTypeDeclared(symbol: Symbol, tpt: Tree)(using Context): Tree =
Copy link
Member

Choose a reason for hiding this comment

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

So if I understand correctly, an overridden member:

  1. is typed normally like any definition during Typer,
  2. if its type tree is an InferredTypeTree, it get switched to a TypeTree here during PostTyper,
  3. gets its typed checked against the overloaded definition only later during RefChecks.

Seems to make sense ✅

@odersky
Copy link
Contributor Author

odersky commented Aug 10, 2024

On a more general note, it is however not clear to me that this is yet enough: can't non-sensical inferred types have escaped outside of trees before they are cleaned up, for example in symbol's denotations? Wouldn't there be even more to cleanup?

Only trees are pickled, so that means if we make sure all critical type trees are InferredTypeTrees we should be OK.

@odersky odersky merged commit 55ddaec into scala:main Aug 10, 2024
28 checks passed
@odersky odersky deleted the fix-cleanupRetains branch August 10, 2024 11:40
@WojciechMazur WojciechMazur added this to the 3.6.0 milestone Oct 8, 2024
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.

4 participants