Skip to content

docs: record why {} is a set and {:} is a map - #21

Merged
DerekCorniello merged 2 commits into
mainfrom
docs/empty-map-literal
Jul 16, 2026
Merged

docs: record why {} is a set and {:} is a map#21
DerekCorniello merged 2 commits into
mainfrom
docs/empty-map-literal

Conversation

@DerekCorniello

Copy link
Copy Markdown
Contributor

Design-doc half of the fan-out for muxlang/mux-compiler#266.

docs/design/collections.md covered implementations, BTree-vs-hash, nesting, and reference counting - but said nothing about literals. So the one genuinely non-obvious decision in Mux's collections (map and set share brace syntax, and something has to break the tie) was recorded nowhere.

This repo's job is the reasoning no single code repo owns, and this is a good example: the rule lives in the compiler, but the tradeoff does not belong there.

Adds a section covering:

  • the rule - {} is always the empty set, the empty map is {:}
  • what it replaced - the compiler used to infer which one {} meant from the expected type, which needed a third Type::EmptySetOrMap threaded through semantics and codegen plus a span-keyed override map that rewrote the type after the fact. It worked, but the ambiguity leaked into both stages, and an empty literal with no expected type had no answer at all.
  • the consequences someone will actually trip on - {} in map position is an error rather than an inference, empty literals still need an explicit type, and nesting follows the rule per position (map<int, set<int>> x = {1: {}} vs map<int, map<int, int>> y = {1: {:}})

Companion PRs: muxlang/mux-website#29 (user-facing docs), muxlang/mux-compiler#270 (changelog).

🤖 Generated with Claude Code

The collections design doc described nesting and reference counting but said
nothing about literals, so the one genuinely non-obvious decision - that brace
syntax is shared between map and set, and how Mux breaks the tie - was written
down nowhere.

Explain the tradeoff: the compiler used to infer which one `{}` meant from the
expected type, which required a third EmptySetOrMap type threaded through
semantics and codegen plus a span-keyed override map, and still had no answer
when there was no expected type. `{:}` resolves it in the grammar instead.
@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown

Greptile Summary

This documentation-only PR records the design decision behind Mux's empty-collection literal syntax — {} is always an empty set and {:} is the empty map — along with the historical context of the removed EmptySetOrMap inference machinery that motivated the change.

  • Adds an "Empty literals" section to docs/design/collections.md covering the rule, the prior inference approach and why it was removed, and three practical consequences (map-position error, explicit-type requirement, nesting semantics).
  • Updates the llms.txt entry for Collections to surface the new topic, keeping the agent-facing index in sync as required by AGENTS.md.

Confidence Score: 5/5

Documentation-only change with no runtime code; safe to merge.

Both changed files are pure prose. The new section is factually consistent with the described compiler change, uses ASCII-only text as required by AGENTS.md, and llms.txt is correctly updated to reflect the new section.

No files require special attention.

Important Files Changed

Filename Overview
docs/design/collections.md Adds a new "Empty literals" section explaining the {} = set, {:} = map rule, the removed EmptySetOrMap inference machinery, and three practical consequences; content is accurate and uses ASCII-only prose.
llms.txt One-line description update for the Collections entry to include the new empty-literals topic; kept in sync with the doc as required.

Reviews (2): Last reviewed commit: "docs: index the empty-literal rule in ll..." | Re-trigger Greptile

llms.txt is how agents decide which doc to open, so a rule that is not named in
the description is a rule they will not find. The collections entry listed
BTree and nesting but not literals.
@sonarqubecloud

Copy link
Copy Markdown

@DerekCorniello
DerekCorniello merged commit 79cfd21 into main Jul 16, 2026
3 checks passed
@DerekCorniello
DerekCorniello deleted the docs/empty-map-literal branch July 16, 2026 05:24
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