Skip to content

Conversation

@shreyas-londhe
Copy link
Contributor

Fixes #588

Problem

The #[jolt::provable] proc macro was dropping user-defined attributes (like #[allow(arithmetic_overflow)]) when generating functions, causing compilation errors or unexpected behavior.

Changes

  • make_execute_function: Forward self.func.attrs to the generated host function
  • make_main_func: Wrap guest code in an inner function that carries the user's attributes (avoids unstable "attributes on expressions" feature)

Testing

Added examples/attribute/ with tests for:

  • #[allow(arithmetic_overflow)]
  • #[allow(unused_variables)]
  • #[inline]
  • Multiple attributes combined

Copy link
Collaborator

@0xAndoroid 0xAndoroid left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. I believe that general idea is sound, just some parts need to be addressed.
In addition, can we remove the new attribute example all together, just leaving changes to the macro sdk to not bloat the codebase.
Finally, make sure CI passes.

let inner_fn_name = syn::Ident::new(&format!("__jolt_guest_{}", fn_name), fn_name.span());
let block = quote! {
#(#attrs)*
fn #inner_fn_name() #output #block
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because we don't make this a closure anymore, it can't capture input variables from the outside. We still need to keep this a closure.
I believe in rust you can still apply most of the attributes to closures. But it'd be nice to document this limitation in the jolt book.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, thanks for pointing this out! Unfortunately applying attributes to expressions (closures) is experimental on stable Rust (rust-lang/rust#15701).

We would need to use nightly version to add #![feature(stmt_expr_attributes)] to the generated guest code. Or we can apply the attributes to main which would then propagate down.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jolt::provable attribute omits subsequent attributes

2 participants