-
Notifications
You must be signed in to change notification settings - Fork 64
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
[root6] Fix missing declarations in the code interpreted by Cling #451
Conversation
[snip]
In principle, the BFC.C macro is compiled by cling. So I would expect that any macro which is loaded at a later point would be able to access a global variable that it declares. But ... this is not the first place where my expectations about cling fail. StRoot/macros/bfc.C line 32 should be changed to |
If by "compiled" you mean the JIT compilation by clang, it is still should be considered as interpretation of the code although an enhanced one. I would stick to the term because that is how they use it in early Cling presentations as opposed to "normal" external compilation or via ACLiC.
I would think so too. But in this case a macro (Geometry.blah.C) is interpreted in a compiled library (libStBFChain.so) which in turn is loaded from an interpreted macro (bfc.C). Not sure though if an extra layer of indirection plays any role here... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chain
is the handle assigned to a local variable within code in StBFChain.cxx, so I'm not happy with assigning that handle to a global variable.
Could you point to the code where such assignment take place? |
Roughly 15 lines below where you've inserted the global assignment. |
This line in the original file? star-sw/StRoot/StBFChain/StBFChain.cxx Line 59 in 0c5edf5
I don't think there is a conflict from the language point of view between the global and the local variables in this case, and I also don't see any compiler warning messages... But let's rename the local variable to avoid any confusion. How does that sound? |
The compiler may differentiate local vs. global as the local interpretation gets priority at compile time. But it is good to avoid potentially confusing human code readers :-) I don't have strong feelings about whether the global or local variable should retain the handle |
Well because the "new" one is not really new :) It is essentially re-declaration of the global variable defined in the Line 32 in 827a627
We can't rename it because other codes using it (e.g. the Geometry macros) expect this variable to be the global pointer to the current chain. So, to avoid confusing humans renaming the local variable is the easiest option. Just to reiterate, the reason why we move the declaration from the macro to the library is that Cling cannot see it in another macro loaded/interpreted at runtime. Formally declaring |
This suggestion was tried in 64b449d but the jobs (ROOT5, gcc 4.8.5) fail with the following error:
I am reverting the change. Any more suggestions or shall we merge? |
Since this looks like a cint bug, how about we put |
Fine by me but I think |
#if defined(__CLING__) || !defined(__CINT__)
extern
#endif
StBFChain* chain; |
a192a94
to
cb7c25d
Compare
Unlike `rootcint` `rootcling` needs to see explicit definitions of the types used in an interpreted code. ``` LoadTable: .L /star-sw/StarDb/AgMLGeometry/Geometry.y2021a.C In file included from input_line_732:1: In file included from /star-sw/StarDb/AgMLGeometry/Geometry.y2021a.C:2: /star-sw/StarDb/AgMLGeometry/CreateGeometry.h:10:8: error: use of undeclared identifier 'gGeoManager' if ( gGeoManager ) { ^ /star-sw/StarDb/AgMLGeometry/CreateGeometry.h:11:56: error: use of undeclared identifier 'gGeoManager' cout << "AgML geometry: Existing TGeoManager " << gGeoManager->GetName() ^ /star-sw/StarDb/AgMLGeometry/CreateGeometry.h:36:7: error: use of undeclared identifier 'gGeoManager' gGeoManager = 0; ^ /star-sw/StarDb/AgMLGeometry/CreateGeometry.h:38:7: error: incomplete type 'TGeoManager' named in nested name specifier TGeoManager::Import( filename ); ^~~~~~~~~~~~~ ``` We also hide the included code from the ROOT5 interpreter because it utilizes C++11 features
It appears that the ROOT6 interpreter prefers to see the declaration of the main StBFChain in the compiled code over the one in the `bfc.C` macro: ``` LoadTable: .L /star-sw/StarDb/AgMLGeometry/Geometry.y2021a.C IncrementalExecutor::executeFunction: symbol 'chain' unresolved while linking [cling interface function]! root4star: .sl79_gcc485/OBJ/StRoot/St_db_Maker/St_db_Maker.cxx:934: virtual TDataSet* St_db_Maker::LoadTable(TDataSet*): Assertion `!ee' failed. ``` Could it be that global variables in interpreted code are not visible in other interpreted scripts? Hide valid and appropriate C++ code from ROOT5 interpreter
cb7c25d
to
8d88050
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
If there are no further comments let's merge this pull request |
This should have been a part of #448 as the changes are closely related but unfortunately that PR was merged before I had a chance to update it.
A couple of issues seen in the ROOT6 CI tests are taken care of:
Include missing definitions when interpreting AgMLGeometry. Unlike
rootcint
,rootcling
needs to see explicit definitions of the types used in an interpreted code.StBFChain: Declare global pointer to
chain
in compiled code. It appears that the ROOT6 interpreter prefers to see the declaration of the main StBFChain in the compiled code over the one in thebfc.C
macro.Could it be that global variables in interpreted code are not visible in other interpreted scripts?
From the C++ point of view, the error actually makes sense because of the
extern StBFChain* chain;
statement inStarDb/AgMLGeometry/CreateGeometry.h
As suggested during the review, local variables were renamed to avoid confusion with global name
chain