Skip to content

Commit a8a3eee

Browse files
authored
Merge pull request #1252 from swiftwasm/maxd/master-merge
Resolve conflicts with master
2 parents f2b83a3 + ac7c8ce commit a8a3eee

File tree

157 files changed

+1280
-590
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+1280
-590
lines changed

docs/ABI/TypeMetadata.rst

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,18 @@ classes.
222222
record is stored at **offset 0**, in place of an integer kind discriminator.
223223
- The **super pointer** pointing to the metadata record for the superclass is
224224
stored at **offset 1**. If the class is a root class, it is null.
225-
- Two words are reserved for use by the Objective-C runtime at **offset 2**
226-
and **offset 3**.
227-
- The **rodata pointer** is stored at **offset 4**; it points to an Objective-C
228-
compatible rodata record for the class. This pointer value includes a tag.
225+
- On platforms which support Objective-C interoperability, two words are
226+
reserved for use by the Objective-C runtime at **offset 2** and **offset
227+
3**; on other platforms, nothing is reserved.
228+
- On platforms which support Objective-C interoperability, the **rodata
229+
pointer** is stored at **offset 4**; on other platforms, it is not present.
230+
The rodata pointer points to an Objective-C compatible rodata record for the
231+
class. This pointer value includes a tag.
229232
The **low bit is always set to 1** for Swift classes and always set to 0 for
230233
Objective-C classes.
231-
- The **class flags** are a 32-bit field at **offset 5**.
234+
- The **class flags** are a 32-bit field at **offset 5** on platforms which
235+
support Objective-C interoperability; on other platforms, the field is at
236+
**offset 2**.
232237
- The **instance address point** is a 32-bit field following the class flags.
233238
A pointer to an instance of this class points this number of bytes after the
234239
beginning of the instance.
@@ -246,8 +251,11 @@ classes.
246251
object size. This is the number of bytes of storage in the class metadata
247252
object.
248253
- The `nominal type descriptor`_ for the most-derived class type is referenced
249-
at an offset immediately following the class object address point. This is
250-
**offset 8** on a 64-bit platform or **offset 11** on a 32-bit platform.
254+
at an offset immediately following the class object address point. On 64-bit
255+
and 32-bit platforms which support Objective-C interoperability, this is,
256+
respectively, at **offset 8** and at **offset 11**; in platforms that do not
257+
support Objective-C interoperability, this is, respectively, at **offset 5**
258+
and at **offset 8**.
251259
- For each Swift class in the class's inheritance hierarchy, in order starting
252260
from the root class and working down to the most derived class, the following
253261
fields are present:

include/swift/AST/ASTContext.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,6 @@ class ASTContext final {
254254
/// The request-evaluator that is used to process various requests.
255255
Evaluator evaluator;
256256

257-
/// The set of top-level modules we have loaded.
258-
/// This map is used for iteration, therefore it's a MapVector and not a
259-
/// DenseMap.
260-
llvm::MapVector<Identifier, ModuleDecl*> LoadedModules;
261-
262257
/// The builtin module.
263258
ModuleDecl * const TheBuiltinModule;
264259

@@ -787,8 +782,24 @@ class ASTContext final {
787782
/// The loader is owned by the AST context.
788783
ClangModuleLoader *getDWARFModuleLoader() const;
789784

785+
public:
790786
namelookup::ImportCache &getImportCache() const;
791787

788+
/// Returns an iterator over the modules that are known by this context
789+
/// to be loaded.
790+
///
791+
/// Iteration order is guaranteed to match the order in which
792+
/// \c addLoadedModule was called to register the loaded module
793+
/// with this context.
794+
iterator_range<llvm::MapVector<Identifier, ModuleDecl *>::const_iterator>
795+
getLoadedModules() const;
796+
797+
/// Returns the number of loaded modules known by this context to be loaded.
798+
unsigned getNumLoadedModules() const {
799+
auto eltRange = getLoadedModules();
800+
return std::distance(eltRange.begin(), eltRange.end());
801+
}
802+
792803
/// Asks every module loader to verify the ASTs it has loaded.
793804
///
794805
/// Does nothing in non-asserts (NDEBUG) builds.
@@ -828,6 +839,11 @@ class ASTContext final {
828839
return const_cast<ASTContext *>(this)->getStdlibModule(false);
829840
}
830841

842+
/// Insert an externally-sourced module into the set of known loaded modules
843+
/// in this context.
844+
void addLoadedModule(ModuleDecl *M);
845+
846+
public:
831847
/// Retrieve the current generation number, which reflects the
832848
/// number of times a module import has caused mass invalidation of
833849
/// lookup tables.

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ ERROR(error_optimization_remark_pattern, none, "%0 in '%1'",
295295
ERROR(error_invalid_debug_prefix_map, none,
296296
"invalid argument '%0' to -debug-prefix-map; it must be of the form "
297297
"'original=remapped'", (StringRef))
298+
ERROR(error_invalid_coverage_prefix_map, none,
299+
"invalid argument '%0' to -coverage-prefix-map; it must be of the form "
300+
"'original=remapped'", (StringRef))
298301

299302

300303
ERROR(error_unable_to_write_swift_ranges_file, none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ ERROR(no_candidates_match_result_type,none,
253253
"no '%0' candidates produce the expected contextual result type %1",
254254
(StringRef, Type))
255255

256+
ERROR(no_candidates_match_argument_type,none,
257+
"no '%0' candidates produce the expected type %1 for parameter #%2",
258+
(StringRef, Type, unsigned))
259+
256260
ERROR(cannot_infer_closure_parameter_type,none,
257261
"unable to infer type of a closure parameter %0 in the current context",
258262
(StringRef))

include/swift/AST/FineGrainedDependencies.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/Basic/Range.h"
2020
#include "swift/Basic/ReferenceDependencyKeys.h"
2121
#include "llvm/ADT/Hashing.h"
22+
#include "llvm/ADT/SetVector.h"
2223
#include "llvm/Support/MD5.h"
2324
#include "llvm/Support/MemoryBuffer.h"
2425
#include "llvm/Support/YAMLParser.h"
@@ -684,7 +685,7 @@ class SourceFileDepGraphNode : public DepGraphNode {
684685
size_t sequenceNumber = ~0;
685686

686687
/// Holds the sequence numbers of definitions I depend upon.
687-
std::unordered_set<size_t> defsIDependUpon;
688+
llvm::SetVector<size_t> defsIDependUpon;
688689

689690
/// True iff a Decl exists for this node.
690691
/// If a provides and a depends in the existing system both have the same key,

include/swift/AST/IRGenOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ class IRGenOptions {
169169
/// Path prefixes that should be rewritten in debug info.
170170
PathRemapper DebugPrefixMap;
171171

172+
/// Path prefixes that should be rewritten in coverage info.
173+
PathRemapper CoveragePrefixMap;
174+
172175
/// What level of debug info to generate.
173176
IRGenDebugInfoLevel DebugInfoLevel : 2;
174177

include/swift/AST/ModuleDependencies.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ class SwiftModuleDependenciesStorage : public ModuleDependenciesStorageBase {
7373
/// interface.
7474
const std::vector<std::string> buildCommandLine;
7575

76+
/// To build a PCM to be used by this Swift module, we need to append these
77+
/// arguments to the generic PCM build arguments reported from the dependency
78+
/// graph.
79+
const std::vector<std::string> extraPCMArgs;
80+
7681
/// The hash value that will be used for the generated module
7782
const std::string contextHash;
7883

@@ -92,10 +97,12 @@ class SwiftModuleDependenciesStorage : public ModuleDependenciesStorageBase {
9297
const std::string &compiledModulePath,
9398
const Optional<std::string> &swiftInterfaceFile,
9499
ArrayRef<StringRef> buildCommandLine,
100+
ArrayRef<StringRef> extraPCMArgs,
95101
StringRef contextHash
96102
) : ModuleDependenciesStorageBase(/*isSwiftModule=*/true, compiledModulePath),
97103
swiftInterfaceFile(swiftInterfaceFile),
98104
buildCommandLine(buildCommandLine.begin(), buildCommandLine.end()),
105+
extraPCMArgs(extraPCMArgs.begin(), extraPCMArgs.end()),
99106
contextHash(contextHash) { }
100107

101108
ModuleDependenciesStorageBase *clone() const override {
@@ -176,18 +183,31 @@ class ModuleDependencies {
176183
const std::string &compiledModulePath,
177184
const std::string &swiftInterfaceFile,
178185
ArrayRef<StringRef> buildCommands,
186+
ArrayRef<StringRef> extraPCMArgs,
179187
StringRef contextHash) {
180188
return ModuleDependencies(
181189
std::make_unique<SwiftModuleDependenciesStorage>(
182-
compiledModulePath, swiftInterfaceFile, buildCommands, contextHash));
190+
compiledModulePath, swiftInterfaceFile, buildCommands,
191+
extraPCMArgs, contextHash));
183192
}
184193

185194
/// Describe the module dependencies for a serialized or parsed Swift module.
186195
static ModuleDependencies forSwiftModule(
187196
const std::string &compiledModulePath) {
188197
return ModuleDependencies(
189198
std::make_unique<SwiftModuleDependenciesStorage>(
190-
compiledModulePath, None, ArrayRef<StringRef>(), StringRef()));
199+
compiledModulePath, None, ArrayRef<StringRef>(),
200+
ArrayRef<StringRef>(), StringRef()));
201+
}
202+
203+
/// Describe the main Swift module.
204+
static ModuleDependencies forMainSwiftModule(
205+
const std::string &compiledModulePath,
206+
ArrayRef<StringRef> extraPCMArgs) {
207+
return ModuleDependencies(
208+
std::make_unique<SwiftModuleDependenciesStorage>(
209+
compiledModulePath, None, ArrayRef<StringRef>(), extraPCMArgs,
210+
StringRef()));
191211
}
192212

193213
/// Describe the module dependencies for a Clang module that can be

include/swift/AST/ModuleLoader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct SubCompilerInstanceInfo {
8989
CompilerInstance* Instance;
9090
StringRef Hash;
9191
ArrayRef<StringRef> BuildArguments;
92+
ArrayRef<StringRef> ExtraPCMArgs;
9293
};
9394

9495
/// Abstract interface to run an action in a sub ASTContext.
@@ -97,7 +98,8 @@ struct InterfaceSubContextDelegate {
9798
StringRef interfacePath,
9899
StringRef outputPath,
99100
SourceLoc diagLoc,
100-
llvm::function_ref<bool(ASTContext&,ArrayRef<StringRef>, StringRef)> action) = 0;
101+
llvm::function_ref<bool(ASTContext&,ArrayRef<StringRef>,
102+
ArrayRef<StringRef>, StringRef)> action) = 0;
101103
virtual bool runInSubCompilerInstance(StringRef moduleName,
102104
StringRef interfacePath,
103105
StringRef outputPath,

include/swift/AST/SILOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ class SILOptions {
161161
/// Enable large loadable types IRGen pass.
162162
bool EnableLargeLoadableTypes = true;
163163

164-
/// Should the default pass pipelines strip ownership during the diagnostic
165-
/// pipeline or after serialization.
166-
bool StripOwnershipAfterSerialization = true;
167-
168164
/// The name of the file to which the backend should save optimization
169165
/// records.
170166
std::string OptRecordFile;

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
244244
llvm::StringSaver ArgSaver;
245245
std::vector<StringRef> GenericArgs;
246246
CompilerInvocation subInvocation;
247-
std::vector<SupplementaryOutputPaths> ModuleOutputPaths;
248247

249248
template<typename ...ArgTypes>
250249
InFlightDiagnostic diagnose(StringRef interfacePath,
@@ -280,7 +279,8 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
280279
StringRef interfacePath,
281280
StringRef outputPath,
282281
SourceLoc diagLoc,
283-
llvm::function_ref<bool(ASTContext&, ArrayRef<StringRef>, StringRef)> action) override;
282+
llvm::function_ref<bool(ASTContext&, ArrayRef<StringRef>,
283+
ArrayRef<StringRef>, StringRef)> action) override;
284284
bool runInSubCompilerInstance(StringRef moduleName,
285285
StringRef interfacePath,
286286
StringRef outputPath,

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,6 @@ def disable_sil_partial_apply : Flag<["-"], "disable-sil-partial-apply">,
289289
def enable_spec_devirt : Flag<["-"], "enable-spec-devirt">,
290290
HelpText<"Enable speculative devirtualization pass.">;
291291

292-
def enable_ownership_stripping_after_serialization
293-
: Flag<["-"], "enable-ownership-stripping-after-serialization">,
294-
HelpText<"Strip ownership after serialization">;
295-
296292
def disable_access_control : Flag<["-"], "disable-access-control">,
297293
HelpText<"Don't respect access control restrictions">;
298294
def enable_access_control : Flag<["-"], "enable-access-control">,

include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,9 @@ def gdwarf_types : Flag<["-"], "gdwarf-types">,
724724
def debug_prefix_map : Separate<["-"], "debug-prefix-map">,
725725
Flags<[FrontendOption]>,
726726
HelpText<"Remap source paths in debug info">;
727+
def coverage_prefix_map : Separate<["-"], "coverage-prefix-map">,
728+
Flags<[FrontendOption]>,
729+
HelpText<"Remap source paths in coverage info">;
727730

728731
def debug_info_format : Joined<["-"], "debug-info-format=">,
729732
Flags<[FrontendOption]>,

lib/AST/ASTContext.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ struct ASTContext::Implementation {
156156
/// The set of cleanups to be called when the ASTContext is destroyed.
157157
std::vector<std::function<void(void)>> Cleanups;
158158

159+
/// The set of top-level modules we have loaded.
160+
/// This map is used for iteration, therefore it's a MapVector and not a
161+
/// DenseMap.
162+
llvm::MapVector<Identifier, ModuleDecl *> LoadedModules;
163+
159164
// FIXME: This is a StringMap rather than a StringSet because StringSet
160165
// doesn't allow passing in a pre-existing allocator.
161166
llvm::StringMap<Identifier::Aligner, llvm::BumpPtrAllocator&>
@@ -1538,8 +1543,18 @@ ModuleDecl *ASTContext::getLoadedModule(
15381543
return nullptr;
15391544
}
15401545

1546+
iterator_range<llvm::MapVector<Identifier, ModuleDecl *>::const_iterator>
1547+
ASTContext::getLoadedModules() const {
1548+
return {getImpl().LoadedModules.begin(), getImpl().LoadedModules.end()};
1549+
}
1550+
15411551
ModuleDecl *ASTContext::getLoadedModule(Identifier ModuleName) const {
1542-
return LoadedModules.lookup(ModuleName);
1552+
return getImpl().LoadedModules.lookup(ModuleName);
1553+
}
1554+
1555+
void ASTContext::addLoadedModule(ModuleDecl *M) {
1556+
assert(M);
1557+
getImpl().LoadedModules[M->getName()] = M;
15431558
}
15441559

15451560
static AllocationArena getArena(GenericSignature genericSig) {

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,9 +1829,9 @@ ModuleDecl *ClangImporter::Implementation::finishLoadingClangModule(
18291829
if (clangModule->isSubModule()) {
18301830
finishLoadingClangModule(clangModule->getTopLevelModule(), importLoc);
18311831
} else {
1832-
ModuleDecl *&loaded = SwiftContext.LoadedModules[result->getName()];
1833-
if (!loaded)
1834-
loaded = result;
1832+
1833+
if (!SwiftContext.getLoadedModule(result->getName()))
1834+
SwiftContext.addLoadedModule(result);
18351835
}
18361836

18371837
return result;
@@ -3372,10 +3372,12 @@ ModuleDecl *ClangModuleUnit::getOverlayModule() const {
33723372
if (overlay == M) {
33733373
overlay = nullptr;
33743374
} else {
3375-
auto &sharedModuleRef = Ctx.LoadedModules[M->getName()];
3375+
// FIXME: This bizarre and twisty invariant is due to nested
3376+
// re-entrancy in both clang module loading and overlay module loading.
3377+
auto *sharedModuleRef = Ctx.getLoadedModule(M->getName());
33763378
assert(!sharedModuleRef || sharedModuleRef == overlay ||
33773379
sharedModuleRef == M);
3378-
sharedModuleRef = overlay;
3380+
Ctx.addLoadedModule(overlay);
33793381
}
33803382

33813383
auto mutableThis = const_cast<ClangModuleUnit *>(this);

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,23 @@ void ClangImporter::recordModuleDependencies(
229229
swiftArgs.push_back(arg.str());
230230
};
231231
// Add all args inheritted from creating the importer.
232-
for (auto arg: allArgs) {
233-
addClangArg(arg);
232+
auto It = allArgs.begin();
233+
while(It != allArgs.end()) {
234+
StringRef arg = *It;
235+
// Remove the -target arguments because we should use the target triple
236+
// from the depending Swift modules.
237+
if (arg == "-target") {
238+
It += 2;
239+
} else if (arg.startswith("-fapinotes-swift-version=")) {
240+
// Remove the apinotes version because we should use the language version
241+
// specified in the interface file.
242+
It += 1;
243+
} else {
244+
addClangArg(*It);
245+
++ It;
246+
}
234247
}
248+
235249
// Swift frontend action: -emit-pcm
236250
swiftArgs.push_back("-emit-pcm");
237251
swiftArgs.push_back("-module-name");

lib/ClangImporter/DWARFImporter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,8 @@ ModuleDecl *ClangImporter::Implementation::loadModuleDWARF(
121121
(void) namelookup::getAllImports(decl);
122122

123123
// Register the module with the ASTContext so it is available for lookups.
124-
ModuleDecl *&loaded = SwiftContext.LoadedModules[name];
125-
if (!loaded)
126-
loaded = decl;
124+
if (!SwiftContext.getLoadedModule(name))
125+
SwiftContext.addLoadedModule(decl);
127126

128127
return decl;
129128
}

lib/Driver/Driver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ static void validateDebugInfoArgs(DiagnosticEngine &diags,
179179
for (auto A : args.getAllArgValues(options::OPT_debug_prefix_map))
180180
if (A.find('=') == StringRef::npos)
181181
diags.diagnose(SourceLoc(), diag::error_invalid_debug_prefix_map, A);
182+
183+
// Check for any -coverage-prefix-map options that aren't of the form
184+
// 'original=remapped' (either side can be empty, however).
185+
for (auto A : args.getAllArgValues(options::OPT_coverage_prefix_map))
186+
if (A.find('=') == StringRef::npos)
187+
diags.diagnose(SourceLoc(), diag::error_invalid_coverage_prefix_map, A);
182188
}
183189

184190
static void validateVerifyIncrementalDependencyArgs(DiagnosticEngine &diags,

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
262262

263263
// Pass on file paths that should be remapped in debug info.
264264
inputArgs.AddAllArgs(arguments, options::OPT_debug_prefix_map);
265+
inputArgs.AddAllArgs(arguments, options::OPT_coverage_prefix_map);
265266

266267
// Pass through the values passed to -Xfrontend.
267268
inputArgs.AddAllArgValues(arguments, options::OPT_Xfrontend);

0 commit comments

Comments
 (0)