mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 04:43:26 +03:00
Inline execution should support FQNs (#8454)
* Test illustrating problems with FQNs Inline execution fails with `Compile error: The name `Standard` could not be found.`. * Ensure InlineContext carries Package Repos info Previously, there was no requirement that inline execution should allow for FQNs. This meant that the omission of Package Repository info went unnoticed. In order to be able to refer to `Standard.Visualization.Preprocessor` it has to be exported as well.
This commit is contained in:
parent
c5a6859654
commit
a11bddcb74
@ -7,4 +7,5 @@ import project.Preprocessor
|
||||
|
||||
export project.Helpers
|
||||
export project.Id.Id
|
||||
export project.Preprocessor
|
||||
from project.File_Upload export file_uploading
|
||||
|
@ -37,19 +37,23 @@ object InlineContext {
|
||||
* @param module the module defining the context
|
||||
* @param isInTailPosition whether or not the inline expression occurs in a
|
||||
* tail position
|
||||
* @param compilerConfig the compiler configuration
|
||||
* @param pkgRepo the compiler's package repository
|
||||
* @return the [[InlineContext]] instance corresponding to the arguments
|
||||
*/
|
||||
def fromJava(
|
||||
localScope: LocalScope,
|
||||
module: CompilerContext.Module,
|
||||
isInTailPosition: Option[Boolean],
|
||||
compilerConfig: CompilerConfig
|
||||
compilerConfig: CompilerConfig,
|
||||
pkgRepo: Option[PackageRepository]
|
||||
): InlineContext = {
|
||||
InlineContext(
|
||||
localScope = Option(localScope),
|
||||
module = ModuleContext(module, compilerConfig),
|
||||
isInTailPosition = isInTailPosition,
|
||||
compilerConfig = compilerConfig
|
||||
compilerConfig = compilerConfig,
|
||||
pkgRepo = pkgRepo
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -3880,4 +3880,184 @@ class RuntimeVisualizationsTest
|
||||
}
|
||||
new String(data) shouldEqual "85"
|
||||
}
|
||||
|
||||
it should "execute default visualization preprocessor" in {
|
||||
val contextId = UUID.randomUUID()
|
||||
val requestId = UUID.randomUUID()
|
||||
val visualizationId = UUID.randomUUID()
|
||||
val moduleName = "Enso_Test.Test.Main"
|
||||
val metadata = new Metadata
|
||||
|
||||
val idMain = metadata.addItem(60, 6)
|
||||
|
||||
val code =
|
||||
"""import Standard.Visualization.Preprocessor
|
||||
|
|
||||
|main =
|
||||
| fn = x -> x
|
||||
| fn
|
||||
|""".stripMargin.linesIterator.mkString("\n")
|
||||
val contents = metadata.appendToCode(code)
|
||||
val mainFile = context.writeMain(contents)
|
||||
|
||||
// create context
|
||||
context.send(Api.Request(requestId, Api.CreateContextRequest(contextId)))
|
||||
context.receive shouldEqual Some(
|
||||
Api.Response(requestId, Api.CreateContextResponse(contextId))
|
||||
)
|
||||
|
||||
// Open the new file
|
||||
context.send(
|
||||
Api.Request(requestId, Api.OpenFileRequest(mainFile, contents))
|
||||
)
|
||||
context.receive shouldEqual Some(
|
||||
Api.Response(Some(requestId), Api.OpenFileResponse)
|
||||
)
|
||||
|
||||
// push main
|
||||
val item1 = Api.StackItem.ExplicitCall(
|
||||
Api.MethodPointer(moduleName, moduleName, "main"),
|
||||
None,
|
||||
Vector()
|
||||
)
|
||||
context.send(
|
||||
Api.Request(requestId, Api.PushContextRequest(contextId, item1))
|
||||
)
|
||||
context.receiveNIgnorePendingExpressionUpdates(
|
||||
3
|
||||
) should contain theSameElementsAs Seq(
|
||||
Api.Response(requestId, Api.PushContextResponse(contextId)),
|
||||
TestMessages.update(
|
||||
contextId,
|
||||
idMain,
|
||||
ConstantsGen.FUNCTION
|
||||
),
|
||||
context.executionComplete(contextId)
|
||||
)
|
||||
|
||||
// execute expression
|
||||
context.send(
|
||||
Api.Request(
|
||||
requestId,
|
||||
Api.ExecuteExpression(
|
||||
contextId,
|
||||
visualizationId,
|
||||
idMain,
|
||||
"Preprocessor.default_preprocessor 85"
|
||||
)
|
||||
)
|
||||
)
|
||||
val executeExpressionResponses =
|
||||
context.receiveNIgnoreExpressionUpdates(3)
|
||||
executeExpressionResponses should contain allOf (
|
||||
Api.Response(requestId, Api.VisualizationAttached()),
|
||||
context.executionComplete(contextId)
|
||||
)
|
||||
val Some(data) = executeExpressionResponses.collectFirst {
|
||||
case Api.Response(
|
||||
None,
|
||||
Api.VisualizationUpdate(
|
||||
Api.VisualizationContext(
|
||||
`visualizationId`,
|
||||
`contextId`,
|
||||
`idMain`
|
||||
),
|
||||
data
|
||||
)
|
||||
) =>
|
||||
data
|
||||
}
|
||||
new String(data) shouldEqual "85"
|
||||
}
|
||||
|
||||
it should "execute default visualization preprocessor with a FQN" in {
|
||||
val contextId = UUID.randomUUID()
|
||||
val requestId = UUID.randomUUID()
|
||||
val visualizationId = UUID.randomUUID()
|
||||
val moduleName = "Enso_Test.Test.Main"
|
||||
val metadata = new Metadata
|
||||
|
||||
val idMain = metadata.addItem(90, 6)
|
||||
|
||||
val code =
|
||||
"""import Standard.Visualization
|
||||
|import Standard.Visualization.Preprocessor
|
||||
|
|
||||
|main =
|
||||
| fn = x -> x
|
||||
| fn
|
||||
|""".stripMargin.linesIterator.mkString("\n")
|
||||
val contents = metadata.appendToCode(code)
|
||||
val mainFile = context.writeMain(contents)
|
||||
|
||||
// create context
|
||||
context.send(Api.Request(requestId, Api.CreateContextRequest(contextId)))
|
||||
context.receive shouldEqual Some(
|
||||
Api.Response(requestId, Api.CreateContextResponse(contextId))
|
||||
)
|
||||
|
||||
// Open the new file
|
||||
context.send(
|
||||
Api.Request(requestId, Api.OpenFileRequest(mainFile, contents))
|
||||
)
|
||||
context.receive shouldEqual Some(
|
||||
Api.Response(Some(requestId), Api.OpenFileResponse)
|
||||
)
|
||||
|
||||
// push main
|
||||
val item1 = Api.StackItem.ExplicitCall(
|
||||
Api.MethodPointer(moduleName, moduleName, "main"),
|
||||
None,
|
||||
Vector()
|
||||
)
|
||||
context.send(
|
||||
Api.Request(requestId, Api.PushContextRequest(contextId, item1))
|
||||
)
|
||||
context.receiveNIgnorePendingExpressionUpdates(
|
||||
3
|
||||
) should contain theSameElementsAs Seq(
|
||||
Api.Response(requestId, Api.PushContextResponse(contextId)),
|
||||
TestMessages.update(
|
||||
contextId,
|
||||
idMain,
|
||||
ConstantsGen.FUNCTION
|
||||
),
|
||||
context.executionComplete(contextId)
|
||||
)
|
||||
|
||||
// execute expression
|
||||
context.send(
|
||||
Api.Request(
|
||||
requestId,
|
||||
Api.ExecuteExpression(
|
||||
contextId,
|
||||
visualizationId,
|
||||
idMain,
|
||||
"Standard.Visualization.Preprocessor.default_preprocessor 85"
|
||||
)
|
||||
)
|
||||
)
|
||||
val executeExpressionResponses =
|
||||
context.receiveNIgnoreExpressionUpdates(3)
|
||||
executeExpressionResponses should contain allOf (
|
||||
Api.Response(requestId, Api.VisualizationAttached()),
|
||||
context.executionComplete(contextId)
|
||||
)
|
||||
val Some(data) = executeExpressionResponses.collectFirst {
|
||||
case Api.Response(
|
||||
None,
|
||||
Api.VisualizationUpdate(
|
||||
Api.VisualizationContext(
|
||||
`visualizationId`,
|
||||
`contextId`,
|
||||
`idMain`
|
||||
),
|
||||
data
|
||||
)
|
||||
) =>
|
||||
data
|
||||
}
|
||||
new String(data) shouldEqual "85"
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -64,13 +64,15 @@ public abstract class EvalNode extends BaseNode {
|
||||
RootCallTarget parseExpression(LocalScope scope, ModuleScope moduleScope, String expression) {
|
||||
EnsoContext context = EnsoContext.get(this);
|
||||
LocalScope localScope = scope.createChild();
|
||||
var compiler = context.getCompiler();
|
||||
InlineContext inlineContext =
|
||||
InlineContext.fromJava(
|
||||
localScope,
|
||||
moduleScope.getModule().asCompilerModule(),
|
||||
scala.Option.apply(getTailStatus() != TailStatus.NOT_TAIL),
|
||||
context.getCompilerConfig());
|
||||
var compiler = context.getCompiler();
|
||||
context.getCompilerConfig(),
|
||||
scala.Option.apply(compiler.packageRepository()));
|
||||
|
||||
var tuppleOption = compiler.runInline(expression, inlineContext);
|
||||
if (tuppleOption.isEmpty()) {
|
||||
throw new RuntimeException("Invalid code passed to `eval`: " + expression);
|
||||
|
@ -241,6 +241,10 @@ class Package[F](
|
||||
.asScala
|
||||
.toList
|
||||
}
|
||||
|
||||
override def toString: String = {
|
||||
s"Package[$name]"
|
||||
}
|
||||
}
|
||||
|
||||
/** A class responsible for creating and parsing package structures.
|
||||
|
Loading…
Reference in New Issue
Block a user