diff options
| author | Cliff Click <cliffc@acm.org> | 2026-12-04 18:27:51 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-12-04 18:27:51 -0800 |
| commit | da70ff420d27029ff622b1862d4c43f8273c04a4 (patch) | |
| tree | 0376cd3c5a3eeab384a5d24e9bb4ecf6aedd7b15 | |
| parent | 236e343e995a18129ca6c666ff0e7bfaa500d5e4 (diff) | |
| download | Simple-da70ff420d27029ff622b1862d4c43f8273c04a4.tar.gz Simple-da70ff420d27029ff622b1862d4c43f8273c04a4.zip | |
Size stores to broad field declarations consistently with layout
A BOTTOM field reserves a full-width slot; do not leave its Store width unresolved. Add an IR layout/store consistency regression and native coverage for a wide inferred field initialized from an imported call.
Full make -k -j8 tests passes. One earlier sweep hit the live-clock sleep timing check; the focused rerun and full confirmation pass.
3 files changed, 36 insertions, 3 deletions
diff --git a/chapter33/src/main/java/com/seaofnodes/simple/node/StoreNode.java b/chapter33/src/main/java/com/seaofnodes/simple/node/StoreNode.java index 204e0c4b..511afa4e 100644 --- a/chapter33/src/main/java/com/seaofnodes/simple/node/StoreNode.java +++ b/chapter33/src/main/java/com/seaofnodes/simple/node/StoreNode.java @@ -251,8 +251,8 @@ public class StoreNode extends MemOpNode { Field fld = obj.field(_name); if( fld == null || fld._t == null ) return 0; - if( fld._t == Type.BOTTOM ) - return 0; // Store into a final field + // Broad inferred declarations still reserve full-width slots. Match + // TypeStruct's layout rather than leaving these Stores unsized. assert fld._t != Type.TOP; // Freshly parsed field stores retain the declaring structure on their // symbolic offset even after the pointer's flow type sharpens. diff --git a/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java b/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java index b243beb2..87f9564d 100644 --- a/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java +++ b/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java @@ -3,7 +3,8 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.codegen.CodeGen; import com.seaofnodes.simple.node.*; import com.seaofnodes.simple.util.WorkList; -import com.seaofnodes.simple.type.TypeInteger; +import com.seaofnodes.simple.type.*; +import com.seaofnodes.simple.parser.Parser; import java.nio.file.Files; import java.nio.file.Path; import org.junit.Test; @@ -11,6 +12,19 @@ import static org.junit.Assert.*; /** Regressions for the independent compiler fixes introduced in this chapter. */ public class Chapter33Test { + @Test public void testBroadFieldStoreMatchesLayout() { + CodeGen code=new CodeGen("return 0;").driver(CodeGen.Phase.FinalizeIR); + int alias=code.alias("Test"); + TypeStruct ts=TypeStruct.make("Test.Broad",false,Field.make("value",Type.BOTTOM,alias,false)); + Parser.TYPES.put(ts._name,ts); + Node ptr=code.con(TypeMemPtr.make(ts)); + StoreNode store=new StoreNode(null,"value",alias,Type.BOTTOM,null, + code.con(TypeMem.make(alias,Type.BOTTOM)),ptr,code.con(ts.offset(0)),code.con(4294967297L),false).init(); + store.idealize(); + assertEquals("A broad declaration still reserves a complete storage slot", + ts.offset(1)-ts.offset(0),store.storeSize()); + } + @Test public void testWorkListRequeueAndTraversal() { CodeGen code = new CodeGen("return arg;").parse(); Node arg = code.expr(); diff --git a/chapter33/src/test/java/com/seaofnodes/simple/SeparateCompilationTest.java b/chapter33/src/test/java/com/seaofnodes/simple/SeparateCompilationTest.java index db8e696c..be20b41d 100644 --- a/chapter33/src/test/java/com/seaofnodes/simple/SeparateCompilationTest.java +++ b/chapter33/src/test/java/com/seaofnodes/simple/SeparateCompilationTest.java @@ -10,6 +10,25 @@ import org.junit.Test; import static org.junit.Assert.*; public class SeparateCompilationTest { + @Test public void testInferredImportedFieldStoreWidth() throws Exception { + Path lib=Files.createTempDirectory(Files.createDirectories(Path.of("build/objs/separate")),"inferred-store-"); + new CodeGen(null,lib.toString(),null,"Library", + "val number_noInline={ -> 7; };",123,true,TypeInteger.BOT) + .driver(TestC.CPU_PORT,TestC.CALL_CONVENTION,false,false); + var paths=new Ary<>(new String[]{lib.toString()}); + String src=""" + struct Box { var value=Library.number_noInline(); }; + val b=new Box; + b.value=4294967297; + return b.value; + """; + CodeGen code=new CodeGen(null,lib.toString(),paths,"Client",src,123,true,TypeInteger.BOT) + .driver(CodeGen.Phase.TypeCheck); + assertEquals("4294967297",Eval2.eval(code,0)); + TestC.run(src.replace("return b.value;","return b.value!=4294967297;"), + "inferred_import_store",paths,TestC.CALL_CONVENTION,null,null,"",-1); + } + @Test public void testImportedNestedTypeOnlyReference() throws Exception { Path lib=Files.createTempDirectory(Files.createDirectories(Path.of("build/objs/separate")),"nested-type-"); new CodeGen(null,lib.toString(),null,"Library", |
