8000 [OM] Use custom CAPI wrappers for Object. by mikeurbach · Pull Request #5275 · llvm/circt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[OM] Use custom CAPI wrappers for Object. #5275

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

Merged
merged 2 commits into from
May 30, 2023

Conversation

mikeurbach
Copy link
Contributor

This adds custom CAPI wrap and unwrap functionality for Object to better align with the std::shared_ptr functionality. Object now enables the shared_from_this functionality, which allows the unwrap function to more seamlessly create shared pointers to the Object with the appropriate reference count. Similarly, the wrap functionality is updated to always allocate new shared pointers, to ensure reference counts are incremented appropriately. This was done at the instantiate API previously, but is now handled generically whenever an Object is wrapped.

These changes are required to avoid double frees of Objects in general. A test case has been added that demonstrated the faulty behavior, which now succeeds.

This adds custom CAPI wrap and unwrap functionality for Object to
better align with the std::shared_ptr functionality. Object now
enables the shared_from_this functionality, which allows the unwrap
function to more seamlessly create shared pointers to the Object with
the appropriate reference count. Similarly, the wrap functionality is
updated to always allocate new shared pointers, to ensure reference
counts are incremented appropriately. This was done at the instantiate
API previously, but is now handled generically whenever an Object is
wrapped.

These changes are required to avoid double frees of Objects in
general. A test case has been added that demonstrated the faulty
behavior, which now succeeds.
@mikeurbach mikeurbach requested review from prithayan and uenoku May 26, 2023 04:47
mikeurbach added a commit that referenced this pull request May 26, 2023
This adds support for Objects in the Fields of other Objects. This is
handled in the pure Python layer of the Evaluator API, which is
enhanced to support recursively instantiating Objects. The
functionality for creating a dataclass instance from an instantiated
Object is factored out into a new helper. In the case an Object field
is itself an Object, the new helper is called recursively with the
child dataclass and the child Object.

A simple integration test for this behavior is added.

This uncovered undefined behavior in the previous use of shared
pointers, so this patch depends on PR #5275.
Copy link
Member
@uenoku uenoku left a comment

Choose a reason for hiding this comment

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

LGTM. Nice improvement!

Copy link
Member
@uenoku uenoku left a comment

Choose a reason for hiding this comment

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

LGTM. Nice improvement!

@mikeurbach mikeurbach merged commit a02644a into main May 30, 2023
@mikeurbach mikeurbach deleted the mikeurbach/om-dialect-capi-object-wrappers branch May 30, 2023 16:28
mikeurbach added a commit that referenced this pull request May 30, 2023
This adds support for Objects in the Fields of other Objects. This is
handled in the pure Python layer of the Evaluator API, which is
enhanced to support recursively instantiating Objects. The
functionality for creating a dataclass instance from an instantiated
Object is factored out into a new helper. In the case an Object field
is itself an Object, the new helper is called recursively with the
child dataclass and the child Object.

A simple integration test for this behavior is added.

This uncovered undefined behavior in the previous use of shared
pointers, so this patch depends on PR #5275.
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.

2 participants
0