Make annotation typechecking lazier#9302
Merged
lrytz merged 2 commits intoscala:2.13.xfrom Nov 9, 2020
Merged
Conversation
2abc534 to
db2b8f6
Compare
db2b8f6 to
a61e4fe
Compare
Now that `Typer.stabilize` ends up checking for `@uncheckedStable` annotations to support defs's as stable paths, new opportunities arise for cyclic errors. This PR reduces the likelihood of cycles by typechecking the only core of an annotation (_not_ the full application to the annotation arguments) to determine its type symbol. pos/unchecked-stable-cyclic-error.scala test case started to fail since scala#8338 with: ``` |-- object Test BYVALmode-EXPRmode (site: package <empty>) | |-- super APPSELmode-EXPRmode-POLYmode-QUALmode (silent: <init> in Test) | | |-- this EXPRmode (silent: <init> in Test) | | | \-> Test.type | | \-> Test.type | |-- def foo BYVALmode-EXPRmode (site: object Test) | | |-- attr EXPRmode (site: method foo in Test) | | | |-- Int TYPEmode (site: method attr in Test) | | | | \-> Int | | | |-- new anno APPSELmode-BYVALmode-EXPRmode-FUNmode-POLYmode (site: object Test) | | | | |-- new anno APPSELmode-EXPRmode-POLYmode-QUALmode (site: object Test) | | | | | |-- anno FUNmode-TYPEmode (site: object Test) | | | | | | \-> anno | | | | | \-> anno | | | | \-> (a: Any): anno | | | |-- (a: Any): anno : pt=anno EXPRmode (site: value <local Test> in Test) | | | | |-- foo : pt=Any BYVALmode-EXPRmode (site: value <local Test> in Test) | | | | | caught scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving method foo: while typing foo /Users/jz/code/scala/sandbox/test.scala:7: error: recursive method foo needs result type @anno(foo) def attr: Int = foo ^ | | | | \-> anno ``` Another variant, pos/annotation-cycle.scala, fails only on 2.12.x (after the backport of scala#8338). Backporting this fix makes that test start passing on 2.12.x.
a61e4fe to
9d9635d
Compare
Member
|
@retronym see also #9144 where I had some reservations about building more stuff on top of |
Member
Author
|
@lrytz Test case added. |
c8d27c2 to
1d5c0ad
Compare
lrytz
reviewed
Nov 6, 2020
lrytz
approved these changes
Nov 6, 2020
Member
lrytz
left a comment
There was a problem hiding this comment.
LGTM otherwise. The main differences to #9144 are:
- Here we have
ExtraLazyAnnotationInfo extends LazyAnnotationInfo, where the other PR didQualifierTypedAnnotationInfo extends AnnotationInfo. This requires fewer overrides. - Here, typing the qualifier / annotation symbol is lazy, in the other PR it's done eagerly during Namer.
1d5c0ad to
2408bad
Compare
retronym
added a commit
to retronym/scala
that referenced
this pull request
Nov 10, 2020
Now that `Typer.stabilize` ends up checking for `@uncheckedStable` annotations to support defs's as stable paths, new opportunities arise for cyclic errors. This PR reduces the likelihood of cycles by typechecking the only core of an annotation (_not_ the full application to the annotation arguments) to determine its type symbol. pos/unchecked-stable-cyclic-error.scala test case started to fail since scala#8338 with: ``` |-- object Test BYVALmode-EXPRmode (site: package <empty>) | |-- super APPSELmode-EXPRmode-POLYmode-QUALmode (silent: <init> in Test) | | |-- this EXPRmode (silent: <init> in Test) | | | \-> Test.type | | \-> Test.type | |-- def foo BYVALmode-EXPRmode (site: object Test) | | |-- attr EXPRmode (site: method foo in Test) | | | |-- Int TYPEmode (site: method attr in Test) | | | | \-> Int | | | |-- new anno APPSELmode-BYVALmode-EXPRmode-FUNmode-POLYmode (site: object Test) | | | | |-- new anno APPSELmode-EXPRmode-POLYmode-QUALmode (site: object Test) | | | | | |-- anno FUNmode-TYPEmode (site: object Test) | | | | | | \-> anno | | | | | \-> anno | | | | \-> (a: Any): anno | | | |-- (a: Any): anno : pt=anno EXPRmode (site: value <local Test> in Test) | | | | |-- foo : pt=Any BYVALmode-EXPRmode (site: value <local Test> in Test) | | | | | caught scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving method foo: while typing foo /Users/jz/code/scala/sandbox/test.scala:7: error: recursive method foo needs result type @anno(foo) def attr: Int = foo ^ | | | | \-> anno ``` Another variant, pos/annotation-cycle.scala, fails only on 2.12.x (after the backport of scala#8338). Backporting this fix makes that test start passing on 2.12.x. Backports scala#9302
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make annotation typechecking lazier
Now that
Typer.stabilizeends up checking for@uncheckedStableannotations to support defs's as stable paths, new opportunities arise for cyclic errors.This PR reduces the likelihood of cycles by typechecking the only core of an annotation (not the full application to the annotation arguments) to determine its type symbol.
pos/unchecked-stable-cyclic-error.scala test case started to fail since #8338 with:
Another variant, pos/annotation-cycle.scala, fails only on 2.12.x (after the backport of #8338). Backporting this fix makes that test start passing on 2.12.x.
References scala/bug#12216 (which will be fixed after this is backported to 2.12.x)
Fixes scala/bug#11870