Skip to content

Create an RMC crate and load it as part of rmc-rustc#597

Merged
celinval merged 6 commits intomodel-checking:mainfrom
celinval:issue-231
Oct 29, 2021
Merged

Create an RMC crate and load it as part of rmc-rustc#597
celinval merged 6 commits intomodel-checking:mainfrom
celinval:issue-231

Conversation

@celinval
Copy link
Copy Markdown
Contributor

Description of changes:

Users should now be able to use rmc::nondet(), rmc::assume(bool) and rmc::expect_fail as part of their test harnesses. RMC will automatically load the rmc library as part of any crate compilation.

Resolved issues:

Resolves #231 and #589.

Call-outs:

This PR also include updates to enable this change.

  • I have also updated rmc-rustc to include the flags required by rmc so we don't need to maintain them in so many different places.
  • I updated the tests to use the new definition.s
  • I fixed an issue in the rmc codegen that was ignoring no-codegen option. This was breaking the compiletest check.

Testing:

  • How is this change tested? In all tests that were updated.

  • Is this a refactor change? No

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

- Create an rmc crate (model-checking#231).
- Used rust compliant names for the functions (model-checking#589).
- Changed rmc-rustc to inject the rmc prelude as part of the compilation
  as well as other rmc configuration flags.
- Added options to rmc-rustc to print binary path and flags so it can be
  used in other scripts.
RMC code generation was creating artifacts even if rustc was run with
-Z no-codegen. I changed the codegen to check for this option before
writing the json files.

This issue was uncovered by my change to move the rmc flags to
rmc-rustc. This script is used during compiletest. In the check stage,
the test runs rustc with --no-codegen.
Copy link
Copy Markdown
Contributor

@adpaco-aws adpaco-aws left a comment

Choose a reason for hiding this comment

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

This is awesome! Some comments.

./x.py build -i --stage 1 library/std

- name: Build RMC Library
run: bash -x ./scripts/setup/build_rmc_lib.sh
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any advantage to having -x written here and not in the script itself?

Copy link
Copy Markdown
Contributor Author

@celinval celinval Oct 29, 2021

Choose a reason for hiding this comment

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

I was wondering if this script will be helpful for users to build RMC library. In this case, we can keep the trace turned off by default, but still turn them on in the CI. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense.

// "path.o"
let base_filename = outputs.path(OutputType::Object);
// No output should be generated if user selected no_codegen.
if !sess.opts.debugging_opts.no_codegen && sess.opts.output_types.should_codegen() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this need to be in the same PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. The regression will fail if this is not here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can submit a separate PR and merge it first if that makes more sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

@adpaco-aws adpaco-aws left a comment

Choose a reason for hiding this comment

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

LGTM! My only concern now is that compiling the RMC library is necessary to use these predicates, so we should update the documentation accordingly. But we can have that in a follow-up PR.

./x.py build -i --stage 1 library/std

- name: Build RMC Library
run: bash -x ./scripts/setup/build_rmc_lib.sh
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense.

@celinval
Copy link
Copy Markdown
Contributor Author

LGTM! My only concern now is that compiling the RMC library is necessary to use these predicates, so we should update the documentation accordingly. But we can have that in a follow-up PR.

Good point. I'll submit a PR for that!

@celinval celinval merged commit b5f2044 into model-checking:main Oct 29, 2021
@celinval celinval deleted the issue-231 branch October 29, 2021 20:28
/// ```
#[inline(never)]
#[rustc_diagnostic_item = "RmcNonDet"]
pub fn nondet<T>() -> T {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This really needs to be marked as unsafe as callers need to ensure all of the type's invariants are met.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have pushed this code already, but I created #607 to capture the work to fix this. Thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

/// ```
#[inline(never)]
#[rustc_diagnostic_item = "RmcAssume"]
pub fn assume(_cond: bool) {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For a better docs and IDE experience, it would be preferable to do something like:

pub fn assume(cond: bool) {
    let _ = cond;
}

Same goes for the other arguments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. I'll fix this next time I push some updates to this crate. Thanks for the suggestion.

tedinski pushed a commit to tedinski/rmc that referenced this pull request Apr 26, 2022
)

* Adding support to new rmc prelude definitions

- Create an rmc crate (model-checking#231).
- Used rust compliant names for the functions (model-checking#589).
- Changed rmc-rustc to inject the rmc prelude as part of the compilation
  as well as other rmc configuration flags.
- Added options to rmc-rustc to print binary path and flags so it can be
  used in other scripts.

* Add a script to build rmc library

* Update tests to use new injected prelude.
tedinski pushed a commit that referenced this pull request Apr 27, 2022
* Adding support to new rmc prelude definitions

- Create an rmc crate (#231).
- Used rust compliant names for the functions (#589).
- Changed rmc-rustc to inject the rmc prelude as part of the compilation
  as well as other rmc configuration flags.
- Added options to rmc-rustc to print binary path and flags so it can be
  used in other scripts.

* Add a script to build rmc library

* Update tests to use new injected prelude.
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.

Have a crate for RMC prelude instead of using an include macro

4 participants