Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Migrate types from a macro to a trait #349

Merged
merged 3 commits into from
Nov 2, 2024

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Oct 30, 2024

This allows us to move a lot of logic out of macros and into generic functions, which is a nice cleanup and much better for usability.

@tgross35 tgross35 force-pushed the better-typing branch 3 times, most recently from 8988118 to c7119b9 Compare October 30, 2024 19:02
@tgross35
Copy link
Contributor Author

@beetrees I'm still working on some better naming cleanup / docs / comments, but you may want to take a look at this. Basically migrating from always relying on macro expansion to putting everything into a trait, which should help avoid string matching problems (like you pointed out on a different PR).

None of the possible refactoring of ULP / precision is done here.

@tgross35 tgross35 marked this pull request as ready for review October 31, 2024 07:53
@tgross35 tgross35 force-pushed the better-typing branch 3 times, most recently from 7f1985b to 456dac6 Compare October 31, 2024 22:32
@tgross35
Copy link
Contributor Author

tgross35 commented Nov 1, 2024

Let me know if you have any name suggestions too. I feel like too much here is some variation of "function" or "op", but I can't come up with anything much better.

Currently the macro always provides `CFn`, `RustFn`, `RustArgs`, etc.
Change this so that:

1. This information must be explicily requested in the invocation.
2. There is a new `FTy` field available that emits a single float type,
   rather than a tuple or signature.

Additionally, add two new macros that create enums representing function
names.
@tgross35 tgross35 force-pushed the better-typing branch 3 times, most recently from 403b95b to 7081592 Compare November 2, 2024 21:30
This contains:

1. Per-function and per-operation enums created by the proc macro
2. The `MathOp` trait which is implemented once per struct representing
   a function
3. Submodules for each function, each containing a `Routine` struct that
   implements `MathOp`
@tgross35
Copy link
Contributor Author

tgross35 commented Nov 2, 2024

I still don't have great names but I added the following to hopefully disambiguate a bit

//! Basically everything could be called a "function" here, so we loosely use the following
//! terminology:
//!
//! - "Function": the math operation that does not have an associated precision. E.g. `f(x) = e^x`,
//! `f(x) = log(x)`.
//! - "Routine": A code implementation of a math operation with a specific precision. E.g. `exp`,
//! `expf`, `expl`, `log`, `logf`.
//! - "Operation" / "Op": Something that relates a routine to a function or is otherwise higher
//! level. `Op` is also used as the name for generic parameters since it is terse.

@tgross35 tgross35 enabled auto-merge November 2, 2024 21:41
@tgross35 tgross35 merged commit 5e360c1 into rust-lang:master Nov 2, 2024
30 checks passed
@tgross35 tgross35 deleted the better-typing branch November 2, 2024 21:49
@beetrees
Copy link
Contributor

beetrees commented Nov 3, 2024

I think the naming here is always going to be somewhat arbitrary, but I think what you've gone with is perfectly reasonable terminology (I don't have any unequivocally better ideas). The most important thing (which I can see you have done) is to make sure it's documented.

tgross35 added a commit that referenced this pull request Apr 18, 2025
Migrate types from a macro to a trait
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants