Skip to content

Fix generator layout and sizes#1607

Merged
fzaiser merged 5 commits intomodel-checking:mainfrom
fzaiser:fix-generator-layout
Aug 30, 2022
Merged

Fix generator layout and sizes#1607
fzaiser merged 5 commits intomodel-checking:mainfrom
fzaiser:fix-generator-layout

Conversation

@fzaiser
Copy link
Contributor

@fzaiser fzaiser commented Aug 30, 2022

Description of changes:

This PR fixes a bug in how Kani lays out generators. Previously, Kani got some offsets (and as a consequence, the size) wrong sometimes.

In the process, @celinval also discovered that the size of a generator may depend on the panic strategy, which explains the discrepancy of the sizes in #1395. This issue is resolved here as well.

Resolved issues:

Resolves #1395
Resolves #1593

Testing:

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.

@fzaiser fzaiser requested a review from a team as a code owner August 30, 2022 19:26
($which: ident) => {{
let tp_ty = instance.substs.type_at(0);
if tp_ty.is_generator() {
let e = self.codegen_unimplemented_expr(
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this previously missed because sitting inside a macro made it hard to find references? Just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the macro had no effect on this as far as I can tell.

name: field_name,
typ: ctx.codegen_ty(field_ty),
});
offset += field_size;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the core of the fix right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that was the bug.

// But it also fails for WASM (https://github.com/rust-lang/rust/issues/62807),
// so it is probably not a big problem:
assert_eq!(1026, std::mem::size_of_val(&move_before_yield_with_noop()));
// With panic=unwind, the following assertion passes:
Copy link
Contributor

Choose a reason for hiding this comment

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

Please improve this doc. Maybe add as a document of the harness itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

typ: ctx.codegen_ty(field_ty),
});
offset += field_size;
offset = field_offset + field_size;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a comment here? You really only care about the last field, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What kind of comment do you mean? We also use the offset earlier to figure out how much padding to insert before a field.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. That's fine, thanks

Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks

@fzaiser fzaiser merged commit 281d0bb into model-checking:main Aug 30, 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.

Assertion failure in check_vtable_size Difference in size of generators between rustc (with panic=unwind!) and Kani

4 participants