summaryrefslogtreecommitdiff
path: root/chapter33/src/test
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-12-04 15:08:30 -0800
committerCliff Click <cliffc@acm.org>2026-12-04 15:08:30 -0800
commit05769745f8050155332597c701455be0fac59e18 (patch)
tree868b808d95cb2ca28a3d60d6a7820005144b4945 /chapter33/src/test
parent58ede6e92922602a4b4f1b46cdcb8b6082e931e7 (diff)
downloadSimple-ch33_try2.tar.gz
Simple-ch33_try2.zip
Refresh singleton escapes after type closure and preserve saved calleesch33_try2
Recompute final singleton-slot escapes after recursive types are interned. Preserve aggregate, mutable-slot, and opaque bounds. Sharper escapes allow unused imported helpers to die: restore their summaries when later direct calls appear, and retain native entries referenced by serialized IR even when lowering removes the last local caller. Seed those entries with analyzed ranges, and interpret only callback default memory as an outside interface. Add recursive-type and native interpolation regressions; full make -k -j8 tests passes (844 executions).
Diffstat (limited to 'chapter33/src/test')
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java6
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/StringFormatTest.java4
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/TypeTest.java35
3 files changed, 44 insertions, 1 deletions
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java b/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java
index 4cacd0e6..999e518d 100644
--- a/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java
+++ b/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java
@@ -429,7 +429,11 @@ public class ClassInitDependenciesTest {
if( n instanceof CLInitNode init && init.fun()==fun && init.cu()==b ) {
touches[0]++;
TypeTuple state=(TypeTuple)init._type;
- assertSame(TypeMem.BOT,state._types[1]);
+ // Initialization merges whole memory; its escape sets
+ // can be sharper than the all-escaped MemBot bound.
+ TypeMem memory=(TypeMem)state._types[1];
+ assertEquals(1,memory._alias);
+ assertSame(Type.BOTTOM,memory._t);
TypeMem flag=(TypeMem)state._types[2];
assertEquals(b._clz.field("$init")._alias,flag._alias);
assertSame(TypeInteger.TRUE,flag._t);
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/StringFormatTest.java b/chapter33/src/test/java/com/seaofnodes/simple/StringFormatTest.java
index d6783380..0163de05 100644
--- a/chapter33/src/test/java/com/seaofnodes/simple/StringFormatTest.java
+++ b/chapter33/src/test/java/com/seaofnodes/simple/StringFormatTest.java
@@ -11,6 +11,10 @@ import org.junit.Test;
import static org.junit.Assert.*;
public class StringFormatTest extends TestC {
+ @Test public void testSingleIntegerInterpolation() throws Exception {
+ runSYS("val main={ -> sys.io.p(\"%(7)\"); return 0; };","singleIntegerInterpolation","7",-1);
+ }
+
// Share a few native programs, retaining a separately reported assertion
// for each case. Blocks isolate locals; the delimiter preserves embedded
// NULs and newlines in the expected output.
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/TypeTest.java b/chapter33/src/test/java/com/seaofnodes/simple/TypeTest.java
index 28b6b0fb..fb1834fa 100644
--- a/chapter33/src/test/java/com/seaofnodes/simple/TypeTest.java
+++ b/chapter33/src/test/java/com/seaofnodes/simple/TypeTest.java
@@ -1,12 +1,47 @@
package com.seaofnodes.simple;
import com.seaofnodes.simple.type.*;
+import java.util.HashMap;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertSame;
public class TypeTest {
+ @Test public void testSingletonMemoryUpgradeEscapes() {
+ TypeStruct open = TypeStruct.open("class:UpgradeChild");
+ TypeMemPtr ptr = TypeMemPtr.make((byte)2,open,true);
+ TypeFunPtr callback = TypeFunPtr.make1((byte)2,true,TypeFunPtr.TEMPTY,TypeInteger.BOT,11);
+ TypeStruct child = open.add(Field.make("self",ptr,7,true))
+ .add(Field.make("callback",callback,8,true))
+ .add(Field.make("value",TypeInteger.BOT,9,false)).close();
+ HashMap<String,Type> types = new HashMap<>();
+ types.put(child._name,child);
+ TypeMem initial = TypeMem.make(6,ptr,true,true,true,TypeSet.FULL,TypeSet.FULL);
+ TypeMem upgraded = (TypeMem)initial.upgradeType(types);
+ assertSame(child,((TypeMemPtr)upgraded._t)._obj);
+ assertSame(TypeSet.of(11),upgraded._escFs);
+ assertSame(TypeSet.of(7).with(8).with(9),upgraded._escAs);
+ assertSame(upgraded,upgraded.upgradeType(types));
+
+ // Only a final singleton class slot can replace its old escape bound.
+ // Aggregate memory and mutable/non-class slots retain prior escapes.
+ for( TypeMem other : new TypeMem[]{
+ TypeMem.make(6,ptr,true,true,false,TypeSet.FULL,TypeSet.FULL),
+ TypeMem.make(6,ptr,true,false,true,TypeSet.FULL,TypeSet.FULL),
+ TypeMem.make(6,ptr,false,true,true,TypeSet.FULL,TypeSet.FULL),
+ TypeMem.make(1,ptr,true,true,true,TypeSet.FULL,TypeSet.FULL)} ) {
+ TypeMem kept = (TypeMem)other.upgradeType(types);
+ assertSame(TypeSet.FULL,kept._escFs);
+ assertSame(TypeSet.FULL,kept._escAs);
+ }
+ TypeStruct opaque = TypeStruct.forward("ExternalUpgradeChild");
+ types.put(opaque._name,opaque);
+ TypeMem external = TypeMem.make(6,TypeMemPtr.make((byte)2,opaque,true),
+ true,true,true,TypeSet.FULL,TypeSet.FULL);
+ assertSame(external,external.upgradeType(types));
+ }
+
@Test public void testFinalPointerCycles() {
TypeStruct cycle = TypeStruct.open("FinalPointerCycle");
Assert.assertFalse(cycle.isFinal());