HighCommander4 wrote:
Here's how we get into `InstantiateFunctionDefinition` in both cases:
```
#13 0x00007fe16ae9a7ba in clang::Sema::InstantiateFunctionDefinition
(this=0x5567dee76e90, PointOfInstantiation=..., Function=0x5567dee90b60,
Recursive=true, DefinitionRequired=false,
AtEndOfTU=true) at clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5431
#14 0x00007fe16ae9e361 in clang::Sema::PerformPendingInstantiations
(this=0x5567dee76e90, LocalOnly=false, AtEndOfTU=true)
at clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:7095
#15 0x00007fe169f6e644 in clang::Sema::ActOnEndOfTranslationUnitFragment
(this=0x5567dee76e90, Kind=clang::TUFragmentKind::Normal)
at clang/lib/Sema/Sema.cpp:1221
#16 0x00007fe169f6e93c in clang::Sema::ActOnEndOfTranslationUnit
(this=0x5567dee76e90) at clang/lib/Sema/Sema.cpp:1245
#17 0x00007fe15f46505a in clang::Parser::ParseTopLevelDecl
(this=0x5567deeb1870, Result=..., ImportState=@0x7fffcb39e504:
clang::Sema::ModuleImportState::NotACXX20Module)
at clang/lib/Parse/Parser.cpp:712
#18 0x00007fe15f3075bc in clang::ParseAST (S=..., PrintStats=false,
SkipFunctionBodies=false) at clang/lib/Parse/ParseAST.cpp:170
```
The key part is that it happens in `ActOnEndOfTranslationUnit`, i.e. at the end
of the parse.
Now let's look at how the background indexer calls into `SymbolCollector`:
```
#14 0x00007f870f56686c in
clang::clangd::SymbolCollector::findIndirectConstructors (this=0x7f86f000d010,
D=0x7f86f012e520)
at clang-tools-extra/clangd/index/SymbolCollector.cpp:587
#15 0x00007f870f5671d4 in clang::clangd::SymbolCollector::handleDeclOccurrence
(this=0x7f86f000d010, D=0x7f86f008d850, Roles=147492, Relations=llvm::ArrayRef
of length 2 = {...}, Loc=...,
ASTNode=...) at clang-tools-extra/clangd/index/SymbolCollector.cpp:701
#16 0x00007f870ce305c5 in clang::index::IndexingContext::handleDeclOccurrence
(this=0x7f86f0040100, D=0x7f86f008d850, Loc=..., IsRef=true,
Parent=0x7f86f012e128, Roles=147492,
Relations=llvm::ArrayRef of length 1 = {...}, OrigE=0x7f86f012e630,
OrigD=0x7f86f012e520, ContainerDC=0x7f86f012e000)
at clang/lib/Index/IndexingContext.cpp:461
#17 0x00007f870ce306e8 in clang::index::IndexingContext::handleReference
(this=0x7f86f0040100, D=0x7f86f012e520, Loc=..., Parent=0x7f86f012e128,
DC=0x7f86f012e000, Roles=32,
Relations=llvm::ArrayRef of length 1 = {...}, RefE=0x7f86f012e630) at
clang/lib/Index/IndexingContext.cpp:100
#18 0x00007f870cda1f84 in (anonymous namespace)::BodyIndexer::VisitDeclRefExpr
(this=0x7f86fa5fd058, E=0x7f86f012e630)
at clang/lib/Index/IndexBody.cpp:147
#19 0x00007f870cd4fd60 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::WalkUpFromDeclRefExpr (this=0x7f86fa5fd058,
S=0x7f86f012e630)
at tools/clang/include/clang/AST/StmtNodes.inc:468
#20 0x00007f870cd4fab5 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::TraverseDeclRefExpr (this=0x7f86fa5fd058,
S=0x7f86f012e630, Queue=0x7f86fa5fcfc8)
at clang/include/clang/AST/RecursiveASTVisitor.h:2618
#21 0x00007f870cd43ee2 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::dataTraverseNode (this=0x7f86fa5fd058,
S=0x7f86f012e630, Queue=0x7f86fa5fcfc8)
at tools/clang/include/clang/AST/StmtNodes.inc:468
#22 0x00007f870cd32aa5 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::TraverseStmt (this=0x7f86fa5fd058, S=0x7f86f012e718,
Queue=0x0)
at clang/include/clang/AST/RecursiveASTVisitor.h:695
#23 0x00007f870cd32852 in clang::index::IndexingContext::indexBody
(this=0x7f86f0040100, S=0x7f86f012e718, Parent=0x7f86f012e128,
DC=0x7f86f012e000)
at clang/lib/Index/IndexBody.cpp:524
#24 0x00007f870ce1cd94 in (anonymous
namespace)::IndexingDeclVisitor::VisitVarDecl (this=0x7f86fa5fd238,
D=0x7f86f012e128)
at clang/lib/Index/IndexDecl.cpp:310
#25 0x00007f870ce1a0a2 in clang::declvisitor::Base<llvm::make_const_ptr,
(anonymous namespace)::IndexingDeclVisitor, bool>::Visit (this=0x7f86fa5fd238,
D=0x7f86f012e128)
at tools/clang/include/clang/AST/DeclNodes.inc:290
#26 0x00007f870ce19c5f in clang::index::IndexingContext::indexDecl
(this=0x7f86f0040100, D=0x7f86f012e128) at clang/lib/Index/IndexDecl.cpp:788
#27 0x00007f870ce1a69b in clang::index::IndexingContext::indexTopLevelDecl
(this=0x7f86f0040100, D=0x7f86f012e128) at clang/lib/Index/IndexDecl.cpp:815
#28 0x00007f870ce1a6fc in clang::index::IndexingContext::indexDeclGroupRef
(this=0x7f86f0040100, DG=...) at clang/lib/Index/IndexDecl.cpp:820
#29 0x00007f870cda41db in (anonymous namespace)::BodyIndexer::VisitDeclStmt
(this=0x7f86fa5fd578, S=0x7f86f012e830) at clang/lib/Index/IndexBody.cpp:386
#30 0x00007f870cd68930 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::WalkUpFromDeclStmt (this=0x7f86fa5fd578,
S=0x7f86f012e830)
at tools/clang/include/clang/AST/StmtNodes.inc:1622
#31 0x00007f870cd686f5 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::TraverseDeclStmt (this=0x7f86fa5fd578,
S=0x7f86f012e830, Queue=0x7f86fa5fd4e8)
at clang/include/clang/AST/RecursiveASTVisitor.h:2550
#32 0x00007f870cd4513c in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::dataTraverseNode (this=0x7f86fa5fd578,
S=0x7f86f012e830, Queue=0x7f86fa5fd4e8)
at tools/clang/include/clang/AST/StmtNodes.inc:1622
#33 0x00007f870cd32aa5 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::TraverseStmt (this=0x7f86fa5fd578, S=0x7f86f012e848,
Queue=0x0)
at clang/include/clang/AST/RecursiveASTVisitor.h:695
#34 0x00007f870cd32852 in clang::index::IndexingContext::indexBody
(this=0x7f86f0040100, S=0x7f86f012e848, Parent=0x7f86f012dfb8,
DC=0x7f86f012e000)
at clang/lib/Index/IndexBody.cpp:524
#35 0x00007f870ce1cb6c in (anonymous
namespace)::IndexingDeclVisitor::VisitFunctionDecl (this=0x7f86fa5fd9e8,
D=0x7f86f012dfb8)
at clang/lib/Index/IndexDecl.cpp:299
#36 0x00007f870ce1a018 in clang::declvisitor::Base<llvm::make_const_ptr,
(anonymous namespace)::IndexingDeclVisitor, bool>::Visit (this=0x7f86fa5fd9e8,
D=0x7f86f012dfb8)
at tools/clang/include/clang/AST/DeclNodes.inc:250
#37 0x00007f870ce19c5f in clang::index::IndexingContext::indexDecl
(this=0x7f86f0040100, D=0x7f86f012dfb8) at clang/lib/Index/IndexDecl.cpp:788
#38 0x00007f870ce1a69b in clang::index::IndexingContext::indexTopLevelDecl
(this=0x7f86f0040100, D=0x7f86f012dfb8) at clang/lib/Index/IndexDecl.cpp:815
#39 0x00007f870ce1a6fc in clang::index::IndexingContext::indexDeclGroupRef
(this=0x7f86f0040100, DG=...) at clang/lib/Index/IndexDecl.cpp:820
#40 0x00007f870ce28921 in (anonymous
namespace)::IndexASTConsumer::HandleTopLevelDecl (this=0x7f86f0040060, DG=...)
at clang/lib/Index/IndexingAction.cpp:127
#41 0x00007f86ff907593 in clang::ParseAST (S=..., PrintStats=false,
SkipFunctionBodies=false) at clang/lib/Parse/ParseAST.cpp:174
#42 0x00007f870c5aa019 in clang::ASTFrontendAction::ExecuteAction
(this=0x7f86f00022c0) at clang/lib/Frontend/FrontendAction.cpp:1428
#43 0x00007f870c5a99f6 in clang::FrontendAction::Execute (this=0x7f86f00022c0)
at clang/lib/Frontend/FrontendAction.cpp:1308
#44 0x00007f870f4ee093 in clang::clangd::BackgroundIndex::index
(this=0x7ffca1421bd0, Cmd=...) at
clang-tools-extra/clangd/index/Background.cpp:325
```
versus how the dynamic indexer calls into `SymbolCollector`:
```
#13 0x00007fe16ef6688c in
clang::clangd::SymbolCollector::findIndirectConstructors (this=0x7fffcb3a1698,
D=0x5567dee90b60)
at clang-tools-extra/clangd/index/SymbolCollector.cpp:587
#14 0x00007fe16ef671f4 in clang::clangd::SymbolCollector::handleDeclOccurrence
(this=0x7fffcb3a1698, D=0x5567dee902f0, Roles=147492, Relations=llvm::ArrayRef
of length 2 = {...}, Loc=...,
ASTNode=...) at clang-tools-extra/clangd/index/SymbolCollector.cpp:701
#15 0x00007fe16c8305c5 in clang::index::IndexingContext::handleDeclOccurrence
(this=0x7fffcb3a1368, D=0x5567dee902f0, Loc=..., IsRef=true,
Parent=0x5567dee8ff88, Roles=147492,
Relations=llvm::ArrayRef of length 1 = {...}, OrigE=0x5567deebb790,
OrigD=0x5567dee90b60, ContainerDC=0x5567dee8fe50)
at clang/lib/Index/IndexingContext.cpp:461
#16 0x00007fe16c8306e8 in clang::index::IndexingContext::handleReference
(this=0x7fffcb3a1368, D=0x5567dee90b60, Loc=..., Parent=0x5567dee8ff88,
DC=0x5567dee8fe50, Roles=32,
Relations=llvm::ArrayRef of length 1 = {...}, RefE=0x5567deebb790) at
clang/lib/Index/IndexingContext.cpp:100
#17 0x00007fe16c7a1f84 in (anonymous namespace)::BodyIndexer::VisitDeclRefExpr
(this=0x7fffcb3a08f8, E=0x5567deebb790)
at clang/lib/Index/IndexBody.cpp:147
#18 0x00007fe16c74fd60 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::WalkUpFromDeclRefExpr (this=0x7fffcb3a08f8,
S=0x5567deebb790)
at tools/clang/include/clang/AST/StmtNodes.inc:468
#19 0x00007fe16c74fab5 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::TraverseDeclRefExpr (this=0x7fffcb3a08f8,
S=0x5567deebb790, Queue=0x7fffcb3a0868)
at clang/include/clang/AST/RecursiveASTVisitor.h:2618
#20 0x00007fe16c743ee2 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::dataTraverseNode (this=0x7fffcb3a08f8,
S=0x5567deebb790, Queue=0x7fffcb3a0868)
at tools/clang/include/clang/AST/StmtNodes.inc:468
#21 0x00007fe16c732aa5 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::TraverseStmt (this=0x7fffcb3a08f8, S=0x5567deebb878,
Queue=0x0)
at clang/include/clang/AST/RecursiveASTVisitor.h:695
#22 0x00007fe16c732852 in clang::index::IndexingContext::indexBody
(this=0x7fffcb3a1368, S=0x5567deebb878, Parent=0x5567dee8ff88,
DC=0x5567dee8fe50)
at clang/lib/Index/IndexBody.cpp:524
#23 0x00007fe16c81cd94 in (anonymous
namespace)::IndexingDeclVisitor::VisitVarDecl (this=0x7fffcb3a0ad8,
D=0x5567dee8ff88)
at clang/lib/Index/IndexDecl.cpp:310
#24 0x00007fe16c81a0a2 in clang::declvisitor::Base<llvm::make_const_ptr,
(anonymous namespace)::IndexingDeclVisitor, bool>::Visit (this=0x7fffcb3a0ad8,
D=0x5567dee8ff88)
at tools/clang/include/clang/AST/DeclNodes.inc:290
#25 0x00007fe16c819c5f in clang::index::IndexingContext::indexDecl
(this=0x7fffcb3a1368, D=0x5567dee8ff88) at clang/lib/Index/IndexDecl.cpp:788
#26 0x00007fe16c81a69b in clang::index::IndexingContext::indexTopLevelDecl
(this=0x7fffcb3a1368, D=0x5567dee8ff88) at clang/lib/Index/IndexDecl.cpp:815
#27 0x00007fe16c81a6fc in clang::index::IndexingContext::indexDeclGroupRef
(this=0x7fffcb3a1368, DG=...) at clang/lib/Index/IndexDecl.cpp:820
#28 0x00007fe16c7a41db in (anonymous namespace)::BodyIndexer::VisitDeclStmt
(this=0x7fffcb3a0e18, S=0x5567deebb9a8) at clang/lib/Index/IndexBody.cpp:386
#29 0x00007fe16c768930 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::WalkUpFromDeclStmt (this=0x7fffcb3a0e18,
S=0x5567deebb9a8)
at tools/clang/include/clang/AST/StmtNodes.inc:1622
#30 0x00007fe16c7686f5 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::TraverseDeclStmt (this=0x7fffcb3a0e18,
S=0x5567deebb9a8, Queue=0x7fffcb3a0d88)
at clang/include/clang/AST/RecursiveASTVisitor.h:2550
#31 0x00007fe16c74513c in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::dataTraverseNode (this=0x7fffcb3a0e18,
S=0x5567deebb9a8, Queue=0x7fffcb3a0d88)
at tools/clang/include/clang/AST/StmtNodes.inc:1622
#32 0x00007fe16c732aa5 in clang::RecursiveASTVisitor<(anonymous
namespace)::BodyIndexer>::TraverseStmt (this=0x7fffcb3a0e18, S=0x5567deebb9c0,
Queue=0x0)
at clang/include/clang/AST/RecursiveASTVisitor.h:695
#33 0x00007fe16c732852 in clang::index::IndexingContext::indexBody
(this=0x7fffcb3a1368, S=0x5567deebb9c0, Parent=0x5567dee8fe08,
DC=0x5567dee8fe50)
at clang/lib/Index/IndexBody.cpp:524
#34 0x00007fe16c81cb6c in (anonymous
namespace)::IndexingDeclVisitor::VisitFunctionDecl (this=0x7fffcb3a1288,
D=0x5567dee8fe08)
at clang/lib/Index/IndexDecl.cpp:299
#35 0x00007fe16c81a018 in clang::declvisitor::Base<llvm::make_const_ptr,
(anonymous namespace)::IndexingDeclVisitor, bool>::Visit (this=0x7fffcb3a1288,
D=0x5567dee8fe08)
at tools/clang/include/clang/AST/DeclNodes.inc:250
#36 0x00007fe16c819c5f in clang::index::IndexingContext::indexDecl
(this=0x7fffcb3a1368, D=0x5567dee8fe08) at clang/lib/Index/IndexDecl.cpp:788
#37 0x00007fe16c81a69b in clang::index::IndexingContext::indexTopLevelDecl
(this=0x7fffcb3a1368, D=0x5567dee8fe08) at clang/lib/Index/IndexDecl.cpp:815
#38 0x00007fe16c8279af in clang::index::indexTopLevelDecls (Ctx=..., PP=...,
Decls=llvm::ArrayRef of length 1 = {...}, DataConsumer=..., Opts=...)
at clang/lib/Index/IndexingAction.cpp:284
#39 0x00007fe16ef0c849 in clang::clangd::(anonymous namespace)::indexSymbols
(AST=..., PP=..., DeclsToIndex=llvm::ArrayRef of length 1 = {...},
MacroRefsToIndex=0x7fffcb3a1ef8, PI=...,
IsIndexMainAST=true, Version="null", CollectMainFileRefs=true,
Origin=clang::clangd::SymbolOrigin::Open)
at clang-tools-extra/clangd/index/FileIndex.cpp:82
#40 0x00007fe16ef0c6ac in clang::clangd::indexMainDecls (AST=...) at
clang-tools-extra/clangd/index/FileIndex.cpp:224
#41 0x00007fe16ef0e9e6 in clang::clangd::FileIndex::updateMain
(this=0x5567dedba100, Path="/clangd-test/main.cpp", AST=...)
at clang-tools-extra/clangd/index/FileIndex.cpp:472
#42 0x00005567bc054a63 in clang::clangd::TestWorkspace::index
(this=0x7fffcb3a29a0) at clang-tools-extra/clangd/unittests/TestWorkspace.cpp:33
```
The two are hooking into libIndex in different ways: the background indexer
runs `SymbolCollector` **during** the parse, on each declarations after it's
been parsed, while the dynamic indexer parses the whole translation unit up
front and then runs `SymbolCollector` on all the declarations. As a result, the
dynamic indexer gets to observe end-of-translation-unit events (like,
apparently, instantiations of function definitions), while the background
indexer doesn't.
https://github.com/llvm/llvm-project/pull/169742
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits