Skip to content

Commit

Permalink
Fallback to old parser when the .so file of the new one cannot be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Nov 9, 2022
1 parent 54857c1 commit 8f33e0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
16 changes: 14 additions & 2 deletions engine/runtime/src/main/java/org/enso/compiler/EnsoCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@ public final class EnsoCompiler implements AutoCloseable {
private final Parser parser;

public EnsoCompiler() {
this.parser = Parser.create();
Parser p;
try {
p = Parser.create();
} catch (LinkageError err) {
p = null;
}
this.parser = p;
}

@Override
public void close() throws Exception {
this.parser.close();
if (parser != null) {
parser.close();
}
}

boolean isReady() {
return parser != null;
}

IR.Module compile(Source src) {
Expand Down
22 changes: 11 additions & 11 deletions engine/runtime/src/main/scala/org/enso/compiler/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class Compiler(
)
private val serializationManager: SerializationManager =
new SerializationManager(this)
private val logger: TruffleLogger = context.getLogger(getClass)
private val ensoCompiler: EnsoCompiler = new EnsoCompiler();
private val logger: TruffleLogger = context.getLogger(getClass)
private lazy val ensoCompiler: EnsoCompiler = new EnsoCompiler();

/** Run the initialization sequence. */
def initialize(): Unit = {
Expand Down Expand Up @@ -445,15 +445,15 @@ class Compiler(
val tree = parse(src)
generateIR(tree)
}
def newParser() = {
val tree = ensoCompiler.parse(src)
ensoCompiler.generateIR(tree)
}
val expr = if ("scala".equals(System.getenv("ENSO_PARSER"))) {
oldParser()
} else {
newParser()
}
val expr =
if (
!"scala".equals(System.getenv("ENSO_PARSER")) && ensoCompiler.isReady()
) {
val tree = ensoCompiler.parse(src)
ensoCompiler.generateIR(tree)
} else {
oldParser()
}

val exprWithModuleExports =
if (module.isSynthetic)
Expand Down

0 comments on commit 8f33e0a

Please sign in to comment.