From d9a46e588fe09ed58e160778b0d8dcee62d4d0e4 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Mon, 30 Nov 2026 10:43:11 -0800 Subject: Checkpoint Allocation2 before separate-compilation redesign Replace the legacy allocation planner, deletion proof engine, and independent FunctionEffects pass with Allocation2 as the sole allocation-analysis phase. Keep one Site per optimized allocation/static object, per-site weak field facts, dependency-driven escape propagation, incoming-edge counts, and points-to dumps. Move the shared node WorkList into util. Normalize Never exits before allocation analysis and TypeCheck while preserving semantic nonreturning summaries. Keep internal class-init call dependencies out of global escapes, sharpen hidden private-memory defaults, refresh singleton constant escape sets after type closure, and publish field-local escape facts. Detach unloaded summary wrappers from scheduling roots. Retain declaration metadata and optimized return states in C0DA objects without legacy contracts. Keep qualified forward type names separate from expression member access, allow peepholes to return dead self, and retain the supporting regressions. Use integer types for symbolic field offsets and Opto-high uninitialized fields. Make Breakout's debounce helper private. Remove disabled escape implementations, obsolete null assertions, duplicate graphics compilation, survey runners/results, investigation transcripts, and source archives. Consolidate the selected ownership, lifetime, storage, deletion, and growing-array designs with their rationale/examples and academic references. Replace the obsolete Chapter33 handoff in the AI notes with current guidance. This is an unfinished analysis checkpoint. Imported pointer identities, transitive escapes, intrinsic calls, construction checks, and cofinite-summary universe rebasing still need work. Import loading order is unchanged. Validation: main/test compilation and git diff --check pass. Before/after make -k -j8 tests_nographics both report 825 executions and 78 failures, with unchanged extracted failure names; all lattice shards pass. Chapter33 retains its three failing deletion/imported-identity/transitive-escape regressions. --- chapter33/docs/AllocationSurvey.java | 138 ----------------------------------- 1 file changed, 138 deletions(-) delete mode 100644 chapter33/docs/AllocationSurvey.java (limited to 'chapter33/docs/AllocationSurvey.java') diff --git a/chapter33/docs/AllocationSurvey.java b/chapter33/docs/AllocationSurvey.java deleted file mode 100644 index 108cbfb3..00000000 --- a/chapter33/docs/AllocationSurvey.java +++ /dev/null @@ -1,138 +0,0 @@ -import com.seaofnodes.simple.codegen.*; -import com.seaofnodes.simple.node.*; -import com.seaofnodes.simple.type.*; -import com.seaofnodes.simple.util.Ary; -import java.nio.file.*; -import java.lang.reflect.Field; -import java.util.*; - -// Standalone survey, not a test or a compiler option. Run from chapter33. -public class AllocationSurvey { - static Object field(Object object, String name) throws Exception { - Field f=object.getClass().getDeclaredField(name); - f.setAccessible(true); - return f.get(object); - } - static String clean(Object s) { return s==null ? "" : s.toString().replace('\t',' ').replace('\n',' '); } - static String category(String reason) { - if( reason==null ) return "supported"; - if( reason.contains("opaque body") ) return "opaque body"; - if( reason.contains("opaque or indirect") ) return "indirect call"; - if( reason.contains("recursive call") ) return "recursion"; - if( reason.contains("raw address") ) return "raw address"; - if( reason.contains("variable-size") ) return "variable size"; - if( reason.contains("across its backedge") ) return "loop retention"; - if( reason.contains("cyclic field-path") ) return "field paths"; - if( reason.contains("reference origin") ) return "reference origin"; - if( reason.contains("native result storage") ) return "native result"; - return "other"; - } - static String probe(String name) { - return switch(name) { - case "LocalArray" -> """ - val work_noInline={ u32 n -> - val xs=new i64[n]; - for( u32 i=0; i """ - val make_noInline={ u32 n -> new i64[n]; }; - u32 len=arg; - return make_noInline(len)#; - """; - case "OverwrittenSlot" -> """ - struct Thing { i64 !x; new Thing={i64 n -> x=n;}; }; - struct Holder { Thing? !c=null; }; - val work_noInline={i64 n -> - val h=new Holder; - while(n>0) { h.c=new Thing(n); n--; } - return h.c ? h.c.x : 0; - }; - return work_noInline(arg); - """; - case "ReusedObject" -> """ - struct Thing { i64 !x; new Thing={i64 n -> x=n;}; }; - val read_noInline={Thing t -> t.x;}; - val work_noInline={i64 n -> - val t=new Thing(0); - i64 sum=0; - while(n>0) { t.x=n; sum+=read_noInline(t); n--; } - return sum; - }; - return work_noInline(arg); - """; - default -> throw new IllegalArgumentException(name); - }; - } - @SuppressWarnings("unchecked") - public static void main(String[] args) throws Exception { - String name=args[0], mode=args.length>1 ? args[1] : "source"; - Path out=Path.of("build/allocation-survey",name+"-"+mode); - Files.createDirectories(out); - for( String file : new String[]{"error.txt","dump.txt","functions.tsv","sites.tsv","allocations.tsv","calls.tsv"} ) - Files.deleteIfExists(out.resolve(file)); - String src=mode.equals("probe") ? probe(name) : name.equals("sys") ? null : - name.equals("RuntimeArgs") ? Files.readString(Path.of("src/main/smp/sys/rt/simple_args.smp")) : - Files.readString(Path.of("docs/examples",name+".smp")); - if( src!=null && !name.equals("RuntimeArgs") && mode.equals("source") ) src="val _survey_sys=sys;\n"+src; - String root=mode.equals("source") ? "src/main/smp" : "docs/examples"; - Ary libs=mode.equals("object") ? new Ary<>(new String[]{"build/release/x86_64_v2_win64"}) : null; - CodeGen code=new CodeGen(root,out.resolve("objects").toString(),libs,name,src,456,true,TypeInteger.BOT); - long start=System.nanoTime(); - try { code.driver(CodeGen.Phase.TypeCheck); } - catch(Throwable t) { - StringBuilder error=new StringBuilder(t.toString()+"\nphase="+code._phase+"\n"); - if( t instanceof com.seaofnodes.simple.parser.Parser.ParseException p ) error.append(p.diagnostic()).append('\n'); - for( StackTraceElement frame : t.getStackTrace() ) error.append(frame).append('\n'); - Files.writeString(out.resolve("error.txt"),error); - System.out.println(name+" "+mode+" ERROR "+t); - return; - } - Allocation.Summary[] summaries=(Allocation.Summary[])field(code._allocation,"_summaries"); - Files.writeString(out.resolve("dump.txt"),code._allocation.toString()); - StringBuilder rows=new StringBuilder("program\tmode\tunit\tfunction\tid\tstatus\tcategory\troot_function\troot_id\troot_unit\tnew_user\tnew_class\tvariable\tplaced_user\tplaced_class\tloops\treason\n"); - StringBuilder sites=new StringBuilder("program\tmode\tunit\tfunction\tsite\ttype\tbytes\tdestination\n"); - StringBuilder nodes=new StringBuilder("program\tmode\tunit\tfunction\tnode\tsize\ttype\n"); - StringBuilder calls=new StringBuilder("program\tmode\tunit\tfunction\tnode\ttarget\tsignature\n"); - int total=0,pass=0,allocated=0; - for( Allocation.Summary sum : summaries ) { - if( sum==null ) continue; - FunNode fun=sum._fun; - String unit=fun._compunit==null ? "" : fun._compunit._cname; - Allocation.Summary cause=sum; - HashSet seen=new HashSet<>(); - while( cause._reject!=null && cause._reject.startsWith("call #") && seen.add(cause) ) { - int id=Integer.parseInt(cause._reject.substring(6,cause._reject.indexOf(' ',6))); - Allocation.Summary next=null; - for( CallNode call : (ArrayList)field(cause,"_calls") ) - if( call._nid==id && call.fptr()._type instanceof TypeFunPtr fp && fp.isConstant() ) next=summaries[fp.fidx()]; - if( next==null ) break; - cause=next; - } - int local=0,clz=0,variable=0,placed=0,placedClz=0; - for( CallNode call : (ArrayList)field(sum,"_calls") ) - calls.append(name).append('\t').append(mode).append('\t').append(clean(unit)).append('\t').append(clean(fun._name)).append('\t').append(call._nid).append('\t').append(clean(call.name())).append('\t').append(clean(call.fptr()._type)).append('\n'); - for( Node n : (ArrayList)field(sum,"_nodes") ) if( n instanceof NewNode a ) { - if( TypeStruct.startsClzPrefix(a._ts._name) ) clz++; else local++; - if( !(a.size()._type instanceof TypeInteger sz) || !sz.isConstant() ) variable++; - nodes.append(name).append('\t').append(mode).append('\t').append(clean(unit)).append('\t').append(clean(fun._name)).append('\t').append(a._nid).append('\t').append(clean(a.size()._type)).append('\t').append(clean(a._ts._name)).append('\n'); - } - if( sum.supported() ) for( Allocation.Site site : sum._sites ) if( site._allocation!=null ) { - if( TypeStruct.startsClzPrefix(site._allocation._ts._name) ) placedClz++; else placed++; - sites.append(name).append('\t').append(mode).append('\t').append(clean(unit)).append('\t').append(clean(fun._name)).append('\t').append(clean(site._name)).append('\t').append(clean(site._allocation._ts._name)).append('\t').append(site._bytes).append('\t').append(clean(site.destination())).append('\n'); - } - String status=sum.supported() ? "pass" : sum._reject.startsWith("call #") ? "blocked" : "direct"; - rows.append(name).append('\t').append(mode).append('\t').append(clean(unit)).append('\t').append(clean(fun._name)).append('\t').append(fun.sig().fidx()).append('\t').append(status).append('\t').append(category(cause._reject)).append('\t').append(clean(cause._fun._name)).append('\t').append(cause._fun.sig().fidx()).append('\t').append(clean(cause._fun._compunit==null ? null : cause._fun._compunit._cname)).append('\t').append(local).append('\t').append(clz).append('\t').append(variable).append('\t').append(placed).append('\t').append(placedClz).append('\t').append(((IdentityHashMap)field(sum,"_loops")).size()).append('\t').append(clean(sum._reject)).append('\n'); - total++; - if( sum.supported() ) { pass++; if( placed>0 ) allocated++; } - } - Files.writeString(out.resolve("functions.tsv"),rows); - Files.writeString(out.resolve("sites.tsv"),sites); - Files.writeString(out.resolve("allocations.tsv"),nodes); - Files.writeString(out.resolve("calls.tsv"),calls); - System.out.println(name+" "+mode+": "+pass+"/"+total+" pass, "+allocated+" with user allocations; "+((System.nanoTime()-start)/1000000)+" ms"); - } -} -- cgit v1.2.3