Skip to content

Commit b7c1965

Browse files
committed
[Serialization] Minor ModuleFile/ModuleFileSharedCore improvements
* Add properties to ModuleFile which holds information from the control block. * 'ExtendedValidationInfo' parameter for 'ModuleFileSharedCore::load()' cannot be 'nullptr'. Make it non-defaulted Rvalue reference.
1 parent e524b1c commit b7c1965

File tree

5 files changed

+52
-18
lines changed

5 files changed

+52
-18
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ ModuleFile::getModuleName(ASTContext &Ctx, StringRef modulePath,
357357
nullptr,
358358
nullptr,
359359
/*isFramework*/isFramework, loadedModuleFile,
360-
&ExtInfo);
360+
ExtInfo);
361361
Name = loadedModuleFile->Name.str();
362362
return std::move(moduleBuf.get());
363363
}

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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
10881088
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
10891089
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
10901090
bool isFramework, serialization::ValidationInfo &info,
1091-
serialization::ExtendedValidationInfo *extInfo)
1091+
serialization::ExtendedValidationInfo &extInfo)
10921092
: ModuleInputBuffer(std::move(moduleInputBuffer)),
10931093
ModuleDocInputBuffer(std::move(moduleDocInputBuffer)),
10941094
ModuleSourceInfoInputBuffer(std::move(moduleSourceInfoInputBuffer)) {
@@ -1137,15 +1137,19 @@ ModuleFileSharedCore::ModuleFileSharedCore(
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: 17 additions & 7 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 = {};
@@ -327,7 +337,7 @@ class ModuleFileSharedCore {
327337
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
328338
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
329339
bool isFramework, serialization::ValidationInfo &info,
330-
serialization::ExtendedValidationInfo *extInfo);
340+
serialization::ExtendedValidationInfo &extInfo);
331341

332342
/// Change the status of the current module.
333343
Status error(Status issue) {
@@ -456,7 +466,7 @@ class ModuleFileSharedCore {
456466
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
457467
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
458468
bool isFramework, std::shared_ptr<const ModuleFileSharedCore> &theModule,
459-
serialization::ExtendedValidationInfo *extInfo = nullptr) {
469+
serialization::ExtendedValidationInfo &extInfo) {
460470
serialization::ValidationInfo info;
461471
auto *core = new ModuleFileSharedCore(
462472
std::move(moduleInputBuffer), std::move(moduleDocInputBuffer),

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ llvm::ErrorOr<ModuleDependencies> SerializedModuleLoaderBase::scanModuleFile(
394394
nullptr,
395395
nullptr,
396396
isFramework, loadedModuleFile,
397-
&extInfo);
397+
extInfo);
398398

399399
// Map the set of dependencies over to the "module dependencies".
400400
auto dependencies = ModuleDependencies::forSwiftModule(modulePath.str(), isFramework);
@@ -704,19 +704,19 @@ FileUnit *SerializedModuleLoaderBase::loadAST(
704704
std::move(moduleDocInputBuffer),
705705
std::move(moduleSourceInfoInputBuffer),
706706
isFramework, loadedModuleFileCore,
707-
&extendedInfo);
707+
extendedInfo);
708708
if (loadInfo.status == serialization::Status::Valid) {
709709
loadedModuleFile =
710710
std::make_unique<ModuleFile>(std::move(loadedModuleFileCore));
711-
M.setResilienceStrategy(extendedInfo.getResilienceStrategy());
711+
M.setResilienceStrategy(loadedModuleFile->getResilienceStrategy());
712712

713713
// We've loaded the file. Now try to bring it into the AST.
714714
auto fileUnit = new (Ctx) SerializedASTFile(M, *loadedModuleFile);
715-
if (extendedInfo.isTestable())
715+
if (loadedModuleFile->isTestable())
716716
M.setTestingEnabled();
717-
if (extendedInfo.arePrivateImportsEnabled())
717+
if (loadedModuleFile->arePrivateImportsEnabled())
718718
M.setPrivateImportsEnabled();
719-
if (extendedInfo.isImplicitDynamicEnabled())
719+
if (loadedModuleFile->isImplicitDynamicEnabled())
720720
M.setImplicitDynamicEnabled();
721721

722722
auto diagLocOrInvalid = diagLoc.getValueOr(SourceLoc());

0 commit comments

Comments
 (0)