diff options
| author | Cliff Click <cliffc@acm.org> | 2026-11-16 15:45:47 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-16 15:45:47 -0800 |
| commit | 650f541f976c03e22a4bc93bb9b09d81a7f810ba (patch) | |
| tree | 082ceafa0e11a9688b5db69c94b1f2d9fb6785dc | |
| parent | 0dcd3513a633479ce228f24826db4f09e4c0fc8b (diff) | |
| download | Simple-650f541f976c03e22a4bc93bb9b09d81a7f810ba.tar.gz Simple-650f541f976c03e22a4bc93bb9b09d81a7f810ba.zip | |
Another round of test speedup
More TestType lattice test speedups.
Collapse together some expensive tests.
Trim some tests from `sanity` target
| -rw-r--r-- | chapter32/Makefile | 31 | ||||
| -rw-r--r-- | chapter32/README.md | 87 | ||||
| -rw-r--r-- | chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java | 28 | ||||
| -rw-r--r-- | chapter32/src/test/java/com/seaofnodes/simple/ModTest.java | 27 | ||||
| -rw-r--r-- | chapter32/src/test/java/com/seaofnodes/simple/StringFormatTest.java | 113 | ||||
| -rw-r--r-- | chapter32/src/test/java/com/seaofnodes/simple/TestWorkspace.java | 2 | ||||
| -rw-r--r-- | chapter32/src/test/java/com/seaofnodes/simple/TypeTest.java | 81 | ||||
| -rw-r--r-- | skills/chapter25-codex-notes.md | 11 |
8 files changed, 286 insertions, 94 deletions
diff --git a/chapter32/Makefile b/chapter32/Makefile index af6da154..d91f59e0 100644 --- a/chapter32/Makefile +++ b/chapter32/Makefile @@ -30,13 +30,23 @@ test_cp := $(filter-out $(test_sys) ,$(test_cp4)) test_group0 := com.seaofnodes.simple.DrawTest test_group1 := com.seaofnodes.simple.GraphicsTest test_group2 := $(addprefix com.seaofnodes.simple.,TimeTest MemoryEncodingTest ChainedComparisonTest ParserTest Chapter28bTest) -test_group3 := $(addprefix com.seaofnodes.simple.,StringFormatTest FinalConstructionTest PartialReadTest EscapeFlowTest CallEndTest BulkMemPhiTest) -test_group4 := $(addprefix com.seaofnodes.simple.,BreakoutTest ArithNodeTest PhaseTest MethodAccessTest Int32Test MinusNodeTest ConstructorCompletionTest) -test_group5 := $(addprefix com.seaofnodes.simple.,TerminalInputTest ParserDiagnosticTest StaticDataTest ArrayInitTest MethodFieldsTest ConstantArrayTest BoundaryTest IntegerLiteralTest ConstructionRequirementsTest) -test_group6 := $(addprefix com.seaofnodes.simple.,AssemblyDumpTest AudioTest MathTest TicTacToeTest SelectiveLoadingTest FloatComparisonNativeTest SchedulingTest SeparateCompilationTest ConstructionGroupTest CompoundAssignmentTest) +test_group3 := $(addprefix com.seaofnodes.simple.,StringFormatTest StaticDataTest PhaseTest FinalConstructionTest PartialReadTest EscapeFlowTest CallEndTest BulkMemPhiTest) +test_group4 := $(addprefix com.seaofnodes.simple.,BreakoutTest ConvertNodeTest ArithNodeTest MethodAccessTest Int32Test MinusNodeTest ConstructorCompletionTest) +test_group5 := $(addprefix com.seaofnodes.simple.,TerminalInputTest ParserDiagnosticTest ArrayInitTest MethodFieldsTest ConstantArrayTest BoundaryTest IntegerLiteralTest ConstructionRequirementsTest) +test_group6 := $(addprefix com.seaofnodes.simple.,AssemblyDumpTest AudioTest MathTest TicTacToeTest ModTest SelectiveLoadingTest FloatComparisonNativeTest SchedulingTest SeparateCompilationTest ConstructionGroupTest CompoundAssignmentTest) test_group7 := $(filter-out $(test_group0) $(test_group1) $(test_group2) $(test_group3) $(test_group4) $(test_group5) $(test_group6),$(test_cp)) test_groups := $(addprefix tests_group,0 1 2 3 4 5 6 7) +# Fast compiler checks retain the full lattice, chapter/backend regressions, +# fuzzer regression seeds, and focused compiler tests. Library/application and +# CLI integration remains in `tests`. New compiler tests join sanity group 2. +sanity_omit := $(addprefix com.seaofnodes.simple.,DrawTest GraphicsTest TimeTest StringFormatTest BreakoutTest TerminalInputTest AudioTest MathTest TicTacToeTest StreamIOTest RuntimeArgsTest NativeExecutionTest ParserDiagnosticTest) +sanity_cp := $(filter-out $(sanity_omit),$(test_cp)) +sanity_group0 := $(addprefix com.seaofnodes.simple.,ClassInitDependenciesTest ConvertNodeTest ArithNodeTest MemoryEncodingTest ModTest IntrinsicTest AssemblyDumpTest) +sanity_group1 := $(addprefix com.seaofnodes.simple.,StaticDataTest FloatComparisonNativeTest ArrayInitTest ConstantArrayTest BoundaryTest Int32Test ReceiverTest GlobalAssignmentTest IncrementalBuildTest SeparateCompilationTest) +sanity_group2 := $(filter-out $(sanity_group0) $(sanity_group1),$(sanity_cp)) +sanity_groups := $(addprefix sanity_group,0 1 2) + # Size each test JVM for a share of the machine, instead of giving every JVM # JIT and GC pools sized for all cores. Absolute paths also serve child JVMs # launched from a group's private working directory (native Java on Windows). @@ -158,6 +168,15 @@ $(test_groups): tests_group%: $(test_classes) $(TEST_SYS) $(RELEASE_SYS) $(RELEA @echo "testing $@: $(test_group$*)" @cd build/tests/$@ && $(TEST_JVM) org.junit.runner.JUnitCore $(test_group$*) +.PHONY: sanity $(sanity_groups) +$(sanity_groups): sanity_group%: $(test_classes) $(TEST_SYS) $(RELEASE_SYS) $(RELEASE_CRT) + @$(TEST_JVM) com.seaofnodes.simple.TestWorkspace $@ $(CPU_ABI) + @echo "testing $@: $(sanity_group$*)" + @cd build/tests/$@ && $(TEST_JVM) org.junit.runner.JUnitCore $(sanity_group$*) + +sanity: $(sanity_groups) tests_raw0 tests_raw1 fuzzer tests_lattice0 tests_lattice1 tests_lattice2 tests_lattice3 + @echo "All sanity checks passed" + # One test method (or the whole class when METHOD is omitted). CLASS ?= Chapter25Test METHOD ?= @@ -165,7 +184,9 @@ METHOD ?= test: $(main_classes) $(test_classes) $(RELEASE_SYS) $(RELEASE_CRT) @$(TEST_JVM) com.seaofnodes.simple.TestRunner "$(CLASS)" "$(METHOD)" -tests: $(test_groups) tests_sys fuzzer tests_alone tests_raw1 tests_raw0 +# At -j8, start the remaining chapter cohorts before the short lattice parts +# so their native links overlap the earlier groups instead of forming a tail. +tests: $(test_groups) tests_sys fuzzer tests_raw1 tests_raw0 tests_alone @echo "All tests passed" diff --git a/chapter32/README.md b/chapter32/README.md index 7a814966..6883d65f 100644 --- a/chapter32/README.md +++ b/chapter32/README.md @@ -4,9 +4,9 @@ English | [日本語](README.ja.md) [Previous: Chapter 31 — Software Drawing, Time, and Graphical Games](../chapter31/README.md) -Chapter 31 completes the graphics, games, and library work. This chapter keeps +Chapter 31 completes the graphics, games, and library work. This chapter keeps that language and those programs, then investigates the cost of compiling and -testing them. Larger programs have made repeated graph walks, unnecessary +testing them. Larger programs have made repeated graph walks, unnecessary worklist visits, and uneven test parallelism visible in the test runtime. The starting changes address four costs: test JVM scheduling, scratch-state @@ -56,6 +56,89 @@ pair and triple. Separate processes also isolate the mutable type interning and traversal state. A direct JUnit or IDE invocation still runs the complete lattice test in one JVM; part zero of the Make run also runs the other type tests. +## Reduce test overhead before reducing coverage + +The November 16 follow-up uses `make -j8 tests` as the normal run. On the same +Windows/JDK 21 host, warm runs took 25.4–26.0 seconds; four workers took 30.5 +seconds and sixteen took 33.1. More concurrent JVMs did not help. Keep the +two-processor JVM sizing and distinguish warm testing from rebuilding the +compiler and released library. + +The serial attribution run spent 29.8 seconds in 153 GCC calls, mostly linking, +and 29.7 seconds in compiler phases. These are summed serial costs, not portions +of the parallel elapsed time. Four changes reduce work while retaining the +existing test methods and their value checks: + +* [TypeTest](src/test/java/com/seaofnodes/simple/TypeTest.java) constructs lattice + assertion messages only when the identity comparison fails. Formatting types + inside every successful triple was more expensive than the comparison. The + standalone lattice fell from 10.6 to 4.5 seconds, with all pairs and triples + still checked. +* [ModTest](src/test/java/com/seaofnodes/simple/ModTest.java) puts its native + division/remainder matrix into constant arrays and loops. All 200 checks, + including zero divisors and signed overflow, remain. This avoids compiling a + long chain of calls and conditional returns; the isolated test fell from + 2.75 to 0.62 seconds. +* [StringFormatTest](src/test/java/com/seaofnodes/simple/StringFormatTest.java) + shares three small native programs between compatible cases. Each original + test checks its own output, including embedded NULs and UTF-8 bytes. Separate + import, forward-reference, evaluator, and error tests remain. The class now + makes seven GCC calls instead of nineteen. +* [AssemblyDumpTest](src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java) + compiles two small modules containing the real Canvas font declaration. It + still checks unit headings, all 96 glyphs, exported data aliases, and repeated + dumps without changing the active encoding. Drawing integration remains in + DrawTest; inspecting assembly no longer requires recompiling all of `sys`. + +The Make groups redistribute the now-cheaper formatting and assembly work and +the tests accumulated in the fallback group. Remaining chapter cohorts start +before the short lattice partitions so their native links can overlap earlier +work. Rebalanced warm runs took 22.1 and 24.3 seconds and passed the same 819 +executions, including the three additional lattice partitions. Their mean is +about 10% below the earlier baseline; individual parallel runs vary. Compiler +verification remains enabled. + +## Keep the lattice in the fast checks + +`make -j8 sanity` retains the entire lattice, chapters 1–24's existing test +cohorts, saved fuzzer regression seeds, and the focused compiler tests. Its +three compiler groups have private native-output directories just like the +full suite. New compiler test classes enter the last sanity group automatically. +Warm runs on the same host took 8.77 and 8.85 seconds and passed 680 executions. +`make -j8 tests` still runs all 819 executions. + +The fast set leaves graphics, audio, time, math-library, formatting, game, terminal, stream, +runtime-argument, CLI-diagnostic, and native-harness integration in the full +suite, along with Chapter25Test and the larger BrainFuck/MergeSort programs. +It retains native execution for arithmetic, memory encoding, static data, +receivers, separate compilation, incremental rebuilds, and the chapter backend +tests. This selects a cheaper set of checks; it does not replace native +execution with evaluator-only coverage. Full tests remain necessary when +changing the omitted libraries, interfaces, or programs. + +The lattice itself now does less redundant work. It caches each pair's meet +and join, computing both operand orders before checking commutativity. For +associativity it visits `i <= j <= k`: `n(n+1)(n+2)/6` triples instead of `n^3`. +For each triple it checks all six intermediate results: + +``` +(a & b) & c c & (a & b) +(a & c) & b b & (a & c) +(b & c) & a a & (b & c) +``` + +Once the original pairs commute, the six original associativity equalities +connect these results in a cycle. Comparing all six to one common result +checks the same property. Both operand orders involving an intermediate meet +remain explicit: that intermediate type need not belong to the gathered set. +Repeated operands are included, and all comparable-pair monotonicity checks +remain. No random sampling or smaller type collection is used. + +The unpartitioned TypeTest now takes about 0.7 seconds, following the earlier +reduction to roughly four seconds from lazy assertion messages. The existing +four process partitions remain; in the warm sanity run each took 0.3–0.4 +seconds. Reducing duplicate operations made additional JVMs unnecessary. + ## Shallow type queries need no recursive scratch state [Type.isConstant and Type.isFinal](src/main/java/com/seaofnodes/simple/type/Type.java) diff --git a/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java b/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java index 0e4c230a..5399aecf 100644 --- a/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java +++ b/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java @@ -13,25 +13,39 @@ public class AssemblyDumpTest { @Test public void libraryUnitsAndGlyphs() throws Exception { Path root=Path.of("build/objs/assembly-dump"); Files.createDirectories(root); - Path build=Files.createTempDirectory(root,"sys-"); - CodeGen code=new CodeGen("src/main/smp",build.toString(),null,"sys",null,123,true,TypeInteger.BOT) + Path fixture=Files.createTempDirectory(root,"font-"); + Path source=Files.createDirectories(fixture.resolve("src")); + Path build=Files.createDirectories(fixture.resolve("obj")); + Files.createDirectories(source.resolve("Atlas")); + // Use the real font, but only two tiny modules: drawing integration is + // covered by DrawTest. This test needs multiple units and constant data. + String canvasSource=Files.readString(Path.of("src/main/smp/sys/draw/Canvas.smp")); + int fontStart=canvasSource.indexOf("val _glyphs ="); + assertTrue("Font declaration",fontStart>=0); + int fontEnd=canvasSource.indexOf("};",fontStart); + assertTrue("Font initializer",fontEnd>=0); + Files.writeString(source.resolve("Atlas/Font.smp"),canvasSource.substring(fontStart,fontEnd+2)+ + "\nval glyph={int i -> _glyphs[i];};\n"); + Files.writeString(source.resolve("Atlas.smp"),"val glyph={int i -> Font.glyph(i);};\n"); + CodeGen code=new CodeGen(source.toString(),build.toString(),null,"Atlas",null,123,true,TypeInteger.BOT) .driver(CodeGen.Phase.Serialize,TestC.CPU_PORT,TestC.CALL_CONVENTION) .driver(CodeGen.Phase.Encoding,TestC.CPU_PORT,TestC.CALL_CONVENTION); var entry=code._encoding; String before=code.asm(); assertSame("Dumping another unit must not change the active encoding",entry,code._encoding); + assertEquals(2,code._compunits.size()); for( var unit : code._compunits.values() ) if( unit._src!=null ) { String heading="=== Compilation unit: "+unit._cname+" ==="; assertEquals("Exactly one heading for "+unit._cname,2,before.split(heading,-1).length); } - int start=before.indexOf("=== Compilation unit: sys.draw.Canvas ==="); + int start=before.indexOf("=== Compilation unit: Atlas.Font ==="); assertTrue(start>=0); int end=before.indexOf("=== Compilation unit:",start+1); String canvas=before.substring(start,end<0 ? before.length() : end); assertTrue(canvas.contains("Constant Pool")); - assertTrue(canvas.contains("sys.draw.Canvas._glyphs: []u16")); - TypeMemPtr ptr=(TypeMemPtr)code._compunits.get("sys/draw/Canvas")._clz.field("_glyphs")._t; + assertTrue(canvas.contains("Atlas.Font._glyphs: []u16")); + TypeMemPtr ptr=(TypeMemPtr)code._compunits.get("Atlas/Font")._clz.field("_glyphs")._t; TypeConAry glyphs=(TypeConAry)ptr._obj.field("[]")._t; assertEquals(96,glyphs.len()); BAOS bytes=new BAOS(); @@ -40,10 +54,10 @@ public class AssemblyDumpTest { canvas.contains("60000000"+HexFormat.of().formatHex(bytes.toByteArray()))); code.exportELF(false,false); com.seaofnodes.simple.codegen.PrintRegTestSupport.checkDataAliases( - build.resolve("sys/draw/Canvas.o"),196,"sys.draw.Canvas._glyphs"); + build.resolve("Atlas/Font.o"),196,"Atlas.Font._glyphs"); assertSame(entry,code._encoding); assertEquals("Export must not truncate the dump to its entry unit",before,code.asm()); - Files.writeString(build.resolve("sys.asm"),before); + Files.writeString(build.resolve("Atlas.asm"),before); } @Test public void combinedEncodingAndEarlierPhase() { diff --git a/chapter32/src/test/java/com/seaofnodes/simple/ModTest.java b/chapter32/src/test/java/com/seaofnodes/simple/ModTest.java index 7f79599d..c06e99f1 100644 --- a/chapter32/src/test/java/com/seaofnodes/simple/ModTest.java +++ b/chapter32/src/test/java/com/seaofnodes/simple/ModTest.java @@ -166,20 +166,31 @@ public class ModTest { return integerEdges(new long[]{Long.MIN_VALUE,Long.MIN_VALUE+1,-17,-5,-1,0,1,5,17,Long.MAX_VALUE}); } private static String integerEdges(long[] values) { + // Keep the full value matrix in data, rather than compiling a long + // chain of constant calls and conditional returns for every pair. StringBuilder source=new StringBuilder(""" val rem_noInline={ i64 x,i64 y -> x%y; }; val div_noInline={ i64 x,i64 y -> x/y; }; val main={ -> + val values=new i64[~]{ """); - int failure=1; - for( long x : values ) - for( long y : values ) { - source.append("if(rem_noInline(").append(literal(x)).append(',').append(literal(y)) - .append(")!=").append(literal(y==0 ? 0 : x%y)).append(") return ").append(failure++).append(';'); - source.append("if(div_noInline(").append(literal(x)).append(',').append(literal(y)) - .append(")!=").append(literal(y==0 ? 0 : x/y)).append(") return ").append(failure++).append(';'); + for(int i=0;i<values.length;i++) source.append(i==0 ? "" : ",").append(literal(values[i])); + source.append("}; val expectedRem=new i64[~]{"); + int n=0; + for(long x:values) for(long y:values) source.append(n++==0 ? "" : ",").append(literal(y==0 ? 0 : x%y)); + source.append("}; val expectedDiv=new i64[~]{"); + n=0; + for(long x:values) for(long y:values) source.append(n++==0 ? "" : ",").append(literal(y==0 ? 0 : x/y)); + return source.append(""" + }; + int index=0; + for(int i=0;i<values#;i++) for(int j=0;j<values#;j++) { + if(rem_noInline(values[i],values[j])!=expectedRem[index]) return index*2+1; + if(div_noInline(values[i],values[j])!=expectedDiv[index]) return index*2+2; + index++; } - return source.append("return 0; };").toString(); + return 0; }; + """).toString(); } @Test public void nativeFloatingEdges() throws Exception { double[][] cases={{Double.MAX_VALUE,0.1},{-Double.MAX_VALUE,0.1}, diff --git a/chapter32/src/test/java/com/seaofnodes/simple/StringFormatTest.java b/chapter32/src/test/java/com/seaofnodes/simple/StringFormatTest.java index 59b62709..d6783380 100644 --- a/chapter32/src/test/java/com/seaofnodes/simple/StringFormatTest.java +++ b/chapter32/src/test/java/com/seaofnodes/simple/StringFormatTest.java @@ -11,28 +11,88 @@ import org.junit.Test; import static org.junit.Assert.*; public class StringFormatTest extends TestC { - private static void prints(String body, String expected) throws Exception { - runSYS("val main={ -> "+body+" return 0; };", "stringFormat",expected,-1); + // Share a few native programs, retaining a separately reported assertion + // for each case. Blocks isolate locals; the delimiter preserves embedded + // NULs and newlines in the expected output. + private enum Format { + DefaultsAndNestedStrings("sys.io.p(\"CPU plays %(2+3). %(\"nested %(7)\") %(true) %(1.5)\\n\");", + "CPU plays 5. nested 7 1 1.5\n"), + Formats("sys.io.p(\"%+06d(17)|%#08x(42)|%-5.3s(\"abcdef\")|%.2f(1.25)|%c(65)|%b(false)\\n\");", + "+00017|0x00002a|abc |1.25|A|false\n"), + RemainderInInterpolation("int mod=17; sys.io.p(\"%(mod%5)|%02d(mod%5)|%%|\\%|%(mod %= 5)|%(mod)\");", + "2|02|%|%|2|2"), + IntegerLimits("i64 lo=-9223372036854775807-1; sys.io.p(\"%(lo)|%(9223372036854775807)|%u(-1)|%X(-1)\");", + "-9223372036854775808|9223372036854775807|18446744073709551615|FFFFFFFFFFFFFFFF"), + IntegerPaddingRules("sys.io.p(\"%#.0o(0)|%#.3o(1)|%#x(0)|%-08d(17)|%08.4d(-17)|%+d(0)|% d(0)\");", + "0|001|0|17 | -0017|+0| 0"), + BuilderNumberUsesFormatter("val b=new sys.aryu8(); b.num(-9223372036854775807-1).add('|').num(9223372036854775807); sys.io.p(sys.text.end(b));", + "-9223372036854775808|9223372036854775807"), + EvaluationOrder("int x=0; val s=\"%(x++)%(x++)%(x++)\"; sys.io.p(\"%(s):%(s#):%(x)|%%|\\%\");", + "012:3:3|%|%"), + EvaluationMutatesBytes("val a=new u8[1]; a[0]='A'; sys.io.p(\"%(a)%(a[0]='B')%(a)\");", "A66B"), + Converters("sys.io.p(sys.text.int(17)); sys.io.p(sys.text.char(65)); sys.io.p(sys.text.bool(true)); sys.io.p(sys.text.flt(1.5));", + "17Atrue1.5"), + FieldNamedInt("struct S { int int=7; }; sys.io.p(\"%((new S).int)\");", "7"), + FloatAndAlternateFormats("f32 x=1.25f; sys.io.p(\"%(x)|%f(x)|%.2e(x)|%.2G(x)|%#o(9)|% d(7)|%.0d(0)|%a(1.5)\");", + "1.25|1.250000|1.25e+00|1.2|011| 7||0x1.8p+0"), + BufferGrowth("sys.io.p(\"%0100d(17)|%.100f(1.0)\");", "0".repeat(98)+"17|1."+"0".repeat(100)), + BytesAndEmptyStrings("val empty=\"%(\"\")\"; val bytes=\"a\\0b\"; sys.io.p(\"%(empty#):%s(bytes):%.2s(bytes):%c(0)\");", + "0:a\0b:a\0:\0"), + Utf8String("val s=\"π\"; sys.io.p(\"%(s):%(s#):%(s[0]):π\");", "π:2:207:π"), + DeferredParsing(""" + struct S { u8[~] s; new S={ -> s="%("}) %(3)")"; }; }; + val s=new S; + sys.io.p(s.s); + for(int i=0; i<2; sys.io.p("%(i++) %("(")")) { } + """, "}) 30 (1 ("); + + final String body, expected; + Format(String body, String expected) { this.body=body; this.expected=expected; } + } + private static final String END="\n--end-format-case--\n"; + private static final int BATCH_SIZE=5; + private static final String[] OUTPUTS=new String[Format.values().length]; + + @org.junit.BeforeClass public static void resetNativeBatches() { + java.util.Arrays.fill(OUTPUTS,null); + } + + private static void prints(Format test) throws Exception { + int index=test.ordinal(); + if( OUTPUTS[index]==null ) { + Format[] cases=Format.values(); + int first=index/BATCH_SIZE*BATCH_SIZE, limit=Math.min(first+BATCH_SIZE,cases.length); + StringBuilder source=new StringBuilder("val main={ -> "); + for( int i=first; i<limit; i++ ) { + assertFalse("Reserved batch delimiter",cases[i].expected.contains(END)); + source.append('{').append(cases[i].body).append('}'); + source.append("sys.io.p(\"\\n--end-format-case--\\n\");"); + } + source.append("return 0; };"); + String exe=compile(source.toString(),"stringFormat"+first, + new Ary<>(new String[]{RELEASE_SYS_DIR}),CALL_CONVENTION,null,null,-1); + String[] outputs=exec(TEST_TIMEOUT_SECONDS,exe).split(java.util.regex.Pattern.quote(END),-1); + assertEquals("Each format case must complete",limit-first+1,outputs.length); + assertEquals("No output after final case", "",outputs[outputs.length-1]); + for( int i=first; i<limit; i++ ) OUTPUTS[i]=outputs[i-first]; + } + assertEquals(test.name(),test.expected,OUTPUTS[index]); } @Test public void testDefaultsAndNestedStrings() throws Exception { - prints("sys.io.p(\"CPU plays %(2+3). %(\"nested %(7)\") %(true) %(1.5)\\n\");", - "CPU plays 5. nested 7 1 1.5\n"); + prints(Format.DefaultsAndNestedStrings); } @Test public void testFormats() throws Exception { - prints("sys.io.p(\"%+06d(17)|%#08x(42)|%-5.3s(\"abcdef\")|%.2f(1.25)|%c(65)|%b(false)\\n\");", - "+00017|0x00002a|abc |1.25|A|false\n"); + prints(Format.Formats); } @Test public void testRemainderInInterpolation() throws Exception { - prints("int mod=17; sys.io.p(\"%(mod%5)|%02d(mod%5)|%%|\\%|%(mod %= 5)|%(mod)\");", - "2|02|%|%|2|2"); + prints(Format.RemainderInInterpolation); } @Test public void testIntegerLimits() throws Exception { - prints("i64 lo=-9223372036854775807-1; sys.io.p(\"%(lo)|%(9223372036854775807)|%u(-1)|%X(-1)\");", - "-9223372036854775808|9223372036854775807|18446744073709551615|FFFFFFFFFFFFFFFF"); + prints(Format.IntegerLimits); } @Test public void testSignedAndUnsignedRadices() throws Exception { @@ -49,13 +109,11 @@ public class StringFormatTest extends TestC { } @Test public void testIntegerPaddingRules() throws Exception { - prints("sys.io.p(\"%#.0o(0)|%#.3o(1)|%#x(0)|%-08d(17)|%08.4d(-17)|%+d(0)|% d(0)\");", - "0|001|0|17 | -0017|+0| 0"); + prints(Format.IntegerPaddingRules); } @Test public void testBuilderNumberUsesFormatter() throws Exception { - prints("val b=new sys.aryu8(); b.num(-9223372036854775807-1).add('|').num(9223372036854775807); sys.io.p(sys.text.end(b));", - "-9223372036854775808|9223372036854775807"); + prints(Format.BuilderNumberUsesFormatter); } @Test public void testFormattingInEvaluatorFromSource() { @@ -74,15 +132,13 @@ public class StringFormatTest extends TestC { } @Test public void testEvaluationOrderAndLength() throws Exception { - prints("int x=0; val s=\"%(x++)%(x++)%(x++)\"; sys.io.p(\"%(s):%(s#):%(x)|%%|\\%\");", - "012:3:3|%|%"); - prints("val a=new u8[1]; a[0]='A'; sys.io.p(\"%(a)%(a[0]='B')%(a)\");", "A66B"); + prints(Format.EvaluationOrder); + prints(Format.EvaluationMutatesBytes); } @Test public void testConverters() throws Exception { - prints("sys.io.p(sys.text.int(17)); sys.io.p(sys.text.char(65)); sys.io.p(sys.text.bool(true)); sys.io.p(sys.text.flt(1.5));", - "17Atrue1.5"); - prints("struct S { int int=7; }; sys.io.p(\"%((new S).int)\");", "7"); + prints(Format.Converters); + prints(Format.FieldNamedInt); } @Test public void testForwardReturnTypes() throws Exception { @@ -91,14 +147,13 @@ public class StringFormatTest extends TestC { } @Test public void testFloatAndAlternateFormats() throws Exception { - prints("f32 x=1.25f; sys.io.p(\"%(x)|%f(x)|%.2e(x)|%.2G(x)|%#o(9)|% d(7)|%.0d(0)|%a(1.5)\");", - "1.25|1.250000|1.25e+00|1.2|011| 7||0x1.8p+0"); + prints(Format.FloatAndAlternateFormats); runSYS("val format_noInline={ f32 x -> \"%(x)|%f(x)\"; }; val main={ -> sys.io.p(format_noInline(1.25f)); return 0; };", "stringFormatFloat","1.25|1.250000",-1); } @Test public void testBufferGrowth() throws Exception { - prints("sys.io.p(\"%0100d(17)|%.100f(1.0)\");", "0".repeat(98)+"17|1."+"0".repeat(100)); + prints(Format.BufferGrowth); } @Test public void testLiteralRemainsConstant() { @@ -107,18 +162,12 @@ public class StringFormatTest extends TestC { } @Test public void testBytesAndEmptyStrings() throws Exception { - prints("val empty=\"%(\"\")\"; val bytes=\"a\\0b\"; sys.io.p(\"%(empty#):%s(bytes):%.2s(bytes):%c(0)\");", - "0:a\0b:a\0:\0"); - prints("val s=\"π\"; sys.io.p(\"%(s):%(s#):%(s[0]):π\");", "π:2:207:π"); + prints(Format.BytesAndEmptyStrings); + prints(Format.Utf8String); } @Test public void testDeferredParsing() throws Exception { - prints(""" - struct S { u8[~] s; new S={ -> s="%("}) %(3)")"; }; }; - val s=new S; - sys.io.p(s.s); - for(int i=0; i<2; sys.io.p("%(i++) %("(")")) { } - """, "}) 30 (1 ("); + prints(Format.DeferredParsing); } @Test public void testImportedFormatter() throws Exception { diff --git a/chapter32/src/test/java/com/seaofnodes/simple/TestWorkspace.java b/chapter32/src/test/java/com/seaofnodes/simple/TestWorkspace.java index 30cff89f..d875c47a 100644 --- a/chapter32/src/test/java/com/seaofnodes/simple/TestWorkspace.java +++ b/chapter32/src/test/java/com/seaofnodes/simple/TestWorkspace.java @@ -7,7 +7,7 @@ import java.nio.file.attribute.BasicFileAttributes; /** Prepare a Make test group's working directory without sharing native outputs. */ public class TestWorkspace { public static void main(String[] args) throws IOException { - if( args.length!=2 || !args[0].matches("tests_group[0-7]") || !args[1].matches("[A-Za-z0-9_]+") ) + if( args.length!=2 || !args[0].matches("tests_group[0-7]|sanity_group[0-2]") || !args[1].matches("[A-Za-z0-9_]+") ) throw new IllegalArgumentException("Expected test group and CPU_ABI"); Path root = Path.of("").toAbsolutePath().normalize(); Path work = root.resolve("build/tests").resolve(args[0]).normalize(); diff --git a/chapter32/src/test/java/com/seaofnodes/simple/TypeTest.java b/chapter32/src/test/java/com/seaofnodes/simple/TypeTest.java index 8f212bda..adcc1b3a 100644 --- a/chapter32/src/test/java/com/seaofnodes/simple/TypeTest.java +++ b/chapter32/src/test/java/com/seaofnodes/simple/TypeTest.java @@ -276,74 +276,77 @@ public class TypeTest { public void testLatticeTheory() { Type[] ts = Type.gather(); // Make partitions the outer loop between independent JVMs. A direct - // JUnit/IDE invocation retains the full Cartesian-product coverage. + // JUnit/IDE invocation retains the full coverage. int parts = Integer.parseInt(System.getProperty("simple.lattice.parts","1")); int part = Integer.parseInt(System.getProperty("simple.lattice.part" ,"0")); Assert.assertTrue("Invalid lattice partition",parts > 0 && parts <= ts.length && part >= 0 && part < parts); - // Confirm commutative & complete - for( int i=part; i<ts.length; i+=parts ) { - Type t0 = ts[i]; - for( Type t1 : ts ) { - check_commute (t0,t1); - check_symmetric(t0,t1); + // Every triple reuses these pairs. Compute both operand orders rather + // than assuming commutativity in the table we are about to check. + Type[][] meets = new Type[ts.length][ts.length]; + Type[][] joins = new Type[ts.length][ts.length]; + for( int i=0; i<ts.length; i++ ) + for( int j=0; j<ts.length; j++ ) { + meets[i][j] = ts[i].meet(ts[j]); + joins[i][j] = ts[i].join(ts[j]); } - } - // Confirm associative + // Confirm commutative & complete, once per unordered pair. for( int i=part; i<ts.length; i+=parts ) { - Type t0 = ts[i]; - for( Type t1 : ts ) - for( Type t2 : ts ) - assoc(t0,t1,t2); + assertSame(ts[i],meets[i][i]); + for( int j=i; j<ts.length; j++ ) { + assertSame(meets[i][j],meets[j][i]); + check_symmetric(ts[i],ts[j],meets[i][j]); + } } + // Each unordered triple represents all six permutations. Check every + // intermediate result in both operand orders; a pair's meet need not + // itself be in ts, so its commutativity must not be assumed. + for( int i=part; i<ts.length; i+=parts ) + for( int j=i; j<ts.length; j++ ) + for( int k=j; k<ts.length; k++ ) + assoc(ts[i],ts[j],ts[k],meets[i][j],meets[i][k],meets[j][k]); + // Confirm symmetry. If A isa B, then A.join(C) isa B.join(C) for( int i=part; i<ts.length; i+=parts ) { Type t0 = ts[i]; - for( Type t1 : ts ) - if( t0.isa(t1) ) - for( Type t2 : ts ) { - Type t02 = t0.join(t2); - Type t12 = t1.join(t2); + for( int j=0; j<ts.length; j++ ) + if( meets[i][j]==ts[j] ) + for( int k=0; k<ts.length; k++ ) { + Type t02 = joins[i][k]; + Type t12 = joins[j][k]; Type mt = t02.meet(t12); - assertSame(t0+" isa "+t1+" joined "+t2, mt,t12); + if( mt!=t12 ) assertSame(t0+" isa "+ts[j]+" joined "+ts[k], mt,t12); } } } - // By design in meet, args are already flipped to order _type, which forces - // symmetry for things with badly ordered _type fields. The question is - // still interesting for other orders. - private static void check_commute( Type t0, Type t1 ) { - if( t0==t1 ) return; - if( t0.is_simple() && !t1.is_simple() ) return; // By design, flipped the only allowed order - Type mta = t0.meet(t1); - Type mtb = t1.meet(t0); // Reverse args and try again - assertSame(mta,mtb); - } - // A & B = MT // Expect: ~A & ~MT == ~A // Expect: ~B & ~MT == ~B private static void check_symmetric( Type t0, Type t1 ) { + check_symmetric(t0,t1,t0.meet(t1)); + } + + private static void check_symmetric( Type t0, Type t1, Type mt ) { if( t1==t0 ) return; - Type mt = t0.meet(t1); Type dm = mt.dual(); Type d0 = t0.dual(); Type d1 = t1.dual(); Type ta = dm.meet(d1); Type tb = dm.meet(d0); - assertSame(t0+" & "+t1+" mt="+mt, ta,d1); - assertSame(t0+" & "+t1+" mt="+mt, tb,d0); + if( ta!=d1 ) assertSame(t0+" & "+t1+" mt="+mt, ta,d1); + if( tb!=d0 ) assertSame(t0+" & "+t1+" mt="+mt, tb,d0); } - private static void assoc( Type t0, Type t1, Type t2 ) { - Type t01 = t0 .meet(t1 ); - Type t12 = t1 .meet(t2 ); - Type t01_2 = t01.meet(t2 ); - Type t0_12 = t0 .meet(t12); - assertSame(t0+" & "+t1+" & "+t2, t01_2,t0_12); + private static void assoc( Type a, Type b, Type c, Type ab, Type ac, Type bc ) { + // The six original associativity equalities connect these six values + // in a cycle. Equality to one common result checks the same property. + Type result = ab.meet(c); + if( result!=c.meet(ab) || result!=ac.meet(b) || result!=b.meet(ac) || + result!=bc.meet(a) || result!=a.meet(bc) ) + Assert.fail("Associativity: "+a+" & "+b+" & "+c); } // Test cyclic types and meets diff --git a/skills/chapter25-codex-notes.md b/skills/chapter25-codex-notes.md index 7cf22839..b32fdd15 100644 --- a/skills/chapter25-codex-notes.md +++ b/skills/chapter25-codex-notes.md @@ -35,6 +35,17 @@ callers promise no initialized fields. No new passes or backward demand walks. ## Chapter 32: restart guidance (2026-11-15) +Use `make -j8 tests` as the normal validation/timing command going forward. +The November 16 sweep found both `-j4` and `-j16` slower on this Windows host; +retain `ActiveProcessorCount=2`. Keep lattice checks in their own JVMs: combining +them after compiler-heavy tests can exhaust the existing 16-bit type IDs. +The full lattice is required even in fast checks. `make -j8 sanity` keeps its +four partitions plus chapter/backend and focused compiler regressions; full +`make -j8 tests` retains library/application/CLI integration. The lattice now +caches pairs and checks all six intermediate results per unordered triple; +do not reduce it to one associativity equality per unordered triple, which +would assume commutativity for intermediate types outside the gathered set. + On 2026-11-16, Cliff requested backporting the shared class receiver to chapter 28a, imported-summary handling to 28b, and both through the later snapshots. The chapter28a README now owns that explanation. Preserve 28a/28b's monolithic |
