diff options
| author | Cliff Click <cliffc@acm.org> | 2026-12-04 14:49:25 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-12-04 14:49:25 -0800 |
| commit | 29db300e59821b0b9c1abf478aade5f6d36bf408 (patch) | |
| tree | b0755539a502b4c94fc80bac3648067d115bbb7a /chapter33/src/test/java/com | |
| parent | d9df5cddeaa20045f1194a4b250041cf88bb8845 (diff) | |
| download | Simple-29db300e59821b0b9c1abf478aade5f6d36bf408.tar.gz Simple-29db300e59821b0b9c1abf478aade5f6d36bf408.zip | |
Start constructor private-memory defaults without escapes
Use the same defaultArg rule for parsed functions and imported summaries, while preserving broad signature bounds and actual call memory. Add source and separately compiled constructor regressions. Full make -k -j8 tests passes.
Diffstat (limited to 'chapter33/src/test/java/com')
| -rw-r--r-- | chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java | 20 | ||||
| -rw-r--r-- | chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java | 23 |
2 files changed, 43 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 4ae7f771..4cacd0e6 100644 --- a/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java +++ b/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java @@ -8,6 +8,7 @@ import com.seaofnodes.simple.type.TypeFunPtr; import com.seaofnodes.simple.type.Field; import com.seaofnodes.simple.type.TypeInteger; import com.seaofnodes.simple.type.TypeMem; +import com.seaofnodes.simple.type.TypeSet; import com.seaofnodes.simple.type.TypeTuple; import com.seaofnodes.simple.util.Ary; import java.nio.file.Files; @@ -549,6 +550,25 @@ public class ClassInitDependenciesTest { assertNull(Eval2.eval(code,0,10)); } + @Test public void testImportedConstructorPrivateMemoryDefault() throws Exception { + Path dir=tempDir("constructor-default-"); + object(dir,dir,"Library","struct Box_noInline { int n; new Box_noInline={int x -> n=x;}; };"); + CodeGen code=new CodeGen(null,dir.toString(),new Ary<>(new String[]{dir.toString()}), + "Main","return new Library.Box_noInline(42).n;",123,true,TypeInteger.BOT).parse(); + int helpers=0; + for( FunNode fun : code._linker ) + if( fun!=null && fun.summary()!=null && fun.sig().nargs()>1 && fun.sig().arg(1) instanceof TypeMem ) { + helpers++; + TypeMem initial=(TypeMem)fun.parm(3).in(1)._type; + assertTrue(initial._one); + assertSame(TypeSet.EMPTY,initial._escFs); + assertSame(TypeSet.EMPTY,initial._escAs); + } + assertTrue(helpers>0); + code.driver(CodeGen.Phase.TypeCheck); + assertEquals("42",Eval2.eval(code,0)); + } + @Test public void testImportedPrivateInitializerCycle() throws Exception { Path dir=tempDir("private-cycle-"), stubs=tempDir("private-stub-"); object(stubs,stubs,"Main","int value=arg;"); diff --git a/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java b/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java index 15495696..d9a9a6fe 100644 --- a/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java +++ b/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java @@ -7,6 +7,29 @@ import org.junit.Test; import static org.junit.Assert.*; public class EscapeFlowTest { + @Test public void testConstructorPrivateMemoryDefault() { + CodeGen code = new CodeGen(""" + struct Box { int n; new Box = { int x -> n=x; }; }; + return new Box(((arg<<32)>>32)).n; + """).parse(); + int helpers=0; + for( FunNode fun : code._linker ) + if( fun!=null && fun.sig().nargs()>1 && fun.sig().arg(1) instanceof TypeMem bound ) { + helpers++; + TypeMem initial=(TypeMem)fun.defaultArg(1); + assertTrue(initial._one); + assertSame(Type.BOTTOM,initial._t); + assertSame(TypeSet.EMPTY,initial._escFs); + assertSame(TypeSet.EMPTY,initial._escAs); + // This is a default, not a restriction on actual private memory. + assertSame(TypeSet.FULL,bound._escFs); + assertSame(TypeSet.FULL,bound._escAs); + } + assertTrue(helpers>0); + code.driver(CodeGen.Phase.TypeCheck); + assertEquals("42",Eval2.eval(code,42)); + } + @Test public void testSummaryCallDependencyDoesNotEscape() { CodeGen code = new CodeGen("return 0;").parse(); code._phase = CodeGen.Phase.Opto; |
