Skip to content

Correctly handle assert_* intrinsics - #742

Merged
adpaco merged 1 commit into
model-checking:mainfrom
adpaco:assert-intrinsics
Jan 19, 2022
Merged

adpaco merged 1 commit into
model-checking:mainfrom
adpaco:assert-intrinsics

Conversation

@adpaco

@adpaco adpaco commented Jan 11, 2022

Copy link
Copy Markdown
Contributor

Description of changes:

Adds support for the assert_uninit and assert_zero intrinsics. Inserts the code for them and assert_inhabited into a single function.

Resolved issues:

Resolves #6
Resolves #7

Call-outs:

  • All backends check the condition for assert_inhabited first, then proceed to do the other ones. This proposal follows the same pattern.
  • The actual error for assert_inhabited (i.e., in src/test/rmc/Intrinsics/Assert/inhabited_panic.rs) is
[main.assertion.1] line 13 a panicking function std::mem::MaybeUninit::<T>::assume_init is invoked: FAILURE

This is due to the Nevers hook being applied instead of the Intrinsics one. I have tried doing some changes to the application condition (for example, return false if the instance is an intrinsic) to no success (ended up in some code that expected the Nevers hook to have applied).

  • Some reorganization in tests. The top level folder Assert now contains the multiple assertions test only, and another Assert folder has been created within Intrinsics to keep the tests related to the intrinsics in this PR.

Testing:

  • How is this change tested? Existing regression + 3 new tests + 1 removed test.

  • 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.

@adpaco
adpaco requested a review from a team as a code owner January 11, 2022 22:44
@adpaco

adpaco commented Jan 12, 2022

Copy link
Copy Markdown
Contributor Author

@zhassan-aws brought #648 to my attention, thanks!!

Removing/Changing output_of_instance_is_never seems the way to go, but it appears that our backend relies on it in a few places so I do not think it will be trivial. I could create a tracking issue for the inhabited.rs test and come back to check once the change has taken place.

@danielsn danielsn left a comment

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.

The tests I see are for primitive types. Would it make sense to also ensure that we do the right thing for enums and structs?

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.

Reference to rust documentation 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.

Added links to rust docs.

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 a spec we can point to 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 was not able to find one as documentation regarding these intrinsics is quite hard to find.

The closest thing I could find is the actual implementation in rustc_codegen_ssa/src/mir/block.rs (codegen_panic_intrinsic) in addition to PR discussions. But if you know of one I will be happy to add it here.

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.

FWIW, I think links directly to code serve as a reasonable reference, too. Maybe add that as a comment? (e.g. link directly to it on github?)

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.

My main concern with that is that links to rustc code may become outdated pretty quickly. But even that is better that no links, so just added a note here linking to that function.

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 a spec we can point to 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.

See above.

Comment on lines 8 to 10

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.

Do we have a tracking issue for this?

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.

Created #751 which I linked here.

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.

Should we also have a test with an expected pass (e.g. zero initializing a u8)?

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.

The test in src/test/rmc/Intrinsics/Assert/zero_valid.rs (path updated in this PR) already does this for several types, including a user-defined struct.

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.

FWIW, I think links directly to code serve as a reasonable reference, too. Maybe add that as a comment? (e.g. link directly to it on github?)

@adpaco
adpaco force-pushed the assert-intrinsics branch from 5cc5515 to e20525f Compare January 18, 2022 22:32
@adpaco
adpaco force-pushed the assert-intrinsics branch from e20525f to 797ecc3 Compare January 18, 2022 22:37
@adpaco
adpaco merged commit b1396f2 into model-checking:main Jan 19, 2022
@adpaco adpaco mentioned this pull request Jan 19, 2022
tedinski pushed a commit to tedinski/rmc that referenced this pull request Apr 26, 2022
tedinski pushed a commit that referenced this pull request Apr 27, 2022
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.

Implement intrinsic assert_zero_valid Implement intrinsic assert_uninit_valid

3 participants