-
Notifications
You must be signed in to change notification settings - Fork 57
Constants #54
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
Constants #54
Conversation
4f4a066
to
bbe4b40
Compare
Done. @harlanhaskins? |
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.
I love it!
} | ||
|
||
public static func +(lhs: Constant, rhs: Constant) -> Constant { | ||
precondition(lhs.repr == rhs.repr, "Mixed-representation constant operations are disallowed") |
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.
I wonder if we could bubble this up to type-level? Make Representation an internal protocol with three members and make Constant generic. Then + wouldn't apply between Constant<Unsigned>
and Constant<Floating>
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.
All these asserts are sanity checks. All operations are homogenous, the type is generic.
/// behavior of the resulting constant value. | ||
/// | ||
/// - returns: A constant value representing the negation of the given constant. | ||
public static func neg(_ lhs: Constant<Signed>, overflowBehavior: OverflowBehavior = .default) -> Constant<Signed> { |
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.
Should these be spelled out?
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.
I think negate should
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.
multiply
and subtract
are out?
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.
Sorry, back to my computer. I'm actually not sure why the spelled-out versions need to exist. But I think maybe they should be fully-spelled-out.
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 need to exist because overflowBehavior
.
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.
Right! Then I think they should be spelled out. 👍
c3d8c85
to
fa9c151
Compare
⛵️ |
Introduces a new typesafe API for integral constants. The intent is to make it as natural as possible to interact with constants, so they come equipped with a DSL that allows Swift's native arithmetic operators to be applied in place of LLVM constant expression calls. Tests are included to make sure const-operand-having instructions really are const-folded away.