Skip to content

feat(ts): translate Debug of VecDeque and std's maps and sets - #312

Merged
kixelated merged 3 commits into
mainfrom
quest/m3/ts-deque-debug
Oct 30, 2026
Merged

kixelated merged 3 commits into
mainfrom
quest/m3/ts-deque-debug

Conversation

@kixelated

@kixelated kixelated commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

format!("{q:?}") of a VecDeque<T> refused with unsupported call to <VecDeque<T> as Debug>::fmt and a span (found by #303). Auditing the rest of std's collections showed that HashMap, HashSet, BTreeMap, and BTreeSet are refused the same way. Vec, BinaryHeap, slices, arrays, and Box<[T]> already translated.

Approach

  • fmt.rs maps each collection's Debug to its iterator, as std's impls do: a deque to rt.fmtList(rt.dequeIter(q)), so items come from its head however the buffer wraps; a set to rt.fmtSet over its keys; a map to rt.fmtMap over its entries.
  • rt.fmtSet is std's DebugSet, which is its DebugList in braces. rt.fmtMap writes each entry as a single set entry: key, ": ", then value, through one PadAdapter, as std's DebugMap does in pretty mode.
  • A new fmt::collections case in the lang fixture runs differentially against native wasm32. It covers a deque driven by random push/pop at both ends; a deque wrapped by push_front and then popped from the back past the buffer's start; empty deques, maps, and sets; VecDeque<()>; nested deques; {:#?}, {:x?}, and width; elements with custom Debug (Hex) and Option<u8> elements; and B-tree maps of deques. To check that the new case is covered, I broke fmtMap's ": ": the differential failed with 212 differences.
  • Hash collections are tested with at most one entry because std leaves their order unspecified. ts/README.md now says that a collection's Debug follows its iteration order.

Impact

  • The translator's output: {:?} of VecDeque, HashMap, HashSet, BTreeMap, and BTreeSet now translates instead of being refused.
  • Runtime: adds rt.fmtSet and rt.fmtMap.

Alternatives

  • Defining rt.DebugSet/rt.DebugMap builders. Not done: no translated code calls f.debug_set() or f.debug_map() yet, so these are plain functions over DebugList.

Follow-ups

  • std iterators' Debug: slice::Iter, vec::IntoIter, the B-tree and hash iterators, Chars, Bytes, and vec_deque::Iter, whose Debug writes its two ring-buffer slices (and VecDeque::as_slices, also refused). These are refused for a different reason: each writes its own wrapper text.
  • LinkedList: the type itself is unsupported.

Choices made without asking: I fixed maps and sets in this PR because they are refused the same way, and recorded iterators and LinkedList as quests.

Review

Codex (quest review), gpt-6.1-sol, medium effort, round 1 on head ae2f61b7a9236402b0bba23f8f8a67b30602bfc7 against origin/main fba78a4a: no findings.

just ci passed locally on that head.

🤖 Generated with Claude Code

(written by Claude Opus 5.5)

@kixelated kixelated changed the title A VecDeque's Debug feat(ts): translate Debug of VecDeque and std's maps and sets Oct 30, 2026
@kixelated
kixelated marked this pull request as ready for review October 30, 2026 23:31
@kixelated
kixelated merged commit 94d4ea0 into main Oct 30, 2026
1 of 2 checks passed
@kixelated
kixelated deleted the quest/m3/ts-deque-debug branch October 30, 2026 23:31
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