Commit Graph

180 Commits

Author SHA1 Message Date
Jonas Hahnfeld
52df1a551a Globally enable incremental extensions
We are relying on this since a while, for example for reemission of
template symbols. At the moment, we get the incremental extensions
because Preprocessor::enableIncrementalProcessing() turns them on
internally, but this will change with LLVM 18 where this method only
controls incremental processing of a single Preprocessor object.
2024-08-09 08:59:03 +02:00
Devajith Valaparambil Sreeramaswamy
c5692e71f1 Use StringRef::{starts,ends}_with
Follows the changes introduced in https://reviews.llvm.org/D136030
2024-02-23 09:44:06 +01:00
Devajith Valaparambil Sreeramaswamy
a085ccebac Use deduction guides for llvm::ArrayRef 2023-12-13 13:29:07 +01:00
Vassil Vassilev
c2562c72b1 ParseTypeName might trigger deserialization. 2023-07-04 19:29:05 +02:00
ferdymercury
9cdbf1d0eb nullptr use
clingUtils modernize nullptr
2023-01-26 08:59:06 +01:00
Vassil Vassilev
c72f7a1109 ParseUnqualifiedId has new set of params.
See llvm/llvm-project@0dd0b1017c
2022-12-09 08:44:17 +01:00
Vassil Vassilev
ec413fe1a8 setSuppressAllDiagnostics has no default anymore.
Remove duplicate line of code.
2022-12-09 08:44:17 +01:00
Vassil Vassilev
0861ee91c2 getTypeAnnotation returns now TypeResult.
See llvm/llvm-project@3308732300
2022-12-09 08:44:17 +01:00
Vassil Vassilev
ff6ccd2dab TypeNameContext was renamed to TypeName.
See llvm/llvm-project@e4d27932a5
2022-12-09 08:44:17 +01:00
Vassil Vassilev
db5f9b7874 Use the synonym interface getBuffer->getBufferData 2022-12-09 08:44:17 +01:00
Vassil Vassilev
6d00a9a9db VK_RValue -> VK_PRValue
See llvm/llvm-project@aef5d8fdc7
2022-12-09 08:44:17 +01:00
Baidyanath Kundu
6cabc7a8f8 Fix long long error in findBuiltinType 2022-09-20 15:14:04 +02:00
Axel Naumann
fc5b3e6f16 Silence GCC 4.8 / CentOS7 warnings:
cling/include/cling/Interpreter/LookupHelper.h:61:69: warning: missing initializer for member ‘std::array<const clang::Type*, 4ul>::_M_elems’ [-Wmissing-field-initializers]
     std::array<const clang::Type*, kNumCachedStrings> m_StringTy = {};
                                                                     ^
2021-05-21 09:44:08 +02:00
Axel Naumann
7a35c2ddbc LookupHelper: suppress diags from adding templt funcs:
Sema::AddTemplateOverloadCandidate() can issue diagnostics as part of the
template instantiation it performs. The LookupHelper just wants to know
whether there is a matching function, which is similar to a SFINAE context
and a good reason to silence potential diagnostics if asked to do so!

Do get there, simple increase the scope of the setSuppressAllDiagnostics()
calls, and make it an RAII for robustness.
2021-04-27 11:29:05 +02:00
Axel Naumann
9432fb6582 LookupHelper must not unload Transactions:
Outer RAIIs might still reference the Transaction, and unload is
assuming that it owns the transaction and can delete it / put it
into the TransactionPool.

This fixes https://github.com/root-project/root/issues/7657

We still need to track ownership as what has happened here (unload
of a Transaction held by an RAII) can happen again / elsewhere.
This will be addressed by a subsequent PR in master.
2021-04-06 00:14:05 +02:00
Axel Naumann
2b1af22926 In failed lookup, unload only decls produced, not existing fwd decl:
Before, pre-existing fwd decls of specializations got unloaded.

OTOH, any decl produced during (failed) template instantiation must
also be unloaded; see #6331. Those are easiest identified by unloading
the whole (failed) transaction.

```
error: no member named 'value' in 'std::__and_<std::is_copy_assignable<std::__cxx11::basic_string<char> >, std::is_copy_assignable<Inner<int> > >'
                       is_copy_assignable<_T2>>::value,
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~^
```

which is due to the first decl being invalid (as `Inner<int>` does not have a deinition and a `static_assert` /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/type_traits:1093 being triggered), then not unloaded, and then picked up again where we *do* have the definition for `Inner<int>`.

Add test for templt spec lookup vs unloading.
2021-03-18 19:59:03 +01:00
Vassil Vassilev
c9fb0ce320 The SourceLocation parameter is optional.
See llvm-mirror/clang@497bb75060
2021-02-25 20:44:17 +01:00
Vassil Vassilev
c85cf9e4ea Use directly the const-checking routine. 2021-02-25 20:44:16 +01:00
Vassil Vassilev
dffacf9ee2 getTypeQualifiers was renamed to getMethodQualifiers.
See llvm-mirror/clang@8a8b20e
2021-02-25 20:44:16 +01:00
Vassil Vassilev
5c5d94f5ac TypeNameContext was moved to DeclaratorContext.
See llvm-mirror/clang@ef699b2164
2021-02-25 20:44:16 +01:00
Vassil Vassilev
e1368fcfbc getLocStart was renamed to getBeginLoc and getLocEnd to getEndLoc. 2021-02-25 20:44:16 +01:00
Axel Naumann
6e5b2b6507 Also capture SFINAE error counts (ROOT-10754, ROOT-10777):
When doing lookup on templates, instantiation can fail.
This can be triggered during template instantiation somewhere
in clang, autoloading, cling-lookup - and SFINAE errors that
occur in cling-lookup must not bubble up to clang, or else
clang will think that there was a problem (where there was
none - just e.g. ROOT trying to autoload a bogus template).

In this concrete case, a template specialized with a lambda
was not found by clang, was tried to be autoloaded, TMetaUtils
produced a broken normalized type name, lookup on the broken
type name failed with a SFINAE error - and that ended up being
swallowed by a clang SFINAETrap by the topmost lookup.

Instead, keep SFINAE errors to ourselves.

This is an improved version of 40673e583fceda8b362a0902c6aba371ddd0cfd8
which lowers the SFINAE-reset to Lookup, as AutoParse can still
see partial template specialization scopes. It fixes ROOT-10777.
2020-05-20 12:59:06 +02:00
Axel Naumann
12259fc4e3 Make use of shared_ptr operators instead of get() (NFC). 2020-05-20 12:59:06 +02:00
Philippe Canal
bd472f9b0a Clang-formatting 2019-09-09 19:15:34 +02:00
Philippe Canal
8b906da196 Expand StartParsingRAII
In particular the CachedTokens need to be pushed/pop or otherwise
give misleading information.

This fixes ROOT-10224.
2019-09-09 19:15:34 +02:00
Vassil Vassilev
d71643dcf8 Support recursive lookup helper calls.
The implementation of class->library mapping makes a call to the
LookupHelper::findScope. This makes the recursive invocations to
LookupHelper::findScope -> ... -> LookupHelper::findScope happen more often.
2019-06-02 21:44:26 +02:00
Vassil Vassilev
fb5a493198 Resize the memory cache before entering the loop.
This prevents the vector to be reallocated if the size exceeds the capacity of
the vector causing invalid pointer accesses.

Fixes ROOT-7749.
2019-04-09 15:29:12 +02:00
Axel Naumann
10828b4be5 Reduce scope of local variable. 2019-01-10 13:29:15 +01:00
Axel Naumann
e93325aeed Look up template function specializations as such (ROOT-9789). 2019-01-10 13:29:14 +01:00
Yuka Takahashi
230031c4cb Implement parsing cache for the LookupHelper.
The operations done by the LookupHelper are costly in both memory and
performance. Almost every operation requires memory allocation and parsing
of often non-trivial C++ code.

Unfortunately, the LookupHelper is used very intensively by rootcling and
ROOT. The callers usually do not use any caching mechanisms and redo the
expensive operations over and over even though the answer is known to be
the same as before. For instance, building the dictionary of shows:

```
MathCore:
  Cached entries: 217
  Total parse requests: 54051
  Cache hits: 53834
TreePlayer:
  Cached entries: 183
  Total parse requests: 57697
  Cache hits: 57514
```

This patch introduces the first set of caching functionality. In
particular, each LookupHelper::find* function allocates a memory buffer
which is then stored in the clang::SourceManager. We hash the buffer
content and keep a mapping between a hash and FileID and next time we
encounter the same content we do not allocate a new FileID but reuse the
old one. We see decrease in memory footprint by 7% for non-cxxmodules ROOT.

For cxxmodules we see significant reduction of the pcm sizes (by half)
which translates into rss improvements:

```
  master before:
    cpu  time = 0.291462 seconds
    sys  time = 0.064409 seconds
    res  memory = 345.816 Mbytes
    vir  memory = 573.508 Mbytes
  master after:
   cpu  time = 0.235828 seconds
   sys  time = 0.098327 seconds
   res  memory = 260.012 Mbytes
   vir  memory = 377.945 Mbytes
```

Patch by Yuka Takahashi and me.
2018-08-24 23:59:47 +02:00
Yuka Takahashi
35a8988d50 Autoload less libraries
In previous allmodules&autoloading patch, we used callback from
DeserializationListener to get Decl and loaded corresponding libraries.
It worked, but the performance was bad because ROOT was loading
excessive libraries.

In this patch, we use TCling::LazyFunctionCreatorAutoloadForModule. This
function gets callback when "mangled_name" was not found in loaded
libraries thus we have to the load corresponding library and lookup
again.

I used unordered_map to store mangled identifier and library pair. I'm
doing an optimization by hashing mangled name and storing library not by
name but by uint8 and hold uint8-name information in another vector.
Also tried std::map but unorderd_map was more performant. There are
better hash table like:
https://probablydance.com/2018/05/28/a-new-fast-hash-table-in-response-to-googles-new-fast-hash-table/
we can try to use them if this part gets crucial.

With this patch:
```
Processing tutorials/hsimple.C...
hsimple   : Real Time =   0.04 seconds Cpu Time =   0.03 seconds
(TFile *) 0x562b37a14fe0
Processing /home/yuka/CERN/ROOT/memory.C...
cpu  time = 0.362307 seconds
sys  time = 0.039741 seconds
res  memory = 278.215 Mbytes
vir  memory = 448.973 Mbytes
```

W/o this patch:
```
Processing tutorials/hsimple.C...
hsimple   : Real Time =   0.08 seconds Cpu Time =   0.07 seconds
(TFile *) 0x5563018a1d30
Processing /home/yuka/CERN/ROOT/memory.C...
cpu  time = 1.524314 seconds
sys  time = 0.157075 seconds
res  memory = 546.867 Mbytes
vir  memory = 895.184 Mbytes
```

So it improves time by 4x times and memory by 2x.
2018-06-02 10:44:38 +02:00
Yuka Takahashi
98719ad352 Preloading modules and autoloading libraries by deserialized decls
Preloading all the modules has several advantages. 1. We do not have to
rely on rootmap files which don't support some features (namespaces and
templates) 2. Lookup would be faster because we don't have to do
trampoline via rootmap files.

Autoloading libraries when decls are deserialized gives us correctness.
However we still need to optimize the performance by reducing the amount
of loaded libraries and improving Clang performance.
2018-05-18 10:14:30 +02:00
Vassil Vassilev
dfc5cf657d The annotation token became a special one.
We can only consume it with calling a special interface or calling ConsumeAnyToken.
2017-11-02 17:59:25 +01:00
Axel Naumann
4681e8014f Do not diagnose instantiation failures during function lookup.
Fixes an issue for ATLAS, where Property<string>::Property<string&> cannot be instantiated by ROOT.
ROOT is trying to do that because the function is templated, with all template parameters having defaults.
(This "let us instantiate if all template params have defaults" is needed e.g. to see pair::pair() which is sfinae protected.)
2017-09-05 10:59:25 +02:00
Axel Naumann
3693489f3d Handle also nested deduced templates, even those wrapped in a LocInfoType.
Fixes cling/test/Lookup/template.C in C++17.
2017-06-27 10:31:08 +02:00
Axel Naumann
07f42c7a51 Fist step towards fixing cling/test/Lookup/template.C for C++17. 2017-06-26 17:44:07 +02:00
Axel Naumann
aae2870f62 Allow getStringType() to reset the cache. 2017-06-23 10:59:10 +02:00
Axel Naumann
65b4cd2cc3 Avoid memset by using in-class member init. 2017-06-22 13:10:37 +02:00
Frederich Munch
7504234e21 Cache all string types. 2017-06-22 13:10:37 +02:00
Frederich Munch
8fab0d5be8 Fix caching of std::string type.
If the Transaction that holds std::string type is unloaded LookupHelper::m_StringTy will point to invalid memory.
LookupHelper::findType can return an invalid QualType causing dereference of null.
2017-06-22 13:10:37 +02:00
Vassil Vassilev
a1bd767b6b Adapt to interface changes due to upgrade to r302975. 2017-06-08 10:29:13 +02:00
Axel Naumann
cb2384fc55 Buffer Interpreter-local std::string lookup; ValuePrinter needs it. 2017-05-08 11:44:07 +02:00
Philippe Canal
e173a95fc1 With module (or pcm) even trivial lookup can lead to deserialization and thus need a transaction 2017-04-11 23:00:40 +02:00
Philippe Canal
f5c7037763 Fix ROOT-8739: Lookup of symbol inside of namespace shadowed by function (in another 'used' namespace).
This was happening when a namespace had the same as the function in a namespace that was 'used'.  Namely,
in the issue report it was the 'next' namespace and the function std::next.

This required the quick search function in LookupHelper.cxx to properly handle the return value of utils::Lookup::Named.
2017-04-07 21:14:06 +02:00
Philippe Canal
3a1db539f6 Revert "Fix ROOT-8739: Lookup of symbol inside of namespace shadowed by function (in another 'used' namespace)."
This reverts commit 0728f30ead6c1cca74bf31b93dc9a1cb616a3e35.
2017-04-07 20:44:04 +02:00
Philippe Canal
68283cac47 Fix ROOT-8739: Lookup of symbol inside of namespace shadowed by function (in another 'used' namespace).
This was happening when a namespace had the same as the function in a namespace that was 'used'.  Namely,
in the issue report it was the 'next' namespace and the function std::next.

This required the quick search function in LookupHelper.cxx to properly handle the return value of utils::Lookup::Named.
2017-04-07 20:29:17 +02:00
Frederich Munch
d68ef916ac Use LLVM stream wrappers to reduce complexity and line counts. 2016-12-20 12:29:06 +01:00
Axel Naumann
c9ad1f4a41 Only skipToEOF if needed. 2016-11-10 18:14:07 +01:00
Philippe Canal
7c9379ac93 Refactor in RequireCompleteDeclContext the 'Update the DeclContext used for lookup to point to the definition.'
This superseeds 4fa2f7a38e37303b3bb5a9ba01d762122e8d9814, 2b4de2603a086162f89fd5eb16aa0d5fddac8a6e and 384f6eabcd2d02512b942215d7ae52ff40954027
2016-11-08 22:59:56 +01:00
Axel Naumann
3847e2560d Split ParserStateRAII into Utils/. We need it in other places. 2016-11-07 15:29:52 +01:00