diff options
| author | Cliff Click <cliffc@acm.org> | 2026-12-05 16:40:47 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-12-05 16:40:47 -0800 |
| commit | 6cc2ed4147962b8a2155e2948bbdd5cf10856e90 (patch) | |
| tree | 81aa22b49867f1669226ef6b2e2ad2ebbf84e761 | |
| parent | 262468253a200c543d03b030a9a9108967d43981 (diff) | |
| download | Simple-6cc2ed4147962b8a2155e2948bbdd5cf10856e90.tar.gz Simple-6cc2ed4147962b8a2155e2948bbdd5cf10856e90.zip | |
Fix a few more issues
3 files changed, 34 insertions, 17 deletions
diff --git a/chapter33/src/main/java/com/seaofnodes/simple/codegen/Iter.java b/chapter33/src/main/java/com/seaofnodes/simple/codegen/Iter.java index 72cca23b..04c4378f 100644 --- a/chapter33/src/main/java/com/seaofnodes/simple/codegen/Iter.java +++ b/chapter33/src/main/java/com/seaofnodes/simple/codegen/Iter.java @@ -22,20 +22,27 @@ public abstract class Iter { private static Type iterImportReset(Type t) { if( t.isHigh() ) return t.dual(); - if( t instanceof TypeMem mem ) - return TypeMem.make(mem._alias,iterImportReset(mem._t),mem._one,mem._clz,mem._final,TypeSet.FULL,TypeSet.FULL); - if( t instanceof TypeMemPtr ) + // Saved escape identities are already rebased into this compilation. + // Repair adds escapes from the new callers. Seeding FULL here instead + // feeds spurious escapes around the Start/Stop cycle, where ordinary + // lifting cannot recover the exclusions. + switch( t ) { + case TypeMem mem -> + return TypeMem.make( mem._alias, iterImportReset( mem._t ), mem._one, mem._clz, mem._final, mem._escFs, mem._escAs ); + case TypeMemPtr typeMemPtr -> return t.makeStorage(); - if( t instanceof TypeStruct ) + case TypeStruct typeStruct -> return t.makeStorage(); - if( t instanceof TypeTuple tt ) { + case TypeTuple tt -> { TypeTuple rez = tt; - for( int i=0; i<tt._types.length; i++ ) { - Type tx = iterImportReset(tt._types[i]); - if( tx != tt._types[i] ) rez = rez.makeFrom(i,tx); + for( int i = 0; i < tt._types.length; i++ ) { + Type tx = iterImportReset( tt._types[i] ); + if( tx != tt._types[i] ) rez = rez.makeFrom( i, tx ); } return rez; } + default -> {} + } return t; } diff --git a/chapter33/src/main/java/com/seaofnodes/simple/node/FunNode.java b/chapter33/src/main/java/com/seaofnodes/simple/node/FunNode.java index b0293718..e91d760d 100644 --- a/chapter33/src/main/java/com/seaofnodes/simple/node/FunNode.java +++ b/chapter33/src/main/java/com/seaofnodes/simple/node/FunNode.java @@ -229,8 +229,13 @@ public class FunNode extends RegionNode { // body's Return rooted even after dropping unknown callers. if( !isClz() || nIns()<=2 ) { StopCUNode stop = _compunit._stop; - CODE.add(stop).delDef(stop._inputs.find(ret())); - CODE.addAll(stop._outputs); // The outer Stop can drop an empty unit. + // A replaced summary can outlive its Return while its + // outgoing callee references are being released. + int idx = stop._inputs.find(ret()); + if( idx!=-1 ) { + CODE.add(stop).delDef(idx); + CODE.addAll(stop._outputs); // The outer Stop can drop an empty unit. + } } return removeDeadPath(1); } else { diff --git a/chapter33/src/test/java/com/seaofnodes/simple/SelectiveLoadingTest.java b/chapter33/src/test/java/com/seaofnodes/simple/SelectiveLoadingTest.java index 8ea351d0..d1bf474f 100644 --- a/chapter33/src/test/java/com/seaofnodes/simple/SelectiveLoadingTest.java +++ b/chapter33/src/test/java/com/seaofnodes/simple/SelectiveLoadingTest.java @@ -53,16 +53,16 @@ public class SelectiveLoadingTest { } @Test public void testSummaryCalleeDefaultAndRelease() throws Exception { - Path root=library("summary-callees-"); - Ary<String> paths=new Ary<>(new String[]{root.toString()}); + Path root = library("summary-callees-"); + Ary<String> paths = new Ary<>(new String[]{root.toString()}); object(root,paths,"Library",""" val _helper_noInline={ int x -> x+1; }; val entry_noInline={ int x -> _helper_noInline(x); }; """); - CodeGen code=new CodeGen(null,root.toString(),paths,"Main", + CodeGen code = new CodeGen(null,root.toString(),paths,"Main", "return Library.entry_noInline(((arg<<32)>>32));",123,true,TypeInteger.BOT) .driver(CodeGen.Phase.IterPostOpto); - FunNode helper=function(code,"_helper_noInline"); + FunNode helper = function(code,"_helper_noInline"); assertTrue("An unloaded caller retains the default",helper.unknownCallers()); assertTrue(helper.hasSummaryCallers()); assertFalse("A summary call does not publish its target", @@ -70,10 +70,15 @@ public class SelectiveLoadingTest { code.loadForInline(code._compunits.get("Library")); code._iter.iterate(code); - helper=function(code,"_helper_noInline"); + helper = function(code,"_helper_noInline"); assertFalse("Concrete calls replace the summary references",helper.hasSummaryCallers()); - assertEquals("Only escapes can retain the default after loading", - ((TypeTuple)helper._compunit._start._type).mem()._escFs.contains(helper.sig().fidx()),helper.unknownCallers()); + // Loading the direct call reveals no publication of the helper's + // function pointer. Neither Start may widen to include that FIDX. + assertFalse("Loading a direct caller must not publish its private callee", + ((TypeTuple)code._start._type).mem()._escFs.contains(helper.sig().fidx())); + assertFalse("The library Start must also exclude its private callee", + ((TypeTuple)helper._compunit._start._type).mem()._escFs.contains(helper.sig().fidx())); + assertFalse("With concrete callers and no escape, the default must be released",helper.unknownCallers()); assertTrue(helper.nIns()>1); code.driver(CodeGen.Phase.TypeCheck); assertEquals("42",Eval2.eval(code,41)); |
