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

#[rune::function] fails when adding a 6th argument #755

Open
VorpalBlade opened this issue Jul 20, 2024 · 5 comments
Open

#[rune::function] fails when adding a 6th argument #755

VorpalBlade opened this issue Jul 20, 2024 · 5 comments
Labels

Comments

@VorpalBlade
Copy link
Contributor

This compiles:

    #[rune::function]
    fn add_from_sysusers(
        &mut self,
        package_manager: &PackageManager,
        //package: &str,
        config_file: &str,
        user_ids: Vec<(String, u32)>,
        group_ids: Vec<(String, u32)>,
    ) -> anyhow::Result<()> {
        //let sysusers = String::from_utf8(package_manager.file_contents(package, config_file)?)?;
        todo!()
    }

Uncommenting the package parameter gives the following (cryptic) error though:

error[E0277]: the trait bound `for<'a, 'b, 'c, 'd> fn(&'a mut Passwd, &'b PackageManager, &'c str, &'d str, std::vec::Vec<(std::string::String, u32)>, std::vec::Vec<(std::string::String, u32)>) -> std::result::Result<(), anyhow::Error> {Passwd::__rune_fn__add_from_sysusers}: InstanceFunction<_, _>` is not satisfied
   --> crates/konfigkoll_script/src/plugins/passwd.rs:150:5
    |
150 |     #[rune::function]
    |     ^^^^^^^^^^^^^^^^^ the trait `InstanceFunction<_, _>` is not implemented for fn item `fn(&mut Passwd, &PackageManager, &str, &str, Vec<(String, u32)>, Vec<(String, u32)>) -> ... {...::__rune_fn__add_from_sysusers}`
    |
note: required by a bound in `FunctionMetaKind::instance`
   --> /home/arvid/src/paketkoll/patches/rune/crates/rune/src/module/function_meta.rs:367:12
    |
364 |     pub fn instance<N, F, A, K>(name: N, f: F) -> alloc::Result<Self>
    |            -------- required by a bound in this associated function
...
367 |         F: InstanceFunction<A, K>,
    |            ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `FunctionMetaKind::instance`
    = note: this error originates in the attribute macro `rune::function` (in Nightly builds, run with -Z macro-backtrace for more info)

In fact, commenting out any of the 6 parameters make it work. I cannot find any mention of a 6 parameter limit in the docs?

@VorpalBlade
Copy link
Contributor Author

In case you need to reproduce this: https://github.com/VorpalBlade/paketkoll/tree/feature/konfigkoll (commit 588104d5), in the file crates/konfigkoll_script/src/plugins/passwd.rs, the function add_from_sysusers.

Notes:

  • This will probably get rebased etc a few times as it gets implemented and tested.
  • It is set up to use a patched rune (with the unreleased 0.13.x changes, nothing else). Just remove that from the top workspace Cargo.toml patch table, as the actual sub-repo isn't added (I'm not going to merge this branch while using [patch] as I want to publish to crates.io)

@udoprog
Copy link
Collaborator

udoprog commented Jul 20, 2024

It's not explicitly spelled out in the documentation, but the Function trait is only implemented up to five parameters.

It's a bit of a pain adding more, since they have to be a permutation between three different traits.

The background for why this is needed is here. Previously the references used were unbound and this pattern is currently needed to unbind them.

However, if we can live with only one trait being implemented for the auxiliary parameters (like FromValue), that might work too!

@VorpalBlade
Copy link
Contributor Author

VorpalBlade commented Jul 20, 2024

Hm, confusingly when I looked at InstanceFunction it was implemented for way more parameters.

Since you already use a macro (declarative) to generate these impls, what is the cost of repeating it for a few more parameters? Is it build time due to combinatorial explosion?

In that case only supporting Value for parameter 7 up to N makes sense as a compromise.

@udoprog
Copy link
Collaborator

udoprog commented Jul 20, 2024

If you want to play around with the problem space, here's a playground I put together.

This is another playground showing how we currently solve it with references.

@udoprog
Copy link
Collaborator

udoprog commented Jul 20, 2024

Since you already use a macro (declarative) to generate these impls, what is the cost of repeating it for a few more parameters? Is it build time due to combinatorial explosion?

I don't remember. Please try it out if you have the time!

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

No branches or pull requests

2 participants