Skip to content

Commit 49d43e8

Browse files
dan-zhengainu-bot
authored andcommitted
Merge remote-tracking branch 'github/master' into HEAD
Fix tensorflow branch SourceKit merge conflicts related to InMemoryOutputFileSystem.
2 parents 7353af1 + a0cdeb5 commit 49d43e8

File tree

287 files changed

+8354
-2835
lines changed

Some content is hidden

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

287 files changed

+8354
-2835
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,6 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
933933
endif()
934934
endif()
935935

936-
find_package(Python2 COMPONENTS Interpreter REQUIRED)
937936
find_package(Python3 COMPONENTS Interpreter REQUIRED)
938937

939938
#

docs/ABI/Mangling.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ Globals
176176
global ::= global 'MJ' // noncanonical specialized generic type metadata instantiation cache associated with global
177177
global ::= global 'MN' // noncanonical specialized generic type metadata for global
178178

179+
#if SWIFT_RUNTIME_VERSION >= 5.4
180+
global ::= context (decl-name '_')+ 'WZ' // global variable one-time initialization function
181+
global ::= context (decl-name '_')+ 'Wz' // global variable one-time initialization token
182+
#endif
183+
179184
A direct symbol resolves directly to the address of an object. An
180185
indirect symbol resolves to the address of a pointer to the object.
181186
They are distinct manglings to make a certain class of bugs

docs/DynamicCasting.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Implementation Note: `AnyObject` is represented in memory as a pointer to a refc
191191
### Objective-C Interactions
192192

193193
Note the invariant above cannot be an equality because Objective-C bridging allows libraries to introduce new relationships that can alter the behavior of seemingly-unrelated casts.
194-
One example of this is Foundation's `Number` (or `NSNumber`) type which conditionally bridges to several Swift numeric types.
194+
One example of this is Foundation's `NSNumber` type which conditionally bridges to several Swift numeric types.
195195
As a result, when Foundation is in scope, `Int(7) is Double == false` but `(Int(7) as! AnyObject) is Double == true`.
196196
In general, the ability to add new bridging behaviors from a single type to several distinct types implies that Swift casting cannot be transitive.
197197

