Skip to content

Modeled C stage 11: convention profiles (ruling §7, §59) - #1628

Merged
ehartford merged 4 commits into
modeled-c-stage12bfrom
modeled-c-stage11
Sep 24, 2026
Merged

ehartford merged 4 commits into
modeled-c-stage12bfrom
modeled-c-stage11

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Stage 11 of docs/modeled-c-implementation-plan.md: use convention pkg.vN adopts a versioned convention profile; unique-or-nothing; explicit clauses override; provenance and the two audit:contract profile checks.

What lands

  • Profile surface (src/Parser.w, src/Ast.w): a profile is the block c convention pkg.vN: in the module pkg.vN; rules are <name>: <template> — a resource clause over a name pattern (unref: drop *_unref, new: from *_new, open: from *_open(out param 1), init: init *_init(self), free: destroys *_free) or an fn-item clause (get: fn *_get* lend, dispose: fn *_dispose destroys). use convention pkg.vN in a facade is also the import use pkg.vN (synthetic use decl), so the profile resolves, pins and reports through ordinary package rules; an unknown package is the unresolved-import error naming it, a package that resolves but declares no block is an error naming the package.
  • The pass (src/compiler/FacadeProfile.w, run from Frontend.w after c_import translation and before the facades render): candidates are judged by name pattern and by the shape the clause needs (the same shape Sema's verification reads). One valid candidate states the clause on the item, carrying its rule as a trailing operand (facade_clause_profile_rule) — the fact's provenance; zero or several contribute nothing; an explicit clause of the fact's class shadows the profile's. Every outcome is an NK_FACADE_PROFILE_MATCH record on the use convention item.
  • Sema / analyze (src/SemaFacade.w, src/AnalysisContract.w): profile-stated clauses are verified like any clause; the contract view prints profile:gobject.v1:unref@test/lib/gobject/v1.w:15 as the provenance of every profile-derived fact and lists each rule's outcome under the use convention subject; Sema warns on an ambiguous match (profile, rule, item, candidates, fix-it); audit:contract reports "ambiguous profile match" as a violation and "profile fact shadowed" as a note (the two stage 10 stubs now fire).

Fixtures

  • test/lib/gobject/v1.w — the suite's profile, reached from every fixture under test/ by the module walk; test/lib/noprofile/v1.w — a module with no block.
  • test/behavior/behav_c_facade_profile_supplies_drop.w — the profile supplies from obj_new and drop obj_unref (and counter_new matches the name but not the shape); unref runs exactly once.
  • test/contract/ok_profile_applied.w (+ .expected), ok_profile_shadowed.w (+ .expected, two shadowed notes), bad_profile_ambiguous.w (a resource rule with two candidates and two fn rules claiming one function: both contribute nothing, two violations).
  • test/compile_errors/err_c_facade_profile_unknown.w, err_c_facade_profile_not_declared.w, err_c_facade_profile_ambiguous_no_drop.w (ambiguity leaves the resource half-modeled: the warning and the never-half-model error), err_c_convention_bad_rule.w.
  • ok_sqlite_shaped needle/snapshot updated for the audit summary's new profile-ambiguous=/profile-shadowed= counts. behav_c_facade_parses.w (which already adopts gobject.v1) now resolves the real profile; none of its rules match that fixture.

Derived decisions

Recorded under Stage 11 in docs/modeled-c-implementation-plan.md with the sections they read from: the profile surface (§7 "ordinary With package rules", §59's examples, §8's "rule unref" naming), what a rule may state (only clause kinds the pass can judge per candidate from the declaration's shape; parameter/origin clauses stay on the fn item), candidates and uniqueness (§7.1; a rule applying to forty operations is the intended use, two rules claiming one operation is the ambiguity), overrides (§7.2/§4: same-class clause shadows; suppression without replacement is not ruled and not invented), and where the pass runs (the renderer reads clauses off the AST).

Verification (iterate tier)

  • stage1 check src/main.w ok; with build :dev green twice.
  • analyze audit:all ok on the new clean fixtures; with build :contract-view-tests: 9 fixtures, every audit verdict, needle and snapshot agreed.
  • with test over every behav_c_facade*, behav_sqlite_facade*, err_c_facade*, err_sqlite_facade* fixture and the new ones: all pass except behav_c_facade_libc_system_headers.w, which fails identically on a clean origin/main worktree with the same seed — it is c_import: a user module's <string.h> memchr wrapper hijacks std.re's memchr when std.re compiles from source (stage1) #1485 (stage1-only <string.h> memchr wrapper hijacking std.re), not this change.
  • with build :spec-inventory-check green (the new words are contextual identifiers; no keyword row).

No :fixpoint/:test/drop-move audits run here (coordinator folds into the stack's battery).

@ehartford
ehartford changed the base branch from main to modeled-c-stage12b September 24, 2026 16:43
@ehartford
ehartford added this pull request to stack #1637 September 24, 2026 16:43
@ehartford
ehartford removed this pull request from stack #1637 September 24, 2026 16:53
@ehartford
ehartford added this pull request to stack #1642 September 24, 2026 16:53
@ehartford
ehartford removed this pull request from stack #1642 September 24, 2026 17:29
@ehartford
ehartford added this pull request to stack #1646 September 24, 2026 17:30
Eric Hartford added 4 commits September 24, 2026 13:32
…rofile's import (ruling §7, §59; §16.2b.12)

A convention profile is the block `c convention pkg.vN:` in the module
`pkg.vN`; its rules are `<name>: <template>` — a resource clause over a
name pattern (`unref: drop *_unref`, `open: from *_open(out param 1)`) or
an fn-item clause (`get: fn *_get lend`). `use convention pkg.vN` inside a
facade is also the import `use pkg.vN` (a synthetic use decl), so the
profile resolves, pins and reports through ordinary package rules and an
unknown package is the unresolved-import error naming it.

AST: NK_C_CONVENTION, NK_FACADE_RULE, NK_FACADE_PROFILE_MATCH; a clause a
profile states carries its rule as a trailing operand
(facade_clause_profile_rule), the fact's provenance.
… (ruling §7.1, §7.2)

compiler/FacadeProfile.w: for each `use convention` item, every rule of the
profile is matched against the imported declarations by name pattern and by
the shape the clause needs (a drop takes the representation alone, a
destroys/init takes it first, a from returns it or fills the named out
parameter); an fn rule's candidates are the rules matching one function
whose first parameter receives a resource of the facade. Exactly one valid
candidate states the clause on the item; zero or several contribute
nothing, and an explicit clause of the fact's class shadows the profile's.
Every outcome is an NK_FACADE_PROFILE_MATCH on the item. A module that
resolved but declares no such block is an error naming the package.
…he two audit:contract profile checks (ruling §8, §63)

A profile-stated clause is collected and verified like any clause; its
provenance prints as `profile:pkg.vN:rule@file:line` in the contract view.
Sema warns on an ambiguous match, naming the profile, the rule, the item,
the candidates and the clause that resolves it. audit:contract reports an
ambiguous profile match as a violation and a profile fact shadowed by an
explicit clause as a note; the `use convention` subject lists every rule's
outcome.
…shadowed, ambiguous, unknown, bad rule), stage 11 derived decisions

test/lib/gobject/v1.w is the suite's profile, reached from every fixture
under test/ by the module walk. A behavior fixture proves a profile
supplies production and destruction (unref exactly once); contract fixtures
snapshot the profile provenance, the shadowed notes and the two ambiguous
violations; compile-error fixtures pin the unknown package, the package
without a block, the ambiguity that leaves a resource half-modeled, and a
rule stating a clause a profile may not. The audit summary line gained
profile-ambiguous/profile-shadowed counts (ok_sqlite_shaped updated).
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.

1 participant