Skip to content

Add softdeps to module macro #143

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

Open
wants to merge 1 commit into
base: rust
Choose a base branch
from

Conversation

dlrobertson
Copy link

  • Add the optional softdeps argument to allow for specifying softdep to
    the module! macro
  • Make the module! macro parameters argument optional
  • Allow users to place module! macro arguments in an arbitrary order

Signed-off-by: Dan Robertson [email protected]

rust/module.rs Outdated
@@ -171,7 +170,14 @@ fn __build_modinfo_string_base(
}

fn __build_modinfo_string_variable(module: &str, field: &str) -> String {
format!("__{module}_{field}", module = module, field = field)
static COUNTER: AtomicUsize = AtomicUsize::new(0);
Copy link
Author

@dlrobertson dlrobertson Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed a little heavy handed, but currently __MODULE_INFO uses __UNIQUE_ID which adds in __COUNTER__ to the variable name. This was the simplest quick thing I could think of. Without the added count we try to reuse the same name for each softdep.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this function take counter: &mut usize as argument and then pass this around such that each module!() invocation uses the same counter. You can then increment this counter and use it. Proc macros are ideally pure functions of their arguments. The order of invocation of proc macros is not guaranteed in case of rustc and proc macros may be invoked multiple times in case of rust-analyzer. Rustc doesn't care about non-determinism in proc macros at the moment, but rust-analyzer used to crash on non-deterministic proc macros. This has since been fixed, but it is still not a good idea.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use a usize here.

@dlrobertson
Copy link
Author

Just a nit I noticed when trying out the repo. Comments and critiques would be welcomed.

@dlrobertson dlrobertson force-pushed the add-module-softdeps branch from d52dcc3 to 6d34e19 Compare March 25, 2021 02:57
@ojeda
Copy link
Member

ojeda commented Mar 25, 2021

Dan, thanks for this! Having MODULE_SOFTDEP's equivalent is very nice (likely post-RFC) and the example of the syntax you propose looks good.

The commit appears to do a reorganization/cleanup at the same time, changing some unrelated lines too (#142 is also doing a couple of those cleanups too). So it would be best to split each logical change into several PRs (or at least several commits).

Allow users to place module! macro arguments in an arbitrary order

I'm not sure about this one: having all module! invocations written the same way sounds better, unless there is a need to allow arbitrary orders.

@dlrobertson
Copy link
Author

dlrobertson commented Mar 26, 2021

The commit appears to do a reorganization/cleanup at the same time, changing some unrelated lines too (#142 is also doing a couple of those cleanups too). So it would be best to split each logical change into several PRs (or at least several commits).

Completely agree. This was just me being lazy and just wanting to get some early thoughts from reviewers.

Allow users to place module! macro arguments in an arbitrary order

I'm not sure about this one: having all module! invocations written the same way sounds better, unless there is a need to allow arbitrary orders.

True. I'm definitely willing to concede this point, but it could increase frustration for new users that have all the entries (name, description, author, etc) set, but do not have them set in the right order. It was confusing for me at least when I first set all of these in a module definition (but didn't have them in the exact order as the docs) and got an error. At a minimum I think there should be a very descriptive message detailing that they must be in the right order.

@ojeda
Copy link
Member

ojeda commented Mar 26, 2021

Agreed! Improving the docs and the error messages is always worth it to avoid making others spend time figuring things out.

rust/module.rs Outdated
"__{module}_{field}{counter}",
module = module,
field = field,
counter = COUNTER.load(Ordering::SeqCst)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
counter = COUNTER.load(Ordering::SeqCst)
counter = COUNTER.fetch_add(1, Ordering::SeqCst)

fetch_add returns the old value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good point. that would increase readability

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current version this isn't needed.

rust/module.rs Outdated
@@ -171,7 +170,14 @@ fn __build_modinfo_string_base(
}

fn __build_modinfo_string_variable(module: &str, field: &str) -> String {
format!("__{module}_{field}", module = module, field = field)
static COUNTER: AtomicUsize = AtomicUsize::new(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this function take counter: &mut usize as argument and then pass this around such that each module!() invocation uses the same counter. You can then increment this counter and use it. Proc macros are ideally pure functions of their arguments. The order of invocation of proc macros is not guaranteed in case of rustc and proc macros may be invoked multiple times in case of rust-analyzer. Rustc doesn't care about non-determinism in proc macros at the moment, but rust-analyzer used to crash on non-deterministic proc macros. This has since been fixed, but it is still not a good idea.

@alex
Copy link
Member

alex commented May 12, 2021

FYI: there's a merge conflict here.

@dlrobertson dlrobertson force-pushed the add-module-softdeps branch from 6d34e19 to cdec777 Compare May 13, 2021 04:01
@dlrobertson
Copy link
Author

Updated

@ksquirrel

This comment has been minimized.

Add support for declaring module softdeps in the generated
module info. The module macro may now include something
like the following:

  module! {
    ...
    softdeps {
        pre: keywrap,
        post: sha512,
        ...
    }

Signed-off-by: Dan Robertson <[email protected]>
@dlrobertson dlrobertson force-pushed the add-module-softdeps branch from cdec777 to 06759a2 Compare June 11, 2021 23:16
@ksquirrel
Copy link
Member

Review of 06759a2f15d7:

  • ✔️ Commit 06759a2: Looks fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants