Skip to content
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

Merged
merged 4 commits into from
Sep 28, 2023
Merged

Conversation

sekerez
Copy link
Contributor

@sekerez sekerez commented Sep 25, 2023

Resolves this issue.

This PR does the following:

  • Add abs support to Dec by defining a new method in the Zig struct, and an associated function.
  • Sort a few lists in both a 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 or negateC function in dec.zig, am I missing something?

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),
Copy link
Contributor Author

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:

  1. 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,
    ...
}

...
  1. More of a nitpick, but functions like build_dec_unary_op suggest that traits should be used instead - something like a Num trait that Dec, Int etc. implement.

Does that sound fair? Can I, in a separate PR, refactor the typing in lowlevel.rs accordingly?

Copy link
Contributor

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.

@sekerez
Copy link
Contributor Author

sekerez commented Sep 26, 2023

@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?

@bhansconnect
Copy link
Contributor

@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.

@bhansconnect
Copy link
Contributor

Thanks for this work. Assuming tests don't flake with the latest main merged in, I have set this to autosubmit.

@rtfeldman rtfeldman merged commit ab718ae into roc-lang:main Sep 28, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add abs support to Dec
3 participants