summaryrefslogtreecommitdiff
path: root/chapter33
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-12-04 14:52:23 -0800
committerCliff Click <cliffc@acm.org>2026-12-04 14:52:23 -0800
commit58ede6e92922602a4b4f1b46cdcb8b6082e931e7 (patch)
treee28e74afa62233d7ca9b890ccfddf731145a164b /chapter33
parent29db300e59821b0b9c1abf478aade5f6d36bf408 (diff)
downloadSimple-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')
-rw-r--r--chapter33/src/main/java/com/seaofnodes/simple/node/EscapeNode.java15
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/EscapeFlowTest.java51
2 files changed, 58 insertions, 8 deletions
diff --git a/chapter33/src/main/java/com/seaofnodes/simple/node/EscapeNode.java b/chapter33/src/main/java/com/seaofnodes/simple/node/EscapeNode.java
index 3c759c48..cc1b3b58 100644
--- a/chapter33/src/main/java/com/seaofnodes/simple/node/EscapeNode.java
+++ b/chapter33/src/main/java/com/seaofnodes/simple/node/EscapeNode.java
@@ -93,14 +93,13 @@ public class EscapeNode extends TypeNode {
// edge, not publication to unknown callers. Keep the public escape sets.
if( _borrow )
return TypeMem.make(fld._alias,t,false,false,false,mpub._escFs,mpub._escAs);
- TypeSet fidxes = mpriv._escFs.meet(mpub._escFs);
- TypeSet aliases = mpriv._escAs.meet(mpub._escAs);
- // Keep escapes from the actual private value before narrowing it to
- // the declaration. Selecting its Store from a MemMerge must preserve
- // this result, including Scalar.BOT's unknown pointer escapes.
- TypeMem defaults = CodeGen.CODE._phase.ordinal()<CodeGen.Phase.Opto.ordinal() ? TypeMem.BOT : mpub;
- return TypeMem.make(fld._alias, t, false, false, fld._final, fidxes, aliases)
- .escapesFrom(tpriv,defaults).escapesFrom(t,defaults);
+ // Publish this field's value, bounded by its declaration. The private
+ // aggregate's escapes include other fields, and selecting an alias
+ // from it can expose a weaker scalar/escape bound. Neither changes
+ // which values this field can hold. Opaque referents contribute the
+ // identities already available in public memory.
+ return TypeMem.make(fld._alias,t,false,false,fld._final,mpub._escFs,mpub._escAs)
+ .escapesFrom(t,mpub);
}
@Override public Node idealize() {
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; }; };