@@ -69,7 +69,21 @@ static std::string getFilename(swift::ModuleDecl& module, swift::SourceFile* pri
69
69
return module .getModuleFilename ().str ();
70
70
}
71
71
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) {
73
87
llvm::SmallVector<swift::ValueDecl*> values;
74
88
for (auto symbol : {
75
89
" zeroInitializer" , " BridgeObject" , " Word" , " NativeObject" ,
@@ -91,7 +105,7 @@ static llvm::SmallVector<swift::ValueDecl*> getBuiltinDecls(swift::ModuleDecl& b
91
105
builtinModule.lookupValue (builtinModule.getASTContext ().getIdentifier (symbol),
92
106
swift::NLKind::QualifiedLookup, values);
93
107
}
94
- return values;
108
+ decls. insert (decls. end (), values. begin (), values. end ()) ;
95
109
}
96
110
97
111
static llvm::SmallVector<swift::Decl*> getTopLevelDecls (swift::ModuleDecl& module ,
@@ -101,9 +115,7 @@ static llvm::SmallVector<swift::Decl*> getTopLevelDecls(swift::ModuleDecl& modul
101
115
if (primaryFile) {
102
116
primaryFile->getTopLevelDecls (ret);
103
117
} else if (module .isBuiltinModule ()) {
104
- for (auto d : getBuiltinDecls (module )) {
105
- ret.push_back (d);
106
- }
118
+ getBuiltinDecls (module , ret);
107
119
} else {
108
120
module .getTopLevelDecls (ret);
109
121
}
0 commit comments