Skip to content

Commit 67bbab7

Browse files
committed
serialization: encode allowable client names in binary module format
1 parent 1f3e159 commit 67bbab7

File tree

15 files changed

+61
-2
lines changed

15 files changed

+61
-2
lines changed

include/swift/AST/Module.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,18 @@ class ModuleDecl
418418
return UserModuleVersion;
419419
}
420420

421+
void addAllowableClientName(Identifier name) {
422+
allowableClientNames.push_back(name);
423+
}
424+
ArrayRef<Identifier> getAllowableClientNames() const {
425+
return allowableClientNames;
426+
}
421427
private:
428+
429+
/// An array of module names that are allowed to import this one.
430+
/// Any module can import this one if empty.
431+
std::vector<Identifier> allowableClientNames;
432+
422433
/// A cache of this module's underlying module and required bystander if it's
423434
/// an underscored cross-import overlay.
424435
Optional<std::pair<ModuleDecl *, Identifier>> declaringModuleAndBystander;

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class FrontendOptions {
9797
/// User-defined module version number.
9898
llvm::VersionTuple UserModuleVersion;
9999

100+
/// A set of modules allowed to import this module.
101+
std::set<std::string> AllowableClients;
102+
100103
/// Emit index data for imported serialized swift system modules.
101104
bool IndexSystemModules = false;
102105

include/swift/Serialization/SerializationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace swift {
3535
std::string ABIDescriptorPath;
3636
bool emptyABIDescriptor = false;
3737
llvm::VersionTuple UserModuleVersion;
38+
std::set<std::string> AllowableClients;
3839
std::string SDKName;
3940

4041
StringRef GroupInfoPath;

include/swift/Serialization/Validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct ValidationInfo {
9393
StringRef sdkName = {};
9494
size_t bytes = 0;
9595
Status status = Status::Malformed;
96+
std::vector<StringRef> allowableClients;
9697
};
9798

9899
/// A collection of options that can be used to set up a new AST context

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ bool ArgsToFrontendOptionsConverter::convert(
120120
}
121121
}
122122

123+
for (auto A : Args.getAllArgValues(options::OPT_allowable_client)) {
124+
Opts.AllowableClients.insert(StringRef(A).str());
125+
}
126+
123127
Opts.DisableImplicitModules |= Args.hasArg(OPT_disable_implicit_swift_modules);
124128

125129
Opts.ImportPrescan |= Args.hasArg(OPT_import_prescan);

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
154154
serializationOpts.ImportedHeader = opts.ImplicitObjCHeaderPath;
155155
serializationOpts.ModuleLinkName = opts.ModuleLinkName;
156156
serializationOpts.UserModuleVersion = opts.UserModuleVersion;
157+
serializationOpts.AllowableClients = opts.AllowableClients;
157158

158159
serializationOpts.PublicDependentLibraries =
159160
getIRGenOptions().PublicLinkLibraries;

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(
266266
SerializationOpts.AutolinkForceLoad =
267267
!Invocation.getIRGenOptions().ForceLoadSymbolName.empty();
268268
SerializationOpts.UserModuleVersion = FEOpts.UserModuleVersion;
269+
SerializationOpts.AllowableClients = FEOpts.AllowableClients;
269270

270271
// Record any non-SDK module interface files for the debug info.
271272
StringRef SDKPath = Instance.getASTContext().SearchPathOpts.getSDKPath();

lib/Serialization/ModuleFile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ class ModuleFile
480480
return Core->UserModuleVersion;
481481
}
482482

483+
ArrayRef<StringRef> getAllowableClientNames() const {
484+
return Core->AllowableClientNames;
485+
}
486+
483487
/// The Swift compatibility version in use when this module was built.
484488
const version::Version &getCompatibilityVersion() const {
485489
return Core->CompatibilityVersion;

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ static ValidationInfo validateControlBlock(
310310
case control_block::TARGET:
311311
result.targetTriple = blobData;
312312
break;
313+
case control_block::ALLOWABLE_CLIENT_NAME:
314+
result.allowableClients.push_back(blobData);
315+
break;
313316
case control_block::SDK_NAME: {
314317
result.sdkName = blobData;
315318

@@ -1320,6 +1323,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
13201323
SDKName = info.sdkName;
13211324
CompatibilityVersion = info.compatibilityVersion;
13221325
UserModuleVersion = info.userModuleVersion;
1326+
AllowableClientNames = info.allowableClients;
13231327
Bits.ArePrivateImportsEnabled = extInfo.arePrivateImportsEnabled();
13241328
Bits.IsSIB = extInfo.isSIB();
13251329
Bits.IsStaticLibrary = extInfo.isStaticLibrary();

lib/Serialization/ModuleFileSharedCore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class ModuleFileSharedCore {
8888
/// \c true if this module was compiled with -enable-ossa-modules.
8989
bool RequiresOSSAModules;
9090

91+
/// An array of module names that are allowed to import this one.
92+
ArrayRef<StringRef> AllowableClientNames;
93+
9194
public:
9295
/// Represents another module that has been imported as a dependency.
9396
class Dependency {

0 commit comments

Comments
 (0)