@@ -1103,7 +1103,7 @@ class SourceFile::Impl {
1103
1103
// / Only intended for use by lookupOperatorDeclForName.
1104
1104
static ArrayRef<SourceFile::ImportedModuleDesc>
1105
1105
getImportsForSourceFile (const SourceFile &SF) {
1106
- return SF.Imports ;
1106
+ return * SF.Imports ;
1107
1107
}
1108
1108
};
1109
1109
@@ -1408,7 +1408,10 @@ SourceFile::getImportedModules(SmallVectorImpl<ModuleDecl::ImportedModule> &modu
1408
1408
// We currently handle this for a direct import from the overlay, but not when
1409
1409
// it happens through other imports.
1410
1410
assert (filter && " no imports requested?" );
1411
- for (auto desc : Imports) {
1411
+ if (!Imports)
1412
+ return ;
1413
+
1414
+ for (auto desc : *Imports) {
1412
1415
ModuleDecl::ImportFilter requiredFilter;
1413
1416
if (desc.importOptions .contains (ImportFlags::Exported))
1414
1417
requiredFilter |= ModuleDecl::ImportFilterKind::Public;
@@ -2036,23 +2039,14 @@ void SourceFile::print(ASTPrinter &Printer, const PrintOptions &PO) {
2036
2039
}
2037
2040
}
2038
2041
2039
- void SourceFile::addImports (ArrayRef<ImportedModuleDesc> IM) {
2040
- if (IM.empty ())
2041
- return ;
2042
- ASTContext &ctx = getASTContext ();
2043
- auto newBuf =
2044
- ctx.AllocateUninitialized <ImportedModuleDesc>(Imports.size () + IM.size ());
2045
-
2046
- auto iter = newBuf.begin ();
2047
- iter = std::uninitialized_copy (Imports.begin (), Imports.end (), iter);
2048
- iter = std::uninitialized_copy (IM.begin (), IM.end (), iter);
2049
- assert (iter == newBuf.end ());
2050
-
2051
- Imports = newBuf;
2042
+ void SourceFile::setImports (ArrayRef<ImportedModuleDesc> imports) {
2043
+ assert (!Imports && " Already computed imports" );
2044
+ Imports = getASTContext ().AllocateCopy (imports);
2052
2045
2053
2046
// Update the HasImplementationOnlyImports flag.
2047
+ // TODO: Requestify this.
2054
2048
if (!HasImplementationOnlyImports) {
2055
- for (auto &desc : IM ) {
2049
+ for (auto &desc : imports ) {
2056
2050
if (desc.importOptions .contains (ImportFlags::ImplementationOnly))
2057
2051
HasImplementationOnlyImports = true ;
2058
2052
}
@@ -2070,7 +2064,7 @@ bool SourceFile::hasTestableOrPrivateImport(
2070
2064
// filename does not need to match (and we don't serialize it for such
2071
2065
// decls).
2072
2066
return std::any_of (
2073
- Imports. begin (), Imports. end (),
2067
+ Imports-> begin (), Imports-> end (),
2074
2068
[module , queryKind](ImportedModuleDesc desc) -> bool {
2075
2069
if (queryKind == ImportQueryKind::TestableAndPrivate)
2076
2070
return desc.module .second == module &&
@@ -2112,7 +2106,7 @@ bool SourceFile::hasTestableOrPrivateImport(
2112
2106
if (filename.empty ())
2113
2107
return false ;
2114
2108
2115
- return std::any_of (Imports. begin (), Imports. end (),
2109
+ return std::any_of (Imports-> begin (), Imports-> end (),
2116
2110
[module , filename](ImportedModuleDesc desc) -> bool {
2117
2111
return desc.module .second == module &&
2118
2112
desc.importOptions .contains (
@@ -2130,7 +2124,7 @@ bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
2130
2124
auto &imports = getASTContext ().getImportCache ();
2131
2125
2132
2126
// Look at the imports of this source file.
2133
- for (auto &desc : Imports) {
2127
+ for (auto &desc : * Imports) {
2134
2128
// Ignore implementation-only imports.
2135
2129
if (desc.importOptions .contains (ImportFlags::ImplementationOnly))
2136
2130
continue ;
@@ -2147,7 +2141,7 @@ bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
2147
2141
2148
2142
void SourceFile::lookupImportedSPIGroups (const ModuleDecl *importedModule,
2149
2143
SmallVectorImpl<Identifier> &spiGroups) const {
2150
- for (auto &import : Imports) {
2144
+ for (auto &import : * Imports) {
2151
2145
if (import .importOptions .contains (ImportFlags::SPIAccessControl) &&
2152
2146
importedModule == std::get<ModuleDecl*>(import .module )) {
2153
2147
auto importedSpis = import .spiGroups ;
0 commit comments