Skip to content

Commit adba35c

Browse files
committed
[cling] use one instead of two lookups within TClass::Init()
Fixes #7123
1 parent 11accb8 commit adba35c

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

core/meta/inc/TInterpreter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ class TInterpreter : public TNamed {
208208
virtual void UpdateListOfGlobals() = 0;
209209
virtual void UpdateListOfGlobalFunctions() = 0;
210210
virtual void UpdateListOfTypes() = 0;
211-
virtual void SetClassInfo(TClass *cl, Bool_t reload = kFALSE) = 0;
211+
virtual void SetClassInfo(TClass *cl, Bool_t reload = kFALSE, TDictionary::DeclId_t decl = nullptr) = 0;
212212

213213
enum ECheckClassInfo {
214214
kUnknown = 0, // backward compatible with false
215215
kKnown = 1,
216216
kWithClassDefInline = 2
217217
};
218-
virtual ECheckClassInfo CheckClassInfo(const char *name, Bool_t autoload, Bool_t isClassOrNamespaceOnly = kFALSE) = 0;
218+
virtual ECheckClassInfo CheckClassInfo(const char *name, TDictionary::DeclId_t &decl, Bool_t autoload, Bool_t isClassOrNamespaceOnly = kFALSE) = 0;
219219

220220
virtual Bool_t CheckClassTemplate(const char *name) = 0;
221221
virtual Longptr_t Calc(const char *line, EErrorCode* error = nullptr) = 0;

core/meta/src/TClass.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,8 +1513,9 @@ void TClass::Init(const char *name, Version_t cversion,
15131513
if (proto)
15141514
proto->FillTClass(this);
15151515
}
1516-
if (!fHasRootPcmInfo && gInterpreter->CheckClassInfo(fName, /* autoload = */ kTRUE)) {
1517-
gInterpreter->SetClassInfo(this); // sets fClassInfo pointer
1516+
TDictionary::DeclId_t decl {};
1517+
if (!fHasRootPcmInfo && gInterpreter->CheckClassInfo(fName, decl, /* autoload = */ kTRUE)) {
1518+
gInterpreter->SetClassInfo(this, kFALSE, decl); // sets fClassInfo pointer
15181519
if (fClassInfo) {
15191520
// This should be moved out of GetCheckSum itself however the last time
15201521
// we tried this cause problem, in particular in the end-of-process operation.
@@ -3187,7 +3188,8 @@ TClass *TClass::GetClass(const char *name, Bool_t load, Bool_t silent, size_t hi
31873188
printf("TClass::GetClass: Header Parsing - The representation of %s was not found in the type system. A lookup in the interpreter is about to be tried: this can cause parsing. This can be avoided selecting %s in the linkdef/selection file.\n",normalizedName.c_str(), normalizedName.c_str());
31883189
}
31893190
if (normalizedName.length()) {
3190-
auto cci = gInterpreter->CheckClassInfo(normalizedName.c_str(), kTRUE /* autoload */,
3191+
TDictionary::DeclId_t decl {};
3192+
auto cci = gInterpreter->CheckClassInfo(normalizedName.c_str(), decl, kTRUE /* autoload */,
31913193
kTRUE /*Only class, structs and ns*/);
31923194

31933195
// We could have an interpreted class with an inline ClassDef, in this case we do not

core/metacling/src/TCling.cxx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,8 +3985,9 @@ static std::string AlternateTuple(const char *classname, const cling::LookupHelp
39853985
/// Set pointer to the TClingClassInfo in TClass.
39863986
/// If 'reload' is true, (attempt to) generate a new ClassInfo even if we
39873987
/// already have one.
3988+
/// \param decl pointer to decl if already found one by CheckClassInfo
39883989

3989-
void TCling::SetClassInfo(TClass* cl, Bool_t reload)
3990+
void TCling::SetClassInfo(TClass* cl, Bool_t reload, TDictionary::DeclId_t decl)
39903991
{
39913992
// We are shutting down, there is no point in reloading, it only triggers
39923993
// redundant deserializations.
@@ -4046,7 +4047,7 @@ void TCling::SetClassInfo(TClass* cl, Bool_t reload)
40464047
// that is currently in the caller (like SetUnloaded) that disable AutoLoading and AutoParsing and
40474048
// code is in the callee (disabling template instantiation) and end up with a more explicit class:
40484049
// TClingClassInfoReadOnly.
4049-
TClingClassInfo* info = new TClingClassInfo(GetInterpreterImpl(), name.c_str(), instantiateTemplate);
4050+
TClingClassInfo* info = (decl && !static_cast<const clang::Decl *>(decl)->isInvalidDecl()) ? new TClingClassInfo(GetInterpreterImpl(), decl) : new TClingClassInfo(GetInterpreterImpl(), name.c_str(), instantiateTemplate);
40504051
if (!info->IsValid()) {
40514052
SetWithoutClassInfoState(cl);
40524053
delete info;
@@ -4121,9 +4122,11 @@ void TCling::SetClassInfo(TClass* cl, Bool_t reload)
41214122
/// specifically check that each level of nesting is already loaded.
41224123
/// In case of templates the idea is that everything between the outer
41234124
/// '<' and '>' has to be skipped, e.g.: `aap<pippo<noot>::klaas>::a_class`
4125+
///
4126+
/// \param decl parameter passed by reference and set to the found decl, if any
41244127

41254128
TInterpreter::ECheckClassInfo
4126-
TCling::CheckClassInfo(const char *name, Bool_t autoload, Bool_t isClassOrNamespaceOnly /* = kFALSE*/)
4129+
TCling::CheckClassInfo(const char *name, TDictionary::DeclId_t &decl, Bool_t autoload, Bool_t isClassOrNamespaceOnly /* = kFALSE*/)
41274130
{
41284131
R__LOCKGUARD(gInterpreterMutex);
41294132
static const char *anonEnum = "anonymous enum ";
@@ -4191,19 +4194,18 @@ TCling::CheckClassInfo(const char *name, Bool_t autoload, Bool_t isClassOrNamesp
41914194
// this forward declaration.
41924195
const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
41934196
const clang::Type *type = nullptr;
4194-
const clang::Decl *decl
4197+
decl
41954198
= lh.findScope(classname,
41964199
gDebug > 5 ? cling::LookupHelper::WithDiagnostics
41974200
: cling::LookupHelper::NoDiagnostics,
4198-
&type, /* intantiateTemplate= */ false );
4201+
&type, /* instantiateTemplate= */ false);
41994202
if (!decl) {
42004203
std::string buf = TClassEdit::InsertStd(classname);
42014204
decl = lh.findScope(buf,
42024205
gDebug > 5 ? cling::LookupHelper::WithDiagnostics
42034206
: cling::LookupHelper::NoDiagnostics,
4204-
&type,false);
4207+
&type, /* instantiateTemplate= */ false);
42054208
}
4206-
42074209
if (type) {
42084210
// If decl==0 and the type is valid, then we have a forward declaration.
42094211
if (!decl) {

core/metacling/src/TCling.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ class TCling final : public TInterpreter {
270270
void UpdateListOfGlobals() final;
271271
void UpdateListOfGlobalFunctions() final;
272272
void UpdateListOfTypes() final;
273-
void SetClassInfo(TClass* cl, Bool_t reload = kFALSE) final;
273+
void SetClassInfo(TClass* cl, Bool_t reload = kFALSE, TDictionary::DeclId_t decl = nullptr) final;
274274

275-
ECheckClassInfo CheckClassInfo(const char *name, Bool_t autoload, Bool_t isClassOrNamespaceOnly = kFALSE) final;
275+
ECheckClassInfo CheckClassInfo(const char *name, TDictionary::DeclId_t &decl, Bool_t autoload, Bool_t isClassOrNamespaceOnly = kFALSE) final;
276276

277277
Bool_t CheckClassTemplate(const char *name) final;
278278
Longptr_t Calc(const char* line, EErrorCode* error = nullptr) final;

core/metacling/src/TClingClassInfo.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ TClingClassInfo::TClingClassInfo(cling::Interpreter *interp, Bool_t all)
7878
SetDecl(TU);
7979
}
8080

81-
TClingClassInfo::TClingClassInfo(cling::Interpreter *interp, const char *name, bool intantiateTemplate /* = true */)
81+
TClingClassInfo::TClingClassInfo(cling::Interpreter *interp, const char *name, bool instantiateTemplate /* = true */)
8282
: TClingDeclInfo(nullptr), fInterp(interp), fFirstTime(true), fDescend(false), fIterAll(kTRUE), fIsIter(false),
8383
fOffsetCache(0)
8484
{
@@ -87,14 +87,14 @@ TClingClassInfo::TClingClassInfo(cling::Interpreter *interp, const char *name, b
8787
const Decl *decl = lh.findScope(name,
8888
gDebug > 5 ? cling::LookupHelper::WithDiagnostics
8989
: cling::LookupHelper::NoDiagnostics,
90-
&type, intantiateTemplate);
90+
&type, instantiateTemplate);
9191
if (!decl) {
9292
std::string buf = TClassEdit::InsertStd(name);
9393
if (buf != name) {
9494
decl = lh.findScope(buf,
9595
gDebug > 5 ? cling::LookupHelper::WithDiagnostics
9696
: cling::LookupHelper::NoDiagnostics,
97-
&type, intantiateTemplate);
97+
&type, instantiateTemplate);
9898
}
9999
}
100100
if (!decl && type) {

core/metacling/src/TClingClassInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class TClingClassInfo final : public TClingDeclInfo {
9494
fDeclFileName(rhs.fDeclFileName), fOffsetCache(rhs.fOffsetCache)
9595
{}
9696
explicit TClingClassInfo(cling::Interpreter *, Bool_t all = kTRUE);
97-
explicit TClingClassInfo(cling::Interpreter *, const char *classname, bool intantiateTemplate = kTRUE);
97+
explicit TClingClassInfo(cling::Interpreter *, const char *classname, bool instantiateTemplate = kTRUE);
9898
explicit TClingClassInfo(cling::Interpreter *interp, const clang::Type &tag);
9999
explicit TClingClassInfo(cling::Interpreter *interp, const clang::Decl *D);
100100
TClingClassInfo &operator=(const TClingClassInfo &rhs)

core/textinput/src/Getline_color.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ void ROOT::TextInputColorizer::ProcessTextChange(EditorRange& Modification,
232232
}
233233
std::string word = text.substr(i, wordLen);
234234
char color = kColorNone;
235+
TDictionary::DeclId_t decl;
235236
if (gClassTable->GetDict(word.c_str())
236237
|| gInterpreter->GetClassSharedLibs(word.c_str())
237-
|| gInterpreter->CheckClassInfo(word.c_str(), false /*autoload*/)
238+
|| gInterpreter->CheckClassInfo(word.c_str(), decl, false /*autoload*/)
238239
|| ((THashTable*)gROOT->GetListOfTypes())
239240
->THashTable::FindObject(word.c_str())) {
240241
color = kColorType;

0 commit comments

Comments
 (0)