Implement Param add/mul as proper methods#15032
Conversation
|
One or more of the following people are relevant to this code:
|
jakelishman
left a comment
There was a problem hiding this comment.
If we're going to raise these to Param, they need to be given names that clearly indicate at the call site that they do not actually support all Param instances, or we're just asking to make mistakes.
| left.add(right).expect("Name conflict during add."), | ||
| )) | ||
| } | ||
| _ => unreachable!("Unsupported addition."), |
There was a problem hiding this comment.
This is not unreachable. Unreachable isn't for marking "I don't want you to get here", it's for marking "this is literally impossible but the compiler can't reason about it".
There was a problem hiding this comment.
yep, that's an oversight from copying it over 😅
There was a problem hiding this comment.
A nicer way would be to have a proper error here -- we should also propagate the name-conflict error that we currently just .expect()
There was a problem hiding this comment.
The panic is suitable if it could only have been caused by an internal logic error within the Rust code, but yeah, a non-aborting error for the name conflict would be nicer.
Pull Request Test Coverage Report for Build 17910214757Details
💛 - Coveralls |
|
The conflicts here are probably mostly related to the move to Rust 2024, especially the format update. Do you want to include all the mathematical operations on numeric-like arguments that we identified in #14837, so that we can (in a follow up PR) then migrate the C API code of |
|
Yeah we can already include them in this PR 👍🏻 though if we move them here, then we should maybe directly update the |
|
I don't mind if you want to do it in this PR, or move them over in a follow-up. |
Summary
This commit implements the methods
Param::add(_f64)andParam::mul(_f64), which previously existed as standalone functions in various places. This ensures we have a single place for these methods which is easily discoverable and cleans up the code.Details and comments
This came up when implementing the C API for
Paramin #14837.This also removes the single call to
clone_param(&Param) -> Paramwhich is already covered byParam::clone.