Skip to content

Fix drop of Wrapper<dyn T> and fix unsized cast too - #1981

Merged
celinval merged 8 commits into
model-checking:mainfrom
celinval:issue-426-drop
Dec 13, 2022
Merged

celinval merged 8 commits into
model-checking:mainfrom
celinval:issue-426-drop

Conversation

@celinval

Copy link
Copy Markdown
Contributor

Description of changes:

Fix direct call to drop a fat pointer to a structure with an unsized element. Join similar code that we had to build a reference to a place.

Resolved issues:

Resolves #426

Related RFC:

Call-outs:

While inspecting the code, I realized that we were probably not handling slice correctly. The test I added also uncovered an issue with unsized cast, which I also fixed here.

Testing:

  • How is this change tested? New test + fixme 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.

  - TODO: Check if we need to handle slice.
I also joined the code to handle referencing a place.
@celinval
celinval requested a review from a team as a code owner December 10, 2022 00:50
@celinval celinval changed the title Fix drop of Wrapper<[T]> and fix unsized cast too Fix drop of Wrapper<dyn T> and fix unsized cast too Dec 10, 2022
Comment on lines +586 to +592
let data = if proj_expr.typ().is_pointer() {
proj_expr
} else if proj_expr.typ().is_array_like() {
proj_expr.array_to_ptr()
} else {
proj_expr.address_of()
};

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 happen often enough it could use a utility fn?

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 haven't bumped into it in other places yet but I can still move this to a utility function.

Comment on lines +1059 to +1065
let src_pointee_ty = pointee_type(coerce_info.src_ty).unwrap();
let dst_data_expr = if src_pointee_ty.is_array() {
src_goto_expr.cast_to(self.codegen_ty(*src_elt_type).to_pointer())
} else {
// A struct that contains the type being coerced to a slice.
src_goto_expr.cast_to(dst_data_type)
};

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.

A comment explaining this using C like pseudocode might make it easier to follow

Stmt::skip(loc)
}
InstanceDef::DropGlue(_def_id, Some(_)) => {
let place_ref = self.codegen_place_ref(place);

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.

nice

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

Fix drop type checking for nested Arc/Mutex objects

3 participants