Skip to content

Commit aa3836f

Browse files
committed
[NFC] Add SerializationOptions to ASTContext
1 parent 75ec2ff commit aa3836f

File tree

12 files changed

+190
-165
lines changed

12 files changed

+190
-165
lines changed

include/swift/AST/ASTContext.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
#include "swift/AST/Type.h"
2828
#include "swift/AST/TypeAlignments.h"
2929
#include "swift/AST/Types.h"
30+
#include "swift/Basic/BlockList.h"
3031
#include "swift/Basic/CASOptions.h"
3132
#include "swift/Basic/LangOptions.h"
3233
#include "swift/Basic/Located.h"
3334
#include "swift/Basic/Malloc.h"
34-
#include "swift/Basic/BlockList.h"
35+
#include "swift/Serialization/SerializationOptions.h"
3536
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
3637
#include "clang/AST/DeclTemplate.h"
3738
#include "clang/Basic/DarwinSDKInfo.h"
@@ -266,7 +267,8 @@ class ASTContext final {
266267
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
267268
ClangImporterOptions &ClangImporterOpts,
268269
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts,
269-
SourceManager &SourceMgr, DiagnosticEngine &Diags,
270+
SerializationOptions &serializationOpts, SourceManager &SourceMgr,
271+
DiagnosticEngine &Diags,
270272
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr);
271273

272274
public:
@@ -283,7 +285,8 @@ class ASTContext final {
283285
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
284286
ClangImporterOptions &ClangImporterOpts,
285287
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts, CASOptions &casOpts,
286-
SourceManager &SourceMgr, DiagnosticEngine &Diags,
288+
SerializationOptions &serializationOpts, SourceManager &SourceMgr,
289+
DiagnosticEngine &Diags,
287290
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr);
288291
~ASTContext();
289292

@@ -314,6 +317,9 @@ class ASTContext final {
314317
/// The CAS options used by this AST context.
315318
const CASOptions &CASOpts;
316319

320+
/// Options for Serialization
321+
const SerializationOptions &SerializationOpts;
322+
317323
/// The source manager object.
318324
SourceManager &SourceMgr;
319325

include/swift/Frontend/Frontend.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class CompilerInvocation {
104104
TBDGenOptions TBDGenOpts;
105105
ModuleInterfaceOptions ModuleInterfaceOpts;
106106
CASOptions CASOpts;
107+
SerializationOptions SerializationOpts;
107108
llvm::MemoryBuffer *IDEInspectionTargetBuffer = nullptr;
108109

109110
/// The offset that IDEInspection wants to further examine in offset of bytes
@@ -327,6 +328,11 @@ class CompilerInvocation {
327328
IRGenOptions &getIRGenOptions() { return IRGenOpts; }
328329
const IRGenOptions &getIRGenOptions() const { return IRGenOpts; }
329330

331+
SerializationOptions &getSerializationOptions() { return SerializationOpts; }
332+
const SerializationOptions &getSerializationOptions() const {
333+
return SerializationOpts;
334+
}
335+
330336
void setParseStdlib() {
331337
FrontendOpts.ParseStdlib = true;
332338
}

include/swift/Serialization/SerializationOptions.h

Lines changed: 135 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -24,144 +24,144 @@
2424

2525
namespace swift {
2626

27-
class SerializationOptions {
28-
SerializationOptions(const SerializationOptions &) = delete;
29-
void operator=(const SerializationOptions &) = delete;
27+
class SerializationOptions {
28+
public:
29+
SerializationOptions() = default;
30+
SerializationOptions(SerializationOptions &&) = default;
31+
SerializationOptions &operator=(SerializationOptions &&) = default;
32+
SerializationOptions(const SerializationOptions &) = default;
33+
SerializationOptions &operator=(const SerializationOptions &) = default;
34+
~SerializationOptions() = default;
35+
36+
StringRef OutputPath;
37+
StringRef DocOutputPath;
38+
StringRef SourceInfoOutputPath;
39+
std::string ABIDescriptorPath;
40+
bool emptyABIDescriptor = false;
41+
llvm::VersionTuple UserModuleVersion;
42+
std::set<std::string> AllowableClients;
43+
std::string SDKName;
44+
std::string SDKVersion;
45+
46+
StringRef GroupInfoPath;
47+
StringRef ImportedHeader;
48+
StringRef ModuleLinkName;
49+
StringRef ModuleInterface;
50+
std::vector<std::string> ExtraClangOptions;
51+
std::vector<swift::PluginSearchOption> PluginSearchOptions;
52+
53+
/// Path prefixes that should be rewritten in debug info.
54+
PathRemapper DebuggingOptionsPrefixMap;
55+
56+
/// Obfuscate the serialized paths so we don't have the actual paths encoded
57+
/// in the .swiftmodule file.
58+
PathObfuscator PathObfuscator;
59+
60+
/// Describes a single-file dependency for this module, along with the
61+
/// appropriate strategy for how to verify if it's up-to-date.
62+
class FileDependency {
63+
/// The size of the file on disk, in bytes.
64+
uint64_t Size : 62;
65+
66+
/// A dependency can be either hash-based or modification-time-based.
67+
bool IsHashBased : 1;
68+
69+
/// The dependency path can be absolute or relative to the SDK
70+
bool IsSDKRelative : 1;
71+
72+
union {
73+
/// The last modification time of the file.
74+
uint64_t ModificationTime;
75+
76+
/// The xxHash of the full contents of the file.
77+
uint64_t ContentHash;
78+
};
79+
80+
/// The path to the dependency.
81+
std::string Path;
82+
83+
FileDependency(uint64_t size, bool isHash, uint64_t hashOrModTime,
84+
StringRef path, bool isSDKRelative)
85+
: Size(size), IsHashBased(isHash), IsSDKRelative(isSDKRelative),
86+
ModificationTime(hashOrModTime), Path(path) {}
3087

3188
public:
32-
SerializationOptions() = default;
33-
SerializationOptions(SerializationOptions &&) = default;
34-
SerializationOptions &operator=(SerializationOptions &&) = default;
35-
~SerializationOptions() = default;
36-
37-
StringRef OutputPath;
38-
StringRef DocOutputPath;
39-
StringRef SourceInfoOutputPath;
40-
std::string ABIDescriptorPath;
41-
bool emptyABIDescriptor = false;
42-
llvm::VersionTuple UserModuleVersion;
43-
std::set<std::string> AllowableClients;
44-
std::string SDKName;
45-
std::string SDKVersion;
46-
47-
StringRef GroupInfoPath;
48-
StringRef ImportedHeader;
49-
StringRef ModuleLinkName;
50-
StringRef ModuleInterface;
51-
std::vector<std::string> ExtraClangOptions;
52-
std::vector<swift::PluginSearchOption> PluginSearchOptions;
53-
54-
/// Path prefixes that should be rewritten in debug info.
55-
PathRemapper DebuggingOptionsPrefixMap;
56-
57-
/// Obfuscate the serialized paths so we don't have the actual paths encoded
58-
/// in the .swiftmodule file.
59-
PathObfuscator PathObfuscator;
60-
61-
/// Describes a single-file dependency for this module, along with the
62-
/// appropriate strategy for how to verify if it's up-to-date.
63-
class FileDependency {
64-
/// The size of the file on disk, in bytes.
65-
uint64_t Size : 62;
66-
67-
/// A dependency can be either hash-based or modification-time-based.
68-
bool IsHashBased : 1;
69-
70-
/// The dependency path can be absolute or relative to the SDK
71-
bool IsSDKRelative : 1;
72-
73-
union {
74-
/// The last modification time of the file.
75-
uint64_t ModificationTime;
76-
77-
/// The xxHash of the full contents of the file.
78-
uint64_t ContentHash;
79-
};
80-
81-
/// The path to the dependency.
82-
std::string Path;
83-
84-
FileDependency(uint64_t size, bool isHash, uint64_t hashOrModTime,
85-
StringRef path, bool isSDKRelative):
86-
Size(size), IsHashBased(isHash), IsSDKRelative(isSDKRelative),
87-
ModificationTime(hashOrModTime), Path(path) {}
88-
public:
89-
FileDependency() = delete;
90-
91-
/// Creates a new hash-based file dependency.
92-
static FileDependency
93-
hashBased(StringRef path, bool isSDKRelative, uint64_t size, uint64_t hash) {
94-
return FileDependency(size, /*isHash*/true, hash, path, isSDKRelative);
95-
}
96-
97-
/// Creates a new modification time-based file dependency.
98-
static FileDependency
99-
modTimeBased(StringRef path, bool isSDKRelative, uint64_t size, uint64_t mtime) {
100-
return FileDependency(size, /*isHash*/false, mtime, path, isSDKRelative);
101-
}
102-
103-
/// Updates the last-modified time of this dependency.
104-
/// If the dependency is a hash-based dependency, it becomes
105-
/// modification time-based.
106-
void setLastModificationTime(uint64_t mtime) {
107-
IsHashBased = false;
108-
ModificationTime = mtime;
109-
}
110-
111-
/// Updates the content hash of this dependency.
112-
/// If the dependency is a modification time-based dependency, it becomes
113-
/// hash-based.
114-
void setContentHash(uint64_t hash) {
115-
IsHashBased = true;
116-
ContentHash = hash;
117-
}
118-
119-
/// Determines if this dependency is hash-based and should be validated
120-
/// based on content hash.
121-
bool isHashBased() const { return IsHashBased; }
122-
123-
/// Determines if this dependency is absolute or relative to the SDK.
124-
bool isSDKRelative() const { return IsSDKRelative; }
125-
126-
/// Determines if this dependency is hash-based and should be validated
127-
/// based on modification time.
128-
bool isModificationTimeBased() const { return !IsHashBased; }
129-
130-
/// Gets the modification time, if this is a modification time-based
131-
/// dependency.
132-
uint64_t getModificationTime() const {
133-
assert(isModificationTimeBased() &&
134-
"cannot get modification time for hash-based dependency");
135-
return ModificationTime;
136-
}
137-
138-
/// Gets the content hash, if this is a hash-based
139-
/// dependency.
140-
uint64_t getContentHash() const {
141-
assert(isHashBased() &&
142-
"cannot get content hash for mtime-based dependency");
143-
return ContentHash;
144-
}
145-
146-
StringRef getPath() const { return Path; }
147-
uint64_t getSize() const { return Size; }
148-
};
149-
ArrayRef<FileDependency> Dependencies;
150-
ArrayRef<std::string> PublicDependentLibraries;
151-
152-
bool AutolinkForceLoad = false;
153-
bool SerializeAllSIL = false;
154-
bool SerializeOptionsForDebugging = false;
155-
bool IsSIB = false;
156-
bool DisableCrossModuleIncrementalInfo = false;
157-
bool StaticLibrary = false;
158-
bool HermeticSealAtLink = false;
159-
bool EmbeddedSwiftModule = false;
160-
bool IsOSSA = false;
161-
bool SkipNonExportableDecls = false;
162-
bool ExplicitModuleBuild = false;
163-
bool EnableSerializationRemarks = false;
89+
FileDependency() = delete;
90+
91+
/// Creates a new hash-based file dependency.
92+
static FileDependency hashBased(StringRef path, bool isSDKRelative,
93+
uint64_t size, uint64_t hash) {
94+
return FileDependency(size, /*isHash*/ true, hash, path, isSDKRelative);
95+
}
96+
97+
/// Creates a new modification time-based file dependency.
98+
static FileDependency modTimeBased(StringRef path, bool isSDKRelative,
99+
uint64_t size, uint64_t mtime) {
100+
return FileDependency(size, /*isHash*/ false, mtime, path, isSDKRelative);
101+
}
102+
103+
/// Updates the last-modified time of this dependency.
104+
/// If the dependency is a hash-based dependency, it becomes
105+
/// modification time-based.
106+
void setLastModificationTime(uint64_t mtime) {
107+
IsHashBased = false;
108+
ModificationTime = mtime;
109+
}
110+
111+
/// Updates the content hash of this dependency.
112+
/// If the dependency is a modification time-based dependency, it becomes
113+
/// hash-based.
114+
void setContentHash(uint64_t hash) {
115+
IsHashBased = true;
116+
ContentHash = hash;
117+
}
118+
119+
/// Determines if this dependency is hash-based and should be validated
120+
/// based on content hash.
121+
bool isHashBased() const { return IsHashBased; }
122+
123+
/// Determines if this dependency is absolute or relative to the SDK.
124+
bool isSDKRelative() const { return IsSDKRelative; }
125+
126+
/// Determines if this dependency is hash-based and should be validated
127+
/// based on modification time.
128+
bool isModificationTimeBased() const { return !IsHashBased; }
129+
130+
/// Gets the modification time, if this is a modification time-based
131+
/// dependency.
132+
uint64_t getModificationTime() const {
133+
assert(isModificationTimeBased() &&
134+
"cannot get modification time for hash-based dependency");
135+
return ModificationTime;
136+
}
137+
138+
/// Gets the content hash, if this is a hash-based
139+
/// dependency.
140+
uint64_t getContentHash() const {
141+
assert(isHashBased() &&
142+
"cannot get content hash for mtime-based dependency");
143+
return ContentHash;
144+
}
145+
146+
StringRef getPath() const { return Path; }
147+
uint64_t getSize() const { return Size; }
164148
};
149+
ArrayRef<FileDependency> Dependencies;
150+
ArrayRef<std::string> PublicDependentLibraries;
151+
152+
bool AutolinkForceLoad = false;
153+
bool SerializeAllSIL = false;
154+
bool SerializeOptionsForDebugging = false;
155+
bool IsSIB = false;
156+
bool DisableCrossModuleIncrementalInfo = false;
157+
bool StaticLibrary = false;
158+
bool HermeticSealAtLink = false;
159+
bool EmbeddedSwiftModule = false;
160+
bool IsOSSA = false;
161+
bool SkipNonExportableDecls = false;
162+
bool ExplicitModuleBuild = false;
163+
bool EnableSerializationRemarks = false;
164+
};
165165

166166
} // end namespace swift
167167
#endif

0 commit comments

Comments
 (0)