Skip to content

Spec: :? rows for HashSet/Box/Rc/Arc/raw pointers (#1564); two D71 drafting corrections - #1776

Merged
ehartford merged 2 commits into
mainfrom
debug-rows-1564
Sep 27, 2026
Merged

ehartford merged 2 commits into
mainfrom
debug-rows-1564

Conversation

@ehartford

@ehartford ehartford commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Eric's "predicted" on #1564, plus two corrections to text I drafted in #1767, found by the implementing agent. Merging blesses all of it.

  1. §15.4.7 :? rows: HashSet[T] prints {elem, elem} ordered by Debug text; Box/Rc/Arc print the value they hold; a raw pointer prints its address in hexadecimal (0x…; today decimal).
  2. §16.4: I wrote that repr(packed(N)) is the layout of #pragma pack(N) and __attribute__((packed, aligned(N))). The second is false ({char a; int b;}: b at 1 under packed+aligned(2), at 2 under pack(2)). The text now says pack(N) only, and that c_import emits it only for records whose clang layout it reproduces exactly (others stay opaque) — which is what the implementation does.
  3. §16.2b.4: the valid on failed code fence I added swallowed the next sentence; fixed.

Docs only; spec-inventory-check green.

Eric Hartford added 2 commits September 27, 2026 03:34
…k(N)'s layout, not packed+aligned(N)'s; close the valid-on-failed code fence
@ehartford ehartford changed the title Spec §15.4.7: :? rows for HashSet, Box/Rc/Arc, raw pointers (#1564) Spec: :? rows for HashSet/Box/Rc/Arc/raw pointers (#1564); two D71 drafting corrections Sep 27, 2026
@ehartford
ehartford merged commit 10273d3 into main Sep 27, 2026
@ehartford
ehartford deleted the debug-rows-1564 branch September 27, 2026 07:41
ehartford added a commit that referenced this pull request Sep 27, 2026
…closure -> T, :? coverage and rows (#1787)

* @[flags] doubles without a representation type (§4.4a, D71)

An @[flags] enum with no representation type doubles in its default
integer representation; the attribute is never ignored. The parser set
the flags bit only beside an explicit repr, so a backing-less @[flags]
enum counted 0 1 2.

parse_enum_named_decl now sets TDK_FLAG_FLAGS on every discriminant
enum, and a backing-less @[flags] enum is one in the inferred i32:
the block form with payloads (tags 1 2 4, as `enum E: i32:` would be)
and the braced form, which never inferred a representation. One helper,
add_backingless_enum_extras, writes both extras formats.

A generic enum with a payload variant cannot be a discriminant enum yet
(#1768: its payload type reaches MIR unresolved), so @[flags] on one is
refused by name instead of ignored. Found on the way: an explicit
`= N` on a backing-less payload enum is still dropped (#1769).

Fixes #1482

* from_int exists only on an all-unit enum (§4.4a, D71)

`from_int` exists only on an enum whose variants are all unit variants;
no value of the enum exists for a payload variant's discriminant alone,
so on an enum with a payload variant a `from_int` call is a compile
error naming that variant. On a discriminant enum with payloads it
compiled and returned the repr's Option (`Msg.from_int(7)` was
`Some(7)`); on any other payload enum it was "unknown method".

check_method_call_parts's from_int branch asks enum_first_payload_variant
(new, next to enum_has_variant) first and reports the variant; the
repr's-Option branch is gone, so from_int is always Option[Type]. A
`from_int` the program declares on such an enum is its own static
method and still resolves.

Fixes #1497

* A closure's `-> T` is checked like a declared return type (§12, D71)

A closure may state its result type as a function does, `(x: i32) -> str
=> f"{x}"`; the annotation is checked like a declared return type and is
never dropped. Parser.parse_fat_arrow_paren_closure and parse_closure
parsed the `-> T` and discarded it, so `(x: i32) -> str => x` compiled
and returned the i32, and `(x: i32) -> i64 => x` returned an i32.

The parser keeps the type node in an AstPool side table
(set_closure_ret_type / closure_ret_type, copied by astpool_clone_deep
and the comptime tree clone like the other closure marks); Resolve walks
it and render prints it. Sema.check_closure checks the body against it
and makes it the closure's result type, ahead of the partial-application
and context results.

A context expecting a closure that returns another type is an error at
the annotation. The check is the closure's own (Sema.types_identical, an
exact structural comparison): types_compatible takes any fn type for any
other (#1772), so the closure would otherwise reach the context returning
the wrong representation.

Fixes #1508

* :? with no Debug form is an error at the program's `:?` (§15.4.7, D71)

§15.4.7 now reads: `:?` is available for the table's types, their
compositions and any `impl Debug`; a value with no Debug form (a
function value, a closure, `dyn Trait`, a range, a `va_list`) is a
compile error under `:?` naming its type, never a placeholder.

D61's implementation already refuses each of those by name, at every
depth; the new tests pin the closure, `dyn Trait`, range, `va_list`
and enum-payload cases beside the existing fn-value test. One case
disagreed: a HashMap or BTreeMap whose key or value has no form was
reported from the std formatter's own `{v:?}`, at
<embedded-std>/std/collections.w, a line the program never wrote.
ensure_debug_formatter now asks debug_fmt_has_form of K and V before
binding the std `debug_form` and reports the one without a form at the
`:?` that reached the map.

Refs #1564 (the raw-pointer / Box / Rc Debug rows wait on Eric)

* :? rows for HashSet, Box/Rc/Arc and raw pointers (§15.4.7, D71)

Eric's rows for §15.4.7 (docs PR #1776):
- `HashSet[T]` prints `{elem, elem}`, elements ordered by their Debug
  text. It printed its generated struct form, `HashSet { ptr: 4339450384 }`.
- `Box[T]`, `Rc[T]`, `Arc[T]` print the value they hold with `:?`. Box
  already did; Rc and Arc printed `Rc { ptr: ... }`.
- A raw pointer prints its address in hexadecimal. It printed decimal.

Sema: debug_fmt_transparent_owner (Box, or std's Rc/Arc by
type_symbol_is_std_rc_owner) replaces the Box-only checks in
ensure_debug_formatter, debug_fmt_has_form and debug_fmt_components, and
binds each one's as_ref through the new debug_fmt_bind_aux. A HashSet
is a synthesized formatter whose component is T and whose aux method is
std's new HashSet.debug_form_of; Sema ensures the element view and
Vec[str] types MIR needs.

MirLower.lower_debug_form reads the transparent owner from Sema, and
the new lower_debug_set walks the set's table as a map's traversal does
(MAP_CAPACITY / MAP_SLOT_OCCUPIED / MAP_KEY_AT, each element viewed in
place), pushes each element's `:?` text onto a Vec[str] and calls
debug_form_of (lower_debug_borrowing_call2), which orders them with the
HashMap form's debug_entry_order. The set has no traversal of its own:
`for x in set` is unspecified and fails in MIR lowering today.

Codegen.gen_debug_format and emit-C's debug_format_expr format a raw
pointer as `{:#x}` through with_fmt_int_spec. emit-C still refuses a
HashSet's form loudly, as it refuses a HashMap traversal.

Fixes #1564

---------

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

Development

Successfully merging this pull request may close these issues.

1 participant