-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid AliasAnalysis for Hello_World.enso #10996
Changes from all commits
e24a199
dfe42a8
8c89abd
63e875d
2ada503
569a802
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import org.enso.common.CompilationStage | |
|
||
import scala.collection.mutable | ||
import java.io.IOException | ||
import java.util.logging.Level | ||
|
||
/** Runs imports resolution. Starts from a given module and then recursively | ||
* collects all modules that are reachable from it. | ||
|
@@ -46,7 +47,12 @@ final class ImportResolver(compiler: Compiler) extends ImportResolverForIR { | |
) | ||
(ir, currentLocal) | ||
} catch { | ||
case _: IOException => | ||
case ex: IOException => | ||
context.logSerializationManager( | ||
Level.WARNING, | ||
"Deserialization of " + module.getName() + " failed", | ||
ex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hubertp, when this exception is logged, the stack trace isn't printed on the console. What's the recommended way of logging an exception with stacktrace via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think I'm surprised anymore. It looks like the included There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will file a separate ticket to enable those. Right now the default and only appender is console. We could easily log those to the file but I'm still against printing those in the console. |
||
) | ||
context.updateModule( | ||
current, | ||
u => { | ||
|
@@ -85,6 +91,7 @@ final class ImportResolver(compiler: Compiler) extends ImportResolverForIR { | |
|
||
currentLocal.resolvedImports = | ||
resolvedImports ++ resolvedSyntheticImports | ||
|
||
val newIr = ir.copy(imports = newImportIRs) | ||
context.updateModule( | ||
current, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.enso.interpreter.caches; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.PrintStream; | ||
import java.util.logging.Level; | ||
import java.util.stream.Collectors; | ||
import org.enso.common.RuntimeOptions; | ||
import org.enso.test.utils.ContextUtils; | ||
import org.graalvm.polyglot.Source; | ||
import org.junit.Test; | ||
|
||
public class HelloWorldCacheTest { | ||
|
||
@Test | ||
public void loadingHelloWorldTwiceUsesCaching() throws Exception { | ||
var root = new File("../..").getAbsoluteFile(); | ||
assertTrue("build.sbt exists at " + root, new File(root, "build.sbt").exists()); | ||
var helloWorld = children(root, "test", "Benchmarks", "src", "Startup", "Hello_World.enso"); | ||
assertTrue("Hello_World.enso found", helloWorld.exists()); | ||
|
||
// the first run may or may not use caches | ||
var firstMsgs = executeOnce(helloWorld); | ||
assertTrue("Contains hello world:\n" + firstMsgs, firstMsgs.endsWith("Hello World")); | ||
// after the first run the caches for Hello_World.enso must be generated | ||
|
||
// the second run must read Hello_World from its .ir file! | ||
var secondMsgs = executeOnce(helloWorld); | ||
assertTrue("Contains hello world:\n" + secondMsgs, secondMsgs.contains("Hello World")); | ||
assertTrue( | ||
"Properly deserialized:\n" + secondMsgs, | ||
secondMsgs.contains("Deserializing module Hello_World from IR file: true")); | ||
} | ||
|
||
private static String executeOnce(File src) throws Exception { | ||
var backLog = new ByteArrayOutputStream(); | ||
var log = new PrintStream(backLog); | ||
|
||
try (var ctx = | ||
ContextUtils.defaultContextBuilder() | ||
.out(log) | ||
.err(log) | ||
.logHandler(log) | ||
.option(RuntimeOptions.LOG_LEVEL, Level.FINE.getName()) | ||
.option(RuntimeOptions.DISABLE_IR_CACHES, "false") | ||
.option(RuntimeOptions.PROJECT_ROOT, findBenchmarks(src).getAbsolutePath()) | ||
.build()) { | ||
var code = Source.newBuilder("enso", src).build(); | ||
var res = ContextUtils.evalModule(ctx, code, "main"); | ||
assertTrue("Result of IO.println is Nothing", res.isNull()); | ||
} | ||
return backLog | ||
.toString() | ||
.lines() | ||
.filter(l -> l.toUpperCase().contains("HELLO")) | ||
.collect(Collectors.joining("\n")); | ||
} | ||
|
||
private static File children(File f, String... names) { | ||
for (var n : names) { | ||
f = new File(f, n); | ||
} | ||
return f; | ||
} | ||
|
||
private static File findBenchmarks(File f) { | ||
for (; ; ) { | ||
if (f.getName().equals("Benchmarks")) { | ||
return f; | ||
} | ||
f = f.getParentFile(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the core of the change. Delaying
toConcrete
until all modules are registered to package repository.It is also potentially dangerous change. Previously, when the
restoreFromSerialization
failed, it would returnNone
and that would trigger parsing. Right now we optimistically claim everything is all right and then we may get failures later when someone calls for exampleResolvedModule.unsafeModule
.It is probably OK (everything is green; but we aren't testing broken scenarios much), but we should get ready for such reports in the future and fix them when they appear.