Skip to content

Commit

Permalink
Delay creation of project root EnsoFile until it is really needed (#6149
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
JaroslavTulach authored Apr 3, 2023
1 parent f26bcf6 commit 310a2d8
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Package<TruffleFile>> pkgOpt;

public EnsoProjectNode(
TruffleLanguage<?> language, EnsoContext context, Optional<Package<TruffleFile>> 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<TruffleFile> 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;
}
}

0 comments on commit 310a2d8

Please sign in to comment.