Skip to content

Commit 6e16c07

Browse files
authored
Merge pull request #63688 from tshortli/diagnose-ignored-swiftmodules
Frontend: Add a rebuild diagnostic explaining why the adjacent swiftmodule was ignored
2 parents 4cca9a6 + b11dcb9 commit 6e16c07

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ REMARK(rebuilding_module_from_interface,none,
431431
NOTE(sdk_version_pbm_version,none,
432432
"SDK build version is '%0'; prebuilt modules were "
433433
"built using SDK build version: '%1'", (StringRef, StringRef))
434+
NOTE(compiled_module_ignored_reason,none,
435+
"compiled module '%0' was ignored because %select{%error"
436+
"|it belongs to a framework in the SDK"
437+
"|loading from module interfaces is prefered}1",
438+
(StringRef, unsigned))
434439
NOTE(out_of_date_module_here,none,
435440
"%select{compiled|cached|forwarding|prebuilt}0 module is out of date: '%1'",
436441
(unsigned, StringRef))

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,54 +223,73 @@ struct ModuleRebuildInfo {
223223
Forwarding,
224224
Prebuilt
225225
};
226-
struct OutOfDateModule {
226+
enum class ReasonIgnored {
227+
NotIgnored,
228+
PublicFramework,
229+
InterfacePreferred,
230+
};
231+
struct CandidateModule {
227232
std::string path;
228233
Optional<serialization::Status> serializationStatus;
229234
ModuleKind kind;
235+
ReasonIgnored reasonIgnored;
230236
SmallVector<std::string, 10> outOfDateDependencies;
231237
SmallVector<std::string, 10> missingDependencies;
232238
};
233-
SmallVector<OutOfDateModule, 3> outOfDateModules;
239+
SmallVector<CandidateModule, 3> candidateModules;
234240

235-
OutOfDateModule &getOrInsertOutOfDateModule(StringRef path) {
236-
for (auto &mod : outOfDateModules) {
241+
CandidateModule &getOrInsertCandidateModule(StringRef path) {
242+
for (auto &mod : candidateModules) {
237243
if (mod.path == path) return mod;
238244
}
239-
outOfDateModules.push_back({path.str(), None, ModuleKind::Normal, {}, {}});
240-
return outOfDateModules.back();
245+
candidateModules.push_back({path.str(),
246+
None,
247+
ModuleKind::Normal,
248+
ReasonIgnored::NotIgnored,
249+
{},
250+
{}});
251+
return candidateModules.back();
241252
}
242253

243254
/// Sets the kind of a module that failed to load.
244255
void setModuleKind(StringRef path, ModuleKind kind) {
245-
getOrInsertOutOfDateModule(path).kind = kind;
256+
getOrInsertCandidateModule(path).kind = kind;
246257
}
247258

248259
/// Sets the serialization status of the module at \c path. If this is
249260
/// anything other than \c Valid, a note will be added stating why the module
250261
/// was invalid.
251262
void setSerializationStatus(StringRef path, serialization::Status status) {
252-
getOrInsertOutOfDateModule(path).serializationStatus = status;
263+
getOrInsertCandidateModule(path).serializationStatus = status;
253264
}
254265

255266
/// Registers an out-of-date dependency at \c depPath for the module
256267
/// at \c modulePath.
257268
void addOutOfDateDependency(StringRef modulePath, StringRef depPath) {
258-
getOrInsertOutOfDateModule(modulePath)
269+
getOrInsertCandidateModule(modulePath)
259270
.outOfDateDependencies.push_back(depPath.str());
260271
}
261272

262273
/// Registers a missing dependency at \c depPath for the module
263274
/// at \c modulePath.
264275
void addMissingDependency(StringRef modulePath, StringRef depPath) {
265-
getOrInsertOutOfDateModule(modulePath)
276+
getOrInsertCandidateModule(modulePath)
266277
.missingDependencies.push_back(depPath.str());
267278
}
268279

280+
/// Sets the reason that the module at \c path was ignored. If this is
281+
/// anything besides \c NotIgnored a note will be added stating why the module
282+
/// was ignored.
283+
void addIgnoredModule(StringRef modulePath, ReasonIgnored reasonIgnored) {
284+
getOrInsertCandidateModule(modulePath).reasonIgnored = reasonIgnored;
285+
}
286+
269287
/// Determines if we saw the given module path and registered is as out of
270288
/// date.
271289
bool sawOutOfDateModule(StringRef modulePath) {
272-
for (auto &mod : outOfDateModules)
273-
if (mod.path == modulePath)
290+
for (auto &mod : candidateModules)
291+
if (mod.path == modulePath &&
292+
mod.reasonIgnored == ReasonIgnored::NotIgnored)
274293
return true;
275294
return false;
276295
}
@@ -310,9 +329,15 @@ struct ModuleRebuildInfo {
310329
}
311330
// We may have found multiple failing modules, that failed for different
312331
// reasons. Emit a note for each of them.
313-
for (auto &mod : outOfDateModules) {
314-
diags.diagnose(loc, diag::out_of_date_module_here,
315-
(unsigned)mod.kind, mod.path);
332+
for (auto &mod : candidateModules) {
333+
// If a the compiled module was ignored, diagnose the reason.
334+
if (mod.reasonIgnored != ReasonIgnored::NotIgnored) {
335+
diags.diagnose(loc, diag::compiled_module_ignored_reason, mod.path,
336+
(unsigned)mod.reasonIgnored);
337+
} else {
338+
diags.diagnose(loc, diag::out_of_date_module_here, (unsigned)mod.kind,
339+
mod.path);
340+
}
316341

317342
// Diagnose any out-of-date dependencies in this module.
318343
for (auto &dep : mod.outOfDateDependencies) {
@@ -677,6 +702,7 @@ class ModuleInterfaceLoaderImpl {
677702
}
678703

679704
std::pair<std::string, std::string> getCompiledModuleCandidates() {
705+
using ReasonIgnored = ModuleRebuildInfo::ReasonIgnored;
680706
std::pair<std::string, std::string> result;
681707
// Should we attempt to load a swiftmodule adjacent to the swiftinterface?
682708
bool shouldLoadAdjacentModule = !ctx.IgnoreAdjacentModules;
@@ -690,6 +716,7 @@ class ModuleInterfaceLoaderImpl {
690716
if (!ctx.SearchPathOpts.getSDKPath().empty() &&
691717
modulePath.startswith(publicFrameworksPath)) {
692718
shouldLoadAdjacentModule = false;
719+
rebuildInfo.addIgnoredModule(modulePath, ReasonIgnored::PublicFramework);
693720
}
694721

695722
switch (loadMode) {
@@ -702,6 +729,8 @@ class ModuleInterfaceLoaderImpl {
702729
// skip the module adjacent to the interface, but use the caches if
703730
// they're present.
704731
shouldLoadAdjacentModule = false;
732+
rebuildInfo.addIgnoredModule(modulePath,
733+
ReasonIgnored::InterfacePreferred);
705734
break;
706735
case ModuleLoadingMode::PreferSerialized:
707736
// The rest of the function should be covered by this.

test/ModuleInterface/ignore-adjacent-swiftmodules.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// RUN: -verify -Rmodule-interface-rebuild
3030

3131
import PublicSwift // expected-remark {{rebuilding module 'PublicSwift' from interface}}
32+
// expected-note @-1 {{was ignored because it belongs to a framework in the SDK}}
3233

3334
// The private adjacent module under PrivateFrameworks should still be tried first, and then rebuilt.
3435
import PrivateSwift

0 commit comments

Comments
 (0)