diff options
| author | Cliff Click <cliffc@acm.org> | 2026-12-04 14:52:23 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-12-04 14:52:23 -0800 |
| commit | 58ede6e92922602a4b4f1b46cdcb8b6082e931e7 (patch) | |
| tree | e28e74afa62233d7ca9b890ccfddf731145a164b /chapter33/src/test/java | |
| parent | 29db300e59821b0b9c1abf478aade5f6d36bf408 (diff) | |
| download | Simple-58ede6e92922602a4b4f1b46cdcb8b6082e931e7.tar.gz Simple-58ede6e92922602a4b4f1b46cdcb8b6082e931e7.zip | |
Publish escapes from the selected field value
Keep prior public escapes and derive new escapes from the field value bounded by its declaration. Do not import unrelated aggregate-private escapes or broaden them when selecting a weaker alias slice. Cover callback publication, alias selection, borrows, and opaque referents. Full make -k -j8 tests passes.
Diffstat (limited to 'chapter33/src/test/java')
| -rw-r--r-- | chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java b/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java index d9a9a6fe..57954652 100644 --- a/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java +++ b/chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java @@ -7,6 +7,57 @@ import org.junit.Test; import static org.junit.Assert.*; public class EscapeFlowTest { + @Test public void testFieldPublicationSelectsValue() { + CodeGen code = new CodeGen("return 0;").parse(); + TypeFunPtr callback = TypeFunPtr.make1((byte)2,true,TypeFunPtr.TEMPTY,TypeInteger.BOT,7); + TypeFunPtr unrelated = TypeFunPtr.make1((byte)2,true,TypeFunPtr.TEMPTY,TypeInteger.BOT,9); + Field selected = Field.make("callback",callback,21,true); + TypeStruct shape = TypeStruct.make("PublishFields",false, + selected,Field.make("other",unrelated,22,true)); + Node self = code.con(TypeMemPtr.make(shape)); + TypeMem pub = TypeMem.START.makeFrom(TypeSet.of(3),TypeSet.of(4)); + // The aggregate includes escapes from other fields. Publishing just + // callback must not publish the whole construction group. + Node priv = code.con(TypeMem.makePrivate(shape)); + EscapeNode esc = new EscapeNode(selected,self,priv,code.con(pub)); + TypeMem result = (TypeMem)esc.compute(); + assertSame(TypeSet.of(3).with(7),result._escFs); + assertSame(TypeSet.of(4),result._escAs); + assertSame(callback,result._t); + EscapeNode borrow = new EscapeNode(selected,self,priv,code.con(pub),true); + assertSame(pub._escFs,((TypeMem)borrow.compute())._escFs); + assertSame(pub._escAs,((TypeMem)borrow.compute())._escAs); + } + + @Test public void testFieldPublicationAfterAliasSelection() { + CodeGen code = new CodeGen("return 0;").parse(); + Field selected = Field.make("count",TypeInteger.I32,21,false); + TypeStruct shape = TypeStruct.make("PublishCount",false,selected); + Node self = code.con(TypeMemPtr.make(shape)); + TypeMem pub = TypeMem.START.makeFrom(TypeSet.of(3),TypeSet.of(4)); + EscapeNode esc = new EscapeNode(selected,self,code.con(TypeMem.makePrivate(shape)),code.con(pub)); + TypeMem before = (TypeMem)esc.compute(); + // An alias selected from a MemMerge can have a weaker scalar bound + // and escape summary. The declared integer field cannot hold pointers. + esc.setDef(2,code.con(TypeMem.make(21,TypeScalar.BOT,true,false,false,TypeSet.FULL,TypeSet.FULL))); + assertSame(before,esc.compute()); + assertSame(pub._escFs,before._escFs); + assertSame(pub._escAs,before._escAs); + } + + @Test public void testOpaqueFieldPublication() { + CodeGen code = new CodeGen("return 0;").parse(); + TypeMemPtr opaque = TypeMemPtr.makeNullable(TypeStruct.forward("PublishedExternal")); + Field selected = Field.make("external",opaque,21,false); + TypeStruct shape = TypeStruct.make("PublishOpaque",false,selected); + TypeMem pub = TypeMem.START.makeFrom(TypeSet.of(3),TypeSet.of(4)); + EscapeNode esc = new EscapeNode(selected,code.con(TypeMemPtr.make(shape)), + code.con(TypeMem.makePrivate(shape)),code.con(pub)); + TypeMem result = (TypeMem)esc.compute(); + assertSame(pub._escFs,result._escFs); + assertSame(pub._escAs,result._escAs); + } + @Test public void testConstructorPrivateMemoryDefault() { CodeGen code = new CodeGen(""" struct Box { int n; new Box = { int x -> n=x; }; }; |