@@ -407,9 +407,10 @@ S.self.svar // 2
407407
```
408408

409409
Invariants
410-
* If `T` conforms to `P` and `t` is an instance of `T`, then `t is P`, and `T.self is P.Type`
410+
* If `T` conforms to `P` and `t` is an instance of `T`, then `t is P` and `T.self is P.Type`
411+
* If `P` is a sub-protocol of `P1` and `T` is any type, then `T.self is P.Type` implies that `T.self is P1.Type`
411412
* Since every type `T` conforms to `Any`, `T.self is Any.Type` is always true
412-
* `Any` self-conforms: `Any.self is Any.Type == true`
413+
* Since every class type `C` conforms to `AnyObject`, `C.self is AnyObject.Type` is always true (this includes Objective-C class types)
413414

414415
### Note: "Self conforming" protocols
415416

@@ -439,10 +440,14 @@ let b : MyGenericType(a)
439440
As above, since `a` has type `P`, this code is instantiating `MyGenericType` with `T = P`, which is only valid if `P` conforms to `P`.
440441

441442
Note that any protocol that specifies static methods, static properties, associated types, or initializers cannot possibly be self-conforming.
442-
As of Swift 5.3, there are only three kinds of self-conforming protocols:
443-
* `Any` must be self-conforming since every `T.self` is an instance of `Any.Type`
444-
* `Error` is a self-conforming protocol
445-
* Objective-C protocols that have no static requirements are self-conforming
443+
As of Swift 5.3, the only self-conforming protocols are `Any`, `Error`, and Objective-C protocols that have no static requirements.
444+
445+
Invariants
446+
* `Any` self-conforms: `Any.self is Any.Type == true`
447+
* `Error` self-conforms: `Error.self is Error.Type == true`
448+
* If `P` self-conforms and is a sub-protocol of `P1`, then `P.self is P1.Type == true`
449+
450+
For example, the last invariant here implies that for any Objective-C protocol `OP` that has no static requirements, `OP.self is AnyObject.Type`. This follows from the fact that `OP` self-conforms and that every Objective-C protocol has `AnyObject` as an implicit parent protocol.
446451

447452
## CoreFoundation types
448453

include/swift/AST/ASTContext.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace swift {
6262
class BoundGenericType;
6363
class ClangModuleLoader;
6464
class ClangNode;
65+
class ClangTypeConverter;
6566
class ConcreteDeclRef;
6667
class ConstructorDecl;
6768
class Decl;
@@ -618,6 +619,10 @@ class ASTContext final {
618619
Type getBridgedToObjC(const DeclContext *dc, Type type,
619620
Type *bridgedValueType = nullptr) const;
620621

622+
private:
623+
ClangTypeConverter &getClangTypeConverter();
624+
625+
public:
621626
/// Get the Clang type corresponding to a Swift function type.
622627
///
623628
/// \param params The function parameters.
@@ -627,6 +632,14 @@ class ASTContext final {
627632
getClangFunctionType(ArrayRef<AnyFunctionType::Param> params, Type resultTy,
628633
FunctionTypeRepresentation trueRep);
629634

635+
/// Get the canonical Clang type corresponding to a SIL function type.
636+
///
637+
/// SIL analog of \c ASTContext::getClangFunctionType .
638+
const clang::Type *
639+
getCanonicalClangFunctionType(
640+
ArrayRef<SILParameterInfo> params, Optional<SILResultInfo> result,
641+
SILFunctionType::Representation trueRep);
642+
630643
/// Get the Swift declaration that a Clang declaration was exported from,
631644
/// if applicable.
632645
const Decl *getSwiftDeclForExportedClangDecl(const clang::Decl *decl);

include/swift/AST/ASTMangler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ class ASTMangler : public Mangler {
146146

147147
std::string mangleGlobalVariableFull(const VarDecl *decl);
148148

149-
std::string mangleGlobalInit(const VarDecl *decl, int counter,
149+
std::string mangleGlobalInit(const PatternBindingDecl *decl,
150+
unsigned entry,
150151
bool isInitFunc);
151152

152153
std::string mangleReabstractionThunkHelper(CanSILFunctionType ThunkType,

include/swift/AST/Decl.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ namespace swift {
6363
class Type;
6464
class Expr;
6565
class DeclRefExpr;
66+
class ForeignAsyncConvention;
6667
class ForeignErrorConvention;
6768
class LiteralExpr;
6869
class BraceStmt;
@@ -6171,7 +6172,15 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
61716172
/// being dropped altogether. `None` is returned for a normal function
61726173
/// or method.
61736174
Optional<int> getForeignFunctionAsMethodSelfParameterIndex() const;
6174-
6175+
6176+
/// Set information about the foreign async convention used by this
6177+
/// declaration.
6178+
void setForeignAsyncConvention(const ForeignAsyncConvention &convention);
6179+
6180+
/// Get information about the foreign async convention used by this
6181+
/// declaration, given that it is @objc and 'async'.
6182+
Optional<ForeignAsyncConvention> getForeignAsyncConvention() const;
6183+
61756184
static bool classof(const Decl *D) {
61766185
return D->getKind() >= DeclKind::First_AbstractFunctionDecl &&
61776186
D->getKind() <= DeclKind::Last_AbstractFunctionDecl;
@@ -6300,7 +6309,8 @@ class FuncDecl : public AbstractFunctionDecl {
63006309
DeclContext *Parent);
63016310

63026311
static FuncDecl *createImported(ASTContext &Context, SourceLoc FuncLoc,
6303-
DeclName Name, SourceLoc NameLoc, bool Throws,
6312+
DeclName Name, SourceLoc NameLoc,
6313+
bool Async, bool Throws,
63046314
ParameterList *BodyParams, Type FnRetType,
63056315
DeclContext *Parent, ClangNode ClangN);
63066316

include/swift/AST/DiagnosticsCommon.def

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,19 @@ ERROR(scanner_find_cycle, none,
188188
ERROR(scanner_arguments_invalid, none,
189189
"dependencies scanner cannot be configured with arguments: '%0'", (StringRef))
190190

191+
//------------------------------------------------------------------------------
192+
// MARK: custom attribute diagnostics
193+
//------------------------------------------------------------------------------
194+
195+
ERROR(ambiguous_custom_attribute_ref,none,
196+
"ambiguous use of attribute %0", (Identifier))
197+
NOTE(ambiguous_custom_attribute_ref_fix,none,
198+
"use '%0.' to reference the attribute %1 in module %2",
199+
(StringRef, Identifier, Identifier))
200+
NOTE(found_attribute_candidate,none,
201+
"found this attribute", ())
202+
ERROR(unknown_attribute,none,
203+
"unknown attribute '%0'", (StringRef))
204+
191205
#define UNDEFINE_DIAGNOSTIC_MACROS
192206
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,8 +1324,6 @@ ERROR(replace_equal_with_colon_for_value,none,
13241324
"'=' has been replaced with ':' in attribute arguments", ())
13251325
ERROR(expected_attribute_name,none,
13261326
"expected an attribute name", ())
1327-
ERROR(unknown_attribute,none,
1328-
"unknown attribute '%0'", (StringRef))
13291327
ERROR(unexpected_lparen_in_attribute,none,
13301328
"unexpected '(' in attribute '%0'", (StringRef))
13311329
ERROR(duplicate_attribute,none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ ERROR(expected_argument_in_contextual_member,none,
112112
"member %0 expects argument of type %1", (DeclName, Type))
113113
ERROR(expected_parens_in_contextual_member,none,
114114
"member %0 is a function; did you mean to call it?", (DeclName))
115+
ERROR(expected_parens_in_contextual_member_type,none,
116+
"member %0 is a function that produces expected type %1; did you mean to "
117+
"call it?", (DeclName, Type))
115118

116119
ERROR(expected_result_in_contextual_member,none,
117120
"member %0 in %2 produces result of type %1, but context expects %2",
@@ -453,6 +456,10 @@ ERROR(cannot_convert_closure_result_nil,none,
453456
ERROR(cannot_convert_parent_type,none,
454457
"cannot convert parent type %0 to expected type %1",
455458
(Type, Type))
459+
ERROR(cannot_convert_chain_result_type,none,
460+
"member chain produces result of type %0 but contextual base was "
461+
"inferred as %1",
462+
(Type, Type))
456463

457464
NOTE(generic_argument_mismatch,none,
458465
"arguments to generic parameter %0 (%1 and %2) are expected to be equal",
@@ -1082,13 +1089,22 @@ NOTE(unwrap_with_guard,none,
10821089
ERROR(optional_base_not_unwrapped,none,
10831090
"value of optional type %0 must be unwrapped to refer to member %1 of "
10841091
"wrapped base type %2", (Type, DeclNameRef, Type))
1092+
ERROR(invalid_optional_infered_keypath_root, none,
1093+
"key path root inferred as optional type %0 must be unwrapped to refer to member %1 "
1094+
"of unwrapped type %2", (Type, DeclNameRef, Type))
10851095
NOTE(optional_base_chain,none,
10861096
"chain the optional using '?' to access member %0 only for non-'nil' "
10871097
"base values", (DeclNameRef))
10881098
NOTE(optional_base_remove_optional_for_keypath_root, none,
10891099
"use unwrapped type %0 as key path root", (Type))
10901100
NOTE(optional_keypath_application_base, none,
10911101
"use '?' to access key path subscript only for non-'nil' base values", ())
1102+
NOTE(optional_key_path_root_base_chain, none,
1103+
"chain the optional using '?.' to access unwrapped type member %0",
1104+
(DeclNameRef))
1105+
NOTE(optional_key_path_root_base_unwrap, none,
1106+
"unwrap the optional using '!.' to access unwrapped type member %0",
1107+
(DeclNameRef))
10921108

10931109
ERROR(missing_unwrap_optional_try,none,
10941110
"value of optional type %0 not unwrapped; did you mean to use 'try!' "

include/swift/AST/Expr.h

Lines changed: 56 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,8 @@ class alignas(8) Expr {
249249
NumArgLabels : 16
250250
);
251251

252-
SWIFT_INLINE_BITFIELD_FULL(UnresolvedMemberExpr, Expr, 1+1+1+16,
253-
/// Whether the UnresolvedMemberExpr has arguments.
254-
HasArguments : 1,
255-
/// Whether the UnresolvedMemberExpr also has source locations for the
256-
/// argument label.
257-
HasArgLabelLocs : 1,
258-
/// Whether the last argument is a trailing closure.
259-
HasTrailingClosure : 1,
260-
: NumPadBits,
261-
/// # of argument labels stored after the UnresolvedMemberExpr.
262-
NumArgLabels : 16
252+
SWIFT_INLINE_BITFIELD_FULL(UnresolvedMemberExpr, Expr, 2,
253+
FunctionRefKind : 2
263254
);
264255

265256
SWIFT_INLINE_BITFIELD(OverloadSetRefExpr, Expr, 2,
@@ -1841,71 +1832,49 @@ class DynamicSubscriptExpr final
18411832
/// member, which is to be resolved with context sensitive type information into
18421833
/// bar.foo. These always have unresolved type.
18431834
class UnresolvedMemberExpr final
1844-
: public Expr,
1845-
public TrailingCallArguments<UnresolvedMemberExpr> {
1835+
: public Expr {
18461836
SourceLoc DotLoc;
18471837
DeclNameLoc NameLoc;
18481838
DeclNameRef Name;
1849-
Expr *Argument;
1850-
1851-
UnresolvedMemberExpr(SourceLoc dotLoc, DeclNameLoc nameLoc,
1852-
DeclNameRef name, Expr *argument,
1853-
ArrayRef<Identifier> argLabels,
1854-
ArrayRef<SourceLoc> argLabelLocs,
1855-
bool hasTrailingClosure,
1856-
bool implicit);
18571839

18581840
public:
1859-
/// Create a new unresolved member expression with no arguments.
1860-
static UnresolvedMemberExpr *create(ASTContext &ctx, SourceLoc dotLoc,
1861-
DeclNameLoc nameLoc, DeclNameRef name,
1862-
bool implicit);
1863-
1864-
/// Create a new unresolved member expression.
1865-
static UnresolvedMemberExpr *create(ASTContext &ctx, SourceLoc dotLoc,
1866-
DeclNameLoc nameLoc, DeclNameRef name,
1867-
SourceLoc lParenLoc,
1868-
ArrayRef<Expr *> args,
1869-
ArrayRef<Identifier> argLabels,
1870-
ArrayRef<SourceLoc> argLabelLocs,
1871-
SourceLoc rParenLoc,
1872-
ArrayRef<TrailingClosure> trailingClosures,
1873-
bool implicit);
1841+
UnresolvedMemberExpr(SourceLoc dotLoc, DeclNameLoc nameLoc, DeclNameRef name,
1842+
bool implicit)
1843+
: Expr(ExprKind::UnresolvedMember, implicit), DotLoc(dotLoc),
1844+
NameLoc(nameLoc), Name(name) {
1845+
// FIXME: Really, we should be setting this to `FunctionRefKind::Compound`
1846+
// if `NameLoc` is compound, but this would be a source break for cases like
1847+
// ```
1848+
// struct S {
1849+
// static func makeS(_: Int) -> S! { S() }
1850+
// }
1851+
//
1852+
// let s: S = .makeS(_:)(0)
1853+
// ```
1854+
// Instead, we should store compound-ness as a separate bit from applied/
1855+
// unapplied.
1856+
Bits.UnresolvedMemberExpr.FunctionRefKind =
1857+
static_cast<unsigned>(FunctionRefKind::Unapplied);
1858+
}
18741859

18751860
DeclNameRef getName() const { return Name; }
18761861
DeclNameLoc getNameLoc() const { return NameLoc; }
18771862
SourceLoc getDotLoc() const { return DotLoc; }
1878-
Expr *getArgument() const { return Argument; }
1879-
void setArgument(Expr *argument) { Argument = argument; }
18801863

1881-
/// Whether this reference has arguments.
1882-
bool hasArguments() const {
1883-
return Bits.UnresolvedMemberExpr.HasArguments;
1884-
}
1885-
1886-
unsigned getNumArguments() const {
1887-
return Bits.UnresolvedMemberExpr.NumArgLabels;
1888-
}
1889-
1890-
bool hasArgumentLabelLocs() const {
1891-
return Bits.UnresolvedMemberExpr.HasArgLabelLocs;
1892-
}
1864+
SourceLoc getLoc() const { return NameLoc.getBaseNameLoc(); }
18931865

1894-
/// Whether this call with written with a trailing closure.
1895-
bool hasTrailingClosure() const {
1896-
return Bits.UnresolvedMemberExpr.HasTrailingClosure;
1897-
}
1866+
SourceLoc getStartLoc() const { return DotLoc; }
1867+
SourceLoc getEndLoc() const { return NameLoc.getSourceRange().End; }
18981868

1899-
/// Return the index of the unlabeled trailing closure argument.
1900-
Optional<unsigned> getUnlabeledTrailingClosureIndex() const {
1901-
return getArgument()->getUnlabeledTrailingClosureIndexOfPackedArgument();
1869+
/// Retrieve the kind of function reference.
1870+
FunctionRefKind getFunctionRefKind() const {
1871+
return static_cast<FunctionRefKind>(
1872+
Bits.UnresolvedMemberExpr.FunctionRefKind);
19021873
}
19031874

1904-
SourceLoc getLoc() const { return NameLoc.getBaseNameLoc(); }
1905-
1906-
SourceLoc getStartLoc() const { return DotLoc; }
1907-
SourceLoc getEndLoc() const {
1908-
return (Argument ? Argument->getEndLoc() : NameLoc.getSourceRange().End);
1875+
/// Set the kind of function reference.
1876+
void setFunctionRefKind(FunctionRefKind refKind) {
1877+
Bits.UnresolvedMemberExpr.FunctionRefKind = static_cast<unsigned>(refKind);
19091878
}
19101879

19111880
static bool classof(const Expr *E) {
@@ -2088,6 +2057,31 @@ class ParenExpr : public IdentityExpr {
20882057

20892058
static bool classof(const Expr *E) { return E->getKind() == ExprKind::Paren; }
20902059
};
2060+
2061+
/// Represents the result of a chain of accesses or calls hanging off of an
2062+
/// \c UnresolvedMemberExpr at the root. This is only used during type checking
2063+
/// to give the result type of such a chain representation in the AST. This
2064+
/// expression type is always implicit.
2065+
class UnresolvedMemberChainResultExpr : public IdentityExpr {
2066+
/// The base of this chain of member accesses.
2067+
UnresolvedMemberExpr *ChainBase;
2068+
public:
2069+
UnresolvedMemberChainResultExpr(Expr *subExpr, UnresolvedMemberExpr *base,
2070+
Type ty = Type())
2071+
: IdentityExpr(ExprKind::UnresolvedMemberChainResult, subExpr, ty,
2072+
/*isImplicit=*/true),
2073+
ChainBase(base) {
2074+
assert(base);
2075+
}
2076+
2077+
UnresolvedMemberExpr *getChainBase() const { return ChainBase; }
2078+
2079+
SWIFT_FORWARD_SOURCE_LOCS_TO(getSubExpr())
2080+
2081+
static bool classof(const Expr *E) {
2082+
return E->getKind() == ExprKind::UnresolvedMemberChainResult;
2083+
}
2084+
};
20912085

20922086
/// AwaitExpr - An 'await' surrounding an expression, marking that the
20932087
/// expression contains code which is a coroutine that may block.

0 commit comments

Comments
 (0)