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

[cling] DeclUnloader: fix unloading of member functions of templated classes #13565

Merged

Conversation

jalopezg-git
Copy link
Collaborator

@jalopezg-git jalopezg-git commented Aug 29, 2023

This pull request fixes the unloading of member functions of templated classes.

Specifically, the body of member functions of a templated class only gets instantiated when the function is first used, e.g. in this example below, the body for the member function T f(T x) (where T is a typename template argument for the templated struct Foo) will not get instantiated until f() is first used.

`-ClassTemplateDecl
  |-TemplateTypeParmDecl referenced typename depth 0 index 0 T
  |-CXXRecordDecl struct Foo definition
  | |-DefinitionData
  | `-CXXMethodDecl f 'T (T)'
  |   |-ParmVarDecl 0x55e5787cac70 referenced x 'T'
  |   `-CompoundStmt
  |     `-ReturnStmt
  |       `-DeclRefExpr 'T' lvalue ParmVar 0x55e5787cac70 'x' 'T'
  `-ClassTemplateSpecializationDecl struct Foo definition
    |-DefinitionData
    |-TemplateArgument type 'int'
    | `-BuiltinType 'int'
    |-CXXMethodDecl f 'int (int)'    <<<< Instantiation pending
    | `-ParmVarDecl x 'int':'int'
    |-CXXConstructorDecl implicit used constexpr Foo 'void () noexcept' inline default trivial

Such functions should not be deleted from the AST, but returned to the 'pending instantiation' state.

Also, any function template instantiation, even if coming from an external AST source, needs some handling in order for it to be re-emitted the next time.

Changes or fixes:

  • Replace StaticVarCollector by simpler code. Static local variables always appear in the enclosing DeclContext
  • Apply the patch described above.

Checklist:

  • tested changes locally
  • updated the docs (if necessary)
  • Passes cling test suite

This PR fixes #10049, #6439, #7970, ROOT-10848 and ROOT-8084 and (hopefully also ROOT-8245).

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac11/noimt, mac12arm/cxx20, windows10/default
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on windows10/default.
See console output.

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-ubuntu2004/python3.
Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Collaborator

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-performance-centos8-multicore/soversion.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Collaborator

Build failed on mac11/noimt.
Running on macphsft23.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Collaborator

Build failed on mac12arm/cxx20.
Running on 194.12.161.128:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@github-actions
Copy link

github-actions bot commented Aug 29, 2023

Test Results

       10 files         10 suites   1d 15h 31m 33s ⏱️
  2 483 tests   2 483 ✔️ 0 💤 0
23 757 runs  23 757 ✔️ 0 💤 0

Results for commit c224025.

♻️ This comment has been updated with latest results.

@jalopezg-git
Copy link
Collaborator Author

Build failed on mac12arm/cxx20. Running on 194.12.161.128:/Users/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

* [projectroot.test.test_stressinterpreter](https://lcgapp-services.cern.ch/root-jenkins/job/root-pullrequests-build/183553/testReport/projectroot/test/test_stressinterpreter/)

* [projectroot.roottest.root.meta.cmsUnload.roottest_root_meta_cmsUnload_make](https://lcgapp-services.cern.ch/root-jenkins/job/root-pullrequests-build/183553/testReport/projectroot.roottest.root.meta/cmsUnload/roottest_root_meta_cmsUnload_make/)

I'll check these failing tests in the next few days, but for the rest it should be ready for review.

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac11/noimt, mac12arm/cxx20, windows10/default
How to customize builds

@jalopezg-git
Copy link
Collaborator Author

This patchset should be ready now 🚀! @Axel-Naumann, @hahnjo, @vgvassilev Could you review when you have some spare time?

@phsft-bot
Copy link
Collaborator

Build failed on ROOT-ubuntu2204/nortcxxmod.
Running on root-ubuntu-2204-3.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Collaborator

Build failed on mac11/noimt.
Running on macphsft23.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@Axel-Naumann
Copy link
Member

Fantastic, thanks, @jalopezg-git ! Is the mac11 failure in stressInterpreter caused by this PR?

@jalopezg-git
Copy link
Collaborator Author

Fantastic, thanks, @jalopezg-git ! Is the mac11 failure in stressInterpreter caused by this PR?

Apparently, yes. Ugghh, that wasn't expected; all the other platforms seem to be happy now.

Any chance that I can still access one of these machines to debug the issue?

@pcanal
Copy link
Member

pcanal commented Sep 26, 2023

@phsft-bot build just on mac11/noimt

@phsft-bot
Copy link
Collaborator

Starting build on mac11/noimt
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on mac11/noimt.
Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@hahnjo
Copy link
Member

hahnjo commented Nov 22, 2023

For now, this is just a rebase of Javier's original changes. I think I have an idea what could be wrong, but I first want to have a clean set of reports from Jenkins and the new CI. In any case, I'll try to take care of this PR now because it seems required for some recent progress I'm making regarding #13815, in turn blocking the upgrade to LLVM 16.

@phsft-bot
Copy link
Collaborator

Build failed on mac12arm/cxx20.
Running on 194.12.161.128:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

jalopezg-git and others added 3 commits November 24, 2023 11:13
StaticVarCollector recursively visited descendants of a `FunctionDecl`
node to collect static local variables.  However, these always appear
in the enclosing DeclContext.
The body of member functions of a templated class only gets instantiated
when the function is used.  These `CXXMethodDecl` should not be deleted
from the AST; instead return them to the 'instantiation pending' state.
This effectively reverts commit 74472ca ("[cling] Fixes issue in
DeclUnloader: do not unload templates intantiated in the PCH"), it's
not needed anymore, all tests pass and the snippet in the summary of
root-project#4447 works, but it filters
too many declarations from the unloader.
@hahnjo hahnjo force-pushed the cling-DeclUnloader-fix-memberfunc branch from 0089635 to c224025 Compare November 24, 2023 14:12
@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@jalopezg-git
Copy link
Collaborator Author

For now, this is just a rebase of Javier's original changes. I think I have an idea what could be wrong, but I first want to have a clean set of reports from Jenkins and the new CI. In any case, I'll try to take care of this PR now because it seems required for some recent progress I'm making regarding #13815, in turn blocking the upgrade to LLVM 16.

Great! Let's give this a push 🙂!

@hahnjo
Copy link
Member

hahnjo commented Nov 24, 2023

So it wasn't what I initially thought, but it seems to work now on all platforms (except the spurious failure on Windows).

@hahnjo hahnjo mentioned this pull request Nov 25, 2023
23 tasks
Copy link
Member

@hahnjo hahnjo left a comment

Choose a reason for hiding this comment

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

I'm accepting this pro-forma, Javier's changes look good to me and my additional commit is a continuation of that work. All tests pass and check-cling stays clean (on my EL8 at least). If others want more time to review this, please comment!

Copy link
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.

LGTM!

@jalopezg-git
Copy link
Collaborator Author

jalopezg-git commented Nov 29, 2023

Awesome! @Axel-Naumann, @hahnjo, I'll let you decide when to click merge 🙂!

@hahnjo hahnjo merged commit 1c3ea0a into root-project:master Nov 30, 2023
14 of 16 checks passed
@jalopezg-git jalopezg-git deleted the cling-DeclUnloader-fix-memberfunc branch December 1, 2023 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[cling] A failed compilation unloads more decls than strictly neccesary
6 participants