@@ -69,7 +69,21 @@ static std::string getFilename(swift::ModuleDecl& module, swift::SourceFile* pri
6969 return module .getModuleFilename ().str ();
7070}
7171
72- static llvm::SmallVector<swift::ValueDecl*> getBuiltinDecls (swift::ModuleDecl& builtinModule) {
72+ /* The builtin module is special, as it does not publish any top-level declaration
73+ * It creates (and caches) declarations on demand when a lookup is carried out
74+ * (see BuiltinUnit in swift/AST/FileUnit.h for the cache details, and getBuiltinValueDecl in
75+ * swift/AST/Builtins.h for the creation details)
76+ * As we want to create the Builtin trap file once and for all so that it works for other
77+ * extraction runs, rather than collecting what we need we pre-populate the builtin trap with
78+ * what we expect. This list might need thus to be expanded.
79+ * Notice, that while swift/AST/Builtins.def has a list of builtin symbols, it does not contain
80+ * all information required to instantiate builtin variants.
81+ * Other possible approaches:
82+ * * create one trap per builtin declaration when encountered
83+ * * expand the list to all possible builtins (of which there are a lot)
84+ */
85+ static void getBuiltinDecls (swift::ModuleDecl& builtinModule,
86+ llvm::SmallVector<swift::Decl*>& decls) {
7387 llvm::SmallVector<swift::ValueDecl*> values;
7488 for (auto symbol : {
7589 " zeroInitializer" , " BridgeObject" , " Word" , " NativeObject" ,
@@ -91,7 +105,7 @@ static llvm::SmallVector<swift::ValueDecl*> getBuiltinDecls(swift::ModuleDecl& b
91105 builtinModule.lookupValue (builtinModule.getASTContext ().getIdentifier (symbol),
92106 swift::NLKind::QualifiedLookup, values);
93107 }
94- return values;
108+ decls. insert (decls. end (), values. begin (), values. end ()) ;
95109}
96110
97111static llvm::SmallVector<swift::Decl*> getTopLevelDecls (swift::ModuleDecl& module ,
@@ -101,9 +115,7 @@ static llvm::SmallVector<swift::Decl*> getTopLevelDecls(swift::ModuleDecl& modul
101115 if (primaryFile) {
102116 primaryFile->getTopLevelDecls (ret);
103117 } else if (module .isBuiltinModule ()) {
104- for (auto d : getBuiltinDecls (module )) {
105- ret.push_back (d);
106- }
118+ getBuiltinDecls (module , ret);
107119 } else {
108120 module .getTopLevelDecls (ret);
109121 }
0 commit comments