Skip to content

Commit bec6a8f

Browse files
authored
Merge pull request #33789 from rintaro/serialization-modulefile-extinfo
[Serialization] Minor ModuleFile/ModuleFileSharedCore improvements
2 parents ea6cae6 + 6a0a448 commit bec6a8f

File tree

6 files changed

+58
-33
lines changed

6 files changed

+58
-33
lines changed

include/swift/Serialization/Validation.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ ValidationInfo validateSerializedAST(
177177
/// - \p ModuleName is the name used to refer to the module in diagnostics.
178178
void diagnoseSerializedASTLoadFailure(
179179
ASTContext &Ctx, SourceLoc diagLoc, const ValidationInfo &loadInfo,
180-
const ExtendedValidationInfo &extendedInfo, StringRef moduleBufferID,
181-
StringRef moduleDocBufferID, ModuleFile *loadedModuleFile,
182-
Identifier ModuleName);
180+
StringRef moduleBufferID, StringRef moduleDocBufferID,
181+
ModuleFile *loadedModuleFile, Identifier ModuleName);
183182

184183
} // end namespace serialization
185184
} // end namespace swift

lib/Serialization/ModuleFile.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,13 @@ ModuleFile::getModuleName(ASTContext &Ctx, StringRef modulePath,
349349
llvm::MemoryBuffer::getMemBuffer(llvm::MemoryBufferRef(*moduleBuf.get()),
350350
/*RequiresNullTerminator=*/false);
351351
std::shared_ptr<const ModuleFileSharedCore> loadedModuleFile;
352-
ExtendedValidationInfo ExtInfo;
353352
bool isFramework = false;
354353
serialization::ValidationInfo loadInfo =
355354
ModuleFileSharedCore::load(modulePath.str(),
356355
std::move(newBuf),
357356
nullptr,
358357
nullptr,
359-
/*isFramework*/isFramework, loadedModuleFile,
360-
&ExtInfo);
358+
/*isFramework*/isFramework, loadedModuleFile);
361359
Name = loadedModuleFile->Name.str();
362360
return std::move(moduleBuf.get());
363361
}

lib/Serialization/ModuleFile.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,31 @@ class ModuleFile
438438
return Core->CompatibilityVersion;
439439
}
440440

441+
/// Whether this module is compiled with `-enable-private-imports`.
442+
bool arePrivateImportsEnabled() const {
443+
return Core->Bits.ArePrivateImportsEnabled;
444+
}
445+
441446
/// Is this module file actually a .sib file? .sib files are serialized SIL at
442447
/// arbitrary granularity and arbitrary stage; unlike serialized Swift
443448
/// modules, which are assumed to contain canonical SIL for an entire module.
444449
bool isSIB() const {
445-
return Core->IsSIB;
450+
return Core->Bits.IsSIB;
451+
}
452+
453+
/// Whether this module file is compiled with '-enable-testing'.
454+
bool isTestable() const {
455+
return Core->Bits.IsTestable;
456+
}
457+
458+
/// Whether the module is resilient. ('-enable-library-evolution')
459+
ResilienceStrategy getResilienceStrategy() const {
460+
return ResilienceStrategy(Core->Bits.ResilienceStrategy);
461+
}
462+
463+
/// Whether this module is compiled with implicit dynamic.
464+
bool isImplicitDynamicEnabled() const {
465+
return Core->Bits.IsImplicitDynamicEnabled;
446466
}
447467

448468
/// Associates this module file with the AST node representing it.

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
10871087
std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,
10881088
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
10891089
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
1090-
bool isFramework, serialization::ValidationInfo &info,
1091-
serialization::ExtendedValidationInfo *extInfo)
1090+
bool isFramework, serialization::ValidationInfo &info)
10921091
: ModuleInputBuffer(std::move(moduleInputBuffer)),
10931092
ModuleDocInputBuffer(std::move(moduleDocInputBuffer)),
10941093
ModuleSourceInfoInputBuffer(std::move(moduleSourceInfoInputBuffer)) {
@@ -1134,18 +1133,23 @@ ModuleFileSharedCore::ModuleFileSharedCore(
11341133
return;
11351134
}
11361135

1136+
ExtendedValidationInfo extInfo;
11371137
info = validateControlBlock(cursor, scratch,
11381138
{SWIFTMODULE_VERSION_MAJOR,
11391139
SWIFTMODULE_VERSION_MINOR},
1140-
extInfo);
1140+
&extInfo);
11411141
if (info.status != Status::Valid) {
11421142
error(info.status);
11431143
return;
11441144
}
11451145
Name = info.name;
11461146
TargetTriple = info.targetTriple;
11471147
CompatibilityVersion = info.compatibilityVersion;
1148-
IsSIB = extInfo->isSIB();
1148+
Bits.ArePrivateImportsEnabled = extInfo.arePrivateImportsEnabled();
1149+
Bits.IsSIB = extInfo.isSIB();
1150+
Bits.IsTestable = extInfo.isTestable();
1151+
Bits.ResilienceStrategy = unsigned(extInfo.getResilienceStrategy());
1152+
Bits.IsImplicitDynamicEnabled = extInfo.isImplicitDynamicEnabled();
11491153
MiscVersion = info.miscVersion;
11501154

11511155
hasValidControlBlock = true;

