Skip to content

fix(parser)!: preserve contextual literal substitutions - #300

Merged
Teakowa merged 1 commit into
mainfrom
fix/preserve-coerced-literals
Sep 26, 2026
Merged

Teakowa merged 1 commit into
mainfrom
fix/preserve-coerced-literals

Conversation

@e54-bot

@e54-bot e54-bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Catalog coercion facts now decide only which literal substitutions a parameter accepts; the parser keeps the authored literal. Parse → emit no longer rewrites False/True → 0/1, 0/Vector(0, 0, 0) → Null, or Empty Array → "".

  • Removes the parse-time normalization (normalize_contextual_argument, normalize_modify_value, normalize_modify_call_value) from value, assignment, and modify parsing. Validation already accepted the authored forms via contextual_value_matches, so acceptance is unchanged.
  • ADR-0015 records the decision (option 2 of Decide whether parsing may discard OverPy optimizeForSize literal substitutions #298) and supersedes ADR-0011 decision 2. Emission-side size optimization (option 3) is rejected: optimizeForSize stays opy-rs policy, which can now write the substituted form into Program itself.
  • docs/element-count.md records the evidence gap: no client capture establishes whether a numeric literal and False/True/Null cost the same. The model is unchanged; the analysis now sees the authored literal and can apply whatever rule a capture establishes.

Behavior change

Program and round-trip equivalence now distinguish 0 from False, 1 from True, and 0/zero vector from Null at coerced positions (marked breaking). Consumers that compared against normalized output (e.g. opy-rs reference comparisons) adopt this in their own PRs.

Client evidence

None available: no capture of the element cost of 0 versus False in a numeric argument exists. The ADR-0005 capture is follow-up work and does not change this decision.

Verification

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace --all-targets (all pass), workshop-catalog-gen -- check, git diff --check.
  • New contextual_aliases_survive_parse_and_emit_in_each_locale: the Decide whether parsing may discard OverPy optimizeForSize literal substitutions #298 table spellings survive en-US parse → emit verbatim, and a zh-CN emit → parse → emit is stable and equivalent to the authored program.
  • Existing contextual-semantics tests now assert the authored value is preserved at each coerced position (actions, vector components, operators, conditional, array index, indexed/modify contexts).
  • Not run: the motivating OWBastion/Bastion Wright build comparison, which needs the opy-rs adoption.

Fixes #298

Catalog coercion facts now decide only which literal substitutions a parameter accepts. The parser keeps the authored literal, so parsing and emitting Workshop text no longer rewrites False/True to 0/1, 0 or a zero vector to Null, or Empty Array to an empty string, and the result no longer depends on which identity a locale spelling resolves to.

BREAKING CHANGE: Program and round-trip equivalence now distinguish 0 from False, 1 from True, and 0 or Vector(0, 0, 0) from Null at coerced positions.

ADR-0015 records the decision; docs/element-count.md records that the element cost of these substitutions has no client evidence.

Fixes #298

@Teakowa Teakowa 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.

LGTM

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.

Decide whether parsing may discard OverPy optimizeForSize literal substitutions

2 participants