-
-
Notifications
You must be signed in to change notification settings - Fork 313
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 support for Num.abs to Dec type #5853
Conversation
NumCos => dec_unary_op(env, bitcode::DEC_COS, arg), | ||
NumTan => dec_unary_op(env, bitcode::DEC_TAN, arg), | ||
NumAsin => dec_unary_op(env, bitcode::DEC_ASIN, arg), | ||
NumAbs => dec_unary_op(env, bitcode::DEC_ABS, arg), |
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 feel like this code could better leverage Rust's type system in at least two ways:
- Since all "lowlevel" operations are bunched up in the same enum, no pattern matching of this type can be explicitly exhaustive, as e.g. Dec deoesn't implement StrConcat. It would be better to have the
LowLevel
enum instead be something like:
pub enum LowLevel {
Num(NumOp),
Str(StrOp),
...
}
enum NumOp {
Add,
Mul,
...
}
...
- More of a nitpick, but functions like
build_dec_unary_op
suggest that traits should be used instead - something like aNum
trait thatDec
,Int
etc. implement.
Does that sound fair? Can I, in a separate PR, refactor the typing in lowlevel.rs accordingly?
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 this is a pretty reasonable idea, but I think numerics would need to be split farther if you are trying to reach exhaustiveness. For example, some ops may run on integer but on float types.
@bhansconnect do you know why the performance regression test is failing? I'm up to date with main - could any code change plausibly have caused this? If it's noise, should I raise that as an issue? |
Benchmarks flake on rare occasion. Should be good to just rerun and submit. |
Thanks for this work. Assuming tests don't flake with the latest main merged in, I have set this to autosubmit. |
Resolves this issue.
This PR does the following:
abs
support toDec
by defining a new method in the Zig struct, and an associated function.match
statement and a list of constants (mapping Rust enums to corresponding zig functions).Question: what QA is acceptable? I saw there were no tests for the
negate
method ornegateC
function indec.zig
, am I missing something?