Skip to content

Modeled C: typed element buffers; tally at zero unsafe (#1643, #1644) - #1675

Merged
ehartford merged 1 commit into
mainfrom
modeled-c-element-buffers
Sep 25, 2026
Merged

ehartford merged 1 commit into
mainfrom
modeled-c-element-buffers

Conversation

@ehartford

@ehartford ehartford commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Typed C buffers accept the approved elements qualifier, presenting []T or []mut T with checked C-count conversion and bounded copy-back. Buffer clauses compose with free callbacks, so tally receives typed slices and a callback borrowing a collecting closure. Its four unsafe blocks are removed under the D64 ruling.

The shared bridge checks byte counts too. Sema projects callback positions and resource effects through removed count/fixed parameters; generic calls reuse slice coercion and exclusivity checks and carry Sema's selected facade template into MIR. Translated C bodies retain their C signatures.

Regressions cover scalar/typedef/record elements, empty buffers, input/inout callback composition, narrow counts, invalid copy-back, mutable aliases, and stale views after projected resource effects. Tally's facade was checked against its real header before migration; all 12 example tests pass and its debug allocator reports zero leaks. LLDB evidence for the corrected generic callee and resource-effect projection is recorded in the commits. The audit projection gap is tracked in #1674; usize: Display is #1673.

At exact head 590aa2be, the full pinned-seed build, fixpoint, drop/move audits, :test, :test-green, :last-green, and :user-programs-safe all passed. This includes 1,282 behavior files and 20 example steps. A second full test pass with a fresh C-import cache passed too: all 1,282 behavior files ran with zero cached verdicts, and the test/last-green/user-programs-safe gates passed afterward.

The clean rebase onto main c5aaf76f produces head 78edfb7a; the combined stable patch ID remains 9bfe49f5d021fa84ec5606b207841e33cd94fef4. Per the handoff's rebase rule, this retains the unchanged patches' validation. An integrated main battery is required before installation.

This PR and #1672 are being validated independently of unfinished #1652.

Closes #1643. Completes #1644's tally migration with parent #1672.

@ehartford
ehartford added this pull request to stack #1676 September 25, 2026 13:14
@ehartford
ehartford force-pushed the modeled-c-element-buffers branch from 39eb1c4 to 590aa2b Compare September 25, 2026 15:00
@ehartford
ehartford force-pushed the modeled-c-element-buffers branch from 590aa2b to 78edfb7 Compare September 25, 2026 17:34
@ehartford
ehartford marked this pull request as ready for review September 25, 2026 17:35
@ehartford
ehartford removed this pull request from stack #1676 September 25, 2026 17:38
@ehartford
ehartford added this pull request to stack #1682 September 25, 2026 17:39
@ehartford
ehartford removed this pull request from stack #1682 September 25, 2026 17:41
@ehartford
ehartford added this pull request to stack #1684 September 25, 2026 17:41
@ehartford
ehartford removed this pull request from stack #1684 September 25, 2026 18:06
@ehartford
ehartford added this pull request to stack #1685 September 25, 2026 18:06
Base automatically changed from modeled-c-completion to main September 25, 2026 18:14
Implement approved D64 elements, checked C counts and copy-back bounds;
share parameter rendering across callback and ordinary bridges. Migrate
tally after checking the real-header facade; user-programs-safe passes.

LLDB proofs: translated C redirected in facade_bridge_redirect;
generic slice mismatch in check_selected_generic_call_args;
parameter context lost in check_fn_body_concrete; resource touch mask 4
copied unchanged into a two-argument bridge; MirLower.w:15118 handed
raw callee 13358 to a generic call at node 578114. Propagate owner facts,
project effects, and reuse ordinary slice coercion/exclusivity.

Targeted behavior/negative tests, example's 12 tests and debug allocator
(zero leaks) pass. Full combined-stack battery follows #1652.
@ehartford
ehartford force-pushed the modeled-c-element-buffers branch from 78edfb7 to 46dbcf8 Compare September 25, 2026 18:14
@ehartford
ehartford merged commit a0cd734 into main Sep 25, 2026
@ehartford
ehartford deleted the modeled-c-element-buffers branch September 25, 2026 19:07
ehartford pushed a commit that referenced this pull request Sep 27, 2026
…ucer on its parent projects past its out slot (#1674)

#1674: audit:contract reported `violations=0 ok` over a facade whose
rendered call carried C parameter indices — `touch(values, count,
owner)` presented as `touch(values, owner)` kept the owner's bit 2 on a
two-parameter bridge, and a stale view of the owner was accepted. #1675
projected those masks (facade_presented_touch_mask); the audit still
looked only at the source contracts, so it could not see the class.

audit:contract now checks each entry of Sema's facade_call_effects:
every invalidated parameter is one of that signature's parameters, and
one that holds a modeled resource — facade_param_receives for the raw C
signature, the presented parameter's type (facade_type_holds_resource)
for a rendered bridge, method or constructor.

On its first run it found a live case of the same class. A producer
rendered as a method of its parent (`d.st_new(flags, o)` for
`int st_new(db *, st **out, int flags, other *o)`) is registered twice
in facade_index_call_effects: by the hosted-method pass, which projects
fixed, buffer and destruction-callback parameters but not the out slot,
and by the constructor pass, which removes the slot. When an fn item
describes the producer, the hosted pass ran first and its mask won
(facade_add_call_effect keeps a signature's first registration): bits 1
and 3 on a three-parameter method, so `flags` was "invalidated" and `o`
was not, and a view of `o` survived the call. The SQLite-shaped
fixture's `db.prepare(...)` carried the out slot's bit 3 the same way,
harmlessly past its three parameters. The constructor pass now runs
first, so a producer's parent method takes the slot-aware mask.

Tests:
- err_c_facade_producer_on_parent_effect.w: the view of `o` read after
  `d.st_new(1, o)` is refused. Base stage1 and the audit-only stage1
  accept it; this change refuses it ("view `v` borrows from `o`, which
  `st_new` may have invalidated").
- test/contract/ok_effect_projection.w (+ .expected): a clean facade
  with both projections (a byte buffer's length, a producer's out slot);
  audit:contract and audit:all are ok. With the audit but not the
  reorder: 2 violations ("parameter 1, which holds no modeled
  resource"; "parameter 3, and it has 3"). The other contract fixtures'
  views are unchanged, and ok_sqlite_shaped's audit fails with the audit
  alone ("parameter 3, and it has 3") and is ok with the reorder.

Fixes #1674
ehartford added a commit that referenced this pull request Sep 27, 2026
…res, warnings at real spans, memchr/macro collisions, contract audit, runtime domains (#1789)

* emit-c: == / != and the orderings on &str views compare the text (#1560)

A comparison of two `&str` views compared their addresses in the C
backend: rvalue_text asked raw_pointer_binop_text first, and
type_is_raw_pointer_tid counts TY_REF, so `a == b` on two `&str`
parameters became `(uintptr_t)(_1) == (uintptr_t)(_2)` before the #785
content path below it could see the operands. The LLVM backend reads a
`&str` operand as the str it points at (mir_compare_dispatch_kind 1,
#293), and §11.7 says a view compares the value it observes; only raw
pointers compare by address. `<` on two `&str` views had the same fault
(#1137's class: the text ordering covered only two owned strs).

Now str_compare_text handles every comparison of two text operands, str
or `&str` in any mix, ahead of the raw-pointer path: `==`/`!=` through
with_str_eq_ref and the orderings through with_str_cmp_ref, each view
rendered as its pointee (str_value_text). The two partial paths it
replaces are gone.

The C backend had no behavior corpus: emit-c-smoke ran hello and four
inline programs. test/emit_c/*.w is that corpus now. For each fixture
the smoke runs `with test` (the LLVM backend against the fixture's
`//! expect-stdout:` lines), then `--emit-c`, the host C compiler over
the runtime objects, and the program, whose stdout must be the same
lines; every fixture is surveyed before the verdict. The smoke's inputs
include the directory, so a fixture edit reruns it.

Evidence (test/emit_c/str_view_compare.w, emitted, compiled and run):
base stage1 `false true true false true true` / `true false`; this
change `true true false true false true` / `true false`, as the LLVM
backend prints.

Fixes #1560

* emit-c: lower D44 map traversal (`for (k, v) in map`) (#1434)

The C backend refused every `for (k, v) in map` ("HashMap traversal
lowering is not implemented; use the LLVM backend"), which since D44
includes the compiler's own source, so the emit-C lane of the compiler
stopped before writing any C.

MirLower.lower_for_hashmap already says what the loop is: MAP_CAPACITY
bounds a walk over the table's slots, MAP_SLOT_OCCUPIED skips an empty
one, and MAP_KEY_AT / MAP_VALUE_AT read an occupied slot where it lives.
The C backend now lowers those four intrinsics with the runtime
accessors the LLVM backend calls (with_hashmap_capacity,
with_hashmap_slot_occupied, with_hashmap_key_ptr_at,
with_hashmap_value_ptr_at; their prototypes join the fixed block in
rt_core's own spelling). A view destination (`&K`, `&V`) gets the slot's
address and a Copy value destination is loaded through it, as in the
LLVM lowering (§2.3: nothing non-Copy is duplicated). The destination
types are MirLower's typed temps (call_builtin_ret_tid), so the results
are stored rather than discarded.

Evidence (test/emit_c/map_traversal.w, emitted, compiled and run): base
stage1 refuses the emission with the message above; this change prints
`6 6` / `60 3`, as the LLVM backend does, for a HashMap[i32, str] and a
HashMap[str, i32].

Fixes #1434

* emit-c: a declared generic struct's instance is a C struct; std Box[T] is T* (#1562)

The C backend named every generic instance it does not model itself
(`Wrap_str_`, `Box_Node_`, `BTreeMap_i32__str_`) and never defined one:
collect_struct_types_from_tid collected only TY_STRUCT, payload enums,
tuples and the synthetic containers, so the first use failed at the C
compile ("unknown type name 'Wrap_str_'") — any user generic struct,
reached through a local, a method or a field. Had one been collected,
the definition pass would have read the instance's type-argument list
as a field list (TY_GENERIC_INST's d1/d2).

- An instance of a declared generic struct (its template is a TY_STRUCT;
  Sema.type_reflection_base_template) is collected, ordered after the
  by-value struct types of its fields, and defined from Sema's
  reflection: type_reflection_field_name / _type_frozen give the
  instance's fields and their instantiated types. Field projections on
  it type through the same reflection (generic_inst_field_tid at every
  place-typing site), and its moved-from reset is a compound literal.
  The dependency order counts such an instance as a by-value struct
  wherever a field, payload or tuple element holds one
  (tid_is_c_struct_value).
- std's `Box[T]` is not a struct to C: Sema and MIR treat it as the
  pointer to its T (a Box place dereferences, Box.new casts its `*mut T`
  to the Box), as the LLVM backend does (sema_type_to_llvm). c_type
  spells it `T*`, a deref projection through it types as T, and its T is
  collected.

Evidence (test/emit_c/generic_struct_instances.w: a user Wrap[T] with a
Debug impl and a method, a Node list through Option[Box[Node]], a
struct holding two Wrap instances, a BTreeMap[i32, str]): base stage1's
C does not compile (20 errors, unknown type names Wrap_i32_, Wrap_str_,
Box_Node_, BTreeMap_i32__str_); this change prints `wrapped` / `5` /
`3` / `7 x` / `2 a`, as the LLVM backend does.

Fixes #1562

* emit-c: an array of arrays built from its rows copies each row (#1771)

An array-of-arrays literal in a function body (`[[1, 2], [3, 4]]`)
lowered to an aggregate whose operands are the rows, and the C backend
rendered them by name inside the temporary's initializer list
(`{ int32_t __with_arr_tmp[2][2] = {_1, _2}; ... }`). A row is a C
array, so the C did not compile ("incompatible pointer to integer
conversion ... 'int32_t[2]'"). aggregate_nested_array_assignment now
copies each row into the temporary and the temporary into the
destination; a flat array keeps its initializer list.

Found by #1484's startup initializers: pcre2's `[[u8; 21]; 17]` tables
are the first such aggregates every prelude program carries.

Evidence (test/emit_c/nested_arrays.w, emitted, compiled and run): base
stage1's C does not compile (4 errors); this change prints `3 2`, as the
LLVM backend does.

Fixes #1771

* Warnings under `run` and `build` name their lines: the compilation keeps its source text (#1498)

`with check` put a warning at its line (a facade presentation warning at
the `fn` item, ruling §8; a loop-concatenation warning at the `++`);
`with run` and `with build` put every warning at 1:1 over an empty
line. lldb on the base stage1 during `run`: render_warnings_frontend
asked source_for_file_id_frontend for file 0, which answers with the
Zcu's current_source_text — empty by then. The code generator took it:
Backend.w (all four codegen entries) did `cg.source_text = move
self.current_source_text`, and the MIR-phase Sema in Compilation.w did
`sema.source_text = move self.zcu.current_source_text`, and neither gave
it back; warnings are printed after the build, from the emptied Zcu.
(The per-unit codegen loop also handed every unit after the first an
empty text.) Each now takes a copy; the Zcu keeps the text it renders
diagnostics against. Not facade-specific, which is why the issue's
"not yet located" span mapping looked right under `check`.

Test: behav_warning_location_run_build.w runs `check`, `run` and `build`
over one program with a facade warning and a Sema warning and requires
both at their lines under each (the core prelude keeps the case off the
std.re corpus, which a case directory cannot see from a compiler that
does not embed it). Base stage1: `check` passes, `run` fails ("warnings
not at their lines", both at main.w:1:1); this change: all three pass.

Fixes #1498

* Facade callback userdata: `.Some(x)` is `Some(x)` (#1765)

A nullable callback's userdata parameter is `Option[&U]` (§16.2b.9), and
`U` is bound from that argument, so Sema.facade_prepare_callback_call
checked the argument with no expected type. `Some(x)` infers its enum
from the payload; `.Some(x)` needs an expected enum, so it failed with
"cannot infer the enum type for `.Some`" and then "cannot infer generic
method type parameter 'U'" — where §4's shorthand is the ordinary
spelling wherever an Option is expected.

The parameter's shape is known before `U`: facade_check_userdata_shorthand
checks the payload once, with no expected type (it binds `U`), types the
shorthand `Option[&P]` exactly as the call form's `Some(x)` is typed
there, and borrows the payload for the call through the same
payload_arg_auto_refs path (this constructor is the userdata's), so MIR
lowers `.Some(ctx)` to `Some(&ctx)`: a temporary is dropped at the end
of the statement and a place stays usable. A first cut typed the
shorthand `Option[P]`; MIR then moved the payload into the Option and
the callback received the Option's bytes (the test printed garbage and
leaked both Ctx values) — the typed form is the call form's, not a
second derivation of it. `.None` for the userdata was already the
absent-callback path (facade_arg_is_none).

Test: behav_c_facade_callback_userdata_shorthand.w (a temporary, a
place used twice, and `.None`, with the Drop lines where the call form
prints them). Base stage1: "cannot infer the enum type for `.Some`";
this change: passes.

Fixes #1765

* c_import: a modeled wrapper beside another module's extern of its C function keeps both (#1663)

behav_c_facade_libc_system_headers.w fails under the seed-built stage1,
which compiles std.re from source: "function 'memchr' expects 2
argument(s), found 3" in lib/std/re/pcre2_match.w, the parameter
"expects []u8". The program c_imports <string.h>, whose `memchr`
CImport renders as a safe wrapper over the byte buffer (#379:
`memchr(__s: []u8, __c)`, the raw extern renamed and hidden), and
std.re.defs declares `memchr` as an extern of its own that pcre2_match
calls with a pointer and a length. One flat function table held one
declaration per name and a real fn beats an extern, so std.re's calls
were checked against the importer's wrapper.

They are two With declarations with two signatures, not one C symbol
declared twice. Zcu.displace_c_import_wrappers (after the c_imports are
expanded, beside displace_colliding_globals) displaces a c_import-
rendered fn whose name another module declares as an extern to its
importer's module-qualified identity — the same displacement other
modules' colliding fns take (#1350) — and the extern keeps the flat
name. Sema binds each module's call by §18.2 precedence
(resolve_displaced_fn_ident): the importer's to its wrapper, std.re's to
its own import.

Test: behav_c_import_wrapper_beside_module_extern.w calls the wrapper
from the program and matches a regex whose literal first code unit makes
pcre2 scan with its memchr. Base stage1: the arity error above; this
change passes, and behav_c_facade_libc_system_headers.w passes.

Fixes #1663

* c_import: two headers that define one macro are two imports (D70) (#1753)

`use c_import("a.h")` then `use c_import("b.h")`, both `#define PI`,
failed with "failed to compile C header snippet: b.h". Three things
stood in the way of D70 (§18.2: the later import shadows the earlier,
and each stays reachable through its namespace, the header's file name
without `.h`):

- CImport deduplicates every emitted name across the c_imports of one
  compilation. b.h's PI was skipped because a.h had emitted a PI, so b's
  translation came back empty and b.PI could never resolve. A macro
  constant an earlier c_import defined is now emitted again by a later
  header that defines it: it is that import's own value. Constants are
  tracked per translation (g_ci_current_macro_consts, folded into
  g_ci_prior_macro_consts when the next translation starts, reset per
  compilation beside with_cimport_reset_names), so a macro one header
  redefines is still one constant of that import, and a name an earlier
  import declared as anything but a constant keeps the old dedup.
- An empty translation fell through to Zcu's hand-written `#include`
  fallback, meant for a compiler without libclang, which knows six
  system headers and reported everything else as a failure. When
  libclang is available and read the header without error, an empty
  result means the header adds nothing new; the import continues.
- displace_colliding_globals gave all of a module's c_imports one owner
  (`<path>/c_import`), so two imports' PI were a same-owner duplicate
  ("shadowing is not allowed"). Each c_import is now an owner of its own
  (keyed by its offset, as decl_is_c_import records it); the later PI is
  displaced, and Sema's existing §18.2 resolution (last_import_provider,
  import_position_of) binds bare PI to the last import and each
  namespace to its own.

Tests: behav_d70_c_import_same_macro.w and its _reversed twin import the
two headers in both orders and print the bare name and both namespaced
values. Base stage1: "failed to compile C header snippet:
behav_d70_second_header.h" (and, when the second header adds another
name so its translation is not empty, "namespace
'behav_d70_second_header' provides no 'PI'"); this change prints
`4 3 4 1` and `3 3 4 1`. The c_import, facade and D70 behavior and
compile-error fixtures (333 files) show no change beyond three p7 cases
that need the embedded std.re corpus and fail the same way on base
stage1.

Fixes #1753

* c_import: an omitted static inline body is inexpressible, and says why (#1678, part)

`static inline int probe(int n, ...) { va_list ap; va_start(ap, n);
int x = va_arg(ap, int); ... }` is omitted — c_import does not translate
va_arg — and a use of `probe` reported "inline body translation failed",
categorized raw-modelable: "declare a manual extern \"C\" binding and
call it under unsafe (§16.1)". A static inline function's only
definition is its body; there is no symbol for that extern to bind, so
the remedy cannot link. #1417 made the opaque-record omission in the
same branch inexpressible for that reason; the other three omissions
there still said raw-modelable.

Now a `static inline` function's omitted body is inexpressible (the
diagnostic points at a C shim or allow_untranslated); a non-static
inline, which may have an external definition elsewhere, stays
raw-modelable. The reason carries the translator's own bail message
(g_ci_bail_message) — "inline body translation failed: va_arg is not
supported" — instead of only that it failed.

Test: err_c_import_static_inline_variadic.w requires the reason and
refuses the manual-extern remedy. Base stage1: "missing expected check
error: inline body translation failed: va_arg is not supported" (it
said "inline body translation failed" and the extern remedy); this
change passes.

err_c_import_omitted_directional_raw.w pinned the old claim — a
`static inline` returning a function pointer "is reachable via the raw
surface" — which is false for the same reason (no symbol to bind). It
now uses a plain `inline` function, which may have an external
definition, so it still pins the raw-surface direction; the static case
is the new test's.

Not fixed here: translating the body. With has no definition form for a
C-variadic function (only `extern fn f(x, ...)` declarations) and no
va_arg reader; that is a language question for a ruling, and #1678
stays open for it.

* audit:contract checks every rendered call's invalidation mask; a producer on its parent projects past its out slot (#1674)

#1674: audit:contract reported `violations=0 ok` over a facade whose
rendered call carried C parameter indices — `touch(values, count,
owner)` presented as `touch(values, owner)` kept the owner's bit 2 on a
two-parameter bridge, and a stale view of the owner was accepted. #1675
projected those masks (facade_presented_touch_mask); the audit still
looked only at the source contracts, so it could not see the class.

audit:contract now checks each entry of Sema's facade_call_effects:
every invalidated parameter is one of that signature's parameters, and
one that holds a modeled resource — facade_param_receives for the raw C
signature, the presented parameter's type (facade_type_holds_resource)
for a rendered bridge, method or constructor.

On its first run it found a live case of the same class. A producer
rendered as a method of its parent (`d.st_new(flags, o)` for
`int st_new(db *, st **out, int flags, other *o)`) is registered twice
in facade_index_call_effects: by the hosted-method pass, which projects
fixed, buffer and destruction-callback parameters but not the out slot,
and by the constructor pass, which removes the slot. When an fn item
describes the producer, the hosted pass ran first and its mask won
(facade_add_call_effect keeps a signature's first registration): bits 1
and 3 on a three-parameter method, so `flags` was "invalidated" and `o`
was not, and a view of `o` survived the call. The SQLite-shaped
fixture's `db.prepare(...)` carried the out slot's bit 3 the same way,
harmlessly past its three parameters. The constructor pass now runs
first, so a producer's parent method takes the slot-aware mask.

Tests:
- err_c_facade_producer_on_parent_effect.w: the view of `o` read after
  `d.st_new(1, o)` is refused. Base stage1 and the audit-only stage1
  accept it; this change refuses it ("view `v` borrows from `o`, which
  `st_new` may have invalidated").
- test/contract/ok_effect_projection.w (+ .expected): a clean facade
  with both projections (a byte buffer's length, a producer's out slot);
  audit:contract and audit:all are ok. With the audit but not the
  reorder: 2 violations ("parameter 1, which holds no modeled
  resource"; "parameter 3, and it has 3"). The other contract fixtures'
  views are unchanged, and ok_sqlite_shaped's audit fails with the audit
  alone ("parameter 3, and it has 3") and is ok with the reorder.

Fixes #1674

* Runtime facades declare the process state POSIX names beyond the libc domains (#1608)

Stage 13 (ruling §52, spec §16.2b.14) gave every runtime foreign call a
row under the three libc domains the ruling names (errno thread, environ
process, locale process). #1608 listed the other process-global C state
the runtime's calls touch. Ruling §33 lists domains as examples ("Examples
include"), §35 lets a facade refine a coarse domain, and §36 gives the
scopes, so each is declared in every runtime facade and wired the way
stage 13 wired the three:

  signals     process — dispositions (sigaction; raise, kill, abort)
  signal_mask thread  — the calling thread's mask and alternate stack
                        (sigprocmask, sigaltstack)
  cwd         process — the working directory (chdir)
  fds         process — the descriptor table (open, close, dup2, fcntl,
                        socket, accept, mkstemp, opendir, closedir;
                        getaddrinfo and realpath may open descriptors of
                        their own; exec closes close-on-exec ones)
  rlimits     process — setrlimit
  children    process — the children and process group (fork, waitpid,
                        wait4, setpgid, exec)
  stdio       process — the streams' buffers and positions (fseeko)

In the POSIX/C facades (darwin, linux x86_64/aarch64, fiber_core_darwin,
rt_core, fiber_runtime, fiber_stubs, panic_runtime) a row preserves each
domain unless its C function (the extern's link_name) is one of the
interfaces POSIX.1-2017 names as altering it; the rows were written by a
one-off With rewrite keyed on those names (1574 lines, all additions).
The win32, UCRT and WASI facades declare the domains and, as stage 13
did for calls the C standard does not describe, state no `preserves`:
silence invalidates (§38). The runtime itself calls no PRNG (random
bytes come from arc4random_buf/getrandom/SystemFunction036/random_get),
so no runtime facade has a PRNG domain; std.libc's rand/srand and
whether the toolchain libc facade exposes any of these to user programs
(e.g. getcwd text borrowed from `cwd`) are the user-facing half of #1608,
which the ruling leaves to a facade that models them.

runtime-domain-audit (build/compiler.w) now requires the seven besides
the three in every runtime facade, and its messages name them.
test/runtime_domain_audit/missing_process_domain.w declares everything
but `domain cwd process`; the base audit stays silent on it ("the audit
stayed silent on its negative fixture ... got 0"), this one reports it.
The lane: 16 runtime files, 387 domain rows, 5 fixtures agree. The
darwin runtime objects build in :dev, and `with check --target` passes
for linux_x86_64, linux_aarch64, windows_x86_64, windows_aarch64 and
fiber_core_windows (wasm needs an SDK with the WebAssembly backend).

Part of #1608: the runtime half. Whether the toolchain libc facade exposes
any of these domains to user programs is the issue's open decision.

* Facade effects: an in-place producer is not also a lend method of its resource (#1674 follow-up)

The #1674 audit's first battery run flagged the pinned in-place fixture
(behav_c_facade_resource_in_place_pinned.w, deep-debug-tool-tests
analyze-audit-in-place-pinned): "the rendered call of 'z_init'
invalidates views of its parameter 0, which holds no modeled resource".
The audit is right and the fixture is right; the effect index was wrong.

`init z_init(self)` is rendered as the constructor `Stream.init(ends,
misplaced)` with the storage slot — z_init's first C parameter — removed,
and the constructor pass indexes that signature slot-aware (nothing to
touch here: `ends` and `misplaced` hold no resource). But z_init also has
an fn item (`lend`), and facade_method_host answers Stream for its first
parameter, so the hosted-method pass registered the same signature as
`Stream.init`, a lend method with self at 0: the slot's bit 0 landed on
`ends`. Harmless to programs so far (no view is ever borrowed from an
`int *`), wrong by §16.2b.14, and invisible until the audit looked.
The hosted pass now skips a resource's init/preinit (facade_fn_is_init):
its signature is the constructor pass's.

Evidence: with the stage1 before this change, `analyze
behav_c_facade_resource_in_place_pinned.w audit:all` reports the
violation above; after, `violations=0 ok`, as does the drop-once twin,
every in-place/init/preinit behavior and compile-error fixture (13), and
the four clean contract fixtures. test/contract/ok_in_place_init.w
(+ .expected) pins it under contract-view-tests: 1 violation before, 0
after.

---------

Co-authored-by: Eric Hartford <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant