-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add: Interoperable #74
Labels
addition
oh, so shiny!
Milestone
Comments
I'll conform the core integer types to it, as well as all randomness types. I'll want to conform all integer types at some point, I believe it's just a matter of getting around to implementing generic floating point conversions. |
All of the following methods generate the same machine code in public protocol Interoperable {
associatedtype Stdlib
@inlinable init(_ source: consuming Stdlib)
@inlinable consuming func stdlib() -> Stdlib
}
extension Interoperable {
@inlinable public var stdlib: Stdlib {
mutating _read {
let stdlib = self.stdlib()
yield stdlib
self = Self(stdlib)
}
mutating _modify {
var stdlib = self.stdlib()
yield &stdlib
self = Self(stdlib)
}
}
}
@frozen public struct MyInt: Interoperable {
@usableFromInline let base: Int
@inlinable public init(_ base: Int) { self.base = base }
@inlinable public func stdlib() -> Int { self.base }
}
func foo(a: Int, b: Int) -> (Int, Bool) {
a.addingReportingOverflow(b)
}
func bar(a: MyInt, b: MyInt) -> (MyInt, Bool) {
let x = a.stdlib().addingReportingOverflow(b.stdlib())
return (MyInt(x.partialValue), x.overflow)
}
func baz(a: consuming MyInt, b: consuming MyInt) -> (MyInt, Bool) {
let x = a.stdlib.addingReportingOverflow(b.stdlib)
return (MyInt(x.partialValue), x.overflow)
} |
oscbyspro
added a commit
that referenced
this issue
Aug 25, 2024
oscbyspro
added a commit
that referenced
this issue
Aug 26, 2024
oscbyspro
added a commit
that referenced
this issue
Aug 28, 2024
Its standard-library-compatible representation is FloatingPointSign.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'll add this protocol and extension for interoperability purposes (#73):
The text was updated successfully, but these errors were encountered: