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

Dictionary loading, RootMap forward declarations failed #30

Open
hexomethyl opened this issue Dec 19, 2024 · 29 comments
Open

Dictionary loading, RootMap forward declarations failed #30

hexomethyl opened this issue Dec 19, 2024 · 29 comments

Comments

@hexomethyl
Copy link

hexomethyl commented Dec 19, 2024

Hey,

I'm attempting to load my shared library and rootmap, however I get cling::Interpreter::kFailure when [libCling.so] CppyyLegacy::TCling::LoadLibraryMap attempts to declare the forward declarations from the *.rootmap file.

I'll be honest, I don't really understand whats happening here, my goal is move away for loading header files at startup as this takes around 30-60 seconds, I was hoping that using the dictionary will speed things up. Do I even need a LinkDef.h file ?, it just contains #pragma link C++ defined_in statements for every header in TARGET_INTERFACE_HEADERS anyway.

My call to root is as follows
image

[libCling.so] CppyyLegacy::TCling::LoadLibraryMap TCling.cxx:5330
image

uniqueString: #line 1 "Forward declarations from ./libalgorithms.rootmap" namespace deep_learning { }namespace signals { namespace clustering { } }namespace statistics { namespace distributions { namespace distance { } } }namespace tracking { namespace data_streams { } }namespace common { }namespace common { template <typename T> class TypedColumn; }namespace common { template <typename T> class TypedColumnView; }namespace tracking { namespace modelling { namespace spatial { } } }namespace tracking { namespace modelling { } }namespace gating { }namespace signals { }namespace signals { namespace kalman { } }namespace signals { namespace classification { namespace generic { } } }namespace signals { namespace classification { namespace beam { } } }namespace profiling { namespace metadata { } }namespace tracking { namespace metadata { } }namespace statistics { }namespace assignment { }template <const char*, typename RecordType> class Streamable;template <> class Streamable<tracking::data_streams::best_estimates,std::vector<utils::StrongId<unsigned long,data_aggregator::EntityIdTag>,std::pmr::polymorphic_allocator<utils::StrongId<unsigned long,data_aggregator::EntityIdTag>>>>;namespace tracking { namespace data_records { } }namespace tracking { namespace data_records { class Hypothesis; } }template <> class Streamable<tracking::data_streams::hypotheses,tracking::data_records::Hypothesis>;namespace tracking { namespace data_records { class MatchingScores; } }template <> class Streamable<tracking::data_streams::matching_scores,tracking::data_records::MatchingScores>;namespace tracking { namespace data_records { class Measurement; } }template <> class Streamable<tracking::data_streams::measurements,tracking::data_records::Measurement>;namespace tracking { namespace filter { } }namespace tracking { namespace filter { namespace local_hypothesis { } } } #line 1 "Forward declarations from /opt/project/core/algorithms/target/libalgorithms.rootmap"

@hexomethyl
Copy link
Author

hexomethyl commented Dec 19, 2024

Could it be this line ?
template <> class Streamable<tracking::data_streams::best_estimates,std::vector<utils::StrongId<unsigned long,data_aggregator::EntityIdTag>,std::pmr::polymorphic_allocator<utils::StrongId<unsigned long,data_aggregator::EntityIdTag>>>>;

This line depends on #include <vector> and #include <memory_resource>

@hexomethyl
Copy link
Author

Nevermind, the issue was the Streamable class specializations, as they aren't necessary I have removed them from my LinkDef.h.

@hexomethyl
Copy link
Author

I now seem to be failing in CppyyLegacy::ExecAutoParse, the following code fails on call to cr = interpreter->parseForModule(code);

This occurs after the shared library has been loaded into cppyy, and I attempt to access a class/namespace using cppyy.gbl.*

code

#line 1 "libmIalgorithms dictionary payload"

#ifndef SPDLOG_FMT_EXTERNAL
  #define SPDLOG_FMT_EXTERNAL 1
#endif
#ifndef SPDLOG_FMT_EXTERNAL
  #define SPDLOG_FMT_EXTERNAL 1
#endif
#ifndef USE_DISTRIBUTED
  #define USE_DISTRIBUTED 1
#endif
#ifndef USE_C10D_GLOO
  #define USE_C10D_GLOO 1
