Skip to content

Commit

Permalink
Store unused function argument and pattern binding
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Nov 27, 2023
1 parent 48f9651 commit bb012eb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
@Persistable(clazz = Name.BuiltinAnnotation.class, id = 783)
@Persistable(clazz = Type.Error.class, id = 784)
@Persistable(clazz = Unused.Binding.class, id = 785)
@Persistable(clazz = Unused.PatternBinding.class, id = 786)
@Persistable(clazz = Unused.FunctionArgument.class, id = 787)
@Persistable(clazz = Warning.DuplicatedImport.class, id = 788)
@Persistable(clazz = Warning.WrongBuiltinMethod.class, id = 789)
public final class IrPersistance {
private IrPersistance() {}

Expand Down Expand Up @@ -388,28 +392,15 @@ public PersistDiagnosticStorage() {
}

@Override
protected void writeObject(DiagnosticStorage obj, Output out) throws IOException {}
protected void writeObject(DiagnosticStorage obj, Output out) throws IOException {
out.writeInline(List.class, obj.toList());
}

@Override
@SuppressWarnings("unchecked")
protected DiagnosticStorage readObject(Input in) throws IOException, ClassNotFoundException {
return new DiagnosticStorage(
(scala.collection.immutable.List) scala.collection.immutable.Nil$.MODULE$);
var diags = in.readInline(List.class);
return new DiagnosticStorage(diags);
}
}

@SuppressWarnings("unchecked")
private static <T> scala.collection.immutable.List<T> nil() {
return (scala.collection.immutable.List<T>) scala.collection.immutable.Nil$.MODULE$;
}

private static <T> scala.collection.immutable.List<T> join(
T head, scala.collection.immutable.List<T> tail) {
return scala.collection.immutable.$colon$colon$.MODULE$.apply(head, tail);
}

@SuppressWarnings("unchecked")
private static <E extends Throwable> E raise(Class<E> clazz, Throwable t) throws E {
throw (E) t;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
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 org.graalvm.polyglot.Source;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;

public class ModuleCacheTest extends TestBase {
private static Context ctx;
Expand Down Expand Up @@ -55,4 +52,30 @@ public void testCompareList() throws Exception {
assertNotNull("IR read", cachedIr);
CompilerTest.assertIR(name, ir, cachedIr.moduleIR());
}


@Test
public void testCompareWithWarning() throws Exception {
var ensoCtx = (EnsoContext) ctx.getBindings(LanguageInfo.ID).invokeMember(MethodNames.TopScope.LEAK_CONTEXT).asHostObject();
var name = "TestWarning";
var code = Source.newBuilder("enso", """
empty x = 42
""", "TestWarning.enso")
.build();

var v = ctx.eval(code).invokeMember(MethodNames.Module.EVAL_EXPRESSION, "empty").execute(-1);
assertEquals(42, v.asInt());

var option = ensoCtx.findModule(name);
assertTrue("Module found", option.isPresent());
var module = option.get();
var ir = module.getIr().duplicate(true, true, true, true);
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, ir, cachedIr.moduleIR());
}
}

0 comments on commit bb012eb

Please sign in to comment.