RFR: 7903209: Handle lifecycle of libclang abstractions more explicitly [v2]
Athijegannathan Sundararajan
sundar at openjdk.org
Fri Jul 1 12:52:59 UTC 2022
On Fri, 1 Jul 2022 12:33:41 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> This patch clarifies the lifecycle of the entities generated by jextract. The main changes are two:
>>
>> 1. First, instead of "buffering" cursors in the `Cursor.children` method, so that a `Stream` can be returned, it instead accepts an action which will be executed for each visited cursor. This allows us to get rid of the buffering code, but at the same time it means that the downstream code has to be careful: any attempt to cache the cursor into a field, and access it _after_ the visitor has completed wil result in issues.
>>
>> 2. Secondly, it replaces uses of implicit session and implicit allocator almost everywhere. There are two main lifecycle entities: index and translation unit (there are others too, but these are the main ones). Translation units are created inside an index lifetime, whereas cursors and types are created inside the translation unit lifetime. This patch makes this organization clear, by adding a new type called `ClangDisposable`, an entity that has a session, and an associated arena allocator - and an `Owned` an entity that is owned by some `ClangDisposable` (and so it can use its arena to perform allocation). This scheme is relatively simple, but at the same time quite expressive, and helps keeping the complexity in check.
>>
>> As a result, most of the allocation now occurs in a confined scope, with clear lifetime boundaries. Any attemp to access e.g. a cursor after its translation unit is gone will result in an exception. I believe this can be quite useful to catch latent lifecycle issues in the code (I already fixed a few when working on this patch).
>
> Maurizio Cimadamore has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains seven additional commits since the last revision:
>
> - Merge branch 'master' into cursor_visit_nocopy
> - Fix whitespaces
> - Remove IMPLICIT_ALLOCATOR constant, so that we don't accidentally depend on it
> - Add copyright
> - Various cleanups
> Added more doc
> - Add explicit management of libclang abstractions lifetime
> - Initial push
LGTM
-------------
Marked as reviewed by sundar (Committer).
PR: https://git.openjdk.org/jextract/pull/48
More information about the jextract-dev
mailing list