Skip to content

Commit c45f3a3

Browse files
committed
[Serialization] Stop storing the load Status in ModuleFile itself
The code tried extra hard to make sure this stayed in sync with the returned ValidationInfo, but there's no real reason for that. Just keep a single "HasError" bit for checking that the module's not being obviously misused. (I snuck some groundwork for this into the previous commit.)
1 parent 4497a0c commit c45f3a3

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

include/swift/Serialization/ModuleFile.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -419,21 +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-
Status getStatus() const {
431-
return static_cast<Status>(Bits.Status);
432-
}
433-
434-
void setStatus(Status status) {
435-
Bits.Status = static_cast<unsigned>(status);
436-
assert(status == getStatus() && "not enough bits for status");
430+
bool hasError() const {
431+
return Bits.HasError;
437432
}
438433

439434
void setEntryPointClassID(serialization::DeclID DID) {
@@ -458,8 +453,8 @@ class ModuleFile
458453
assert(issue != Status::Valid);
459454
assert((issue != Status::Malformed || !FileContext) &&
460455
"too late to complain about the well-formedness of the module");
461-
setStatus(issue);
462-
return getStatus();
456+
Bits.HasError = true;
457+
return issue;
463458
}
464459

465460
/// Emits one last diagnostic, logs the error, and then aborts for the stack
@@ -623,7 +618,6 @@ class ModuleFile
623618
theModule.reset(new ModuleFile(std::move(moduleInputBuffer),
624619
std::move(moduleDocInputBuffer),
625620
isFramework, info, extInfo));
626-
assert(info.status == theModule->getStatus());
627621
return info;
628622
}
629623

@@ -655,7 +649,8 @@ class ModuleFile
655649
/// other parts of the compiler could have emitted diagnostics, to keep them
656650
/// alive even if the ModuleFile is destroyed.
657651
///
658-
/// 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.
659654
std::unique_ptr<llvm::MemoryBuffer> takeBufferForDiagnostics();
660655

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

lib/Serialization/ModuleFile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ ModuleFile::ModuleFile(
12421242
: ModuleInputBuffer(std::move(moduleInputBuffer)),
12431243
ModuleDocInputBuffer(std::move(moduleDocInputBuffer)),
12441244
DeserializedTypeCallback([](Type ty) {}) {
1245-
assert(getStatus() == Status::Valid);
1245+
assert(!hasError());
12461246
Bits.IsFramework = isFramework;
12471247

12481248
PrettyStackTraceModuleFile stackEntry(*this);
@@ -1490,7 +1490,7 @@ Status ModuleFile::associateWithFileContext(FileUnit *file,
14901490
bool treatAsPartialModule) {
14911491
PrettyStackTraceModuleFile stackEntry(*this);
14921492

1493-
assert(getStatus() == Status::Valid && "invalid module file");
1493+
assert(!hasError() && "error already detected; should not call this");
14941494
assert(!FileContext && "already associated with an AST module");
14951495
FileContext = file;
14961496

@@ -1612,11 +1612,11 @@ Status ModuleFile::associateWithFileContext(FileUnit *file,
16121612
None);
16131613
}
16141614

1615-
return getStatus();
1615+
return Status::Valid;
16161616
}
16171617

16181618
std::unique_ptr<llvm::MemoryBuffer> ModuleFile::takeBufferForDiagnostics() {
1619-
assert(getStatus() != Status::Valid);
1619+
assert(hasError());
16201620

16211621
// Today, the only buffer that might have diagnostics in them is the input
16221622
// buffer, and even then only if it has imported module contents.

0 commit comments

Comments
 (0)