Skip to content

Commit 8cf1661

Browse files
committed
[Serialization] Write in the swiftmodule if it's built from a swiftinterface
This information will allow us to distinguish swiftmodule built from source vs swiftinterface.
1 parent 27c1578 commit 8cf1661

File tree

8 files changed

+39
-2
lines changed

8 files changed

+39
-2
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
617617
HasAnyUnavailableValues : 1
618618
);
619619

620-
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1+1+1+1+1,
620+
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1+1+1+1+1+1,
621621
/// If the module is compiled as static library.
622622
StaticLibrary : 1,
623623

@@ -632,6 +632,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
632632
/// \sa ResilienceStrategy
633633
RawResilienceStrategy : 1,
634634

635+
/// Whether the module was rebuilt from a module interface instead of being
636+
/// build from the full source.
637+
IsBuiltFromInterface : 1,
638+
635639
/// Whether all imports have been resolved. Used to detect circular imports.
636640
HasResolvedImports : 1,
637641

include/swift/AST/Module.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,15 @@ class ModuleDecl
544544
Bits.ModuleDecl.IsSystemModule = flag;
545545
}
546546

547+
/// Returns true if the module was rebuilt from a module interface instead
548+
/// of being built from the full source.
549+
bool isBuiltFromInterface() const {
550+
return Bits.ModuleDecl.IsBuiltFromInterface;
551+
}
552+
void setIsBuiltFromInterface(bool flag = true) {
553+
Bits.ModuleDecl.IsBuiltFromInterface = flag;
554+
}
555+
547556
/// Returns true if this module is a non-Swift module that was imported into
548557
/// Swift.
549558
///

include/swift/Serialization/Validation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class ExtendedValidationInfo {
114114
unsigned IsTestable : 1;
115115
unsigned ResilienceStrategy : 2;
116116
unsigned IsImplicitDynamicEnabled : 1;
117+
unsigned IsBuiltFromInterface : 1;
117118
unsigned IsAllowModuleWithCompilerErrorsEnabled : 1;
118119
unsigned IsConcurrencyChecked : 1;
119120
} Bits;
@@ -163,6 +164,10 @@ class ExtendedValidationInfo {
163164
void setResilienceStrategy(ResilienceStrategy resilience) {
164165
Bits.ResilienceStrategy = unsigned(resilience);
165166
}
167+
bool isBuiltFromInterface() const { return Bits.IsBuiltFromInterface; }
168+
void setIsBuiltFromInterface(bool val) {
169+
Bits.IsBuiltFromInterface = val;
170+
}
166171
bool isAllowModuleWithCompilerErrorsEnabled() {
167172
return Bits.IsAllowModuleWithCompilerErrorsEnabled;
168173
}

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(
255255

256256
SILOptions &SILOpts = Invocation.getSILOptions();
257257
auto Mod = Instance.getMainModule();
258+
Mod->setIsBuiltFromInterface(true);
258259
auto &TC = Instance.getSILTypes();
259260
auto SILMod = performASTLowering(Mod, TC, SILOpts);
260261
if (!SILMod) {

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
151151
options_block::ResilienceStrategyLayout::readRecord(scratch, Strategy);
152152
extendedInfo.setResilienceStrategy(ResilienceStrategy(Strategy));
153153
break;
154+
case options_block::IS_BUILT_FROM_INTERFACE:
155+
extendedInfo.setIsBuiltFromInterface(true);
156+
break;
154157
case options_block::IS_ALLOW_MODULE_WITH_COMPILER_ERRORS_ENABLED:
155158
extendedInfo.setAllowModuleWithCompilerErrorsEnabled(true);
156159
break;
@@ -1319,6 +1322,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
13191322
Bits.IsTestable = extInfo.isTestable();
13201323
Bits.ResilienceStrategy = unsigned(extInfo.getResilienceStrategy());
13211324
Bits.IsImplicitDynamicEnabled = extInfo.isImplicitDynamicEnabled();
1325+
Bits.IsBuiltFromInterface = extInfo.isBuiltFromInterface();
13221326
Bits.IsAllowModuleWithCompilerErrorsEnabled =
13231327
extInfo.isAllowModuleWithCompilerErrorsEnabled();
13241328
Bits.IsConcurrencyChecked = extInfo.isConcurrencyChecked();

lib/Serialization/ModuleFileSharedCore.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ class ModuleFileSharedCore {
347347
/// Discriminator for resilience strategy.
348348
unsigned ResilienceStrategy : 2;
349349

350+
/// Whether the module was rebuilt from a module interface instead of being
351+
/// build from the full source.
352+
unsigned IsBuiltFromInterface: 1;
353+
350354
/// Whether this module is compiled with implicit dynamic.
351355
unsigned IsImplicitDynamicEnabled: 1;
352356

lib/Serialization/ModuleFormat.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 718; // element archetype
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 719; // isBuiltFromInterface
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -829,6 +829,7 @@ namespace options_block {
829829
IS_ALLOW_MODULE_WITH_COMPILER_ERRORS_ENABLED,
830830
MODULE_ABI_NAME,
831831
IS_CONCURRENCY_CHECKED,
832+
IS_BUILT_FROM_INTERFACE,
832833
};
833834

834835
using SDKPathLayout = BCRecordLayout<
@@ -871,6 +872,10 @@ namespace options_block {
871872
BCFixed<2>
872873
>;
873874

875+
using IsBuiltFromInterfaceLayout = BCRecordLayout<
876+
IS_BUILT_FROM_INTERFACE
877+
>;
878+
874879
using IsAllowModuleWithCompilerErrorsEnabledLayout = BCRecordLayout<
875880
IS_ALLOW_MODULE_WITH_COMPILER_ERRORS_ENABLED
876881
>;

lib/Serialization/Serialization.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,11 @@ void Serializer::writeHeader(const SerializationOptions &options) {
10491049
Strategy.emit(ScratchRecord, unsigned(M->getResilienceStrategy()));
10501050
}
10511051

1052+
if (M->isBuiltFromInterface()) {
1053+
options_block::IsBuiltFromInterfaceLayout BuiltFromInterface(Out);
1054+
BuiltFromInterface.emit(ScratchRecord);
1055+
}
1056+
10521057
if (allowCompilerErrors()) {
10531058
options_block::IsAllowModuleWithCompilerErrorsEnabledLayout
10541059
AllowErrors(Out);

0 commit comments

Comments
 (0)