Skip to content

Commit d6073fe

Browse files
authored
Merge pull request #3624 from swiftwasm/main
2 parents a032d8a + 028b964 commit d6073fe

File tree

65 files changed

+1344
-401
lines changed

Some content is hidden

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

65 files changed

+1344
-401
lines changed

include/swift/AST/ASTContext.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ class ASTContext final {
347347
/// Cache of module names that fail the 'canImport' test in this context.
348348
mutable llvm::SmallPtrSet<Identifier, 8> FailedModuleImportNames;
349349

350+
/// Mapping between aliases and real (physical) names of imported or referenced modules.
351+
mutable llvm::DenseMap<Identifier, Identifier> ModuleAliasMap;
352+
350353
/// Retrieve the allocator for the given arena.
351354
llvm::BumpPtrAllocator &
352355
getAllocator(AllocationArena arena = AllocationArena::Permanent) const;
@@ -471,6 +474,16 @@ class ASTContext final {
471474
/// specified string.
472475
Identifier getIdentifier(StringRef Str) const;
473476

477+
/// Convert a given alias map to a map of Identifiers between module aliases and their actual names.
478+
/// For example, if '-module-alias Foo=X -module-alias Bar=Y' input is passed in, the aliases Foo and Bar are
479+
/// the names of the imported or referenced modules in source files in the main module, and X and Y
480+
/// are the real (physical) module names on disk.
481+
void setModuleAliases(const llvm::StringMap<StringRef> &aliasMap);
482+
483+
/// Retrieve the actual module name if a module alias is used via '-module-alias Foo=X', where Foo is
484+
/// a module alias and X is the real (physical) name. Returns \p key if no aliasing is used.
485+
Identifier getRealModuleName(Identifier key) const;
486+
474487
/// Decide how to interpret two precedence groups.
475488
Associativity associateInfixOperators(PrecedenceGroupDecl *left,
476489
PrecedenceGroupDecl *right) const;

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,8 @@ ERROR(expected_await_not_async,none,
10301030
// Yield Statment
10311031
ERROR(expected_expr_yield,PointsToFirstBadToken,
10321032
"expected expression in 'yield' statement", ())
1033+
ERROR(unexpected_label_yield,none,
1034+
"unexpected label in 'yield' statement", ())
10331035

10341036
// Defer Statement
10351037
ERROR(expected_lbrace_after_defer,PointsToFirstBadToken,

include/swift/AST/Module.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,15 @@ class ModuleDecl
357357
ModuleABIName = name;
358358
}
359359

360+
/// Retrieve the actual module name of an alias used for this module (if any).
361+
///
362+
/// For example, if '-module-alias Foo=Bar' is passed in when building the main module,
363+
/// and this module is (a) not the main module and (b) is named Foo, then it returns
364+
/// the real (physically on-disk) module name Bar.
365+
///
366+
/// If no module aliasing is set, it will return getName(), i.e. Foo.
367+
Identifier getRealName() const;
368+
360369
/// User-defined module version number.
361370
llvm::VersionTuple UserModuleVersion;
362371
void setUserModuleVersion(llvm::VersionTuple UserVer) {
@@ -365,6 +374,7 @@ class ModuleDecl
365374
llvm::VersionTuple getUserModuleVersion() const {
366375
return UserModuleVersion;
367376
}
377+
368378
private:
369379
/// A cache of this module's underlying module and required bystander if it's
370380
/// an underscored cross-import overlay.

include/swift/AST/SearchPathOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_AST_SEARCHPATHOPTIONS_H
1515

1616
#include "swift/Basic/ArrayRefView.h"
17+
#include "swift/Basic/PathRemapper.h"
1718
#include "llvm/ADT/Hashing.h"
1819

1920
#include <string>
@@ -97,6 +98,11 @@ class SearchPathOptions {
9798

9899
/// A file containing modules we should perform batch scanning.
99100
std::string BatchScanInputFilePath;
101+
102+
/// Debug path mappings to apply to serialized search paths. These are
103+
/// specified in LLDB from the target.source-map entries.
104+
PathRemapper SearchPathRemapper;
105+
100106
private:
101107
static StringRef
102108
pathStringFromFrameworkSearchPath(const FrameworkSearchPath &next) {

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,9 @@ namespace swift {
771771
DisableOverlayModules,
772772
EnableClangSPI);
773773
}
774+
775+
std::vector<std::string> getRemappedExtraArgs(
776+
std::function<std::string(StringRef)> pathRemapCallback) const;
774777
};
775778

776779
} // end namespace swift

include/swift/Basic/Statistics.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ FRONTEND_STATISTIC(Sema, NumUnloadedLazyIterableDeclContexts)
268268
#include "swift/AST/TypeCheckerTypeIDZone.def"
269269
#include "swift/Sema/IDETypeCheckingRequestIDZone.def"
270270
#include "swift/IDE/IDERequestIDZone.def"
271+
#include "swift/ClangImporter/ClangImporterTypeIDZone.def"
271272
#undef SWIFT_REQUEST
272273

273274
#define SWIFT_REQUEST(ZONE, NAME, Sig, Caching, LocOptions) FRONTEND_STATISTIC(SILGen, NAME)

include/swift/Basic/TypeIDZones.def

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
//===--- TypeIDZones.def - List of TypeID Zones -----------------*- C++ -*-===//
2-
//
3-
// This source file is part of the Swift.org open source project
4-
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6-
// Licensed under Apache License v2.0 with Runtime Library Exception
7-
//
8-
// See https://swift.org/LICENSE.txt for license information
9-
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10-
//
11-
//===----------------------------------------------------------------------===//
12-
//
13-
// This definition file describes the zones for TypeID.
14-
//
15-
//===----------------------------------------------------------------------===//
16-
17-
SWIFT_TYPEID_ZONE(C, 0)
18-
SWIFT_TYPEID_ZONE(AST, 1)
19-
20-
SWIFT_TYPEID_ZONE(Parse, 8)
21-
SWIFT_TYPEID_ZONE(NameLookup, 9)
22-
23-
SWIFT_TYPEID_ZONE(TypeChecker, 10)
24-
SWIFT_TYPEID_ZONE(AccessControl, 11)
25-
SWIFT_TYPEID_ZONE(SILGen, 12)
26-
SWIFT_TYPEID_ZONE(SILOptimizer, 13)
27-
SWIFT_TYPEID_ZONE(TBDGen, 14)
28-
29-
SWIFT_TYPEID_ZONE(IRGen, 20)
30-
31-
SWIFT_TYPEID_ZONE(IDETypeChecking, 97)
32-
33-
SWIFT_TYPEID_ZONE(IDETypes, 136)
34-
SWIFT_TYPEID_ZONE(IDE, 137)
35-
36-
// N.B. This is not a formal zone and exists solely to support the unit tests.
37-
SWIFT_TYPEID_ZONE(ArithmeticEvaluator, 255)
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This definition file describes the zones for TypeID.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
SWIFT_TYPEID_ZONE(C, 0)
18+
SWIFT_TYPEID_ZONE(AST, 1)
19+
20+
SWIFT_TYPEID_ZONE(Parse, 8)
21+
SWIFT_TYPEID_ZONE(NameLookup, 9)
22+
23+
SWIFT_TYPEID_ZONE(TypeChecker, 10)
24+
SWIFT_TYPEID_ZONE(AccessControl, 11)
25+
SWIFT_TYPEID_ZONE(SILGen, 12)
26+
SWIFT_TYPEID_ZONE(SILOptimizer, 13)
27+
SWIFT_TYPEID_ZONE(TBDGen, 14)
28+
29+
SWIFT_TYPEID_ZONE(IRGen, 20)
30+
31+
SWIFT_TYPEID_ZONE(IDETypeChecking, 97)
32+
33+
SWIFT_TYPEID_ZONE(IDETypes, 136)
34+
SWIFT_TYPEID_ZONE(IDE, 137)
35+
36+
SWIFT_TYPEID_ZONE(ClangImporter, 139)
37+
38+
// N.B. This is not a formal zone and exists solely to support the unit tests.
39+
SWIFT_TYPEID_ZONE(ArithmeticEvaluator, 255)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===--- ClangImporterRequests.h - Clang Importer Requests ------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines clang-importer requests.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
#ifndef SWIFT_CLANG_IMPORTER_REQUESTS_H
17+
#define SWIFT_CLANG_IMPORTER_REQUESTS_H
18+
19+
#include "swift/AST/SimpleRequest.h"
20+
#include "swift/AST/ASTTypeIDs.h"
21+
#include "swift/AST/EvaluatorDependencies.h"
22+
23+
namespace swift {
24+
25+
#define SWIFT_TYPEID_ZONE ClangImporter
26+
#define SWIFT_TYPEID_HEADER "swift/ClangImporter/ClangImporterTypeIDZone.def"
27+
#include "swift/Basic/DefineTypeIDZone.h"
28+
#undef SWIFT_TYPEID_ZONE
29+
#undef SWIFT_TYPEID_HEADER
30+
31+
// Set up reporting of evaluated requests.
32+
template<typename Request>
33+
void reportEvaluatedRequest(UnifiedStatsReporter &stats,
34+
const Request &request);
35+
36+
#define SWIFT_REQUEST(Zone, RequestType, Sig, Caching, LocOptions) \
37+
template <> \
38+
inline void reportEvaluatedRequest(UnifiedStatsReporter &stats, \
39+
const RequestType &request) { \
40+
++stats.getFrontendCounters().RequestType; \
41+
}
42+
#include "swift/ClangImporter/ClangImporterTypeIDZone.def"
43+
#undef SWIFT_REQUEST
44+
45+
} // end namespace swift
46+
47+
#endif // SWIFT_CLANG_IMPORTER_REQUESTS_H
48+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===--- ClangImporterTypeIDZone.def ----------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This definition file describes the types in the clang importer
14+
// TypeID zone, for use with the TypeID template.
15+
//
16+
//===----------------------------------------------------------------------===//
17+

include/swift/Frontend/FrontendOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ class FrontendOptions {
182182
/// module appears to not be a public module.
183183
Optional<bool> SerializeOptionsForDebugging;
184184

185+
/// When true the debug prefix map entries will be applied to debugging
186+
/// options before serialization. These can be reconstructed at debug time by
187+
/// applying the inverse map in SearchPathOptions.SearchPathRemapper.
188+
bool DebugPrefixSerializedDebuggingOptions = false;
189+
185190
/// When true, check if all required SwiftOnoneSupport symbols are present in
186191
/// the module.
187192
bool CheckOnoneSupportCompleteness = false;

include/swift/Option/Options.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def disable_bridging_pch : Flag<["-"], "disable-bridging-pch">,
559559
def lto : Joined<["-"], "lto=">,
560560
Flags<[FrontendOption, NoInteractiveOption]>,
561561
HelpText<"Specify the LTO type to either 'llvm-thin' or 'llvm-full'">;
562-
562+
563563
def lto_library : Separate<["-"], "lto-library">,
564564
Flags<[FrontendOption, ArgumentIsPath, NoInteractiveOption]>,
565565
HelpText<"Perform LTO with <lto-library>">, MetaVarName<"<lto-library>">;
@@ -815,6 +815,10 @@ def debug_info_format : Joined<["-"], "debug-info-format=">,
815815
Flags<[FrontendOption]>,
816816
HelpText<"Specify the debug info format type to either 'dwarf' or 'codeview'">;
817817

818+
def prefix_serialized_debugging_options : Flag<["-"], "prefix-serialized-debugging-options">,
819+
Flags<[FrontendOption]>,
820+
HelpText<"Apply debug prefix mappings to serialized debug info in Swiftmodule files">;
821+
818822
// Verify debug info
819823
def verify_debug_info : Flag<["-"], "verify-debug-info">,
820824
Flags<[NoInteractiveOption, DoesNotAffectIncrementalBuild]>,

include/swift/Serialization/SerializationOptions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_SERIALIZATION_SERIALIZATIONOPTIONS_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "swift/Basic/PathRemapper.h"
1718
#include "llvm/Support/VersionTuple.h"
1819

1920
namespace swift {
@@ -42,7 +43,10 @@ namespace swift {
4243
StringRef ImportedHeader;
4344
StringRef ModuleLinkName;
4445
StringRef ModuleInterface;
45-
ArrayRef<std::string> ExtraClangOptions;
46+
std::vector<std::string> ExtraClangOptions;
47+
48+
/// Path prefixes that should be rewritten in debug info.
49+
PathRemapper DebuggingOptionsPrefixMap;
4650

4751
/// Describes a single-file dependency for this module, along with the
4852
/// appropriate strategy for how to verify if it's up-to-date.

include/swift/Subsystems.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ namespace swift {
363363
/// Calling registerIDERequestFunctions will invoke this function as well.
364364
void registerIDETypeCheckRequestFunctions(Evaluator &evaluator);
365365

366+
/// Register clang importer request functions with the evaluator.
367+
///
368+
/// Clients that form an ASTContext and import any Clang APIs should call this function
369+
/// after forming the ASTContext.
370+
void registerClangImporterRequestFunctions(Evaluator &evaluator);
371+
366372
/// Register SILOptimizer passes necessary for IRGen.
367373
void registerIRGenSILTransforms(ASTContext &ctx);
368374

lib/AST/ASTContext.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,23 @@ void ASTContext::addModuleInterfaceChecker(
16421642
getImpl().InterfaceChecker = std::move(checker);
16431643
}
16441644

1645+
void ASTContext::setModuleAliases(const llvm::StringMap<StringRef> &aliasMap) {
1646+
for (auto k: aliasMap.keys()) {
1647+
auto val = aliasMap.lookup(k);
1648+
if (!val.empty()) {
1649+
ModuleAliasMap[getIdentifier(k)] = getIdentifier(val);
1650+
}
1651+
}
1652+
}
1653+
1654+
Identifier ASTContext::getRealModuleName(Identifier key) const {
1655+
auto found = ModuleAliasMap.find(key);
1656+
if (found != ModuleAliasMap.end()) {
1657+
return found->second;
1658+
}
1659+
return key;
1660+
}
1661+
16451662
Optional<ModuleDependencies> ASTContext::getModuleDependencies(
16461663
StringRef moduleName, bool isUnderlyingClangModule,
16471664
ModuleDependenciesCache &cache, InterfaceSubContextDelegate &delegate,

lib/AST/ArgumentList.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,28 +220,35 @@ Optional<unsigned> ArgumentList::findArgumentExpr(Expr *expr,
220220
Expr *ArgumentList::packIntoImplicitTupleOrParen(
221221
ASTContext &ctx, llvm::function_ref<Type(Expr *)> getType) const {
222222
assert(!hasAnyInOutArgs() && "Cannot construct bare tuple/paren with inout");
223+
224+
// Make sure to preserve the source location info here and below as it may be
225+
// needed for e.g serialization of its textual representation.
223226
if (auto *unary = getUnlabeledUnaryExpr()) {
224-
auto *paren = new (ctx) ParenExpr(SourceLoc(), unary, SourceLoc());
227+
auto *paren = new (ctx) ParenExpr(getLParenLoc(), unary, getRParenLoc());
225228
if (auto ty = getType(unary))
226229
paren->setType(ParenType::get(ctx, ty));
227230
paren->setImplicit();
228231
return paren;
229232
}
230233

231-
SmallVector<Expr *, 8> argExprs;
232-
SmallVector<Identifier, 8> argLabels;
233-
SmallVector<TupleTypeElt, 8> tupleEltTypes;
234+
SmallVector<Expr *, 2> argExprs;
235+
SmallVector<Identifier, 2> argLabels;
236+
SmallVector<SourceLoc, 2> argLabelLocs;
237+
SmallVector<TupleTypeElt, 2> tupleEltTypes;
234238

235239
for (auto arg : *this) {
236240
auto *argExpr = arg.getExpr();
237241
argExprs.push_back(argExpr);
238242
argLabels.push_back(arg.getLabel());
243+
argLabelLocs.push_back(arg.getLabelLoc());
239244
if (auto ty = getType(argExpr))
240245
tupleEltTypes.emplace_back(ty, arg.getLabel());
241246
}
242247
assert(tupleEltTypes.empty() || tupleEltTypes.size() == argExprs.size());
243248

244-
auto *tuple = TupleExpr::createImplicit(ctx, argExprs, argLabels);
249+
auto *tuple =
250+
TupleExpr::create(ctx, getLParenLoc(), argExprs, argLabels, argLabelLocs,
251+
getRParenLoc(), /*implicit*/ true);
245252
if (empty() || !tupleEltTypes.empty())
246253
tuple->setType(TupleType::get(tupleEltTypes, ctx));
247254

lib/AST/Module.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ ModuleDecl::ModuleDecl(Identifier name, ASTContext &ctx,
475475
ctx.addDestructorCleanup(*this);
476476
setImplicit();
477477
setInterfaceType(ModuleType::get(this));
478-
479478
setAccess(AccessLevel::Public);
480479

481480
Bits.ModuleDecl.StaticLibrary = 0;
@@ -1564,6 +1563,11 @@ ImportedModule::removeDuplicates(SmallVectorImpl<ImportedModule> &imports) {
15641563
imports.erase(last, imports.end());
15651564
}
15661565

1566+
Identifier ModuleDecl::getRealName() const {
1567+
// This will return the real name for an alias (if used) or getName()
1568+
return getASTContext().getRealModuleName(getName());
1569+
}
1570+
15671571
Identifier ModuleDecl::getABIName() const {
15681572
if (!ModuleABIName.empty())
15691573
return ModuleABIName;

lib/AST/NameLookupRequests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/AST/Evaluator.h"
2020
#include "swift/AST/Module.h"
2121
#include "swift/AST/SourceFile.h"
22+
#include "swift/ClangImporter/ClangImporterRequests.h"
2223
#include "swift/Subsystems.h"
2324

2425
using namespace swift;

0 commit comments

Comments
 (0)