Skip to content

[6.4 🍒][Literal Expressions] Improvements to semantics to address feedback#89249

Draft
artemcm wants to merge 4 commits into
swiftlang:release/6.4.xfrom
artemcm:64ImprovedLiteralExpressions
Draft

[6.4 🍒][Literal Expressions] Improvements to semantics to address feedback#89249
artemcm wants to merge 4 commits into
swiftlang:release/6.4.xfrom
artemcm:64ImprovedLiteralExpressions

Conversation

@artemcm
Copy link
Copy Markdown
Contributor

@artemcm artemcm commented May 19, 2026

Cherry-pick of #88952

  • Explanation: This change addresses feedback on the initial Literal Expressions pitch, which has also been reflected in the updated proposal.

    • Support Int128 and UInt128.
    • Add support for wrapping arithmetic and masking shift operators. &+,&-,&*,&<<,&>>.
    • Use arithmetic shift for signed >>.
      The expression folder previously applied APInt::lshr for every >> regardless of signedness. For a negative signed operand this yields a large positive value and diverges from Swift runtime behavior, which performs an arithmetic right shift that preserves the sign bit.
    • Reject references to publicly visible let bindings.
      A let binding declared public, package, or open participates in its module's ABI surface as a symbol — clients link against the declaration, not against its value, so the author is free to change the value in a future release. Folding such a reference in a literal expression would risk "baking" a module-private value into client code and remove the author's room to evolve the binding. Reject these references with a new diagnostic that reports the offending access level. internal, fileprivate, and private bindings continue to fold, as do Clang-imported constants.
  • Scope: Uses of experimental feature LiteralExpressions are expanded in some ways, and restricted in the ability to reference public let declarations. Code which does not opt-in to be using this experimental feature is not affected.

  • Risk: Low, does not affect code not guarded by the experimental feature

  • Original PR: [Literal Expressions] Improvements to semantics to address feedback #88952

  • Testing: Tests added to the test suite to validate changes to behavior and added semantics.

  • Reviewers: TBD

artemcm added 4 commits May 19, 2026 11:35
The expression folder previously applied `APInt::lshr` for every `>>` regardless of signedness. For a negative signed operand this yields a large positive value and diverges from Swift runtime behavior, which performs an arithmetic right shift that preserves the sign bit.

Dispatch to `APInt::ashr` when the operand type is signed, and retain `APInt::lshr` for unsigned operands.
…dings

A `let` binding declared `public`, `package`, or `open` participates in its module's ABI surface as a symbol — clients link against the declaration, not against its value, so the author is free to change the value in a future release. Folding such a reference in a literal expression would risk "baking" a module-private value into client code and remove the author's room to evolve the binding. Reject these references with a new diagnostic that reports the offending access level. `internal`, `fileprivate`, and `private` bindings continue to fold, as do Clang-imported constants.
@artemcm artemcm added 🍒 release cherry pick Flag: Release branch cherry picks swift 6.4 labels May 19, 2026
@artemcm
Copy link
Copy Markdown
Contributor Author

artemcm commented May 19, 2026

@swift-ci test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🍒 release cherry pick Flag: Release branch cherry picks swift 6.4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant