From 310a2d8ae753f31e6784d512776465706306f56c Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Mon, 3 Apr 2023 16:03:25 +0200 Subject: [PATCH] Delay creation of project root EnsoFile until it is really needed (#6149) Delay creation of `EnsoFile` until it is needed. # Important Notes By putting breakpoint into `Atom` constructor I realized few `EnsoProjectNode` instances may be created when parsing the project. It makes no sense to also create `EnsoFile` for them - until it is needed. --- .../expression/constant/EnsoProjectNode.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/constant/EnsoProjectNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/constant/EnsoProjectNode.java index 79ba87da4cde..83ea7f7435a6 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/constant/EnsoProjectNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/constant/EnsoProjectNode.java @@ -1,5 +1,6 @@ package org.enso.interpreter.node.expression.constant; +import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.TruffleFile; import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.frame.VirtualFrame; @@ -14,30 +15,38 @@ @NodeInfo(description = "Returns a language-level representation of the given Enso project.") public class EnsoProjectNode extends RootNode { - private final Object result; + private final Optional> pkgOpt; public EnsoProjectNode( TruffleLanguage language, EnsoContext context, Optional> pkgOpt) { super(language); + this.pkgOpt = pkgOpt; + } + + @Override + public Object execute(VirtualFrame frame) { + return createProjectDescription(); + } + + @CompilerDirectives.TruffleBoundary + private Object createProjectDescription() { + var context = EnsoContext.get(this); if (pkgOpt.isPresent()) { Package pkg = pkgOpt.get(); EnsoFile rootPath = new EnsoFile(pkg.root().normalize()); Object cfg = context.getEnvironment().asGuestValue(pkg.config()); - result = + var result = context .getBuiltins() .getProjectDescription() .getUniqueConstructor() .newInstance(rootPath, cfg); + return result; } else { - result = + var result = DataflowError.withoutTrace( context.getBuiltins().error().makeModuleNotInPackageError(), this); + return result; } } - - @Override - public Object execute(VirtualFrame frame) { - return result; - } }