-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Implement Value generics #75518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Value generics #75518
Conversation
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
09935be
to
f5408c9
Compare
@swift-ci please smoke test |
swiftlang/llvm-project#9030 |
Please test with following pull request: @swift-ci please smoke test |
2 similar comments
Please test with following pull request: @swift-ci please smoke test |
Please test with following pull request: @swift-ci please smoke test |
b540d78
to
17eb973
Compare
Please test with following pull request: @swift-ci please test |
Please test with following pull request: @swift-ci please test Windows |
1 similar comment
Please test with following pull request: @swift-ci please test Windows |
The test was failing on 32-bit platforms after swiftlang#75518
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only saw the changes to parse integer values as types now. I think there are some problems with the current implementation.
// Eat any '-' preceding the type. | ||
SourceLoc minusLoc; | ||
if (Tok.isMinus()) { | ||
minusLoc = consumeToken(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that we drop the -
in all cases where it’s not followed by an integer literal? So, does this mean that the following code is now valid?
let x: -String = 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is an issue. I'll make a change that only eats preceding -
if the following token is an integer literal.
@@ -1574,7 +1588,7 @@ bool Parser::canParseType() { | |||
return false; | |||
break; | |||
case tok::oper_prefix: | |||
if (Tok.getText() != "~") { | |||
if (Tok.getText() != "~" && Tok.getText() != "-") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar here, does this mean that we return true from canParseType
for -String
?
This implements the feature described in the GenericsManifesto here: https://github.com/swiftlang/swift/blob/main/docs/GenericsManifesto.md#generic-value-parameters
One can introduce a value generic parameter by marking the type
let
in the generic parameter clause:and you must declare the value type that this is a value for. At the moment this is limited to
Int
(but I've left the door open to "easily" expanding it for potential future directions). You can specialize a type with a value generic with an integer literal or by passing another value generic with the same underlying value type:This is still a WIP.