-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Provide generic impls for Core.Int
and Core.UInt
operations.
#4693
Provide generic impls for Core.Int
and Core.UInt
operations.
#4693
Conversation
b0dfa7f
to
d25e2d7
Compare
We don't support lowering of specific function definitions yet, so avoid defining generic functions in the prelude as that breaks the build for all of our examples.
core/prelude/types/uint.carbon
Outdated
impl u32 as AddAssign { | ||
fn Op[addr self: Self*](other: Self) { | ||
*self = *self + other; | ||
} | ||
} | ||
// TODO: Once we can lower specific functions, change this to: | ||
// impl forall [N:! IntLiteral()] UInt(N) as Inc { | ||
impl u32 as Inc { |
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.
FWIW, I think some of these spacing choices don't make as much sense to me... Like I get the choice to avoid whitespace between BitAnd
and BitAndAssign
, but why isn't Inc
just on its own, and similar for Dec
? I don't really view these as associated with Add
/Sub
-- sort of how Sub
could be written in terms of Add
and Negate
(or Negate
in terms of Sub
), but are treated as distinct.
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.
This is pre-existing (copied from int.carbon
), but IIRC the idea here was that they are grouped together because Inc
is implemented in terms of AddAssign
, so must be ordered after AddAssign
-- the groups with blank lines between them can be put in any order (and are ordered alphabetically by the first interface name in the group) but should be kept as a group if they are reordered due to dependencies.
Perhaps this was more obvious when the Inc
impl actually named the preceding AddAssign
impl rather than implicitly using it via an operator.
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.
As an alternative, we could order these as:
- basic operators, alphabetically
*Assign
operators, alphabeticallyInc
/Dec
operators, alphabetically
Maybe that'd be nicer?
Instead of providing operations only for
i32
, provide them for alliN
anduN
types.For now, this excludes the
*Assign
,Inc
andDec
interfaces, because the implementations for those are defined as Carbon functions rather than builtins, and we can't yet lower definitions for specific functions, so converting those to be generic breaks the build for our examples.