-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Reset comparersInUse to zero in ContextState.reset
#18915
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
Conversation
| def impl()(using Quotes): Expr[Unit] = '{()} | ||
| inline def run(): Unit = ${impl()} | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| sources.clear() | ||
| files.clear() | ||
| comparers.clear() // forces re-evaluation of top and bottom classes in TypeComparer | ||
| comparersInUse = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For additional context, this needs to be reset because the compilation unit was suspended due to the macro dependency. We need to set it back to 0 each time we restart compilation after the suspension.
| @@ -0,0 +1,3 @@ | |||
| import scala.language.experimental.captureChecking | |||
| val x = run() | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| def impl()(using Quotes): Expr[Unit] = '{()} | ||
| inline def run(): Unit = ${impl()} | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
odersky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted!
Fixes #18855
The code in #18855 used to crash the compiler with an out-of-bound access exception. It was because, previously,
ContextState.resetclears thecomparers, the cached pool ofTypeComparers, while keeping the variablecomparersInUseintact. However, thecomparermethod of a context assumescomparershas a size greater than or equal tocomparersInUse. So the invariant is clearly violated here and thus triggers the crash.This PR proposes a straightforward fix. Yet, the reason why only under both macros and cc this code path will be triggered remains to be investigated.