Skip to content

Commit b93a351

Browse files
authored
Merge branch 'master' into patch-1
2 parents 839d92b + 9825111 commit b93a351

Some content is hidden

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

41 files changed

+607
-916
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4729,10 +4729,6 @@ class ParamDecl : public VarDecl {
47294729
/// was specified separately from the parameter name.
47304730
SourceLoc getArgumentNameLoc() const { return ArgumentNameLoc; }
47314731

4732-
/// Retrieve the parameter type flags corresponding to the declaration of
4733-
/// this parameter's argument type.
4734-
ParameterTypeFlags getParameterFlags() const;
4735-
47364732
SourceLoc getSpecifierLoc() const { return SpecifierLoc; }
47374733

47384734
bool isTypeLocImplicit() const { return Bits.ParamDecl.IsTypeLocImplicit; }
@@ -4822,8 +4818,6 @@ class ParamDecl : public VarDecl {
48224818

48234819
/// Describes the kind of subscripting used in Objective-C.
48244820
enum class ObjCSubscriptKind {
4825-
/// Not an Objective-C subscripting kind.
4826-
None,
48274821
/// Objective-C indexed subscripting, which is based on an integral
48284822
/// index.
48294823
Indexed,
@@ -5774,8 +5768,8 @@ class EnumElementDecl : public ValueDecl {
57745768
}
57755769

57765770
/// Set the interface type of this enum element to the constructor function
5777-
/// type; (Self) -> Result or (Self) -> (Args...) -> Result.
5778-
bool computeType();
5771+
/// type; (Self.Type) -> Self or (Self.Type) -> (Args...) -> Self.
5772+
void computeType();
57795773

57805774
Type getArgumentInterfaceType() const;
57815775

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,16 +1064,6 @@ ERROR(c_function_pointer_from_function_with_context,none,
10641064
// MARK: Type Check Declarations
10651065
//------------------------------------------------------------------------------
10661066

1067-
ERROR(var_type_not_materializable,none,
1068-
"variable has type %0 which includes nested inout parameters",
1069-
(Type))
1070-
ERROR(param_type_non_materializable_tuple,none,
1071-
"named parameter has type %0 which includes nested inout parameters",
1072-
(Type))
1073-
ERROR(enum_element_not_materializable,none,
1074-
"enum case has type %0 which includes nested inout parameters",
1075-
(Type))
1076-
10771067
ERROR(missing_initializer_def,PointsToFirstBadToken,
10781068
"initializer requires a body", ())
10791069

@@ -3614,9 +3604,6 @@ WARNING(attribute_meaningless_when_nonobjc,none,
36143604
ERROR(objc_invalid_on_var,none,
36153605
"property cannot be %" OBJC_ATTR_SELECT "0 "
36163606
"because its type cannot be represented in Objective-C", (unsigned))
3617-
ERROR(objc_invalid_subscript_key_type,none,
3618-
"subscript cannot be %" OBJC_ATTR_SELECT "0 because its key "
3619-
"type %1 is neither an integer nor an object", (unsigned, Type))
36203607
ERROR(objc_invalid_on_subscript,none,
36213608
"subscript cannot be %" OBJC_ATTR_SELECT "0 because its type "
36223609
"cannot be represented in Objective-C", (unsigned))

include/swift/AST/ParameterList.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,14 @@ class alignas(ParamDecl *) ParameterList final :
123123
ParameterList *clone(const ASTContext &C,
124124
OptionSet<CloneFlags> options = None) const;
125125

126-
/// Return a TupleType or ParenType for this parameter list,
127-
/// based on types provided by a callback.
128-
Type getType(const ASTContext &C,
129-
llvm::function_ref<Type(ParamDecl *)> getType) const;
130-
131-
/// Return a TupleType or ParenType for this parameter list, written in terms
132-
/// of contextual archetypes.
133-
Type getType(const ASTContext &C) const;
126+
/// Return a list of function parameters for this parameter list,
127+
/// based on the interface types of the parameters in this list.
128+
void getParams(SmallVectorImpl<AnyFunctionType::Param> &params) const;
134129

135-
/// Return a TupleType or ParenType for this parameter list, written in terms
136-
/// of interface types.
137-
Type getInterfaceType(const ASTContext &C) const;
138-
139-
/// Return the full function type for a set of curried parameter lists that
140-
/// returns the specified result type written in terms of interface types.
141-
static Type getFullInterfaceType(Type resultType, ArrayRef<ParameterList*> PL,
142-
const ASTContext &C);
130+
/// Return a list of function parameters for this parameter list,
131+
/// based on types provided by a callback.
132+
void getParams(SmallVectorImpl<AnyFunctionType::Param> &params,
133+
llvm::function_ref<Type(ParamDecl *)> getType) const;
143134

144135

145136
/// Return the full source range of this parameter.

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -187,12 +187,12 @@ class CodeCompletionCallbacks {
187187
virtual void completePoundAvailablePlatform() = 0;
188188

189189
/// Complete the import decl with importable modules.
190-
virtual void completeImportDecl(std::vector<std::pair<Identifier, SourceLoc>> &Path) = 0;
190+
virtual void
191+
completeImportDecl(std::vector<std::pair<Identifier, SourceLoc>> &Path) = 0;
191192

192193
/// Complete unresolved members after dot.
193-
virtual void completeUnresolvedMember(UnresolvedMemberExpr *E,
194-
ArrayRef<StringRef> Identifiers,
195-
bool HasReturn) = 0;
194+
virtual void completeUnresolvedMember(CodeCompletionExpr *E,
195+
SourceLoc DotLoc) = 0;
196196

197197
virtual void completeAssignmentRHS(AssignExpr *E) = 0;
198198

@@ -232,4 +232,3 @@ class CodeCompletionCallbacksFactory {
232232
} // namespace swift
233233

234234
#endif // LLVM_SWIFT_PARSE_CODE_COMPLETION_CALLBACKS_H
235-

include/swift/Sema/IDETypeChecking.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ namespace swift {
5252
void collectDefaultImplementationForProtocolMembers(ProtocolDecl *PD,
5353
llvm::SmallDenseMap<ValueDecl*, ValueDecl*> &DefaultMap);
5454

55-
/// \brief Given an unresolved member E and its parent P, this function tries
56-
/// to infer the type of E.
57-
/// \returns true on success, false on error.
58-
bool typeCheckUnresolvedExpr(DeclContext &DC, Expr* E,
59-
Expr *P, SmallVectorImpl<Type> &PossibleTypes);
60-
6155
enum InterestedMemberKind : uint8_t {
6256
Viable,
6357
Unviable,

include/swift/Serialization/ModuleFile.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ class ModuleFile
506506

507507
/// Main logic of getDeclChecked.
508508
llvm::Expected<Decl *>
509-
getDeclCheckedImpl(serialization::DeclID DID,
510-
Optional<DeclContext *> ForcedContext = None);
509+
getDeclCheckedImpl(serialization::DeclID DID);
511510

512511
/// Reads the index block, which contains global tables.
513512
///
@@ -796,23 +795,15 @@ class ModuleFile
796795
/// Returns the decl with the given ID, deserializing it if needed.
797796
///
798797
/// \param DID The ID for the decl within this module.
799-
/// \param ForcedContext Optional override for the decl context of certain
800-
/// kinds of decls, used to avoid re-entrant
801-
/// deserialization.
802-
///
798+
803799
/// \sa getDeclChecked
804-
Decl *getDecl(serialization::DeclID DID,
805-
Optional<DeclContext *> ForcedContext = None);
800+
Decl *getDecl(serialization::DeclID DID);
806801

807802
/// Returns the decl with the given ID, deserializing it if needed.
808803
///
809804
/// \param DID The ID for the decl within this module.
810-
/// \param ForcedContext Optional override for the decl context of certain
811-
/// kinds of decls, used to avoid re-entrant
812-
/// deserialization.
813805
llvm::Expected<Decl *>
814-
getDeclChecked(serialization::DeclID DID,
815-
Optional<DeclContext *> ForcedContext = None);
806+
getDeclChecked(serialization::DeclID DID);
816807

817808
/// Returns the decl context with the given ID, deserializing it if needed.
818809
DeclContext *getDeclContext(serialization::DeclContextID DID);

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const uint16_t VERSION_MAJOR = 0;
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
5757
/// Don't worry about adhering to the 80-column limit for this line.
58-
const uint16_t VERSION_MINOR = 432; // Last change: default argument text
58+
const uint16_t VERSION_MINOR = 433; // Last change: GenericTypeParamDecl doesn't need a DC
5959

6060
using DeclIDField = BCFixed<31>;
6161

@@ -871,7 +871,6 @@ namespace decls_block {
871871
using GenericTypeParamDeclLayout = BCRecordLayout<
872872
GENERIC_TYPE_PARAM_DECL,
873873
IdentifierIDField, // name
874-
DeclContextIDField, // context decl
875874
BCFixed<1>, // implicit flag
876875
BCVBR<4>, // depth
877876
BCVBR<4> // index

lib/AST/Decl.cpp

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4332,8 +4332,6 @@ AbstractStorageDecl::getObjCGetterSelector(Identifier preferredName) const {
43324332
auto &ctx = getASTContext();
43334333
if (auto *SD = dyn_cast<SubscriptDecl>(this)) {
43344334
switch (SD->getObjCSubscriptKind()) {
4335-
case ObjCSubscriptKind::None:
4336-
llvm_unreachable("Not an Objective-C subscript");
43374335
case ObjCSubscriptKind::Indexed:
43384336
return ObjCSelector(ctx, 1, ctx.Id_objectAtIndexedSubscript);
43394337
case ObjCSubscriptKind::Keyed:
@@ -4365,9 +4363,6 @@ AbstractStorageDecl::getObjCSetterSelector(Identifier preferredName) const {
43654363
auto &ctx = getASTContext();
43664364
if (auto *SD = dyn_cast<SubscriptDecl>(this)) {
43674365
switch (SD->getObjCSubscriptKind()) {
4368-
case ObjCSubscriptKind::None:
4369-
llvm_unreachable("Not an Objective-C subscript");
4370-
43714366
case ObjCSubscriptKind::Indexed:
43724367
return ObjCSelector(ctx, 2,
43734368
{ ctx.Id_setObject, ctx.Id_atIndexedSubscript });
@@ -4804,11 +4799,6 @@ ParamDecl *ParamDecl::createSelf(SourceLoc loc, DeclContext *DC,
48044799
return selfDecl;
48054800
}
48064801

4807-
ParameterTypeFlags ParamDecl::getParameterFlags() const {
4808-
return ParameterTypeFlags::fromParameterType(getType(), isVariadic(),
4809-
getValueOwnership());
4810-
}
4811-
48124802
/// Return the full source range of this parameter.
48134803
SourceRange ParamDecl::getSourceRange() const {
48144804
SourceLoc APINameLoc = getArgumentNameLoc();
@@ -4974,17 +4964,18 @@ Type SubscriptDecl::getElementInterfaceType() const {
49744964
}
49754965

49764966
void SubscriptDecl::computeType() {
4977-
auto &ctx = getASTContext();
4978-
49794967
auto elementTy = getElementTypeLoc().getType();
4980-
auto indicesTy = getIndices()->getInterfaceType(ctx);
4981-
Type funcTy;
49824968

4969+
SmallVector<AnyFunctionType::Param, 2> argTy;
4970+
getIndices()->getParams(argTy);
4971+
4972+
Type funcTy;
49834973
if (auto *sig = getGenericSignature())
4984-
funcTy = GenericFunctionType::get(sig, indicesTy, elementTy,
4974+
funcTy = GenericFunctionType::get(sig, argTy, elementTy,
49854975
AnyFunctionType::ExtInfo());
49864976
else
4987-
funcTy = FunctionType::get(indicesTy, elementTy);
4977+
funcTy = FunctionType::get(argTy, elementTy,
4978+
AnyFunctionType::ExtInfo());
49884979

49894980
// Record the interface type.
49904981
setInterfaceType(funcTy);
@@ -5408,8 +5399,7 @@ void AbstractFunctionDecl::computeType(AnyFunctionType::ExtInfo info) {
54085399

54095400
{
54105401
SmallVector<AnyFunctionType::Param, 4> argTy;
5411-
AnyFunctionType::decomposeInput(
5412-
getParameters()->getInterfaceType(ctx), argTy);
5402+
getParameters()->getParams(argTy);
54135403

54145404
// 'throws' only applies to the innermost function.
54155405
info = info.withThrows(hasThrows());
@@ -5729,30 +5719,38 @@ SourceRange EnumElementDecl::getSourceRange() const {
57295719
return {getStartLoc(), getNameLoc()};
57305720
}
57315721

5732-
bool EnumElementDecl::computeType() {
5722+
void EnumElementDecl::computeType() {
57335723
assert(!hasInterfaceType());
57345724

5735-
EnumDecl *ED = getParentEnum();
5736-
Type resultTy = ED->getDeclaredInterfaceType();
5725+
auto &ctx = getASTContext();
5726+
auto *ED = getParentEnum();
5727+
5728+
// The type of the enum element is either (Self.Type) -> Self
5729+
// or (Self.Type) -> (Args...) -> Self.
5730+
auto resultTy = ED->getDeclaredInterfaceType();
57375731

5738-
Type selfTy = MetatypeType::get(resultTy);
5732+
SmallVector<AnyFunctionType::Param, 1> selfTy;
5733+
selfTy.emplace_back(MetatypeType::get(resultTy, ctx),
5734+
Identifier(),
5735+
ParameterTypeFlags());
57395736

5740-
// The type of the enum element is either (T) -> T or (T) -> ArgType -> T.
57415737
if (auto *PL = getParameterList()) {
5742-
auto paramTy = PL->getInterfaceType(getASTContext());
5743-
resultTy = FunctionType::get(paramTy, resultTy);
5738+
SmallVector<AnyFunctionType::Param, 4> argTy;
5739+
PL->getParams(argTy);
5740+
5741+
resultTy = FunctionType::get(argTy, resultTy,
5742+
AnyFunctionType::ExtInfo());
57445743
}
57455744

5746-
if (auto *genericSig = ED->getGenericSignatureOfContext())
5745+
if (auto *genericSig = ED->getGenericSignature())
57475746
resultTy = GenericFunctionType::get(genericSig, selfTy, resultTy,
57485747
AnyFunctionType::ExtInfo());
57495748
else
5750-
resultTy = FunctionType::get(selfTy, resultTy);
5749+
resultTy = FunctionType::get(selfTy, resultTy,
5750+
AnyFunctionType::ExtInfo());
57515751

57525752
// Record the interface type.
57535753
setInterfaceType(resultTy);
5754-
5755-
return true;
57565754
}
57575755

57585756
Type EnumElementDecl::getArgumentInterfaceType() const {

lib/AST/Parameter.cpp

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -87,56 +87,29 @@ ParameterList *ParameterList::clone(const ASTContext &C,
8787
return create(C, params);
8888
}
8989

90-
/// Return a TupleType or ParenType for this parameter list,
91-
/// based on types provided by a callback.
92-
Type ParameterList::getType(
93-
const ASTContext &C, llvm::function_ref<Type(ParamDecl *)> getType) const {
94-
if (size() == 0)
95-
return TupleType::getEmpty(C);
90+
void ParameterList::getParams(
91+
SmallVectorImpl<AnyFunctionType::Param> &params) const {
92+
getParams(params,
93+
[](ParamDecl *decl) { return decl->getInterfaceType(); });
94+
}
9695

97-
SmallVector<TupleTypeElt, 8> argumentInfo;
96+
void ParameterList::getParams(
97+
SmallVectorImpl<AnyFunctionType::Param> &params,
98+
llvm::function_ref<Type(ParamDecl *)> getType) const {
99+
if (size() == 0)
100+
return;
98101

99102
for (auto P : *this) {
100103
auto type = getType(P);
101-
argumentInfo.emplace_back(
102-
type->getInOutObjectType(), P->getArgumentName(),
103-
ParameterTypeFlags::fromParameterType(type, P->isVariadic(),
104-
P->getValueOwnership()));
105-
}
106-
107-
return TupleType::get(argumentInfo, C);
108-
}
109-
110-
/// Return a TupleType or ParenType for this parameter list, written in terms
111-
/// of contextual archetypes.
112-
Type ParameterList::getType(const ASTContext &C) const {
113-
return getType(C, [](ParamDecl *P) { return P->getType(); });
114-
}
115-
116-
/// Return a TupleType or ParenType for this parameter list, written in terms
117-
/// of interface types.
118-
Type ParameterList::getInterfaceType(const ASTContext &C) const {
119-
return getType(C, [](ParamDecl *P) {
120-
auto type = P->getInterfaceType();
121-
assert(!type->hasArchetype());
122-
return type;
123-
});
124-
}
125104

105+
if (P->isVariadic())
106+
type = ParamDecl::getVarargBaseTy(type);
126107

127-
/// Return the full function type for a set of curried parameter lists that
128-
/// returns the specified result type. This returns a null type if one of the
129-
/// ParamDecls does not have a type set for it yet.
130-
///
131-
Type ParameterList::getFullInterfaceType(Type resultType,
132-
ArrayRef<ParameterList*> PLL,
133-
const ASTContext &C) {
134-
auto result = resultType;
135-
for (auto PL : reversed(PLL)) {
136-
auto paramType = PL->getInterfaceType(C);
137-
result = FunctionType::get(paramType, result);
108+
auto label = P->getArgumentName();
109+
auto flags = ParameterTypeFlags::fromParameterType(type, P->isVariadic(),
110+
P->getValueOwnership());
111+
params.emplace_back(type, label, flags);
138112
}
139-
return result;
140113
}
141114

142115

lib/ClangImporter/ClangAdapter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#define CLANG_ADAPTER_H
2020

2121
#include "swift/Basic/StringExtras.h"
22-
#include "swift/Serialization/ModuleFormat.h"
2322
#include "llvm/ADT/Optional.h"
2423
#include "llvm/ADT/SmallBitVector.h"
2524
#include "clang/Basic/Specifiers.h"

0 commit comments

Comments
 (0)