Skip to content

Commit

Permalink
Cache self argument (#10785)
Browse files Browse the repository at this point in the history
In order for widgets not to invalidate expression's results and trigger computations, we now cache self argument to which visualizations should be attached to.

It should help with #10730 but there is still a bug in GUI.
  • Loading branch information
hubertp authored Aug 14, 2024
1 parent f14b79f commit f8eb922
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package org.enso.compiler.pass.analyse

import org.enso.compiler.context.{InlineContext, ModuleContext}
import org.enso.compiler.core.Implicits.AsMetadata
import org.enso.compiler.core.ir.CallArgument.Specified
import org.enso.compiler.core.{CompilerError, ExternalID}
import org.enso.compiler.core.ir.{
CallArgument,
DefinitionArgument,
Expression,
Module,
Expand All @@ -12,7 +14,7 @@ import org.enso.compiler.core.ir.{
}
import org.enso.compiler.core.ir.module.scope.Definition
import org.enso.compiler.core.ir.module.scope.definition
import org.enso.compiler.core.ir.expression.{Comment, Error}
import org.enso.compiler.core.ir.expression.{Application, Comment, Error}
import org.enso.compiler.core.ir.MetadataStorage._
import org.enso.compiler.pass.IRPass
import org.enso.compiler.pass.desugar._
Expand Down Expand Up @@ -151,16 +153,40 @@ case object CachePreferenceAnalysis extends IRPass {
.updateMetadata(new MetadataPair(this, weights))
case error: Error =>
error
case app: Application.Prefix =>
app.arguments match {
case self :: rest =>
val newSelf = analyseSelfCallArgument(self, weights)
app.copy(arguments = newSelf :: rest)
case _ =>
app
}
case expr =>
expr.getExternalId.collect {
expr.getExternalId.foreach {
case id if !weights.contains(id) => weights.update(id, Weight.Never)
case _ =>
}
expr
.mapExpressions(analyseExpression(_, weights))
.updateMetadata(new MetadataPair(this, weights))
}
}

def analyseSelfCallArgument(
callArgument: CallArgument,
weights: WeightInfo
): CallArgument = {
callArgument.value.getExternalId.foreach(weights.update(_, Weight.Always))
callArgument match {
case arg: Specified =>
arg.copy(value =
analyseExpression(arg.value, weights).updateMetadata(
new MetadataPair(this, weights)
)
)
}
}

/** Performs preference analysis on a function definition argument.
*
* @param argument the definition argument to perform the analysis on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4167,9 +4167,11 @@ class RuntimeVisualizationsTest extends AnyFlatSpec with Matchers {
)
val attachVisualizationResponses =
context.receiveNIgnoreExpressionUpdates(3)
attachVisualizationResponses should contain allOf (
Api.Response(requestId, Api.VisualizationAttached()),
context.executionComplete(contextId)
attachVisualizationResponses should contain(
Api.Response(requestId, Api.VisualizationAttached())
)
attachVisualizationResponses should not contain context.executionComplete(
contextId
)
val Some(data) = attachVisualizationResponses.collectFirst {
case Api.Response(
Expand Down

0 comments on commit f8eb922

Please sign in to comment.