Skip to content

style_lint: add STYLE031 (table insert run → table literal), revive dead STYLE021#3115

Merged
borisbat merged 1 commit into
masterfrom
bbatkin/style031-table-insert-lint
Jun 12, 2026
Merged

style_lint: add STYLE031 (table insert run → table literal), revive dead STYLE021#3115
borisbat merged 1 commit into
masterfrom
bbatkin/style031-table-insert-lint

Conversation

@borisbat

@borisbat borisbat commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

STYLE031 — table insert run → table literal

The table twin of STYLE012: an empty table<K;V> (or table<K> set) declaration followed by ≥ 2 contiguous t |> insert(k, v) / t[k] = v statements collapses to a table (set) literal move-assign:

// Bad
var t : table<string; int>
t |> insert("a", 1)
t["b"] = 2

// Good
var t <- { "a" => 1, "b" => 2 }

Semantics probed before writing the rule:

  • Computed keys are allowed — a runtime-duplicate key in a literal is last-wins, identical to sequential inserts.
  • Runs with a duplicate CONST key stay silent — sequential inserts overwrite, but a literal rejects duplicate constant keys at compile time (error[30706]), so the rewrite would not compile. Type-tagged const-key comparison covers string/int/uint/int64/uint64/float/double/bool/enum keys.
  • insert rejects non-copyable values (error[31400]), so every run the lint can see is literal-compatible — no emplace special-casing needed.
  • Mixed runs (insert + []=) and exact-arity matching (3-arg map, 2-arg set; the positional array overloads can't leak in).

STYLE021 was dead code — revived

Wiring the STYLE031↔STYLE021 handoff (JV tables with const keys should keep the stronger JV((k1=..., k2=...)) suggestion) exposed that STYLE021 never fired since landing: its type check matched a tHandle annotation named "JsonValue", but JsonValue is a das struct (daslib/json.das). It also had no test. Fixed the match (tPointertStructure, name + module json) and added the missing style021_jv_table_insert.das test pinning both the rule and the handoff. Computed-key JV runs now fall through to STYLE031.

Tree sweep (19 hits)

  • 6 fixtures rewritten to literals — linq table-source fixture (now a direct return <- { ... }), long_length, with_boost ×2, serialization + data_walker tutorials.
  • 12 nolint'd with reasons — sites where insert/[]= is the machinery under test: fused tab[k]=v opcodes, packed-table WithHash nodes, dapi layout, value-key table API, and the two tutorials that deliberately teach the insert API. (The fused-overwrite test has duplicate const keys and was already correctly skipped by the dup guard.)
  • Touched files also cleaned of pre-existing STYLE001/STYLE028/LINT003/LINT013 warnings (incl. 16× self->pad( in the data-walker tutorial).

Docs

  • lint.rst: STYLE031 section + STYLE021 fall-through note
  • skills/style_lint.md: rows for 031 and the previously missing 029/030; STYLE021 row corrected
  • CLAUDE.md: idiom-table row; module docstring gained the missing STYLE023 line

Validation

Preflight full tier: 16 passed, 0 failed (cpp-syntax skipped — no C++ changes), including sphinx-latex/html + pdflatex, tests-interp/jit/aot, and sequence smoke. 43/43 lint-rule tests, 190/190 runtime tests in touched dirs, tree re-sweep zero remaining hits, detect-dupe clean on the new functions.

🤖 Generated with Claude Code

…dead STYLE021

STYLE031 is the table twin of STYLE012: an empty table<K;V> (or table<K>
set) declaration followed by >= 2 contiguous `t |> insert(k, v)` /
`t[k] = v` statements collapses to a table (set) literal move-assign.
Computed keys are allowed (runtime-duplicate is last-wins in both forms);
runs with a duplicate CONST key stay silent since a literal rejects them
at compile time (error 30706) while sequential inserts overwrite.

While wiring the STYLE021 handoff (JV tables with const keys keep the
stronger JV((k1=...)) suggestion), the new test exposed that STYLE021 had
been dead code since landing: its type check matched a tHandle "JsonValue"
annotation, but JsonValue is a das struct (daslib/json.das). Fixed the
match (tPointer -> tStructure, name + module json) and added the missing
style021 test; computed-key JV runs now fall through to STYLE031.

Tree sweep: rewrote 6 fixture tables to literals (linq source fixture,
long_length, with_boost x2, serialization + data_walker tutorials),
nolint'd 12 sites where insert/[]= is the machinery under test (fused
tab[k]=v opcodes, packed WithHash nodes, dapi layout, value-key API,
insert-teaching tutorials). Touched files also cleaned of pre-existing
STYLE001/STYLE028/LINT003/LINT013 warnings.

Docs: lint.rst STYLE031 section + STYLE021 fall-through note, skill table
rows for 029/030 (were missing) and 031, CLAUDE.md idiom row, module
docstring lines for STYLE023 (was missing) and STYLE031.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 12, 2026 10:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new style-lint rule (STYLE031) to collapse “empty table + contiguous insert/[]= run” into a table/set literal move-assign, and fixes STYLE021 so it correctly detects table<string; JsonValue?> insert-runs and hands off to STYLE031 for computed-key cases. The PR also updates docs, adds targeted lint-rule tests, and refreshes several tutorials/tests to either use literals or explicitly suppress the new lint where incremental insertion is the point.

Changes:

  • Implement STYLE031 in daslib/style_lint.das, including duplicate-const-key suppression and STYLE021 handoff.
  • Revive STYLE021 by correcting its JsonValue type match and adding regression tests for STYLE021/STYLE031 division of labor.
  • Sweep affected fixtures/tutorials/tests: rewrite eligible insert-runs to literals and add nolint annotations where insert/[]= behavior is under test or being taught; update docs/skills tables accordingly.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
utils/lint/tests/style031_table_insert_run.das New rule test coverage for STYLE031 across map/set/[]=/mixed/computed-key and JV-handoff scenarios.
utils/lint/tests/style021_jv_table_insert.das New regression test ensuring STYLE021 fires for const-key JV table runs and computed-key runs fall through to STYLE031.
tutorials/language/47_data_walker.das Removes self-> noise (STYLE028) and replaces a simple table build with a literal.
tutorials/language/41_serialization.das Rewrites table initialization sequence into a table literal.
tutorials/language/30_json.das Adds nolint:STYLE021 to keep incremental-building tutorial example intact.
tutorials/language/10_tables.das Adds nolint:STYLE031 to preserve insert-API teaching example.
tests/with_boost/test_with_table.das Rewrites contiguous insert-run into a literal to satisfy STYLE031.
tests/with_boost/test_with_lock_panics.das Renames unused with_ binders and rewrites one insert-run into a literal.
tests/table_packed/test_packed.das Adds nolint:STYLE031 where packed-table insert path is the subject under test.
tests/table_packed/test_packed_constkey.das Adds nolint:STYLE031 in const-key insert/[]=-path tests.
tests/long_array_table/test_long_length.das Rewrites a simple table build into a literal.
tests/long_array_table/test_fusion_table_i64.das Adds nolint:STYLE031 where fused tab[k]=v write path is under test.
tests/long_array_table/test_dapi_layout.das Adds nolint:STYLE031 where canonical insert layout behavior is under test.
tests/linq/test_linq_table_source.das Rewrites table factory function to return a table literal.
tests/language/test_value_table_key.das Adds nolint:STYLE031 and updates table get callback callsites to the modern $(...) form.
skills/style_lint.md Documents STYLE031, updates STYLE021 description (including the handoff behavior), and adds missing STYLE029/STYLE030 rows.
doc/source/reference/language/lint.rst Documents STYLE031 and clarifies STYLE021 computed-key fall-through to STYLE031.
daslib/style_lint.das Core implementation: revive STYLE021 type match and add new STYLE031 detection and messaging.
CLAUDE.md Adds STYLE031 to the style-lint idiom migration table.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@borisbat borisbat merged commit 81c1660 into master Jun 12, 2026
33 checks passed
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.

2 participants