lib/Serialization/ModuleFileSharedCore.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ class ModuleFileSharedCore {
6969
/// The data blob containing all of the module's identifiers.
7070
StringRef IdentifierData;
7171

72-
/// Is this module file actually a .sib file? .sib files are serialized SIL at
73-
/// arbitrary granularity and arbitrary stage; unlike serialized Swift
74-
/// modules, which are assumed to contain canonical SIL for an entire module.
75-
bool IsSIB = false;
76-
7772
// Full blob from the misc. version field of the metadata block. This should
7873
// include the version string of the compiler that built the module.
7974
StringRef MiscVersion;
@@ -307,6 +302,21 @@ class ModuleFileSharedCore {
307302
/// Whether an error has been detected setting up this module file.
308303
unsigned HasError : 1;
309304

305+
/// Whether this module is `-enable-private-imports`.
306+
unsigned ArePrivateImportsEnabled : 1;
307+
308+
/// Whether this module file is actually a .sib file.
309+
unsigned IsSIB: 1;
310+
311+
/// Whether this module file is compiled with '-enable-testing'.
312+
unsigned IsTestable : 1;
313+
314+
/// Discriminator for resilience strategy.
315+
unsigned ResilienceStrategy : 2;
316+
317+
/// Whether this module is compiled with implicit dynamic.
318+
unsigned IsImplicitDynamicEnabled: 1;
319+
310320
// Explicitly pad out to the next word boundary.
311321
unsigned : 0;
312322
} Bits = {};
@@ -326,8 +336,7 @@ class ModuleFileSharedCore {
326336
ModuleFileSharedCore(std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,
327337
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
328338
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
329-
bool isFramework, serialization::ValidationInfo &info,
330-
serialization::ExtendedValidationInfo *extInfo);
339+
bool isFramework, serialization::ValidationInfo &info);
331340

332341
/// Change the status of the current module.
333342
Status error(Status issue) {
@@ -455,12 +464,12 @@ class ModuleFileSharedCore {
455464
std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,
456465
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
457466
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
458-
bool isFramework, std::shared_ptr<const ModuleFileSharedCore> &theModule,
459-
serialization::ExtendedValidationInfo *extInfo = nullptr) {
467+
bool isFramework,
468+
std::shared_ptr<const ModuleFileSharedCore> &theModule) {
460469
serialization::ValidationInfo info;
461470
auto *core = new ModuleFileSharedCore(
462471
std::move(moduleInputBuffer), std::move(moduleDocInputBuffer),
463-
std::move(moduleSourceInfoInputBuffer), isFramework, info, extInfo);
472+
std::move(moduleSourceInfoInputBuffer), isFramework, info);
464473
if (!moduleInterfacePath.empty()) {
465474
ArrayRef<char> path;
466475
core->allocateBuffer(path, moduleInterfacePath);

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,12 @@ llvm::ErrorOr<ModuleDependencies> SerializedModuleLoaderBase::scanModuleFile(
387387
// Load the module file without validation.
388388
std::shared_ptr<const ModuleFileSharedCore> loadedModuleFile;
389389
bool isFramework = false;
390-
serialization::ExtendedValidationInfo extInfo;
391390
serialization::ValidationInfo loadInfo =
392391
ModuleFileSharedCore::load(modulePath.str(),
393392
std::move(moduleBuf.get()),
394393
nullptr,
395394
nullptr,
396-
isFramework, loadedModuleFile,
397-
&extInfo);
395+
isFramework, loadedModuleFile);
398396

399397
// Map the set of dependencies over to the "module dependencies".
400398
auto dependencies = ModuleDependencies::forSwiftModule(modulePath.str(), isFramework);
@@ -695,28 +693,26 @@ FileUnit *SerializedModuleLoaderBase::loadAST(
695693
return nullptr;
696694
}
697695

698-
serialization::ExtendedValidationInfo extendedInfo;
699696
std::unique_ptr<ModuleFile> loadedModuleFile;
700697
std::shared_ptr<const ModuleFileSharedCore> loadedModuleFileCore;
701698
serialization::ValidationInfo loadInfo =
702699
ModuleFileSharedCore::load(moduleInterfacePath,
703700
std::move(moduleInputBuffer),
704701
std::move(moduleDocInputBuffer),
705702
std::move(moduleSourceInfoInputBuffer),
706-
isFramework, loadedModuleFileCore,
707-
&extendedInfo);
703+
isFramework, loadedModuleFileCore);
708704
if (loadInfo.status == serialization::Status::Valid) {
709705
loadedModuleFile =
710706
std::make_unique<ModuleFile>(std::move(loadedModuleFileCore));
711-
M.setResilienceStrategy(extendedInfo.getResilienceStrategy());
707+
M.setResilienceStrategy(loadedModuleFile->getResilienceStrategy());
712708

713709
// We've loaded the file. Now try to bring it into the AST.
714710
auto fileUnit = new (Ctx) SerializedASTFile(M, *loadedModuleFile);
715-
if (extendedInfo.isTestable())
711+
if (loadedModuleFile->isTestable())
716712
M.setTestingEnabled();
717-
if (extendedInfo.arePrivateImportsEnabled())
713+
if (loadedModuleFile->arePrivateImportsEnabled())
718714
M.setPrivateImportsEnabled();
719-
if (extendedInfo.isImplicitDynamicEnabled())
715+
if (loadedModuleFile->isImplicitDynamicEnabled())
720716
M.setImplicitDynamicEnabled();
721717

722718
auto diagLocOrInvalid = diagLoc.getValueOr(SourceLoc());
@@ -744,7 +740,7 @@ FileUnit *SerializedModuleLoaderBase::loadAST(
744740

745741
if (diagLoc)
746742
serialization::diagnoseSerializedASTLoadFailure(
747-
Ctx, *diagLoc, loadInfo, extendedInfo, moduleBufferID,
743+
Ctx, *diagLoc, loadInfo, moduleBufferID,
748744
moduleDocBufferID, loadedModuleFile.get(), M.getName());
749745

750746
// Even though the module failed to load, it's possible its contents include
@@ -761,7 +757,6 @@ FileUnit *SerializedModuleLoaderBase::loadAST(
761757
void swift::serialization::diagnoseSerializedASTLoadFailure(
762758
ASTContext &Ctx, SourceLoc diagLoc,
763759
const serialization::ValidationInfo &loadInfo,
764-
const serialization::ExtendedValidationInfo &extendedInfo,
765760
StringRef moduleBufferID, StringRef moduleDocBufferID,
766761
ModuleFile *loadedModuleFile, Identifier ModuleName) {
767762
auto diagnoseDifferentLanguageVersion = [&](StringRef shortVersion) -> bool {

0 commit comments

Comments
 (0)