-
Notifications
You must be signed in to change notification settings - Fork 323
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
Stateless parser API #11147
Stateless parser API #11147
Changes from 16 commits
ce95e4e
285e2e6
23e594f
94ac9a4
2292362
851fda9
4673a1d
b948b2e
8491ce1
6908129
137abbc
8bfe195
be6f9d2
5358f32
f81679a
6edac90
732d1f0
d22c8af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ import org.enso.compiler.phase.exports.{ | |
ExportsResolution | ||
} | ||
import org.enso.syntax2.Tree | ||
import org.enso.syntax2.Parser | ||
|
||
import java.io.PrintStream | ||
import java.util.concurrent.{ | ||
|
@@ -69,7 +70,6 @@ class Compiler( | |
if (config.outputRedirect.isDefined) | ||
new PrintStream(config.outputRedirect.get) | ||
else context.getOut | ||
private lazy val ensoCompiler: EnsoParser = new EnsoParser() | ||
|
||
/** Java accessor */ | ||
def getConfig(): CompilerConfig = config | ||
|
@@ -598,11 +598,8 @@ class Compiler( | |
) | ||
|
||
val src = context.getCharacters(module) | ||
val idMap = context.getIdMap(module) | ||
val tree = ensoCompiler.parse(src) | ||
val expr = | ||
if (idMap == null) ensoCompiler.generateIR(tree) | ||
else ensoCompiler.generateModuleIr(tree, idMap.values) | ||
val idMap = Option(context.getIdMap(module)) | ||
val expr = EnsoParser.compile(src, idMap.map(_.values).orNull) | ||
|
||
val exprWithModuleExports = | ||
if (context.isSynthetic(module)) | ||
|
@@ -685,9 +682,8 @@ class Compiler( | |
inlineContext: InlineContext | ||
): Option[(InlineContext, Expression)] = { | ||
val newContext = inlineContext.copy(freshNameSupply = Some(freshNameSupply)) | ||
val tree = ensoCompiler.parse(srcString) | ||
|
||
ensoCompiler.generateIRInline(tree).map { ir => | ||
EnsoParser.compileInline(srcString).map { ir => | ||
val compilerOutput = runCompilerPhasesInline(ir, newContext) | ||
runErrorHandlingInline(compilerOutput, newContext) | ||
(newContext, compilerOutput) | ||
|
@@ -700,7 +696,7 @@ class Compiler( | |
* @return A Tree representation of `source` | ||
*/ | ||
def parseInline(source: CharSequence): Tree = | ||
ensoCompiler.parse(source) | ||
Parser.parse(source) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer not to expose two different levels of abstraction from |
||
|
||
/** Enhances the provided IR with import/export statements for the provided list | ||
* of fully qualified names of modules. The statements are considered to be "synthetic" i.e. compiler-generated. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1351,6 +1351,17 @@ class RuntimeVisualizationsTest extends AnyFlatSpec with Matchers { | |
) | ||
) | ||
|
||
val attachVisualizationResponses = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is failing in CI. It looks to me like it is a nondeterministic failure related to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CCing @4e6 |
||
context.receiveNIgnoreExpressionUpdates(2) | ||
|
||
attachVisualizationResponses.filter( | ||
_.payload.isInstanceOf[Api.VisualizationAttached] | ||
) shouldEqual List( | ||
Api.Response(requestId, Api.VisualizationAttached()), | ||
Api.Response(requestId, Api.VisualizationAttached()) | ||
) | ||
|
||
// Modify the file | ||
context.send( | ||
Api.Request( | ||
Api.EditFileNotification( | ||
|
@@ -1367,23 +1378,17 @@ class RuntimeVisualizationsTest extends AnyFlatSpec with Matchers { | |
) | ||
) | ||
|
||
val responses = | ||
context.receiveNIgnoreExpressionUpdates(7) | ||
val editFileResponses = | ||
context.receiveNIgnoreExpressionUpdates(5) | ||
|
||
responses should contain allOf ( | ||
Api.Response(requestId, Api.VisualizationAttached()), | ||
editFileResponses should contain( | ||
context.executionComplete(contextId) | ||
) | ||
|
||
responses.filter( | ||
_.payload.isInstanceOf[Api.VisualizationAttached] | ||
) shouldEqual List( | ||
Api.Response(requestId, Api.VisualizationAttached()), | ||
Api.Response(requestId, Api.VisualizationAttached()) | ||
) | ||
|
||
val visualizationUpdatesResponses = | ||
responses.filter(_.payload.isInstanceOf[Api.VisualizationUpdate]) | ||
(attachVisualizationResponses ::: editFileResponses).filter( | ||
_.payload.isInstanceOf[Api.VisualizationUpdate] | ||
) | ||
val expectedExpressionId = context.Main.idMainX | ||
val visualizationUpdates = visualizationUpdatesResponses.map( | ||
_.payload.asInstanceOf[Api.VisualizationUpdate] | ||
|
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.
Looks like the original code was buggy. The
Compiler
should have implementedClosable
interface and callensoCompiler.close()
on theEnsoParser
. I am not sure what's the overhead of a singleEnsoParser
instance and its natively allocated memory, but this must have leaked a lot during unit test execution!@hubertp did reduce the memory, but the Rust parser native part might now even have been visible in the JVM heap dump - only in RSS...