-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add expression compiler #22597
Draft
adpi2
wants to merge
19
commits into
scala:main
Choose a base branch
from
adpi2:add-expression-compiler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add expression compiler #22597
Conversation
This file contains 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
37985f6
to
839713b
Compare
Looks like the tests are not compiling due to usage of newer JDK API? |
I need to configure sbt-jdi-tools to enable JDI on JDK 8. |
55e7262
to
df7f853
Compare
7df3f19
to
f9f8566
Compare
debugMode allows to connect to runner processes with JDI
f9f8566
to
8106811
Compare
Each time we disconnect the debugger, the child process opens a new port that we must read to connect a new debugger
7556b14
to
d60954c
Compare
d60954c
to
b207244
Compare
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.
This PR migrates the expression compiler from scalacenter/scala-debug-adapter to the scala3 repository. This change was agreed upon during the core meeting a few months ago to simplify the release process and coordination. By doing so, we eliminate the need to release any part of scalacenter/scala-debug-adapter after each Scala 3 release to provide full debugging support in Metals.
The
ExpressionCompiler
andExpressionCompilerBridge
is placed in the main compiler module to streamline integration with external tools like sbt, Metals, Bloop, IJ Scala plugin. This avoids the complexity for those tools them to download additional jars.The expression compiler
The expression compiler extends the main compiler with 3 phases:
InsertExpression: Just after parsing. It parses and inserts the expression in the original source tree. It also inserts the expression class, with a placeholder
def evaluate: Any
method.ExtractExpression:
After
Typer
, the pickler phases,ExtensionMethods
andElimByName
.We must extract the expression before
LambdaLift
, otherwise the expression itself can influence how lambdas are going to be lifted. Notably it can contains lambda that needs to be lifted to the expression class.ExtractExpression
extracts the expression from the original tree to theevaluate
method of the expression class.At this time it is too early to know exactly how we can evaluate local variables and inaccessible members, so it transform such trees into magic calls of the
reflectEval
method, whith aReflectEvalStrategy
attachment.ResolveReflectEval:
At the end of the transform phases, it transforms all calls to
reflectEval
into real reflective calls, using info from theReflectEvalStrategy
.Usage of the expression compiler
The expression compiler is used by the debuggers such as scalacenter/scala-debug-adapter and the IJ Scala plugin to provide support for the debug console. It allows to compile any Scala expression against a running Scala program. The compiled class can then be loaded to compute the evaluation output.
The
ExpressionCompilerBridge
can easily be invoked by reflection from an isolated classloader. It takes as input:outputDir: Path
classPath: String
options: Array[String]
: the compiler optionssourceFile: Path
: the source file in which we compile the expressionconfig: ExpressionCompilerConfig
:packageName
: the current package name of the evaluation frameoutputClassName: String
: the name of the output class, that will be loaded by the debuggee to evaluated the expressionbreakpointLine: Int
: the line in source file where we evaluate the expressionexpression: String
: the expression to compilelocalVariables: Set[String]
: a set of visible local variables (useful for checking captures)errorReporter: Consumer[String]
The
ExpressionCompilerConfig
is a factory class. It can evolve in binary compatible ways to allow older and newer versions of the debugger to use older and newer versions of theExpressionCompilerBridge
.