scalacenter / student-projects

The list of the available projects at the Scala Center for bachelor and master students.
8 stars 0 forks source link

Evaluate expression using scalameta in the debugger #9

Closed adpi2 closed 1 year ago

adpi2 commented 2 years ago

Description

The scala-debug-adapter is an implementation of the Debug Adapter Protocol for Scala. It allows users of VSCode to debug their Scala programs, using features such as breakpoints, conditional breakpoints, debug console, log-points and more.

Some of these features depends on the ability to evaluate expression at runtime: we pause the program at some instruction and we evaluate an expression to inspect its state. At the current stage, we have an expression evaluator that depends heavily on the Scala compiler: it recompiles the entire source file in which we inserted the expression. This is very precise but slow and not very flexible.

As an alternative we would like to build an evaluator that is based on scalameta. Scalameta is a parser of scala code: it parses Scala code into syntax trees. We parse the expression, check that it is valid using runtime reflection on the current state of the program, then evaluate by calling methods and accessing fields using runtime calls.

Such evaluator would be faster and more flexible:

However it can only evaluate simple expressions made of field accesses and method calls. It won't be able to do pattern matching or implicit resolution. We will still use the compiler-based evaluator to evaluate more high-level Scala expressions.

Supervisor

Adrien Piquerez(adrien.piquerez@epfl.ch): Tooling Engineer at the Scala Center

Prerequisites