From f8eb922c9d79ed38705cee7ad5392e5078a1c32e Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 14 Aug 2024 12:43:33 +0200 Subject: [PATCH] Cache self argument (#10785) 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. --- .../analyse/CachePreferenceAnalysis.scala | 30 +++++++++++++++++-- .../RuntimeVisualizationsTest.scala | 8 +++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/CachePreferenceAnalysis.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/CachePreferenceAnalysis.scala index 3e5156acf8dd..3d5a1c58d720 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/CachePreferenceAnalysis.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/CachePreferenceAnalysis.scala @@ -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, @@ -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._ @@ -151,9 +153,18 @@ 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)) @@ -161,6 +172,21 @@ case object CachePreferenceAnalysis extends IRPass { } } + 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 diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala index 85d02a6bb92f..f8366e997215 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala @@ -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(