-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compare IR before and after serialization test
- Loading branch information
1 parent
ef84e1d
commit 95ff6a0
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
engine/runtime/src/test/java/org/enso/interpreter/caches/ModuleCacheTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.enso.interpreter.caches; | ||
|
||
import org.enso.compiler.CompilerTest; | ||
import org.enso.compiler.core.IR; | ||
import org.enso.interpreter.Constants; | ||
import org.enso.interpreter.runtime.EnsoContext; | ||
import org.enso.interpreter.runtime.builtin.Builtins; | ||
import org.enso.interpreter.test.TestBase; | ||
import org.enso.interpreter.util.ScalaConversions; | ||
import org.enso.polyglot.CompilationStage; | ||
import org.enso.polyglot.LanguageInfo; | ||
import org.enso.polyglot.MethodNames; | ||
import org.enso.polyglot.RuntimeOptions; | ||
import org.graalvm.polyglot.Context; | ||
import org.junit.Test; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.BeforeClass; | ||
|
||
public class ModuleCacheTest extends TestBase { | ||
private static Context ctx; | ||
|
||
public ModuleCacheTest() { | ||
} | ||
|
||
@BeforeClass | ||
public static void initializeContext() throws Exception { | ||
ctx = defaultContextBuilder() | ||
.option(RuntimeOptions.DISABLE_IR_CACHES, "true") | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void testCompareList() throws Exception { | ||
var ensoCtx = (EnsoContext) ctx.getBindings(LanguageInfo.ID).invokeMember(MethodNames.TopScope.LEAK_CONTEXT).asHostObject(); | ||
var name = "Standard.Base.Data.List"; | ||
|
||
var v = ctx.eval("enso", """ | ||
import Standard.Base.Data.List | ||
empty = List.List.Nil | ||
""").invokeMember(MethodNames.Module.EVAL_EXPRESSION, "empty"); | ||
assertEquals("List", v.getMetaObject().getMetaSimpleName()); | ||
|
||
var option = ensoCtx.findModule(name); | ||
assertTrue("Module found", option.isPresent()); | ||
var module = option.get(); | ||
var ir = module.getIr().duplicate(true, true, true, true); | ||
for (var node : ScalaConversions.asJava(ir.preorder())) { | ||
node.passData().prepareForSerialization(ensoCtx.getCompiler().context()); | ||
} | ||
var cm = new ModuleCache.CachedModule(ir, CompilationStage.AFTER_CODEGEN, module.getSource()); | ||
byte[] arr = module.getCache().serialize(ensoCtx, cm); | ||
|
||
var meta = new ModuleCache.Metadata("hash", "code", CompilationStage.AFTER_CODEGEN.toString()); | ||
var cachedIr = module.getCache().deserialize(ensoCtx, arr, meta, null); | ||
assertNotNull("IR read", cachedIr); | ||
CompilerTest.assertIR(name, module.getIr(), cachedIr.moduleIR()); | ||
} | ||
} |