[6.4 🍒][Literal Expressions] Improvements to semantics to address feedback#89249
Draft
artemcm wants to merge 4 commits into
Draft
[6.4 🍒][Literal Expressions] Improvements to semantics to address feedback#89249artemcm wants to merge 4 commits into
artemcm wants to merge 4 commits into
Conversation
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.
Contributor
Author
|
@swift-ci test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #88952
Explanation: This change addresses feedback on the initial Literal Expressions pitch, which has also been reflected in the updated proposal.
Int128andUInt128.&+,&-,&*,&<<,&>>.>>.The expression folder previously applied
APInt::lshrfor 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.letbindings.A
letbinding declaredpublic,package, oropenparticipates 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, andprivatebindings continue to fold, as do Clang-imported constants.Scope: Uses of experimental feature
LiteralExpressionsare expanded in some ways, and restricted in the ability to referencepubliclet 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