From 58ede6e92922602a4b4f1b46cdcb8b6082e931e7 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Fri, 4 Dec 2026 14:52:23 -0800 Subject: 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. --- .../java/com/seaofnodes/simple/EscapeFlowTest.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'chapter33/src/test/java') 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; }; }; -- cgit v1.2.3