Skip to content

feat: stable type identity, schema IDs, and alignof (Part of #775) - #1340

Merged
godofecht merged 11 commits into
mainfrom
cursor/type-identity-775-59ac
Oct 4, 2026
Merged

godofecht merged 11 commits into
mainfrom
cursor/type-identity-775-59ac

Conversation

@godofecht

@godofecht godofecht commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Part of #775.

First usable compiler surface for cross-target runtime schemas: libraries such as flow-audio can replace a manual endpoint type_key with compiler-derived identity, plus target size/alignment, without new syntax or runtime string reflection on the RT path.

One scalar cannot be both semantic identity and an ABI certificate (a pointer-bearing struct matches on native64 and wasm32 as Flow but not as layout). This slice follows the three-level model from the issue:

  • type_family_id<T>() -> u64 — nominal family for API identity / migration routing
  • type_schema_id<T>() -> u64 — FNV-1a 64 of a versioned (v1;) target-independent public schema (field names/order, semantic field types, extents, enum variants, generic args)
  • sizeof<T>() / alignof<T>() -> i64 — target ABI layout
  • type_transport_safe<T>() -> bool — conservative TransportSafe: fixed-width scalars, fixed arrays, and structs of those; pointers/spans/strings/externs rejected

IDs are compile-time integer constants, independent of C/MLIR/Wasm lowering. The C backend emits ((uint64_t)0x…ULL); the MLIR backend emits the same constants.

Overlap check

  • I searched open pull requests and recent commits for overlapping work.
  • This does not duplicate another active implementation, or the relationship is explained below.

Overlap / dependency notes: No open PR covers #775. The retired Python reference lives at archive/feat/775-type-identity. This is the Flow/flowc first slice, not the full member-table / schema-revision / native-vs-wasm layout parity work.

Evidence

Baseline before this change: sizeof<T>() existed (#952); there was no stable family/schema identity, no generic alignof<T>(), and no TransportSafe predicate. flow-audio still needs a hand-assigned type_key.

Targeted proof that exercises the changed behaviour:

  • flowc selftest type_id_ok=1 (hash determinism + parsed Point/Named/i32/ptr family/schema/transport)
  • Host-emitted C for tests/lang/test_type_identity.flow folds IDs to 0x…ULL constants
  • tests/lang/test_type_identity.flow covers identity stability, distinct types, field-order schema, sizeof/alignof, TransportSafe
  • tests/scripts/type_identity.flow compiles the same public type in two declaration orders and checks field-order / field-type schema vs family

Why that proof would detect the old failure or regression: the old compiler rejects the new builtins; a non-deterministic or lowering-dependent hash would fail the intra-compilation and cross-compilation ID comparisons; a TransportSafe that admitted pointers would fail the HasPtr/ptr cases; missing alignof would fail the Pair/Point layout checks.

Repository gate(s) run:

  • env -u FLOWC_IN -u FLOWC_OUT "$(./flow tool compiler/scripts/flowc_host.flow)" → flowc: PASS including type_id_ok=1
  • ./compiler/scripts/bootstrap_from_c.sh --regen → fixed point at gen2
  • ./compiler/scripts/bootstrap_from_c.sh --verify → ALL PASS bootstrap_from_c
  • ./flow test-lang → all 262 language tests passed (includes test_type_identity.flow and test_sizeof_generic.flow)
  • ./flow tool tests/scripts/type_identity.flow → 3 passed (declaration order, field order vs family, field type vs schema)
  • ./flow tool compiler/scripts/fmt_check.flow --check → fmt gate OK
  • ./flow tool compiler/scripts/roundtrip.flow on 1f6974cc → ALL PASS
  • PATH=/tmp/nopy-mlir:$PATH ./flow tool compiler/scripts/parity_mlir.flow on 4b9e2eba → parity_mlir: PASS (fixtures 23/23; corpus programs=2492 fail=0)
  • ./compiler/scripts/bootstrap_from_c.sh --verify on 4b9e2eba → ALL PASS bootstrap_from_c

Roundtrip CI follow-up (flowc self-host roundtrip on e1d331c8): compile_module cgen host-emits cgen.flow alone and -includes only listed dep headers, so flowc_type_id_* / FLOWC_TID_* were undeclared. Wired type_id into compile_module, self_emit_plan, frontend_modules(), and the g2 fixed-point list.

Main catch-up after #1338 (ad8e50c5 copy elision): merged origin/main. Bootstrap regenerated; --verify passed.

parity_mlir CI follow-up on 472cf753: test_typecheck_overload_integration.flow imports typecheck.flow, whose new type-identity builtins changed the normalized MLIR digest. Refreshed with parity_mlir.flow --record (official scheme).

Main catch-up after #1339 (b9ac6a1e portable C SIMD): merged origin/main. cgen.flow auto-merged (type identity + SIMD lowering). Bootstrap binary conflicted; regenerated to a gen2 fixed point. --record added digests for for_simd_carried.flow and for_simd_hot_loops.flow. type_id roundtrip wiring left intact. Not merged from this session.

Generated/bootstrap state: compiler/bootstrap/flowc_stage_a.c regenerated after the source edits, after merging copy elision, and after merging portable SIMD.

Risk

Compatibility, performance, security, lifetime, backend, or release implications:

Additive builtins only. Existing sizeof<T>() unchanged. Schema scheme is versioned (v1;) so a later digest can change without silently reusing keys. Full member description, schema revision attributes, and native64-vs-wasm32 layout certificates are left for later slices.

  • No unresolved language/API design decision is being implemented implicitly.
  • No unrelated generated artifacts or local state are included.
  • Docs changed when user-visible behaviour or syntax changed.
  • docs/project/Questions.md updated if this needs a language-design decision.

The three-level split was already decided on the issue; this PR implements that surface rather than inventing syntax.

Compatibility

  • No user-visible compatibility change.
  • Compatibility change is documented in docs/project/CHANGELOG.md.

Agent handoff

Cloud agent implementing the first #775 slice. Do not merge from this session.

Open in Web Open in Cursor 

cursoragent and others added 4 commits October 4, 2026 18:42
Expose type_family_id<T>(), type_schema_id<T>(), type_transport_safe<T>(),
and alignof<T>() as compile-time builtins so libraries can stop assigning
manual type keys. Family and schema IDs are target-independent FNV-1a 64
digests of a versioned canonical description; size and alignment stay the
target ABI.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@godofecht
godofecht marked this pull request as ready for review October 4, 2026 18:49
cursoragent and others added 6 commits October 4, 2026 19:13
compile_module cgen force-includes only listed dep headers, so the
new type-identity helpers were undeclared. Emit type_id first, then
-include it for cgen, and link it with the frontend objects.

Co-authored-by: Abhishek Shivakumar <[email protected]>
Resolve bootstrap conflicts in favor of this branch, then keep
main's cgen record-update elision and tests. type_id roundtrip
wiring is unchanged.

Co-authored-by: Abhishek Shivakumar <[email protected]>
Merged cgen now includes both type identity builtins and record-update
copy elision. Rewrite the checked-in bootstrap C to that fixed point.

Co-authored-by: Abhishek Shivakumar <[email protected]>
test_typecheck_overload_integration.flow imports typecheck.flow, whose
new type-identity builtins changed the normalized MLIR digest. Refresh
via parity_mlir.flow --record (also records newly accepted programs,
including test_type_identity.flow).

Co-authored-by: Abhishek Shivakumar <[email protected]>
Take this branch's bootstrap binary; keep main's SIMD cgen lowering
and tests. type_id roundtrip wiring is unchanged. Bootstrap C will
be regenerated next.

Co-authored-by: Abhishek Shivakumar <[email protected]>
Merged cgen now includes type identity builtins and SIMD-aware loop
lowering. Rewrite the checked-in bootstrap C to that fixed point.

Co-authored-by: Abhishek Shivakumar <[email protected]>
#1339 added for_simd_carried and for_simd_hot_loops. Record their
normalized MLIR via parity_mlir.flow --record.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@godofecht
godofecht merged commit 0ee697b into main Oct 4, 2026
37 checks passed
cursor Bot pushed a commit that referenced this pull request Oct 4, 2026
Rebased onto main (#1340). Bootstrap C now includes type identity,
SIMD loop lowering, and FLOWC_PROFILE phase timers.

Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot pushed a commit that referenced this pull request Oct 4, 2026
Fixed-point C after rebasing onto type identity (#1340 / 0ee697b).
bootstrap_from_c.sh --regen (FIXED POINT at gen3) then --verify PASS.

Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot pushed a commit that referenced this pull request Oct 4, 2026
Rebased onto #1340 type identity (0ee697b). Bootstrap C is the
fixed point of compiler/src including both type identity and the
cross-module RT/lifetime summary slice.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 7, 2026
* feat: persistent statics must be TransportSafe (#1421)

Decided 2026-10-07: persistent outlives the process, so it may not hold
a pointer, span, string or other reference into process memory. A
@Lifetime(persistent) static whose declared type is not TransportSafe
(#1340) is rejected, naming the field or element type that carries the
reference:

  persistent static 'held' must hold a TransportSafe value, but its type
  is `ptr<i32>`, which refers to process memory and does not survive a
  restart

flowc_type_transport_blocker in type_id.flow follows the existing
TransportSafe walk and returns the innermost offending field or type.
Checking the declaration covers every store into the static.

domain_application_escape_persistent becomes
domain_persistent_pointer_static (its ptr static is now rejected at the
declaration); domain_persistent_string_array is new. The language test
stores and reads back persistent i64 and [i32; 2] statics.

* fix: regenerate bootstrap C after the persistent TransportSafe check

Fixed point at gen2; bootstrap_from_c.sh --verify passes.
godofecht added a commit that referenced this pull request Oct 7, 2026
Decided 2026-10-07: persistent outlives the process, so it may not hold
a pointer, span, string or other reference into process memory. A
@Lifetime(persistent) static whose declared type is not TransportSafe
(#1340) is rejected, naming the field or element type that carries the
reference.

flowc_type_transport_blocker in type_id.flow follows the existing
TransportSafe walk and returns the innermost offending field or type.
Checking the declaration covers every store into the static.

domain_application_escape_persistent becomes
domain_persistent_pointer_static; domain_persistent_string_array is new.
The language test stores and reads back persistent i64 and [i32; 2]
statics. From PR #1437, which was merged into the #1369 branch.
godofecht added a commit that referenced this pull request Oct 7, 2026
Decided 2026-10-07: persistent outlives the process, so it may not hold
a pointer, span, string or other reference into process memory. A
@Lifetime(persistent) static whose declared type is not TransportSafe
(#1340) is rejected, naming the field or element type that carries the
reference.

flowc_type_transport_blocker in type_id.flow follows the existing
TransportSafe walk and returns the innermost offending field or type.
Checking the declaration covers every store into the static.

domain_application_escape_persistent becomes
domain_persistent_pointer_static; domain_persistent_string_array is new.
The language test stores and reads back persistent i64 and [i32; 2]
statics. From PR #1437, which was merged into the #1369 branch.
@godofecht
godofecht deleted the cursor/type-identity-775-59ac branch October 12, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants