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

vstd: Add no-std build mode #772

Closed
wants to merge 10 commits into from

Conversation

zhaofengli
Copy link
Contributor

@zhaofengli zhaofengli commented Aug 25, 2023

This PR adds a #![no_std] build mode for vstd. It can be activated by passing --vstd-no-std and optionally --vstd-no-alloc to vargo.

@zhaofengli zhaofengli changed the title vstd: Fix no-std compilation vstd: Add no-std build mode Aug 25, 2023
@tjhance tjhance requested a review from utaal August 29, 2023 13:34
@zhaofengli
Copy link
Contributor Author

Rebased after #733. Since Cargo.toml was added to vstd, it makes sense to use the std and alloc features like other crates in the ecosystem instead of negative features as before.

Tested that a default build using vargo produces a std-enabled vstd build, and with --vstd-no-std a no-std build.

@utaal
Copy link
Collaborator

utaal commented Aug 30, 2023

Hi @zhaofengli, and thank you for the PR! I'll try and get to it quickly (likely, in a day or two).

Otherwise fails when alloc is disabled.
This is more idiomatic compared to negative features (non_std,
non_global_allocator). By default, those features are enabled
in Cargo.toml and will be opted-into by vstd_build.

* fixup no-std after 803
@utaal
Copy link
Collaborator

utaal commented Sep 12, 2023

Thank you for rebasing, and sorry for the delay!

@utaal
Copy link
Collaborator

utaal commented Sep 12, 2023

One question: is it correct that with this PR there isn't a way when building to set alloc or std individually? If so, why are they two separate features? As something we can use in the future?

@zhaofengli
Copy link
Contributor Author

One question: is it correct that with this PR there isn't a way when building to set alloc or std individually? If so, why are they two separate features? As something we can use in the future?

I just moved disabling alloc to a separate flag in vargo. Now both --vstd-no-std and --vstd-no-alloc are required for a no-std build without a global allocator available.

@utaal
Copy link
Collaborator

utaal commented Sep 14, 2023

Thank you! Looks good. Just one last check on the #[trigger] annotations (in a comment).

@utaal
Copy link
Collaborator

utaal commented Sep 18, 2023

There seem to be a couple more fixes needed:

  • making sure that vstd is re-built when the --vstd-no-* flags change;
  • fixes the build for --vstd-no-std without --vstd-no-alloc;
  • adding #[verifier::spinoff_prover] as explained in the comment.

I made these fixes and opened a PR against this branch: mars-research#1
I cannot otherwise make edits on this branch. If they look good to you, please merge them in, so that this PR gets updated.

* ensures vstd is rebuilt when the `--vstd-no*` flags change
* use the `alloc` crate when necessary for `--vstd-no-std` without
  `--vstd-no-alloc`
@zhaofengli
Copy link
Contributor Author

Thanks for the fixes! I've merged the commits.

@utaal utaal requested a review from tjhance September 18, 2023 20:28
@utaal
Copy link
Collaborator

utaal commented Sep 18, 2023

@tjhance you added some of the extern crate alloc; imports, and made changes to use alloc::* types when necessary before. Can you take a look and check that my changes in bb7bf7a seem reasonable?

Copy link
Collaborator

@utaal utaal left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'd like for @tjhance to have a look too, in particular at the changes that involve using the alloc crate.

@@ -222,6 +222,7 @@ pub fn ex_vec_as_slice<T, A: Allocator>(vec: &Vec<T, A>) -> (slice: &[T])
vec.as_slice()
}

#[cfg(feature = "std")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

why's this needed? is split_off not available with just alloc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I went over vstd and did the following:

  • Removed the gate in question, changed std::clone::Clone to core::clone::Clone
  • Removed redundant extern crate alloc
  • Made the gate on string more fine-grained (string slices can be used without alloc)

(Sorry for the late reply, was away yesterday)

Copy link
Collaborator

@tjhance tjhance left a comment

Choose a reason for hiding this comment

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

looks fine to me

utaal added a commit that referenced this pull request Sep 21, 2023
@utaal
Copy link
Collaborator

utaal commented Sep 21, 2023

Merged as d2fd642

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.

3 participants