Skip to content

Commit 4705ec9

Browse files
authored
Merge pull request #33717 from nathawes/merge-master-to-master-rebranch-2020-08-31
[master-rebranch] Merge in master resolving conflicts
2 parents 80a0f3e + 9da1d89 commit 4705ec9

File tree

109 files changed

+3314
-1931
lines changed

Some content is hidden

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

109 files changed

+3314
-1931
lines changed

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;
@@ -586,6 +587,10 @@ class ASTContext final {
586587
Type getBridgedToObjC(const DeclContext *dc, Type type,
587588
Type *bridgedValueType = nullptr) const;
588589

590+
private:
591+
ClangTypeConverter &getClangTypeConverter();
592+
593+
public:
589594
/// Get the Clang type corresponding to a Swift function type.
590595
///
591596
/// \param params The function parameters.
@@ -595,6 +600,14 @@ class ASTContext final {
595600
getClangFunctionType(ArrayRef<AnyFunctionType::Param> params, Type resultTy,
596601
FunctionTypeRepresentation trueRep);
597602

603+
/// Get the canonical Clang type corresponding to a SIL function type.
604+
///
605+
/// SIL analog of \c ASTContext::getClangFunctionType .
606+
const clang::Type *
607+
getCanonicalClangFunctionType(
608+
ArrayRef<SILParameterInfo> params, Optional<SILResultInfo> result,
609+
SILFunctionType::Representation trueRep);
610+
598611
/// Get the Swift declaration that a Clang declaration was exported from,
599612
/// if applicable.
600613
const Decl *getSwiftDeclForExportedClangDecl(const clang::Decl *decl);

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;
@@ -6148,7 +6149,15 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
61486149
/// being dropped altogether. `None` is returned for a normal function
61496150
/// or method.
61506151
Optional<int> getForeignFunctionAsMethodSelfParameterIndex() const;
6151-
6152+
6153+
/// Set information about the foreign async convention used by this
6154+
/// declaration.
6155+
void setForeignAsyncConvention(const ForeignAsyncConvention &convention);
6156+
6157+
/// Get information about the foreign async convention used by this
6158+
/// declaration, given that it is @objc and 'async'.
6159+
Optional<ForeignAsyncConvention> getForeignAsyncConvention() const;
6160+
61526161
static bool classof(const Decl *D) {
61536162
return D->getKind() >= DeclKind::First_AbstractFunctionDecl &&
61546163
D->getKind() <= DeclKind::Last_AbstractFunctionDecl;
@@ -6277,7 +6286,8 @@ class FuncDecl : public AbstractFunctionDecl {
62776286
DeclContext *Parent);
62786287

62796288
static FuncDecl *createImported(ASTContext &Context, SourceLoc FuncLoc,
6280-
DeclName Name, SourceLoc NameLoc, bool Throws,
6289+
DeclName Name, SourceLoc NameLoc,
6290+
bool Async, bool Throws,
62816291
ParameterList *BodyParams, Type FnRetType,
62826292
DeclContext *Parent, ClangNode ClangN);
62836293

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,15 +2823,16 @@ WARNING(differentiable_nondiff_type_implicit_noderivative_fixit,none,
28232823
/*nominalCanDeriveAdditiveArithmetic*/ bool))
28242824
WARNING(differentiable_immutable_wrapper_implicit_noderivative_fixit,none,
28252825
"synthesis of the 'Differentiable.move(along:)' requirement for %1 "
2826-
"requires 'wrappedValue' in property wrapper %0 to be mutable; "
2827-
"add an explicit '@noDerivative' attribute"
2826+
"requires 'wrappedValue' in property wrapper %0 to be mutable or have a "
2827+
"non-mutating 'move(along:)'; add an explicit '@noDerivative' attribute"
28282828
"%select{|, or conform %1 to 'AdditiveArithmetic'}2",
28292829
(/*wrapperType*/ Identifier, /*nominalName*/ Identifier,
28302830
/*nominalCanDeriveAdditiveArithmetic*/ bool))
28312831
WARNING(differentiable_let_property_implicit_noderivative_fixit,none,
28322832
"synthesis of the 'Differentiable.move(along:)' requirement for %0 "
28332833
"requires all stored properties not marked with `@noDerivative` to be "
2834-
"mutable; use 'var' instead, or add an explicit '@noDerivative' attribute"
2834+
"mutable or have a non-mutating 'move(along:)'; use 'var' instead, or "
2835+
"add an explicit '@noDerivative' attribute "
28352836
"%select{|, or conform %0 to 'AdditiveArithmetic'}1",
28362837
(/*nominalName*/ Identifier, /*nominalCanDeriveAdditiveArithmetic*/ bool))
28372838

include/swift/AST/ExtInfo.h

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,8 @@ class ASTExtInfoBuilder {
195195

196196
using Representation = FunctionTypeRepresentation;
197197

198-
static void assertIsFunctionType(const clang::Type *);
199-
200198
ASTExtInfoBuilder(unsigned bits, ClangTypeInfo clangTypeInfo)
201-
: bits(bits), clangTypeInfo(clangTypeInfo) {
202-
// TODO: [clang-function-type-serialization] Once we start serializing
203-
// the Clang type, we should also assert that the pointer is non-null.
204-
auto Rep = Representation(bits & RepresentationMask);
205-
if ((Rep == Representation::CFunctionPointer) && clangTypeInfo.type)
206-
assertIsFunctionType(clangTypeInfo.type);
207-
}
199+
: bits(bits), clangTypeInfo(clangTypeInfo) {}
208200

209201
public:
210202
// Constructor with all defaults.
@@ -255,10 +247,7 @@ class ASTExtInfoBuilder {
255247
DifferentiabilityKind::NonDifferentiable;
256248
}
257249

258-
/// Get the underlying ClangTypeInfo value if it is not the default value.
259-
Optional<ClangTypeInfo> getClangTypeInfo() const {
260-
return clangTypeInfo.empty() ? Optional<ClangTypeInfo>() : clangTypeInfo;
261-
}
250+
ClangTypeInfo getClangTypeInfo() const { return clangTypeInfo; }
262251

263252
constexpr SILFunctionTypeRepresentation getSILRepresentation() const {
264253
unsigned rawRep = bits & RepresentationMask;
@@ -405,9 +394,7 @@ class ASTExtInfo {
405394

406395
constexpr bool isDifferentiable() const { return builder.isDifferentiable(); }
407396

408-
Optional<ClangTypeInfo> getClangTypeInfo() const {
409-
return builder.getClangTypeInfo();
410-
}
397+
ClangTypeInfo getClangTypeInfo() const { return builder.getClangTypeInfo(); }
411398

412399
constexpr bool hasSelfParam() const { return builder.hasSelfParam(); }
413400

@@ -519,20 +506,32 @@ class SILExtInfoBuilder {
519506
SILExtInfoBuilder(unsigned bits, ClangTypeInfo clangTypeInfo)
520507
: bits(bits), clangTypeInfo(clangTypeInfo) {}
521508

509+
static constexpr unsigned makeBits(Representation rep, bool isPseudogeneric,
510+
bool isNoEscape, bool isAsync,
511+
DifferentiabilityKind diffKind) {
512+
return ((unsigned)rep) | (isPseudogeneric ? PseudogenericMask : 0) |
513+
(isNoEscape ? NoEscapeMask : 0) | (isAsync ? AsyncMask : 0) |
514+
(((unsigned)diffKind << DifferentiabilityMaskOffset) &
515+
DifferentiabilityMask);
516+
}
517+
522518
public:
523519
// Constructor with all defaults.
524-
SILExtInfoBuilder() : bits(0), clangTypeInfo(ClangTypeInfo(nullptr)) {}
520+
SILExtInfoBuilder() : SILExtInfoBuilder(0, ClangTypeInfo(nullptr)) {}
525521

526522
// Constructor for polymorphic type.
527523
SILExtInfoBuilder(Representation rep, bool isPseudogeneric, bool isNoEscape,
528524
bool isAsync, DifferentiabilityKind diffKind,
529525
const clang::Type *type)
530-
: SILExtInfoBuilder(
531-
((unsigned)rep) | (isPseudogeneric ? PseudogenericMask : 0) |
532-
(isNoEscape ? NoEscapeMask : 0) | (isAsync ? AsyncMask : 0) |
533-
(((unsigned)diffKind << DifferentiabilityMaskOffset) &
534-
DifferentiabilityMask),
535-
ClangTypeInfo(type)) {}
526+
: SILExtInfoBuilder(makeBits(rep, isPseudogeneric, isNoEscape, isAsync,
527+
diffKind),
528+
ClangTypeInfo(type)) {}
529+
530+
SILExtInfoBuilder(ASTExtInfoBuilder info, bool isPseudogeneric)
531+
: SILExtInfoBuilder(makeBits(info.getSILRepresentation(), isPseudogeneric,
532+
info.isNoEscape(), info.isAsync(),
533+
info.getDifferentiabilityKind()),
534+
info.getClangTypeInfo()) {}
536535

537536
void checkInvariants() const;
538537

@@ -567,10 +566,8 @@ class SILExtInfoBuilder {
567566
DifferentiabilityKind::NonDifferentiable;
568567
}
569568

570-
/// Get the underlying ClangTypeInfo value if it is not the default value.
571-
Optional<ClangTypeInfo> getClangTypeInfo() const {
572-
return clangTypeInfo.empty() ? Optional<ClangTypeInfo>() : clangTypeInfo;
573-
}
569+
/// Get the underlying ClangTypeInfo value.
570+
ClangTypeInfo getClangTypeInfo() const { return clangTypeInfo; }
574571

575572
constexpr bool hasSelfParam() const {
576573
switch (getRepresentation()) {
@@ -698,9 +695,7 @@ class SILExtInfo {
698695

699696
constexpr bool isDifferentiable() const { return builder.isDifferentiable(); }
700697

701-
Optional<ClangTypeInfo> getClangTypeInfo() const {
702-
return builder.getClangTypeInfo();
703-
}
698+
ClangTypeInfo getClangTypeInfo() const { return builder.getClangTypeInfo(); }
704699

705700
constexpr bool hasSelfParam() const { return builder.hasSelfParam(); }
706701

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//===--- ForeignAsyncConvention.h - Async conventions -----------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 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 the ForeignAsyncConvention structure, which
14+
// describes the rules for how to detect that a foreign API is asynchronous.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_FOREIGN_ASYNC_CONVENTION_H
19+
#define SWIFT_FOREIGN_ASYNC_CONVENTION_H
20+
21+
#include "swift/AST/Type.h"
22+
23+
namespace swift {
24+
25+
/// A small structure describing the async convention of a foreign declaration.
26+
class ForeignAsyncConvention {
27+
/// The index of the completion handler parameters.
28+
unsigned CompletionHandlerParamIndex;
29+
30+
/// When non-zero, indicates which parameter to the completion handler is the
31+
/// Error? parameter (minus one) that makes this async function also throwing.
32+
unsigned CompletionHandlerErrorParamIndex;
33+
public:
34+
ForeignAsyncConvention()
35+
: CompletionHandlerParamIndex(0), CompletionHandlerErrorParamIndex(0) { }
36+
37+
ForeignAsyncConvention(unsigned completionHandlerParamIndex,
38+
Optional<unsigned> completionHandlerErrorParamIndex)
39+
: CompletionHandlerParamIndex(completionHandlerParamIndex),
40+
CompletionHandlerErrorParamIndex(
41+
completionHandlerErrorParamIndex
42+
? *completionHandlerErrorParamIndex + 1
43+
: 0) {}
44+
45+
/// Retrieve the index of the completion handler parameter, which will be
46+
/// erased from the Swift signature of the imported async function.
47+
unsigned completionHandlerParamIndex() const {
48+
return CompletionHandlerParamIndex;
49+
}
50+
51+
/// Retrieve the index of the \c Error? parameter in the completion handler's
52+
/// parameter list. When argument passed to this parameter is non-null, the
53+
/// provided error will be thrown by the async function.
54+
Optional<unsigned> completionHandlerErrorParamIndex() const {
55+
if (CompletionHandlerErrorParamIndex == 0)
56+
return None;
57+
58+
return CompletionHandlerErrorParamIndex - 1;
59+
}
60+
61+
/// Whether the async function is throwing due to the completion handler
62+
/// having an \c Error? parameter.
63+
///
64+
/// Equivalent to \c static_cast<bool>(completionHandlerErrorParamIndex()).
65+
bool isThrowing() const {
66+
return CompletionHandlerErrorParamIndex != 0;
67+
}
68+
69+
bool operator==(ForeignAsyncConvention other) const {
70+
return CompletionHandlerParamIndex == other.CompletionHandlerParamIndex
71+
&& CompletionHandlerErrorParamIndex ==
72+
other.CompletionHandlerErrorParamIndex;
73+
}
74+
bool operator!=(ForeignAsyncConvention other) const {
75+
return !(*this == other);
76+
}
77+
};
78+
79+
}
80+
81+
#endif

include/swift/AST/ForeignErrorConvention.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ class ForeignErrorConvention {
8181
}
8282

8383
Info() = default;
84+
85+
Kind getKind() const {
86+
return static_cast<Kind>(TheKind);
87+
}
8488
};
8589

8690
private:
@@ -178,11 +182,24 @@ class ForeignErrorConvention {
178182
/// Returns the physical result type of the function, for functions
179183
/// that completely erase this information.
180184
CanType getResultType() const {
181-
assert(getKind() == ZeroResult ||
182-
getKind() == NonZeroResult);
185+
assert(resultTypeErasedToVoid(getKind()));
183186
return ResultType;
184187
}
185-
188+
189+
/// Whether this kind of error import erases the result type to 'Void'.
190+
static bool resultTypeErasedToVoid(Kind kind) {
191+
switch (kind) {
192+
case ZeroResult:
193+
case NonZeroResult:
194+
return true;
195+
196+
case ZeroPreservedResult:
197+
case NilResult:
198+
case NonNilError:
199+
return false;
200+
}
201+
}
202+
186203
bool operator==(ForeignErrorConvention other) const {
187204
return info.TheKind == other.info.TheKind
188205
&& info.ErrorIsOwned == other.info.ErrorIsOwned

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2877,7 +2877,7 @@ class AnyFunctionType : public TypeBase {
28772877
unsigned NumParams, ExtInfo Info)
28782878
: TypeBase(Kind, CanTypeContext, properties), Output(Output) {
28792879
Bits.AnyFunctionType.ExtInfoBits = Info.getBits();
2880-
Bits.AnyFunctionType.HasClangTypeInfo = Info.getClangTypeInfo().hasValue();
2880+
Bits.AnyFunctionType.HasClangTypeInfo = !Info.getClangTypeInfo().empty();
28812881
Bits.AnyFunctionType.NumParams = NumParams;
28822882
assert(Bits.AnyFunctionType.NumParams == NumParams && "Params dropped!");
28832883
// The use of both assert() and static_assert() is intentional.

0 commit comments

Comments
 (0)