Skip to content

[cling] Unload implicit instantiations also from ASTFile#21043

Draft
hahnjo wants to merge 1 commit intoroot-project:masterfrom
hahnjo:cling-unload-implicit-instantiation
Draft

[cling] Unload implicit instantiations also from ASTFile#21043
hahnjo wants to merge 1 commit intoroot-project:masterfrom
hahnjo:cling-unload-implicit-instantiation

Conversation

@hahnjo
Copy link
Copy Markdown
Member

@hahnjo hahnjo commented Jan 27, 2026

The assumption is that serialized declarations must be valid, however that doesn't hold anymore in the presence of static_assert in templated classes.

Fixes #20638

@hahnjo hahnjo self-assigned this Jan 27, 2026
@hahnjo hahnjo requested a review from dpiparo as a code owner January 27, 2026 12:32
if (D->isFromASTFile()) {
// We cannot ignore instantiated CXXMethodDecl's in templated classes:
// They may have failing static_assert.
if (auto* M = dyn_cast<CXXMethodDecl>(D)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is that change sufficient for these things to be reinstantiated? In particular, non-static_assert method decls coming from ast files? We should probably add some tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could be relatively easy, right? If I understand correctly we need a template broghut into memory from a pcm and then 2 instantiations in a row - please correct me if I am wrong.
If the above is correct, and this cannot be put in cling since we need a dictionary, we can comfortably put the test in roottest, maybe even profiting from ROOT helpers that at runtime allow us to generate dictionaries on the fly

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, Dev has a test case (in roottest) for the problem I'm trying to solve. We don't have a (new) test for an unloaded method that does not have a static_assert (I believe that's what Vassil is asking about). It's probably covered by other tests, but I need to check. Moreover there are two failing tests (roottest-cling-reload-reloadvector and roottest-root-tree-selector-selector) that I don't have locally...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, having tests in cling is better because when we break this it's far easier to debug. The test does not need a dictionary. We need a module file with a static assert declaration.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We don't have a single test using modules / pcm's in interpreter/cling/test and I'm not going to invent the infrastructure for this PR. The test is going to go into roottest.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for being constructive. In that case please hold off merging this PR until I provide you with the infrastructure (which is 3 lines).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In fact the infrastructure seems to be there already. Please take a look at cling/test/CodeUnloading/PCH/. We should be able to extend some of these tests to cover that case, too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added a Cling test that is fixed by the change. I also had a quick look at roottest-root-tree-selector-selector and it seems that one is failing because it cannot resolve _ZNKSt13__atomic_baseIhEcvhEv = std::__atomic_base<unsigned char>::operator unsigned char() and some related methods. It's probably now unloaded because of previous errors, but not correctly re-instantiated?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, because the ASTReader has a cache of deserialized declarations. Maybe some parts are in that cache?

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 27, 2026

Test Results

    22 files      22 suites   3d 20h 24m 32s ⏱️
 3 778 tests  3 775 ✅ 0 💤 3 ❌
75 141 runs  75 132 ✅ 0 💤 9 ❌

For more details on these failures, see this check.

Results for commit 1bad32b.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Member

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

This PR needs the appropriate test in cling. I will provide the infrastructure in the next week or so.

@hahnjo hahnjo marked this pull request as draft January 28, 2026 09:39
The assumption is that serialized declarations must be valid, however
that doesn't hold anymore in the presence of static_assert in templated
classes.

Fixes root-project#20638
@hahnjo hahnjo force-pushed the cling-unload-implicit-instantiation branch from f83ce07 to 1bad32b Compare February 3, 2026 12:21
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.

[cling] Able to call function with failing static_assert on second try

3 participants