Repository navigation
selfhost: port the Python type checker to flowc (sem_check) with a parity gate - #1071
Merged
Merged
Conversation
…rity gate Rebuilt on main from selfhost/typecheck-parity (#1071). The bootstrap C is regenerated in the next commit.
ft_read_file returns null as string on the malloc failure path, which the ported checker requires. The MLIR corpus is re-recorded from 84806b0: test_typecheck_overload_integration.flow imports compiler/src/typecheck.flow, so its MLIR follows that module.
godofecht
force-pushed
the
selfhost/typecheck-parity
branch
from
September 29, 2026 23:08
5252b35 to
5086a82
Compare
sem_define_function wrote tys.ret[f] = sem_parse_type(...). The emitted C may load tys->ret before the call, and the call can grow the type table, so gcc stored into the freed old array. glibc had handed that block to the effects array, and flowc crashed on Linux building tools/lsp. Each such store now evaluates the call into a local first.
godofecht
added a commit
that referenced
this pull request
Sep 30, 2026
Rebuilt on main from selfhost/mlir-finish (#1072) after #1071. The scripts/tools programs follow the strict type check, and the tc_reject cgen goldens expect the ported checker's diagnostics. The design note on what the deletion left open now lists the three checks flowc --strict still accepts. The bootstrap C is regenerated in the next commit.
This was referenced Sep 30, 2026
godofecht
added a commit
that referenced
this pull request
Sep 30, 2026
The 11 stores from #1071 that went through a local to dodge gcc reading the array before the call are plain assignments again. cgen now evaluates a call on the right of a store through a pointer before it reads the target.
godofecht
added a commit
that referenced
this pull request
Sep 30, 2026
… target (#1077) cgen evaluates a call on the right of a store into a temporary before it reads the store's target. A call that grows the array under the store, like a type-table append in sem_check, no longer leaves gcc writing into the freed old array. The eleven hand-written locals added to sem_check for #1071 are gone, and tests/cgen and tests/lang each gain a store_after_call case.
This was referenced Sep 30, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports
src/flow/type_checker.pyto flowc, rule by rule and message by message, so the Python checker can be deleted. This branch is built onport/remaining-python-commands(#1064), which is merged in; review after #1064 lands, or read the diff against that branch.What changed
compiler/src/sem_check.flow,sem_model.flow,sem_types.flow,sem_util.flow,sem_cheader.flow: the type checker. It runs in single-file and bundle mode, strict by default and lenient underFLOWC_LENIENT=1(only the errors Python kept fatal stop a lenient compile). Modules are checked in the Python resolver's DFS order. Error positions follow the Python lexer's line counting.@cImportheaders are read withcppfor the names they declare.typecheck.flowkeeps only what C generation needs when the semantic check is on, so no diagnostic is printed twice.FLOWC_CHECK_ONLY=1stops after the type check.roundtrip.shand the self-emit scripts build the new modules one object each.Gates
compiler/scripts/parity_typecheck.sh: the Python verdict and first diagnostic, strict and lenient, for every tracked.flow, 169 snippets extracted from the Python unit tests, and every doc-example harness rung (4506 inputs), recorded as goldens fromf102d88f.--checkneeds no Python and fails above the per-OS ceilings incompiler/fixtures/typecheck_parity/ceiling.txt.compiler/scripts/typecheck_rules.sh: one negative program per ported rule, 113 fixtures incompiler/fixtures/typecheck_rules/. Each file's first line is the Python message it expects. A fixture fails against the checker before the port.Five-way counts (strict / lenient)
"Before" is the old flowc against the first goldens (4324 inputs). The input set grew with the tree.
Remaining differences
All intended, and listed in
ceiling.txt:unknown.gainin two modules. Python kept both as overloads and clang rejected the redefinition.Doc examples
The doc checker compiles each block with
flowc_emit.sh --strictand reports the first type error at stagetypes. The eightexpect-errorblocks that had fallen tounverifiedverify again.docs/generated/example-status.jsonnow matches the Python checker's ledger on every status and stage; one detail differs and is listed intests/doc_examples/KNOWN_DIFFERENCES.md.Codegen gaps from #1064
tests/lang/test_ptr_field_of_call.flow.fdopen,filenoandrealpathcount as libc names, so an extern block that declares them emits no conflicting prototype.tests/lang/test_libc_posix_externs.flow.tois a name outside aforrange.tests/lang/test_to_as_name.flow.Closes #1065. Closes #1067. Closes #1068.
Source fixes
The compiler,
tools/,scripts/tools/and a few library files now pass the strict check: casts such asnull as stringandas ptr<u8>,let mutwhere a binding is reassigned, and@unsafe externforsystem,sprintfandrealpath.Gate results on this branch
bootstrap_from_c.sh --verify,self_host_full.sh,roundtrip.sh,parse_coverage.sh --check,fmt_check.sh --check,tests/cgen/run.sh,./flow test-lang,typecheck_rules.sh,check_doc_examples.sh --check-ledger,tests/doc_examples/run.sh,corpus_parity.sh --check,check_run_without_python.sh,parity_typecheck.sh --check, the tool suites and every otherparity_*.shpass, with two exceptions that fail the same way onport/remaining-python-commands:parity_shader_dsl.sh: the Metal step (xcrun metalrejects the gallery shader).parity_mlir.sh:tests/lang/test_typecheck_overload_integration.flowMLIR changed since its golden was recorded.parity_mlir.shand its GPU-mode emit now run flowc lenient, asflow compile --mlirran the Python checker.Not done
parity_typecheck.sh --checkandtypecheck_rules.sh. The workflow file is guarded here; this needs a follow-up that edits.github/workflows/ci.yml.test "..." { }blocks are not type-checked (the Python checker checked them).