Skip to content

Commit 5579e44

Browse files
Merge pull request #4576 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents 89f6290 + 87d7a25 commit 5579e44

Some content is hidden

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

53 files changed

+1051
-409
lines changed

include/swift/AST/ASTNode.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ namespace swift {
7878

7979
/// Whether the AST node is implicit.
8080
bool isImplicit() const;
81+
82+
friend llvm::hash_code hash_value(ASTNode N) {
83+
return llvm::hash_value(N.getOpaqueValue());
84+
}
8185
};
8286
} // namespace swift
8387

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,9 @@ WARNING(framework_search_path_includes_framework_extension,none,
338338
ERROR(error_optimization_remark_pattern, none, "%0 in '%1'",
339339
(StringRef, StringRef))
340340

341-
ERROR(error_invalid_debug_prefix_map, none,
342-
"values for '-debug-prefix-map' must be in the format 'original=remapped'"
343-
", but '%0' was provided", (StringRef))
344-
ERROR(error_invalid_coverage_prefix_map, none,
345-
"values for '-coverage-prefix-map' must be in the format "
346-
"'original=remapped', but '%0' was provided", (StringRef))
341+
ERROR(error_opt_invalid_mapping, none,
342+
"values for '%0' must be in the format 'original=remapped', but '%1' was "
343+
"provided", (StringRef, StringRef))
347344

348345
ERROR(invalid_vfs_overlay_file,none,
349346
"invalid virtual overlay file '%0'", (StringRef))

include/swift/AST/IRGenOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ class IRGenOptions {
254254
/// Path prefixes that should be rewritten in coverage info.
255255
PathRemapper CoveragePrefixMap;
256256

257+
/// Path prefixes that should be rewritten in info besides debug and coverage
258+
/// (use DebugPrefixMap and CoveragePrefixMap for those) - currently just
259+
/// indexing info.
260+
PathRemapper FilePrefixMap;
261+
257262
/// What level of debug info to generate.
258263
IRGenDebugInfoLevel DebugInfoLevel : 2;
259264

include/swift/AST/TypeCheckRequests.h

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "swift/AST/ActorIsolation.h"
2020
#include "swift/AST/AnyFunctionRef.h"
21+
#include "swift/AST/ASTNode.h"
2122
#include "swift/AST/ASTTypeIDs.h"
2223
#include "swift/AST/Effects.h"
2324
#include "swift/AST/GenericParamList.h"
@@ -1544,12 +1545,82 @@ class TypeCheckFunctionBodyRequest
15441545
readDependencySource(const evaluator::DependencyRecorder &) const;
15451546
};
15461547

1548+
/// Describes the context in which the AST node to type check in a
1549+
/// \c TypeCheckASTNodeAtLocRequest should be searched. This can be either of
1550+
/// two cases:
1551+
/// 1. A \c DeclContext that contains the node representing the location to
1552+
/// type check
1553+
/// 2. If the node that should be type checked that might not be part of the
1554+
/// AST (e.g. because it is a dangling property attribute), an \c ASTNode
1555+
/// that contains the location to type check in together with a DeclContext
1556+
/// in which we should pretend that node occurs.
1557+
class TypeCheckASTNodeAtLocContext {
1558+
DeclContext *DC;
1559+
ASTNode Node;
1560+
1561+
/// Memberwise initializer
1562+
TypeCheckASTNodeAtLocContext(DeclContext *DC, ASTNode Node)
1563+
: DC(DC), Node(Node) {
1564+
assert(DC != nullptr);
1565+
}
1566+
1567+
public:
1568+
static TypeCheckASTNodeAtLocContext declContext(DeclContext *DC) {
1569+
return TypeCheckASTNodeAtLocContext(DC, /*Node=*/nullptr);
1570+
}
1571+
1572+
static TypeCheckASTNodeAtLocContext node(DeclContext *DC, ASTNode Node) {
1573+
assert(!Node.isNull());
1574+
return TypeCheckASTNodeAtLocContext(DC, Node);
1575+
}
1576+
1577+
DeclContext *getDeclContext() const { return DC; }
1578+
1579+
bool isForUnattachedNode() const { return !Node.isNull(); }
1580+
1581+
ASTNode getUnattachedNode() const {
1582+
assert(isForUnattachedNode());
1583+
return Node;
1584+
}
1585+
1586+
ASTNode &getUnattachedNode() {
1587+
assert(isForUnattachedNode());
1588+
return Node;
1589+
}
1590+
1591+
friend llvm::hash_code hash_value(const TypeCheckASTNodeAtLocContext &ctx) {
1592+
return llvm::hash_combine(ctx.DC, ctx.Node);
1593+
}
1594+
1595+
friend bool operator==(const TypeCheckASTNodeAtLocContext &lhs,
1596+
const TypeCheckASTNodeAtLocContext &rhs) {
1597+
return lhs.DC == rhs.DC && lhs.Node == rhs.Node;
1598+
}
1599+
1600+
friend bool operator!=(const TypeCheckASTNodeAtLocContext &lhs,
1601+
const TypeCheckASTNodeAtLocContext &rhs) {
1602+
return !(lhs == rhs);
1603+
}
1604+
1605+
friend SourceLoc
1606+
extractNearestSourceLoc(const TypeCheckASTNodeAtLocContext &ctx) {
1607+
if (!ctx.Node.isNull()) {
1608+
return ctx.Node.getStartLoc();
1609+
} else {
1610+
return extractNearestSourceLoc(ctx.DC);
1611+
}
1612+
}
1613+
};
1614+
1615+
void simple_display(llvm::raw_ostream &out,
1616+
const TypeCheckASTNodeAtLocContext &ctx);
1617+
15471618
/// Request to typecheck a function body element at the given source location.
15481619
///
15491620
/// Produces true if an error occurred, false otherwise.
15501621
class TypeCheckASTNodeAtLocRequest
15511622
: public SimpleRequest<TypeCheckASTNodeAtLocRequest,
1552-
bool(DeclContext *, SourceLoc),
1623+
bool(TypeCheckASTNodeAtLocContext, SourceLoc),
15531624
RequestFlags::Uncached> {
15541625
public:
15551626
using SimpleRequest::SimpleRequest;
@@ -1558,7 +1629,8 @@ class TypeCheckASTNodeAtLocRequest
15581629
friend SimpleRequest;
15591630

15601631
// Evaluation.
1561-
bool evaluate(Evaluator &evaluator, DeclContext *DC, SourceLoc Loc) const;
1632+
bool evaluate(Evaluator &evaluator, TypeCheckASTNodeAtLocContext,
1633+
SourceLoc Loc) const;
15621634
};
15631635

15641636
/// Request to obtain a list of stored properties in a nominal type.
@@ -3606,6 +3678,7 @@ class GetSourceFileAsyncNode
36063678
bool isCached() const { return true; }
36073679
};
36083680

3681+
void simple_display(llvm::raw_ostream &out, ASTNode node);
36093682
void simple_display(llvm::raw_ostream &out, Type value);
36103683
void simple_display(llvm::raw_ostream &out, const TypeRepr *TyR);
36113684
void simple_display(llvm::raw_ostream &out, ImplicitMemberAction action);

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ SWIFT_REQUEST(TypeChecker, TypeCheckFunctionBodyRequest,
345345
BraceStmt *(AbstractFunctionDecl *), SeparatelyCached,
346346
NoLocationInfo)
347347
SWIFT_REQUEST(TypeChecker, TypeCheckASTNodeAtLocRequest,
348-
bool(DeclContext *, SourceLoc),
348+
bool(TypeCheckASTNodeAtLocContext, SourceLoc),
349349
Uncached, NoLocationInfo)
350350
SWIFT_REQUEST(TypeChecker, UnderlyingTypeRequest, Type(TypeAliasDecl *),
351351
SeparatelyCached, NoLocationInfo)

include/swift/Basic/PathRemapper.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define SWIFT_BASIC_PATHREMAPPER_H
2626

2727
#include "swift/Basic/LLVM.h"
28+
#include "clang/Basic/PathRemapper.h"
2829
#include "llvm/ADT/SmallVector.h"
2930
#include "llvm/ADT/Twine.h"
3031

@@ -57,6 +58,15 @@ class PathRemapper {
5758
Path.substr(Mapping.first.size())).str();
5859
return Path.str();
5960
}
61+
62+
/// Returns the Clang PathRemapper equivalent, suitable for use with Clang
63+
/// APIs.
64+
clang::PathRemapper asClangPathRemapper() const {
65+
clang::PathRemapper Remapper;
66+
for (const auto &Mapping : PathMappings)
67+
Remapper.addMapping(Mapping.first, Mapping.second);
68+
return Remapper;
69+
}
6070
};
6171

6272
class PathObfuscator {

include/swift/IDE/Utils.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ struct ResolvedCursorInfo {
166166
Type ContainerType;
167167
Stmt *TrailingStmt = nullptr;
168168
Expr *TrailingExpr = nullptr;
169-
/// If this is a call, whether it is "dynamic", see ide::isDynamicCall.
169+
/// It this is a ref, whether it is "dynamic". See \c ide::isDynamicRef.
170170
bool IsDynamic = false;
171-
/// If this is a call, the types of the base (multiple in the case of
171+
/// If this is a dynamic ref, the types of the base (multiple in the case of
172172
/// protocol composition).
173173
SmallVector<NominalTypeDecl *, 1> ReceiverTypes;
174174

@@ -615,11 +615,22 @@ bool isBeingCalled(ArrayRef<Expr*> ExprStack);
615615
/// stack in eg. the case of a `DotSyntaxCallExpr`).
616616
Expr *getBase(ArrayRef<Expr *> ExprStack);
617617

618-
/// Assuming that we have a call, returns whether or not it is "dynamic" based
619-
/// on its base expression and decl of the callee. Note that this is not
620-
/// Swift's "dynamic" modifier (`ValueDecl::isDynamic`), but rathar "can call a
621-
/// function in a conformance/subclass".
622-
bool isDynamicCall(Expr *Base, ValueDecl *D);
618+
/// Returns whether or not \p D could be overridden, eg. it's a member of a
619+
/// protocol, a non-final method in a class, etc.
620+
bool isDeclOverridable(ValueDecl *D);
621+
622+
/// Given a reference to a member \p D and its \p Base expression, return
623+
/// whether that declaration could be dynamic, ie. may resolve to some other
624+
/// declaration. Note that while the decl itself itself may be overridable, a
625+
/// reference to it is not necessarily "dynamic". Furthermore, is *not* the
626+
/// `dynamic` keyword.
627+
///
628+
/// A simple example is `SomeType.classMethod()`. `classMethod`
629+
/// is itself overridable, but that particular reference to it *has* to be the
630+
/// one in `SomeType`. Contrast that to `type(of: foo).classMethod()` where
631+
/// `classMethod` could be any `classMethod` up or down the hierarchy from the
632+
/// type of the \p Base expression.
633+
bool isDynamicRef(Expr *Base, ValueDecl *D);
623634

624635
/// Adds the resolved nominal types of \p Base to \p Types.
625636
void getReceiverType(Expr *Base,

include/swift/Index/IndexRecord.h

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

1616
#include "swift/Basic/LLVM.h"
17+
#include "swift/Basic/PathRemapper.h"
1718
#include "llvm/ADT/ArrayRef.h"
1819
#include "llvm/ADT/StringRef.h"
1920

@@ -44,11 +45,14 @@ namespace index {
4445
/// \param targetTriple The target for this compilation.
4546
///
4647
/// \param dependencyTracker The set of dependencies seen while building.
48+
///
49+
/// \param pathRemapper Remapper to use for paths in index data.
4750
bool indexAndRecord(SourceFile *primarySourceFile, StringRef indexUnitToken,
4851
StringRef indexStorePath, bool indexSystemModules,
4952
bool skipStdlib, bool isDebugCompilation,
5053
StringRef targetTriple,
51-
const DependencyTracker &dependencyTracker);
54+
const DependencyTracker &dependencyTracker,
55+
const PathRemapper &pathRemapper);
5256

5357
/// Index the given module and store the results to \p indexStorePath.
5458
///
@@ -76,11 +80,14 @@ bool indexAndRecord(SourceFile *primarySourceFile, StringRef indexUnitToken,
7680
/// \param targetTriple The target for this compilation.
7781
///
7882
/// \param dependencyTracker The set of dependencies seen while building.
83+
///
84+
/// \param pathRemapper Remapper to use for paths in index data.
7985
bool indexAndRecord(ModuleDecl *module, ArrayRef<std::string> indexUnitTokens,
8086
StringRef moduleUnitToken, StringRef indexStorePath,
8187
bool indexSystemModules, bool skipStdlib,
8288
bool isDebugCompilation, StringRef targetTriple,
83-
const DependencyTracker &dependencyTracker);
89+
const DependencyTracker &dependencyTracker,
90+
const PathRemapper &pathRemapper);
8491
// FIXME: indexUnitTokens could be StringRef, but that creates an impedance
8592
// mismatch in the caller.
8693

include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,9 @@ def debug_prefix_map : Separate<["-"], "debug-prefix-map">,
857857
def coverage_prefix_map : Separate<["-"], "coverage-prefix-map">,
858858
Flags<[FrontendOption]>,
859859
HelpText<"Remap source paths in coverage info">, MetaVarName<"<prefix=replacement>">;
860+
def file_prefix_map : Separate<["-"], "file-prefix-map">,
861+
Flags<[FrontendOption]>,
862+
HelpText<"Remap source paths in debug, coverage, and index info">, MetaVarName<"<prefix=replacement>">;
860863

861864
def file_compilation_dir : Separate<["-"], "file-compilation-dir">,
862865
Flags<[FrontendOption]>, MetaVarName<"<path>">,

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ class CodeCompletionCallbacks {
118118
/// Set target decl for attribute if the CC token is in attribute of the decl.
119119
virtual void setAttrTargetDeclKind(Optional<DeclKind> DK) {}
120120

121+
/// Set that the code completion token occurred in a custom attribute. This
122+
/// allows us to type check the custom attribute even if it is not attached to
123+
/// the AST, e.g. because there is no var declaration following it.
124+
virtual void setCompletingInAttribute(CustomAttr *Attr){};
125+
121126
/// Complete expr-dot after we have consumed the dot.
122127
virtual void completeDotExpr(CodeCompletionExpr *E, SourceLoc DotLoc) {};
123128

0 commit comments

Comments
 (0)