Skip to content

Declare some FloatingPointSign members explicitly for @inlinable #16043

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

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions stdlib/public/core/FloatingPoint.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,31 @@ public enum FloatingPointSign: Int {

/// The sign for a negative value.
case minus

// Explicit declarations of otherwise-synthesized members to make them
// @inlinable, promising that we will never change the implementation.

@inlinable
public init?(rawValue: Int) {
switch rawValue {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we synthesize @inlinable members for any frozen RawRepresentable enum?

case 0: self = .plus
case 1: self = .minus
default: return nil
}
}

@inlinable
public var rawValue: Int {
switch self {
case .plus: return 0
case .minus: return 1
}
}

@inlinable
public static func ==(a: FloatingPointSign, b: FloatingPointSign) -> Bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a default == witness for RawRepresentable things somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably do, but a client isn't supposed to inline that when using it on someone else's type.

return a.rawValue == b.rawValue
}
}

/// The IEEE 754 floating-point classes.
Expand Down