Skip to content
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

C++: First-class destructors in AST and IR #15318

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rdmarsh2
Copy link
Contributor

This PR adds a new getSyntheticDestructor predicate to Stmt and Expr, and adds destructors to the IR. Currently only the Stmt relation is populated by the extractor.

@github-actions github-actions bot added the C++ label Jan 12, 2024
Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

I started reviewing this before I noticed it was a draft. Sorry! Feel free to ignore my comments if you're still working all these things out 😄

Comment on lines +61 to +64
/**
* Gets the `n`th compiler-generated destructor call that is performed after this expression, in
* order of destruction.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be good to have an example here (specifically, for when there are multiple destructors attached to an element).

* Gets the `n`th compiler-generated destructor call that is performed after this expression, in
* order of destruction.
*/
DestructorCall getSyntheticDestructor(int n) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we avoid using the term "synthetic" in the public API? I don't actually know why the relational is using this term, because I don't think there's anything more "synthetic" about these destructor calls than other things in the AST

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe getImplicitDestructor instead?

Comment on lines 24 to 30
result = expr.getParentWithConversions()
or
result.(Destructor).getADestruction() = expr
or
result.(Expr).getASyntheticDestructor() = expr
or
result.(Stmt).getASyntheticDestructor() = expr
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it ever the case that an expr has multiple parents with these new cases included?

Comment on lines 753 to 756
(
call instanceof ConstructorCall or
call instanceof DestructorCall
) and
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment above here is no longer correct, right? i.e., this part:

// Don't bother with destructor calls for now, since we won't see very many of them in the IR
// until we start injecting implicit destructor calls.

@rdmarsh2 rdmarsh2 force-pushed the rdmarsh2/cpp/first-class-destructors branch from 99b4e63 to 278b22c Compare January 19, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants