From eb9f6b86720c8a5c6c66e1c1837c65a4637aabee Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Tue, 27 Oct 2026 16:37:35 -0700 Subject: Cache Serialize whole-program walks --- .../com/seaofnodes/simple/SelectiveLoadingTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'chapter28b/src/test') diff --git a/chapter28b/src/test/java/com/seaofnodes/simple/SelectiveLoadingTest.java b/chapter28b/src/test/java/com/seaofnodes/simple/SelectiveLoadingTest.java index cfaa0456..d8fad3d5 100644 --- a/chapter28b/src/test/java/com/seaofnodes/simple/SelectiveLoadingTest.java +++ b/chapter28b/src/test/java/com/seaofnodes/simple/SelectiveLoadingTest.java @@ -10,6 +10,25 @@ import org.junit.Test; import static org.junit.Assert.*; public class SelectiveLoadingTest { + @Test public void testSharedConstantsInSeparateObjects() throws Exception { + Path root = library("shared-constants-"); + Path src = Files.createDirectory(root.resolve("src")); + Path obj = Files.createDirectory(root.resolve("obj")); + write(src,"Lib","val sum_noInline = { int n -> Left.at_noInline(n)+Right.at_noInline(n); };"); + write(src,"Lib/Left","val at_noInline = { int n -> n+1000000000000; };"); + write(src,"Lib/Right","val at_noInline = { int n -> n*2+1000000000000; };"); + // Both bodies share a constant in the compiling graph. Each saved + // object must contain it without pulling in the other unit's body. + new CodeGen(src.toString(),obj.toString(),null,"Lib",null,123,true,TypeInteger.BOT) + .driver(TestC.CPU_PORT,TestC.CALL_CONVENTION,false,false); + CodeGen code = new CodeGen(null,null,new Ary<>(new String[]{obj.toString()}), + "Use","return Lib.sum_noInline(arg);",123,true,TypeInteger.BOT).driver(CodeGen.Phase.TypeCheck); + assertNull(code._compunits.get("Lib/Left")._src); + assertNull(code._compunits.get("Lib/Right")._src); + assertEquals("2000000000000",Eval2.eval(code,0)); + assertEquals("2000000000003",Eval2.eval(code,1)); + } + @Test public void testUnreachableImportIsNotARoot() throws Exception { Path root = library("dead-import-"); Ary paths = new Ary<>(new String[]{root.toString()}); -- cgit v1.2.3