summaryrefslogtreecommitdiff
path: root/chapter33/src/test
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-12-04 14:46:06 -0800
committerCliff Click <cliffc@acm.org>2026-12-04 14:46:06 -0800
commitd9df5cddeaa20045f1194a4b250041cf88bb8845 (patch)
tree493c0ac8fd705032c4fd1bc9618a58d8945228ee /chapter33/src/test
parent57f2a6b71e449f323fa944b2d3e34e7fadd54e6d (diff)
downloadSimple-d9df5cddeaa20045f1194a4b250041cf88bb8845.tar.gz
Simple-d9df5cddeaa20045f1194a4b250041cf88bb8845.zip
Separate summary call dependencies from function escapes
Restore a discarded private initializer summary when a later inline import reveals its direct call. Keep class-init dependencies for cycle checking without publishing their function pointers. Cover escape separation and unloaded private initializer cycles; full make -k -j8 tests passes.
Diffstat (limited to 'chapter33/src/test')
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java16
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java16
2 files changed, 32 insertions, 0 deletions
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java b/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java
index 8f1d1ee8..4ae7f771 100644
--- a/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java
+++ b/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java
@@ -549,6 +549,22 @@ public class ClassInitDependenciesTest {
assertNull(Eval2.eval(code,0,10));
}
+ @Test public void testImportedPrivateInitializerCycle() throws Exception {
+ Path dir=tempDir("private-cycle-"), stubs=tempDir("private-stub-");
+ object(stubs,stubs,"Main","int value=arg;");
+ module(dir,stubs,"Library",Map.of("Library","val read_noInline={ -> _Hidden.value; };",
+ "Library/_Hidden","int value=Main.value;"));
+ CodeGen code=new CodeGen(null,dir.toString(),new Ary<>(new String[]{dir.toString()}),
+ "Main","int value=Library.read_noInline();",123,true,TypeInteger.BOT);
+ try {
+ code.driver(CodeGen.Phase.TypeCheck);
+ fail("Expected a cycle through the unloaded private initializer");
+ } catch( Parser.ParseException ex ) {
+ assertCycle(ex.getMessage(),"Main -> Library._Hidden -> Main");
+ assertNull(code.getElf(code._compunits.get("Library/_Hidden")._obj)._nodes);
+ }
+ }
+
@Test public void testImportedPrivateInitializer() throws Exception {
Path dir=tempDir("private-");
module(dir,dir,"Library",Map.of("Library","val read={ -> _Hidden.value; };",
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java b/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java
index 84aa8a3f..15495696 100644
--- a/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java
+++ b/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java
@@ -7,6 +7,22 @@ import org.junit.Test;
import static org.junit.Assert.*;
public class EscapeFlowTest {
+ @Test public void testSummaryCallDependencyDoesNotEscape() {
+ CodeGen code = new CodeGen("return 0;").parse();
+ code._phase = CodeGen.Phase.Opto;
+ TypeFunPtr sig = TypeFunPtr.make1((byte)2,true,TypeFunPtr.TEMPTY,TypeInteger.BOT,100);
+ FunNode fun = new FunNode(null,sig,"summaryOwner",code.compunit(),code._start);
+ fun._type = Type.CONTROL;
+ TypeTuple state = TypeTuple.make(Type.CONTROL,
+ TypeMem.START.makeFrom(TypeSet.of(9),TypeSet.EMPTY),TypeInteger.BOT);
+ SummaryNode summary = new SummaryNode(state,new int[]{7},fun,code.con(TypeMem.START)).init();
+ code.link(fun);
+ assertSame(summary,fun.summary());
+ TypeMem exposed = new GlobalEscapeNode().compute();
+ assertTrue("Published function pointers escape",exposed._escFs.contains(9));
+ assertFalse("Internal call dependencies do not escape",exposed._escFs.contains(7));
+ }
+
@Test public void testArrayGeneratorDoesNotPublishUnrelatedFunctions() {
for( long seed : new long[]{1,123,987654321} )
for( String access : new String[]{"","~"} ) {