-
Notifications
You must be signed in to change notification settings - Fork 748
Destructor codegen #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Destructor codegen #608
Conversation
r? @fitzgen |
6190617
to
afacb8d
Compare
Hm... So this still fails for 3.8. The reason for that is that the symbol produced is for the D0 destructor group, instead of D1. We definitely want the D1 group, so I'm going to change the symbol manually to point to the correct one. See http://stackoverflow.com/questions/6613870/gnu-gcc-g-why-does-it-generate-multiple-dtors/6614369#6614369 for a quick description of the problem. |
Added a commit that should fix that. |
3c8dafb
to
f5188a6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet! Thanks!
Before landing, please:
-
add tests for when we're explicitly not generating ctors and dtors
-
squash to preserve bisect-ability, since tests started failing in the middle of the commit series
Thanks again!
src/ir/comp.rs
Outdated
@@ -434,6 +445,11 @@ impl CompInfo { | |||
&self.constructors | |||
} | |||
|
|||
/// Get this type's destructor. | |||
pub fn destructor(&self) -> &Option<ItemId> { | |||
&self.destructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any reason to avoid copies here; it'll just make using this slightly more annoying. Instead we should do:
pub fn destructor(&self) -> Option<ItemId> {
self.destructor
}
since Option<T>
is Copy
if T
is Copy
.
@@ -0,0 +1,6 @@ | |||
// bindgen-flags: --generate types,constructors,functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also test when we are not generating constructors.
src/ir/comp.rs
Outdated
@@ -446,8 +451,8 @@ impl CompInfo { | |||
} | |||
|
|||
/// Get this type's destructor. | |||
pub fn destructor(&self) -> &Option<ItemId> { | |||
&self.destructor | |||
pub fn destructor(&self) -> Option<(bool, ItemId)> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That bool
is a little gross. As a calller of this API, now I have to remember wait does true
mean virtual or not? Why not reuse MethodKind
here?
Also, the doc comment should be updated to describe the extra information exposed.
// Add a suffix to avoid colliding with constructors. This would be | ||
// technically fine (since we handle duplicated functions/methods), | ||
// but seems easy enough to handle it here. | ||
name.push_str("_destructor"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We definitely don't want to allow bindings users to mix up overloaded constructors and destructors!
@@ -0,0 +1,7 @@ | |||
// bindgen-flags: --generate types,destructors,functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, we should also test not generating destructors.
@@ -21,6 +21,15 @@ Test::Test(double foo) | |||
, m_double(foo) | |||
{} | |||
|
|||
AutoRestoreBool::AutoRestoreBool(bool* ptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding an integration test!
// | ||
// FIXME(emilio): Can a legit symbol in other ABIs end with this string? | ||
// I don't think so, but if it can this would become a linker error | ||
// anyway, not an invalid free at runtime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With weak symbols it could be a runtime error (I'm dealing with this in the SM bindings + mozglue and it is so frustrating), but still memory safe.
This only applies to the Itanium C++ ABI, which pretty much means not windows, so we could if !cfg!(target_os = "windows") { ... }
all this stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we could parse the symbol (using my cpp_demangle
crate) and check if it is the a deleting destructor or not.
https://docs.rs/cpp_demangle/0.2.1/cpp_demangle/ast/enum.CtorDtorName.html
I would just need to expose a getter for a parsed symbol's AST.
How formal and proper do we want to make these hacks? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem of cfg!
checks is basically #593, so I'd prefer to remove the existing ones instead of adding newer ones.
f5188a6
to
0dc7bcd
Compare
Instead of squashing, I moved the symbol hack to the beginning of the PR (GitHub stills shows it chronologically, which sucks, but it's the parent of all-but-the-first commit). That should preserve bisectability. I've left a note about @bors-servo r=fitzgen |
📌 Commit 1f53966 has been approved by |
☀️ Test successful - status-travis |
Based on #542, and on top of #606, with a bunch more tests and fixes.