refactor(tw): extract Tw_section.Encode.ownership; delete orphan tw_ownership_section.ml#456
Merged
Merged
Conversation
…wnership_section.ml
Establishes lib/tw_section.{ml,mli} as the canonical home for typed-wasm
custom-section wire encoders, sized to absorb proposal 0001's two new
sections (typedwasm.regions, typedwasm.capabilities) when they land.
Changes:
- lib/tw_section.ml{,i} created. Encode.ownership operates on
pre-byte-encoded triples ((int * int list * int) list) — avoids
a Codegen→Tw_section→Codegen type cycle while keeping the byte
layout intact.
- lib/codegen.ml:159-177 — build_ownership_section body replaced
with a 6-line wrapper that maps ownership_kind→byte and delegates
to Tw_section.Encode.ownership. Same signature, byte-equal output.
- lib/dune — tw_section module added.
- lib/tw_ownership_section.ml DELETED. Was orphan: not in lib/dune
modules list, no callers, only string-mentioned in tw_verify.ml's
stale doc comment (which is also fixed here).
- lib/tw_verify.ml:213 — stale doc comment updated:
Tw_ownership_section.build_section → Tw_section.Encode.ownership.
Rationale: #444 — prevent the
3-sections × 2-copies = 6-encoder fan-out when proposal 0001
(hyperpolymath/typed-wasm#34, hyperpolymath/typed-wasm#76) lands.
Sharing the internal LE writers (write_u32_le / write_u8) inside
Tw_section.Encode means future Encode.regions / Encode.capabilities
land in one place rather than duplicating the buffer plumbing.
ADR-021 v2-emit flip is OUT OF SCOPE. Tw_section.Encode.ownership
ships v1. When the cross-repo coordination unblocks, the flip is
a localised change to this one module.
Tea_* hand-rolled fixture encoders (lib/tea_bridge.ml,
lib/tea_cs_bridge.ml, lib/tea_router.ml) are intentionally NOT
migrated in this PR — they hard-code demo bytes for tea
demonstrations, which is a separate concern from the live
producer-side dedup.
Verification: dune build clean; dune runtest 352/352 passing
(round-trip tests would catch any byte divergence).
Refs #444
Refs hyperpolymath/typed-wasm#34
Refs hyperpolymath/typed-wasm#76
🔍 Hypatia Security ScanFindings: 82 issues detected
View findings[
{
"reason": "Action perpolymath/standards/.github/workflows/governance-reusable.yml@main\n needs attention",
"type": "unpinned_action",
"file": "governance.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action ons/checkout@v6\n needs attention",
"type": "unpinned_action",
"file": "publish-jsr.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action land/setup-deno@v2\n needs attention",
"type": "unpinned_action",
"file": "publish-jsr.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in affine-vscode-publish.yml",
"type": "unknown",
"file": "affine-vscode-publish.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in casket-pages.yml",
"type": "unknown",
"file": "casket-pages.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in casket-pages.yml",
"type": "unknown",
"file": "casket-pages.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in ci.yml",
"type": "unknown",
"file": "ci.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in ci.yml",
"type": "unknown",
"file": "ci.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in ci.yml",
"type": "unknown",
"file": "ci.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in ci.yml",
"type": "unknown",
"file": "ci.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
}
]Powered by Hypatia Neurosymbolic CI/CD Intelligence |
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.
Summary
Establishes
lib/tw_section.{ml,mli}as the canonical home for typed-wasm custom-section wire encoders, sized to absorb proposal 0001's two new sections (typedwasm.regions,typedwasm.capabilities) when they land.Net change: 6 files, +69 / −115 = net −46 LOC.
What changes
lib/tw_section.mlEncode.ownership(operates on pre-byte-encoded triples, avoids type cycle with Codegen)lib/tw_section.mlilib/dunetw_sectionadded to modules listlib/codegen.mlbuild_ownership_sectionbody replaced with 6-line wrapper delegating toTw_section.Encode.ownership(signature unchanged, byte-equal output)lib/tw_verify.ml:213Tw_ownership_section.build_section→Tw_section.Encode.ownership)lib/tw_ownership_section.mllib/dune, no callersRationale
Filed as #444: prevent the 3-sections × 2-copies = 6-encoder fan-out when proposal 0001 (typed-wasm#34 / typed-wasm#76) lands. Sharing the internal LE writers (
write_u32_le/write_u8) insideTw_section.Encodemeans futureEncode.regions/Encode.capabilitiesland in one place rather than duplicating the buffer plumbing.Out of scope (deliberately)
Tw_section.Encode.ownershipships v1 unchanged. When cross-repo coordination unblocks the flip, it becomes a localised change to this one module.lib/tea_bridge.ml,lib/tea_cs_bridge.ml,lib/tea_router.ml) — these hard-code demo bytes for tea demonstrations, separate concern from live producer-side dedup. Can be migrated in a follow-up if/when the tea demos need updating.tw_interface.mlreads viaTw_verify.parse_ownership_section_payloaddirectly. No change needed;Tw_section.Decodeis not introduced because there's no current duplicate to dedup. Can be added if proposal 0002's access-site codec needs symmetric Decode plumbing.Test plan
dune buildclean.dune runtest352/352 passing.test/test_e2e.ml:1218 test_ownership_roundtrip,:1249 test_ownership_entry_count,:1268 test_ownership_v2_parse_roundtrip,:1296 test_ownership_v2_unknown_version_empty). Any byte divergence would fail the round-trip.Type cycle avoidance
Codegen → Tw_section → Codegenwould cycle ifTw_sectionreferencedCodegen.ownership_kind. Avoided by havingEncode.ownershiptake(int * int list * int) list— already-byte-encoded triples. Codegen does theownership_kind → bytemapping (viaownership_kind_byte) before calling. Tw_section stays type-clean.Refs #444
Refs hyperpolymath/typed-wasm#34
Refs hyperpolymath/typed-wasm#76
🤖 Generated with Claude Code