-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
New integer protocols #3796
New integer protocols #3796
Conversation
@@ -13,14 +13,15 @@ | |||
import SwiftShims | |||
|
|||
/// Convert the given numeric value to a hexadecimal string. | |||
public func asHex<T : Integer>(_ x: T) -> String { | |||
return "0x" + String(x.toIntMax(), radix: 16) | |||
public func asHex<T : FixedWidthInteger>(_ x: T) -> String { |
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.
Can’t we convert an arbitrary-width integer to hex?
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.
Added a FIXME
.
Lots of missing doc comments in the code! |
public func signum() -> Self { | ||
// FIXME(integers): implement | ||
fatalError() | ||
if self < (0 as Self) { return -1 } |
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.
if these as Self
s are really needed I think there’s a compiler bug that should be reported. Otherwise we should just say 0
.
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.
They were needed at some point, but are not now. Removed.
In Swift 3 shifts used to be defined on the concrete integer types, so the right-hand-side value in the shift expression could define a type for the result, as in `1 << i32` would have the type Int32. Swift 4 makes shift operators heterogeneous, so now `1 << i32` will result in an Int, according to the type of the left-hand-side value, which gets a default type for integer literals.
apple/swift-xcode-playground-support#13 |
@swift-ci Please benchmark |
Build failed |
Build comment file:Optimized (O) Regression (42)
Improvement (18)
No Changes (231)
Regression (33)
Improvement (8)
No Changes (250)
|
apple/swift-xcode-playground-support#13 |
swiftlang/swift-corelibs-foundation#951 |
apple/swift-xcode-playground-support#13 |
apple/swift-xcode-playground-support#13 |
swiftlang/swift-corelibs-foundation#951 |
W00t! |
@moiseev https://github.com/dabrahams/swift/tree/integer-merge is the beginning of a merge into the unicode-rethink branch. Everything seems good except for AlternateIntegerWidths.swift.gyb, which you can experiment with in isolation if you like: https://gist.github.com/dabrahams/f7fa2b710b50340e168926842515de4b. Update: I removed that file and made more progress, but will still likely need your help. AlternateIntegerWidths is still interesting as a backward-compatibility corner case. |
Work on integers from @moiseev
What's in this pull request?
Resolved bug number: (SR-)
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.