Skip to content

Implement a Tasty CompilerInterface checker #7517

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

Closed
anatoliykmetyuk opened this issue Nov 7, 2019 · 1 comment
Closed

Implement a Tasty CompilerInterface checker #7517

anatoliykmetyuk opened this issue Nov 7, 2019 · 1 comment

Comments

@anatoliykmetyuk
Copy link
Contributor

anatoliykmetyuk commented Nov 7, 2019

The CompilerInterface implementation has its Term defined to be a Tree:

https://github.com/lampepfl/dotty/blob/b5f2f1831a17efc0bef80742a9b992134dc7061b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala#L226

The fact that a Term can be any tree at all makes the interface unsafe: non-terms may potentially be returned in place of terms when matching on trees. Implementing runtime checks is performance-costly – however we can implement such checks under a separate compiler flag and run them from the CI.

One possible implementation would involve a wrapper around the standard compiler interface:

class CheckingCompilerInterface(val ci: CompilerInterface)
  export ci._
  def matchStatement(tree: Tree)(given ctx: Context): Option[Statement] =
    verifyStatement(ci.matchStatement(tree))
  /* ... */

The verifyStatement method above should do the following:

  • Call the more specific matchers of all the subtypes of Statement
  • Check that exactly one of them returns a Some

See #7503 for an example (test case) of where things go wrong without such checks.

@nicolasstucki
Copy link
Contributor

We started adding assertions within the reflection API directly behind the YCheck flags. This has the advantage of catching errors early. Other checks should be done in normal Ycheck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants