Skip to content

Fix drop for Struct<dyn T> - #1975

Merged
celinval merged 4 commits into
model-checking:mainfrom
celinval:issue-1072-drop-dyn
Dec 9, 2022
Merged

celinval merged 4 commits into
model-checking:mainfrom
celinval:issue-1072-drop-dyn

Conversation

@celinval

@celinval celinval commented Dec 8, 2022

Copy link
Copy Markdown
Contributor

Description of changes:

We were incorrectly using the data pointer of the fat pointer to invoke the drop. Use the expression returned by the projection code instead.

Another issue was that we were incorrectly generating the wrong vtable function signature.

Resolved issues:

Resolves #1072

Related RFC:

Call-outs:

This does not fix #426. This is yet another problem that we currently have where I believe we are misusing fat pointers.

Testing:

  • How is this change tested?

  • Is this a refactor change?

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.

We were incorrectly using the data pointer of the fat pointer to invoke
the drop. Use the expression returned by the projection code instead.
@celinval
celinval requested a review from a team as a code owner December 8, 2022 00:45

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

Looks great, one comment

debug!(?projection, "codegen_drop");
// The data comes from the projection.
let self_ref =
if place_ty != pointee_type(self.local_ty(place.local)).unwrap() {

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 check seems to look for a symptom, not the underlying cause. Is there a better check to use 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 improve the check. No problem!

Comment thread tests/kani/Drop/dyn_struct_member.rs Outdated
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

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.

Apache-2.0 OR MIT

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 suspect that or regression is not correctly checking all files. This file is already in our repo. 😒

@celinval
celinval merged commit ea18901 into model-checking:main Dec 9, 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.

Kani implementation of drop for Struct<dyn T> is broken Fix drop type checking for nested Arc/Mutex objects

2 participants