core: Refactor PrimitiveDefinitionIds into an enum + refactor get_builtins()
#408
No reviewers
Labels
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: M-Labs/nac3#408
Loading…
Reference in New Issue
No description provided.
Delete Branch "issue-385-primdef"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Realizes #385 and #386 (comment).
nac3core/src/toplevel/helper.rs
,struct PrimitiveDefinitionIds
andconst PRIMITIVE_DEF_IDS
are now replaced withenum PrimitiveDefinition
.enum PrimitiveDefinition
now also includes primitive functions (See #386 (comment)).strum
andstrum_macros
are added to implementPrimitiveDefinition::iter
with a macro.b6ded9a869
to3fc8aa8981
3fc8aa8981
to84fc379ef4
@ -24,0 +27,4 @@
OptionUnwrap, // 13
NDArray, // 14
NDArrayCopy, // 15
NDArrayFill, // 16
This doesn't appear to be the entire list of primitive definitions. What about the other Numpy functions?
Also, I would prefer not to comment the ID itself here. Rather, I'd like a test case that asserts that each primitive class/function has the same ID as its index in the
Vec
returned byget_builtins
.I will revise on this.
I commented the IDs here since I find it very helpful when printing
{:?}
s and doing quick lookups to see what is what. Still should I remove them?Ok, I will work on this now.
3aaf21fcf9
to9323877076
core: Refactor PrimitiveDefinitionIds into an enumto core: Refactor PrimitiveDefinitionIds into an enum + refactor `get_builtins()`The design looks good to me, just several nitpicks here and there.
Other general comments:
PrimitiveDefinitionIds
and refactoringget_builtins
cargo clippy --no-deps -p nac3core -- -Wclippy::pedantic -Aclippy::cast-lossless -Aclippy::cast-possible-truncation -Aclippy::cast-sign-loss -Aclippy::enum_glob_use -Aclippy::implicit-hasher -Aclippy::missing-errors-doc -Aclippy::missing_panics_doc -Aclippy::module-name-repetitions -Aclippy::similar_names -Aclippy::too-many-lines -Aclippy::wildcard_imports
and fix all warnings. (I will add a configuration file to make it easier in the future.)@ -58,0 +127,4 @@
/// If the [`PrimDef`] is a function, this corresponds to [`TopLevelDef::Function::simple_name`].
///
/// If the [`PrimDef`] is a class, this is equal to [`PrimDef::name`].
pub fn simple_name<'a>(&'a self) -> &'static str {
The lifetime
'a
can be elided; Same for the functions below.@ -58,0 +148,4 @@
PrimDefDetails { name, simple_name: name }
}
fn new2(simple_name: &'static str, name: &'static str) -> PrimDefDetails {
Could we just have one constructor with
simple_name
being anOption<&'static str>
?Sure, I will also change
PrimDefDetails
to have variantsPrimClass { name: &'static str }
and.PrimFunction { name: &'static str, simple_name: &'static str }
.@ -76,0 +249,4 @@
///
/// Like `debug_assert!`, this statements of this function are only
/// enabled if `cfg!(debug_assertions)` is true.
pub fn debug_assert_prim_is_allowed<const N: usize>(prim: PrimDef, allowlist: [PrimDef; N]) {
allowlist
can just be a&[PrimDef]
.All suggested changes are now implemented.
b7bf6ffc5b
tob08cd7f8e4
Force-pushed to fix typo in commit description
I think the following changes are not yet implemented:
Do you need some help with that?
b08cd7f8e4
toc4420e6ab9
Revised.
LGTM, thanks!