Skip to content

Implement a Tasty CompilerInterface checker #7517

Closed
@anatoliykmetyuk

Description

@anatoliykmetyuk

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions