Skip to content

Commit 6081bcf

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 217265a + 0742e6f commit 6081bcf

File tree

4 files changed

+187
-335
lines changed

4 files changed

+187
-335
lines changed

include/swift/Serialization/ModuleFile.h

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -419,17 +419,16 @@ class ModuleFile
419419
/// Whether or not ImportDecls is valid.
420420
unsigned ComputedImportDecls : 1;
421421

422-
/// Whether this module file can be used, and what's wrong if not.
423-
unsigned Status : 4;
422+
/// Whether an error has been detected setting up this module file.
423+
unsigned HasError : 1;
424424

425425
// Explicitly pad out to the next word boundary.
426426
unsigned : 0;
427427
} Bits = {};
428428
static_assert(sizeof(ModuleBits) <= 8, "The bit set should be small");
429429

430-
void setStatus(Status status) {
431-
Bits.Status = static_cast<unsigned>(status);
432-
assert(status == getStatus() && "not enough bits for status");
430+
bool hasError() const {
431+
return Bits.HasError;
433432
}
434433

435434
void setEntryPointClassID(serialization::DeclID DID) {
@@ -449,25 +448,24 @@ class ModuleFile
449448
serialization::ExtendedValidationInfo *extInfo);
450449

451450
public:
452-
/// Change the status of the current module. Default argument marks the module
453-
/// as being malformed.
454-
Status error(Status issue = Status::Malformed) {
451+
/// Change the status of the current module.
452+
Status error(Status issue) {
455453
assert(issue != Status::Valid);
456-
if (FileContext && issue == Status::Malformed) {
457-
// This would normally be an assertion but it's more useful to print the
458-
// PrettyStackTrace here even in no-asserts builds. Malformed modules are
459-
// generally unrecoverable.
460-
fatal(llvm::make_error<llvm::StringError>(
461-
"(see \"While...\" info below)", llvm::inconvertibleErrorCode()));
462-
}
463-
setStatus(issue);
464-
return getStatus();
454+
assert((issue != Status::Malformed || !FileContext) &&
455+
"too late to complain about the well-formedness of the module");
456+
Bits.HasError = true;
457+
return issue;
465458
}
466459

467460
/// Emits one last diagnostic, logs the error, and then aborts for the stack
468461
/// trace.
469462
LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error error);
470463

464+
LLVM_ATTRIBUTE_NORETURN void fatal() {
465+
fatal(llvm::make_error<llvm::StringError>(
466+
"(see \"While...\" info below)", llvm::inconvertibleErrorCode()));
467+
}
468+
471469
ASTContext &getContext() const {
472470
assert(FileContext && "no associated context yet");
473471
return FileContext->getParentModule()->getASTContext();
@@ -620,9 +618,6 @@ class ModuleFile
620618
theModule.reset(new ModuleFile(std::move(moduleInputBuffer),
621619
std::move(moduleDocInputBuffer),
622620
isFramework, info, extInfo));
623-
assert(info.status == Status::Valid ||
624-
info.status == theModule->getStatus());
625-
info.status = theModule->getStatus();
626621
return info;
627622
}
628623

@@ -650,16 +645,12 @@ class ModuleFile
650645
Status associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
651646
bool treatAsPartialModule);
652647

653-
/// Checks whether this module can be used.
654-
Status getStatus() const {
655-
return static_cast<Status>(Bits.Status);
656-
}
657-
658648
/// Transfers ownership of a buffer that might contain source code where
659649
/// other parts of the compiler could have emitted diagnostics, to keep them
660650
/// alive even if the ModuleFile is destroyed.
661651
///
662-
/// Should only be called when getStatus() indicates a failure.
652+
/// Should only be called when a failure has been reported from
653+
/// ModuleFile::load or ModuleFile::associateWithFileContext.
663654
std::unique_ptr<llvm::MemoryBuffer> takeBufferForDiagnostics();
664655

665656
/// Returns the list of modules this module depends on.

0 commit comments

Comments
 (0)