Throwing this out there for some quick opinions. -- E
Adding "Human"-consumable Precedence Group Presets
- Proposal: SE-00xx
- Authors: Erica Sadun
- Review Manager: TBD
- Status: TBD
- Decision notes: TBD
- Implementation: TBD
- Write-ups and Discussion threads: TBD
- Review thread: TBD
Introduction
This proposal introduces preset precedent groups for utility work.
Motivation
Operators should be used rarely and thoughtfully. Many custom operators are used in lightweight scripting to simplify exploration in playgrounds (such as debugging or casting operators) or as in-house utilities. Of these, many don't use explicit precedence at all. When they do, it's unwieldly to have to start going through Swift source to discover exactly where your operator group should fall:
BitwiseShiftPrecedence >
MultiplicationPrecedence >
AdditionPrecedence >
RangeFormationPrecedence >
CastingPrecedence >
NilCoalescingPrecedence >
ComparisonPrecedence >
LogicalConjunctionPrecedence >
LogicalDisjunctionPrecedence >
TernaryPrecedence >
AssignmentPrecedence >
FunctionArrowPrecedence > [nothing]
It's useful to provide a limited established set of human-centric precedence, easy to remember, easy to use groups that avoid diving into Swift's more nuanced collection.
Proposed solution
Add super-simple, obvious groups for those times you just want to throw together an operator and need precedence:
/// Human-centered low precedence group
precedencegroup LowPrecedence { higherThan: VeryLowPrecedence }
/// Human-centered very low precedence group
precedencegroup VeryLowPrecedence { lowerThan: FunctionArrowPrecedence }
/// Human-centered very high precedence
precedencegroup VeryHighPrecedence { higherThan: HighPrecedence}
/// Human-centered high precedence
precedencegroup HighPrecedence { higherThan: BitwiseShiftPrecedence }
/// Human-centered left associative precedence
precedencegroup LeftAssociativePrecedence { associativity: left }
Source compatibility
This proposal is strictly additive.
Effect on ABI stability
This proposal does not affect ABI stability.
Effect on API resilience
This proposal does not affect ABI resilience.
Alternatives considered
Nope