#endif
#ifndef USE_RPC
  #define USE_RPC 1
#endif
#ifndef USE_TENSORPIPE
  #define USE_TENSORPIPE 1
#endif
#ifndef USE_C10D_NCCL
  #define USE_C10D_NCCL 1
#endif
#ifndef TESTING
  #define TESTING true
#endif
#ifndef __PIC__
  #define __PIC__ 1
#endif

#define _BACKWARD_BACKWARD_WARNING_H
// Inline headers

[REDACTED_HEADERS]

#undef  _BACKWARD_BACKWARD_WARNING_H

The python stack trace

*** Break *** segmentation violation
Generating stack trace...
0x00007dee316e0520 in <unknown> from /usr/lib/x86_64-linux-gnu/libc.so.6
0x00007ded61bae7a4 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f10cbe6 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f10cdd3 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f1171bc in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f1175ff in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f1171bc in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f1175ff in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f0dc82c in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f0dcd96 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f0bd0bb in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f1536b7 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f15616a in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f0bb048 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5ee9e953 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5ee9f1b1 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5ee9f6e0 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5ee852f6 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5ee5f6c1 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f0c5498 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5fb76278 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded603e7667 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded603e7d99 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5fbd33cf in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f0cce2e in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5f0d55b8 in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5ee7b35b in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5ee7eebd in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007ded5eea4d6a in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libCling.so
0x00007dedd665fc72 in Cppyy::IsEnum(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x172 from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libcppyy_backend.so
0x00007dedd666bf00 in Cppyy::ResolveName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x3b0 from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libcppyy_backend.so
0x00007dedd666c64e in Cppyy::GetScope(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0xae from /opt/conda/envs/rapids/lib/python3.10/site-packages/cppyy_backend/lib/libcppyy_backend.so
0x00007ded7c7882ed in CPyCppyy::CreateScopeProxy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _object*, unsigned int) at ProxyWrappers.cxx:? from /opt/conda/envs/rapids/lib/python3.10/site-packages/libcppyy.cpython-310-x86_64-linux-gnu.so
0x00007ded7c732e4d in <unknown> from /opt/conda/envs/rapids/lib/python3.10/site-packages/libcppyy.cpython-310-x86_64-linux-gnu.so
0x000061523911dba8 in <unknown> from python
0x000061523911d934 in <unknown> from python
0x000061523910d892 in _PyEval_EvalFrameDefault + 0x332 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x000061523910dc95 in _PyEval_EvalFrameDefault + 0x735 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x000061523910dc95 in _PyEval_EvalFrameDefault + 0x735 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x000061523910d892 in _PyEval_EvalFrameDefault + 0x332 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x000061523911227d in _PyEval_EvalFrameDefault + 0x4d1d from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x000061523910dc95 in _PyEval_EvalFrameDefault + 0x735 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x000061523910dc95 in _PyEval_EvalFrameDefault + 0x735 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x000061523910dc95 in _PyEval_EvalFrameDefault + 0x735 from python
0x0000615239128fa1 in <unknown> from python
0x00006152391102d9 in _PyEval_EvalFrameDefault + 0x2d79 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x000061523910dc95 in _PyEval_EvalFrameDefault + 0x735 from python
0x0000615239128fa1 in <unknown> from python
0x000061523911a279 in <unknown> from python
0x0000615239239743 in <unknown> from python
0x000061523923962e in <unknown> from python
0x00006152392395c5 in <unknown> from python
0x0000615239114361 in _PyEval_EvalFrameDefault + 0x6e01 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x00006152391072b5 in <unknown> from python
0x00006152391137e3 in _PyEval_EvalFrameDefault + 0x6283 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x00006152391102d9 in _PyEval_EvalFrameDefault + 0x2d79 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x00006152391072b5 in <unknown> from python
0x00006152391137e3 in _PyEval_EvalFrameDefault + 0x6283 from python
0x0000615239128e41 in <unknown> from python
0x00006152391072b5 in <unknown> from python
0x00006152391137e3 in _PyEval_EvalFrameDefault + 0x6283 from python
0x0000615239128e41 in <unknown> from python
0x00006152391072b5 in <unknown> from python
0x0000615239113a7a in _PyEval_EvalFrameDefault + 0x651a from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x00006152391072b5 in <unknown> from python
0x0000615239113534 in _PyEval_EvalFrameDefault + 0x5fd4 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x00006152391072b5 in <unknown> from python
0x0000615239113436 in _PyEval_EvalFrameDefault + 0x5ed6 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x00006152391102d9 in _PyEval_EvalFrameDefault + 0x2d79 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x00006152391072b5 in <unknown> from python
0x00006152391137e3 in _PyEval_EvalFrameDefault + 0x6283 from python
0x0000615239128e41 in <unknown> from python
0x00006152391072b5 in <unknown> from python
0x00006152391137e3 in _PyEval_EvalFrameDefault + 0x6283 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x0000615239116135 in _PyObject_FastCallDictTstate + 0x185 from python
0x0000615239127509 in _PyObject_Call_Prepend + 0x69 from python
0x00006152391f0469 in <unknown> from python
0x0000615239116bdb in _PyObject_MakeTpCall + 0x26b from python
0x0000615239113a7a in _PyEval_EvalFrameDefault + 0x651a from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x00006152391072b5 in <unknown> from python
0x00006152391137e3 in _PyEval_EvalFrameDefault + 0x6283 from python
0x00006152391b5852 in <unknown> from python
0x00006152391b5797 in PyEval_EvalCode + 0x87 from python
0x00006152391bcde0 in <unknown> from python
0x000061523911d934 in <unknown> from python
0x00006152391072b5 in <unknown> from python
0x0000615239113436 in _PyEval_EvalFrameDefault + 0x5ed6 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x00006152391072b5 in <unknown> from python
0x00006152391137e3 in _PyEval_EvalFrameDefault + 0x6283 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x00006152391072b5 in <unknown> from python
0x0000615239113534 in _PyEval_EvalFrameDefault + 0x5fd4 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x000061523910dc95 in _PyEval_EvalFrameDefault + 0x735 from python
0x000061523911d73f in _PyFunction_Vectorcall + 0x6f from python
0x000061523910d892 in _PyEval_EvalFrameDefault + 0x332 from python
0x00006152391b5852 in <unknown> from python
0x00006152391b5797 in PyEval_EvalCode + 0x87 from python
0x00006152391e6eec in <unknown> from python
0x00006152391e1fa4 in <unknown> from python
0x00006152390759ed in <unknown> from python
0x00006152391dc1d5 in _PyRun_SimpleFileObject + 0x1b5 from python
0x00006152391dbd43 in _PyRun_AnyFileObject + 0x43 from python
0x00006152391d8eb9 in Py_RunMain + 0x399 from python
0x00006152391a7e09 in Py_BytesMain + 0x39 from python
*** Break *** segmentation violation

@wlav
Copy link
Owner

wlav commented Dec 19, 2024

Firstly, dictionaries may not give you the hoped for speed-up. Upstream has been touting modules for the longest time, but after never quite pulling it off (or getting the promised speed-up), they now tell me to change the scripts to allow adding headers to the PCH (you already can, it's just manual). A big problem with modules is that they have a custom version (for I/O and to be redistributable) rather than using the native Clang ones.

They have another trick up their sleeves: a parser that only picks up the declarations, not the definitions. That would be game changing. They say it's available, but I haven't seen it work.

Second, the dictonaries will still either contain references to headers to be parsed or the headers as strings (is an option, but doesn't work on Windows b/c it is has a size limit on literal strings). The only speedup that might be seen then, is that not everything is loaded at startup, with the class loader ensuring only loading what is actually used.

Third, what I really would like to see, is multiple interpreters and priority-based linkage. There's nothing stopping me from doing that already, just that the interpreter right now is coded upstream as a global variable.

As for the crash, there's no useful information in the stack trace. Probably deep inside Clang (which is linked statically into libCling.so). Are you using cppyy 3.5 already? (This is just released a few days ago and has LLVM16 as an upgrade over LLVM13 prior.)

@hexomethyl
Copy link
Author

Thanks for the info, I'll give Cppyy 3.5 a shot.

@hexomethyl
Copy link
Author

Using Cppyy 3.5 didn't resolve the issue, the issue seems to be within Clang like you said, do I still need to pass the include paths to Cppyy ?

[libCling.so] clang::DeclContext::removeDecl(clang::Decl *) 0x000074c309bae7a4
image

@wlav
Copy link
Owner

wlav commented Dec 19, 2024

Ouch. But I don't understand ... ExecAutoParse does not call removeDecl? I don't see any call to removeDecl in any of Cling's parsing functions. (It may be inlined from someplace that I missed.) Also, ExecAutoParse doesn't live in libCling, but in libCoreLegacy? The line numbers also don't match.

The include paths will be backed into the dictionary; just have to make sure they're relative (and you can add other search paths it as well).

@hexomethyl
Copy link
Author

hexomethyl commented Dec 19, 2024

The paths are not relative. is that the issue ?

EDIT: The root map file has relative headers, however the code string passed to ExecAutoParse contains headers with absolute paths

@wlav
Copy link
Owner

wlav commented Dec 19, 2024

Sounds good. The relative headers is purely to allow redistribution of binaries. Yes, they then got resolved, so makes sense that ExecAutoParse sees absolute paths.

@hexomethyl
Copy link
Author

Is there a full working example of creating a shared library, generating a dictionary and loading it into Cppyy ?, I feel like I'm missing something fundamental here.

@wlav
Copy link
Owner

wlav commented Dec 19, 2024

The docs has an example: https://cppyy.readthedocs.io/en/latest/utilities.html#dictionaries
The cmake interface uses rootcling: https://cppyy.readthedocs.io/en/latest/cmake_interface.html
The tests have both genreflex (Linux/Mac, see Makefile) and rootcling (Windows, see make_dict_win32.py) examples: https://github.com/wlav/cppyy/tree/master/test
Not developed for a while, but this is a basic repo with some alternative ideas: https://github.com/camillescott/cppyy-bbhash

Most of it is pretty simple/straightforward, though. There really shouldn't be all that much to it: it's a vehicle for putting everything (the headers, include paths, classes, as well as linking with any dependencies) in a single package. But in the end, it's still Cling parsing the same headers and loading the same libraries if done directly in Python code.

@hexomethyl
Copy link
Author

It seems it should "just work" which is a shame.
Is there anything I can do to debug this ?, it loads the shared library and rootmap file fine yet actually utilizing an object fails.

@hexomethyl
Copy link
Author

I managed to compile Clang and Cling as debug and managed to get the following stack trace

image

With the following assertion being raised
image

@hexomethyl
Copy link
Author

Turns that an error occurs during [libCling.so] cling::IncrementalParser::commitTransaction IncrementalParser.cpp:595, which causes Cling to attempt to unload the failed transaction.

image

@hexomethyl
Copy link
Author

hexomethyl commented Dec 20, 2024

The shadows container within [libCling.so] clang::BaseUsingDecl::removeShadowDecl DeclCXX.cpp:3082 turns out to be null/invalid
image

@wlav
Copy link
Owner

wlav commented Dec 20, 2024

Yes, it's not until an object is used when the headers are parsed. (I'll add that IsEnum() is overly greedy.) Are the headers importable with cppyy.include()? Otherwise, how many using declarations are there in the headers? If there are not that many, maybe it's possible to isolate the one that causes the crash and create a reproducer that I can kick upstream?

@hexomethyl
Copy link
Author

hexomethyl commented Dec 20, 2024

Currently all the headers used to generate the dictionary are all working via cppyy.include(...), albeit very slowly....

@wlav
Copy link
Owner

wlav commented Dec 20, 2024

I'll ask whether there's anything that they know of that could cause this.

@hexomethyl
Copy link
Author

hexomethyl commented Dec 20, 2024

Could it be the type alias referenced in #29, it's nested within a class and was previously causing issues

@wlav
Copy link
Owner

wlav commented Dec 20, 2024

That failure itself is in meta, which would be called until parsing completed successfully. But otherwise yes, it's a using and already problematic to some extend.

@wlav
Copy link
Owner

wlav commented Dec 20, 2024

I checked, and for cppyy.include(), auto-loading is off:

   SuspendAutoloadingRAII autoLoadOff(this);
   SuspendAutoParsing autoParseRaii(this);

so it definitely take a different path through the code.

@wlav
Copy link
Owner

wlav commented Dec 20, 2024

Can you try setting:

c = cppyy.gbl.CppyyLegacy.TInterpreter.SuspendAutoParsing(cppyy.gbl.gInterpreter)

before loading anything? The above is a RAII, so auto-parsing is (should be) disabled until that variable is deleted.

@hexomethyl
Copy link
Author

hexomethyl commented Dec 20, 2024

Can you try setting:

c = cppyy.gbl.CppyyLegacy.TInterpreter.SuspendAutoParsing(cppyy.gbl.gInterpreter)

before loading anything? The above is a RAII, so auto-parsing is (should be) disabled until that variable is deleted.

That worked, however I now have a trivial issue, TypeError: cannot instantiate incomplete class "X::Y"
EDIT: Nevermind

@wlav
Copy link
Owner

wlav commented Dec 20, 2024

Upstream asks whether using a typedef instead of using makes a difference and to check you included all header files, in particular the STL ones.

@hexomethyl
Copy link
Author

Upstream asks whether using a typedef instead of using makes a difference and to check you included all header files, in particular the STL ones.

I'll try that and provide a reproducible example if I can later today.

@hexomethyl
Copy link
Author

Firstly, dictionaries may not give you the hoped for speed-up. Upstream has been touting modules for the longest time, but after never quite pulling it off (or getting the promised speed-up), they now tell me to change the scripts to allow adding headers to the PCH (you already can, it's just manual). A big problem with modules is that they have a custom version (for I/O and to be redistributable) rather than using the native Clang ones.

They have another trick up their sleeves: a parser that only picks up the declarations, not the definitions. That would be game changing. They say it's available, but I haven't seen it work.

Second, the dictonaries will still either contain references to headers to be parsed or the headers as strings (is an option, but doesn't work on Windows b/c it is has a size limit on literal strings). The only speedup that might be seen then, is that not everything is loaded at startup, with the class loader ensuring only loading what is actually used.

Third, what I really would like to see, is multiple interpreters and priority-based linkage. There's nothing stopping me from doing that already, just that the interpreter right now is coded upstream as a global variable.

As for the crash, there's no useful information in the stack trace. Probably deep inside Clang (which is linked statically into libCling.so). Are you using cppyy 3.5 already? (This is just released a few days ago and has LLVM16 as an upgrade over LLVM13 prior.)

I'm most likely going to drop attempting to generate a dictionary, given the problems I've encountered trying to generate a dictionary for the existing code base.

My usual approach to loading the headers using 'cppyy.include' works perfectly, however this is incredibly slow. Is there a different approach that will speed up the parsing of the headers?, is it possible to inject 3rd party header only (Which I suspect are the culprits leading to the slow-down) libraries into the PCH ?

@wlav
Copy link
Owner

wlav commented Jan 7, 2025

There's a file called allHeaders.h which you can find under cppyy_backend/etc/dictpch'. This is used by the makepch.py` script in the same directory that cppyy calls on startup if the PCH needs to be rebuild. You can add to that file. Upstream has told me a couple of times that I should just automate that process. Unfortunately, there can always only by one PCH, making it all rather hairy, so I haven't.

However, if you give it a try, you at least will have an indication of what type of speedup is theoretically possible.

@hexomethyl
Copy link
Author

There's a file called allHeaders.h which you can find under cppyy_backend/etc/dictpch'. This is used by the makepch.py` script in the same directory that cppyy calls on startup if the PCH needs to be rebuild. You can add to that file. Upstream has told me a couple of times that I should just automate that process. Unfortunately, there can always only by one PCH, making it all rather hairy, so I haven't.

However, if you give it a try, you at least will have an indication of what type of speedup is theoretically possible.

Thank you, I'll give this a try when I have time.

@wlav
Copy link
Owner

wlav commented Jan 8, 2025

Something like this: compiler-research/CppInterOp#302 (comment) may eventually lead to using multiple PCHs and faster parsing/instantiation times.

Note that there is a solution to multiple PCHs, namely modules. However, Cling doesn't use Clang native modules and does not track versioning or compiler options, so as a practical matter I've never moved to them. Furthermore, modules do not solve the problem that multiple packages all place their code in the same global namespace, so over time, parsing gets slower and slower (in particular template instantiations).

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

No branches or pull requests

2 participants