diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-30 16:55:15 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-30 16:55:15 -0700 |
| commit | 0ac0c9e10287972ac3af5a4ee43d26f0d5b318fe (patch) | |
| tree | 82e136a6511defa167417bc4aaa036bfc4a784ad /chapter28a/src/test/java/com | |
| parent | bed724c88722f332693f41e2329b75c6ce492880 (diff) | |
| download | Simple-0ac0c9e10287972ac3af5a4ee43d26f0d5b318fe.tar.gz Simple-0ac0c9e10287972ac3af5a4ee43d26f0d5b318fe.zip | |
Canonicalize aggregate memory duals and preserve field finalitymain
Diffstat (limited to 'chapter28a/src/test/java/com')
| -rw-r--r-- | chapter28a/src/test/java/com/seaofnodes/simple/BoundaryTest.java | 10 | ||||
| -rw-r--r-- | chapter28a/src/test/java/com/seaofnodes/simple/TypeTest.java | 26 |
2 files changed, 36 insertions, 0 deletions
diff --git a/chapter28a/src/test/java/com/seaofnodes/simple/BoundaryTest.java b/chapter28a/src/test/java/com/seaofnodes/simple/BoundaryTest.java index 68d8175f..4e3fbb1b 100644 --- a/chapter28a/src/test/java/com/seaofnodes/simple/BoundaryTest.java +++ b/chapter28a/src/test/java/com/seaofnodes/simple/BoundaryTest.java @@ -9,6 +9,16 @@ import static org.junit.Assert.*; // The new module boundary must preserve the preceding chapters' examples. public class BoundaryTest { @Test public void testLocalConstruction() throws java.io.IOException { + // Nested factories must preserve memory duals during construction, + // for both direct fields and getters on the returned instance. + for( String body : new String[]{"int x=7;", "int _x=7; val get={ -> _x; };" } ) + for( long seed : new long[]{1,13,123} ) { + String src = "struct Outer { struct _Hidden { "+body+ + " }; val make={ -> new _Hidden(); }; }; return new Outer().make()."; + CodeGen factory = new CodeGen(src+(body.startsWith("int x") ? "x;" : "get();"),seed,true) + .driver(CodeGen.Phase.TypeCheck); + assertEquals("7",Eval2.eval(factory,0)); + } String src="struct Counter { int x; int y; int z; new Counter={int n -> while(x<n) { int old=x; y=x+1; x=y+1; z=old; }}; }; val c=new Counter(arg); return c.x*100+c.z;"; CodeGen code=new CodeGen(src).driver(CodeGen.Phase.LocalSched); assertEquals("2018",Eval2.eval(code,19)); diff --git a/chapter28a/src/test/java/com/seaofnodes/simple/TypeTest.java b/chapter28a/src/test/java/com/seaofnodes/simple/TypeTest.java index f6099607..4090bde3 100644 --- a/chapter28a/src/test/java/com/seaofnodes/simple/TypeTest.java +++ b/chapter28a/src/test/java/com/seaofnodes/simple/TypeTest.java @@ -7,6 +7,32 @@ import static org.junit.Assert.assertSame; public class TypeTest { + // Aggregate finality is carried by its fields. Canonicalizing the unused + // aggregate bit must commute with dual, even for named (non-high) structs. + @Test public void testAggregateMemoryDual() { + TypeStruct obj = TypeStruct.make("AggregateDual",false, + Field.make("x",TypeInteger.BOT,2,false), + Field.make("y",TypeInteger.ZERO,3,true)); + for( Type t : new Type[]{Type.BOTTOM,Type.TOP,TypeStruct.BOT,TypeStruct.TOP,obj,obj.dual()} ) + for( boolean one : new boolean[]{false,true} ) { + TypeMem mem = TypeMem.make(1,t,one,false,false,XInt.EMPTY,XInt.EMPTY); + assertSame(mem,TypeMem.make(1,t,one,false,true,XInt.EMPTY,XInt.EMPTY)); + assertSame(mem,mem.dual().dual()); + assertSame(mem.dual(),TypeMem.make(1,t.dual(),!one,true,true,XInt.FULL,XInt.FULL)); + } + // Precise field slices still distinguish final and mutable storage. + Assert.assertNotEquals(TypeMem.make(2,TypeInteger.BOT,false,false,false,XInt.EMPTY,XInt.EMPTY), + TypeMem.make(2,TypeInteger.BOT,false,false,true ,XInt.EMPTY,XInt.EMPTY)); + for( boolean one : new boolean[]{false,true} ) + for( boolean fin : new boolean[]{false,true} ) { + TypeMem bulk = TypeMem.make(1,Type.TOP,one,false,false,XInt.EMPTY,XInt.EMPTY); + TypeMem slice = TypeMem.make(2,TypeInteger.BOT,false,false,fin,XInt.EMPTY,XInt.EMPTY); + assertSame(slice,bulk.meet(slice)); + check_symmetric(bulk,slice); + check_symmetric(bulk.dual(),slice.dual()); + } + } + // Removing zero must not reset the widening history of a remaining range. @Test public void testNonZeroWidening() { for( byte widen=0; widen<=3; widen++ ) { |
