Skip to content

Commit 7878ece

Browse files
committed
Merge remote-tracking branch 'origin/swift-5.1-old-llvm-branch' into swift-5.1-branch
2 parents 06120c9 + 80ce2c3 commit 7878ece

File tree

66 files changed

+738
-351
lines changed

Some content is hidden

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

66 files changed

+738
-351
lines changed

docs/WindowsBuild.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ cmake -G Ninja^
160160
-DCMAKE_CXX_FLAGS:STRING="-Wno-c++98-compat -Wno-c++98-compat-pedantic"^
161161
-DCMAKE_EXE_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^
162162
-DCMAKE_SHARED_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^
163+
-DSWIFT_BUILD_SOURCEKIT=ON^
163164
-DSWIFT_INCLUDE_DOCS=OFF^
164165
-DSWIFT_PATH_TO_CMARK_SOURCE="S:\cmark"^
165166
-DSWIFT_PATH_TO_CMARK_BUILD="S:\b\cmark"^

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,10 @@ ERROR(type_witness_objc_generic_parameter,none,
17261726
NOTE(witness_fix_access,none,
17271727
"mark the %0 as '%select{%error|fileprivate|internal|public|%error}1' to "
17281728
"satisfy the requirement", (DescriptiveDeclKind, AccessLevel))
1729+
NOTE(witness_move_to_another_extension,none,
1730+
"move the %0 to another extension where it can be declared "
1731+
"'%select{%error|%error|internal|public|%error}1' to "
1732+
"satisfy the requirement", (DescriptiveDeclKind, AccessLevel))
17291733
WARNING(assoc_type_default_conformance_failed,none,
17301734
"default type %0 for associated type %1 does not satisfy constraint "
17311735
"%2: %3", (Type, DeclName, Type, Type))
@@ -1982,6 +1986,9 @@ ERROR(protocol_composition_one_class,none,
19821986
ERROR(requires_conformance_nonprotocol,none,
19831987
"type %0 constrained to non-protocol, non-class type %1",
19841988
(Type, Type))
1989+
NOTE(requires_conformance_nonprotocol_fixit,none,
1990+
"use '%0 == %1' to require '%0' to be '%1'",
1991+
(StringRef, StringRef))
19851992
ERROR(requires_not_suitable_archetype,none,
19861993
"type %0 in conformance requirement does not refer to a "
19871994
"generic parameter or associated type",

include/swift/AST/Expr.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,11 @@ class TapExpr : public Expr {
988988
BraceStmt * getBody() const { return Body; }
989989
void setBody(BraceStmt * b) { Body = b; }
990990

991-
SourceLoc getLoc() const { return SourceLoc(); }
992-
SourceRange getSourceRange() const { return SourceRange(); }
991+
SourceLoc getLoc() const { return SubExpr ? SubExpr->getLoc() : SourceLoc(); }
992+
993+
SourceRange getSourceRange() const {
994+
return SubExpr ? SubExpr->getSourceRange() : SourceRange();
995+
}
993996

994997
static bool classof(const Expr *E) {
995998
return E->getKind() == ExprKind::Tap;

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ class GenericSignatureBuilder {
314314
/// \c ConstraintResult::Unresolved so the caller knows what happened.
315315
GenerateUnresolved = 1,
316316
};
317+
318+
/// The set of constraints that are invalid because the constraint
319+
/// type isn't constrained to a protocol or a class
320+
std::vector<Constraint<Type>> invalidIsaConstraints;
317321

318322
private:
319323
class InferRequirementsWalker;

include/swift/Basic/Statistics.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ FRONTEND_STATISTIC(Sema, NumDeclsDeserialized)
179179
/// Number of declarations validated.
180180
FRONTEND_STATISTIC(Sema, NumDeclsValidated)
181181

182+
/// Number of declarations type checked.
183+
FRONTEND_STATISTIC(Sema, NumDeclsTypechecked)
184+
185+
/// Number of declarations finalized.
186+
FRONTEND_STATISTIC(Sema, NumDeclsFinalized)
187+
182188
/// Number of full function bodies typechecked.
183189
FRONTEND_STATISTIC(Sema, NumFunctionsTypechecked)
184190

include/swift/IDE/Utils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ Decl *getDeclFromUSR(ASTContext &context, StringRef USR, std::string &error);
134134
Decl *getDeclFromMangledSymbolName(ASTContext &context, StringRef mangledName,
135135
std::string &error);
136136

137-
Type getTypeFromMangledSymbolname(ASTContext &Ctx, StringRef mangledName,
138-
std::string &error);
139-
140137
class XMLEscapingPrinter : public StreamPrinter {
141138
public:
142139
XMLEscapingPrinter(raw_ostream &OS) : StreamPrinter(OS){};

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,13 +1034,17 @@ FuncDecl *ASTContext::getEqualIntDecl() const {
10341034
return nullptr;
10351035

10361036
auto intType = getIntDecl()->getDeclaredType();
1037+
auto isIntParam = [&](AnyFunctionType::Param param) {
1038+
return (!param.isVariadic() && !param.isInOut() &&
1039+
param.getPlainType()->isEqual(intType));
1040+
};
10371041
auto boolType = getBoolDecl()->getDeclaredType();
10381042
auto decl = lookupOperatorFunc(*this, "==",
10391043
intType, [=](FunctionType *type) {
10401044
// Check for the signature: (Int, Int) -> Bool
10411045
if (type->getParams().size() != 2) return false;
1042-
if (!type->getParams()[0].getOldType()->isEqual(intType) ||
1043-
!type->getParams()[1].getOldType()->isEqual(intType)) return false;
1046+
if (!isIntParam(type->getParams()[0]) ||
1047+
!isIntParam(type->getParams()[1])) return false;
10441048
return type->getResult()->isEqual(boolType);
10451049
});
10461050
getImpl().EqualIntDecl = decl;
@@ -1227,8 +1231,9 @@ FuncDecl *ASTContext::getIsOSVersionAtLeastDecl() const {
12271231
if (intrinsicsParams.size() != 3)
12281232
return nullptr;
12291233

1230-
if (llvm::any_of(intrinsicsParams, [](const AnyFunctionType::Param &p) {
1231-
return !isBuiltinWordType(p.getOldType());
1234+
if (llvm::any_of(intrinsicsParams, [](AnyFunctionType::Param param) {
1235+
return (param.isVariadic() || param.isInOut() ||
1236+
!isBuiltinWordType(param.getPlainType()));
12321237
})) {
12331238
return nullptr;
12341239
}

lib/AST/Decl.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,8 +4127,15 @@ findProtocolSelfReferences(const ProtocolDecl *proto, Type type,
41274127
// the parameter type.
41284128
if (auto funcTy = type->getAs<AnyFunctionType>()) {
41294129
auto inputKind = SelfReferenceKind::None();
4130-
for (auto &elt : funcTy->getParams()) {
4131-
inputKind |= findProtocolSelfReferences(proto, elt.getOldType(),
4130+
for (auto param : funcTy->getParams()) {
4131+
// inout parameters are invariant.
4132+
if (param.isInOut()) {
4133+
if (findProtocolSelfReferences(proto, param.getPlainType(),
4134+
skipAssocTypes)) {
4135+
return SelfReferenceKind::Other();
4136+
}
4137+
}
4138+
inputKind |= findProtocolSelfReferences(proto, param.getParameterType(),
41324139
skipAssocTypes);
41334140
}
41344141
auto resultKind = findProtocolSelfReferences(proto, funcTy->getResult(),
@@ -4159,14 +4166,6 @@ findProtocolSelfReferences(const ProtocolDecl *proto, Type type,
41594166
skipAssocTypes);
41604167
}
41614168

4162-
// InOut types are invariant.
4163-
if (auto inOutType = type->getAs<InOutType>()) {
4164-
if (findProtocolSelfReferences(proto, inOutType->getObjectType(),
4165-
skipAssocTypes)) {
4166-
return SelfReferenceKind::Other();
4167-
}
4168-
}
4169-
41704169
// Bound generic types are invariant.
41714170
if (auto boundGenericType = type->getAs<BoundGenericType>()) {
41724171
for (auto paramType : boundGenericType->getGenericArgs()) {
@@ -4237,8 +4236,15 @@ ProtocolDecl::findProtocolSelfReferences(const ValueDecl *value,
42374236
// as a function result type.
42384237
if (!allowCovariantParameters) {
42394238
auto inputKind = SelfReferenceKind::None();
4240-
for (auto &elt : type->castTo<AnyFunctionType>()->getParams()) {
4241-
inputKind |= ::findProtocolSelfReferences(this, elt.getOldType(),
4239+
for (auto param : type->castTo<AnyFunctionType>()->getParams()) {
4240+
// inout parameters are invariant.
4241+
if (param.isInOut()) {
4242+
if (::findProtocolSelfReferences(this, param.getPlainType(),
4243+
skipAssocTypes)) {
4244+
return SelfReferenceKind::Other();
4245+
}
4246+
}
4247+
inputKind |= ::findProtocolSelfReferences(this, param.getParameterType(),
42424248
skipAssocTypes);
42434249
}
42444250

lib/AST/Expr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ bool Expr::isTypeReference(
474474
continue;
475475
}
476476

477+
if (auto *USE = dyn_cast<UnresolvedSpecializeExpr>(expr)) {
478+
expr = USE->getSubExpr();
479+
continue;
480+
}
481+
477482
// Anything else is not statically derived.
478483
return false;
479484
} while (true);

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,8 +4629,14 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
46294629
->getDependentType(getGenericParams());
46304630

46314631
Impl->HadAnyError = true;
4632-
Diags.diagnose(source.getLoc(), diag::requires_conformance_nonprotocol,
4633-
subjectType, constraintType);
4632+
4633+
if (subjectType->is<DependentMemberType>()) {
4634+
subjectType = resolveDependentMemberTypes(*this, subjectType);
4635+
}
4636+
4637+
auto invalidConstraint = Constraint<Type>(
4638+
{subject, constraintType, source.getSource(*this, subjectType)});
4639+
invalidIsaConstraints.push_back(invalidConstraint);
46344640
}
46354641

46364642
return ConstraintResult::Conflicting;
@@ -5750,6 +5756,43 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
57505756
}
57515757
}
57525758
}
5759+
5760+
// Emit a diagnostic if we recorded any constraints where the constraint
5761+
// type was not constrained to a protocol or class. Provide a fix-it if
5762+
// allowConcreteGenericParams is true or the subject type is a member type.
5763+
if (!invalidIsaConstraints.empty()) {
5764+
for (auto constraint : invalidIsaConstraints) {
5765+
auto subjectType = constraint.getSubjectDependentType(getGenericParams());
5766+
auto constraintType = constraint.value;
5767+
auto source = constraint.source;
5768+
auto loc = source->getLoc();
5769+
5770+
Diags.diagnose(loc, diag::requires_conformance_nonprotocol,
5771+
subjectType, constraintType);
5772+
5773+
auto getNameWithoutSelf = [&](std::string subjectTypeName) {
5774+
std::string selfSubstring = "Self.";
5775+
5776+
if (subjectTypeName.rfind(selfSubstring, 0) == 0) {
5777+
return subjectTypeName.erase(0, selfSubstring.length());
5778+
}
5779+
5780+
return subjectTypeName;
5781+
};
5782+
5783+
if (allowConcreteGenericParams ||
5784+
(subjectType->is<DependentMemberType>() &&
5785+
!source->isProtocolRequirement())) {
5786+
auto subjectTypeName = subjectType.getString();
5787+
auto subjectTypeNameWithoutSelf = getNameWithoutSelf(subjectTypeName);
5788+
Diags.diagnose(loc, diag::requires_conformance_nonprotocol_fixit,
5789+
subjectTypeNameWithoutSelf, constraintType.getString())
5790+
.fixItReplace(loc, " == ");
5791+
}
5792+
}
5793+
5794+
invalidIsaConstraints.clear();
5795+
}
57535796
}
57545797

57555798
/// Turn a requirement right-hand side into an unresolved type.

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ static std::pair<Type, ParamDecl *> decomposeSubscriptSetter(FuncDecl *setter) {
16541654
->castTo<AnyFunctionType>()
16551655
->getResult()
16561656
->castTo<AnyFunctionType>()
1657-
->getParams().front().getOldType();
1657+
->getParams().front().getParameterType();
16581658
ParamDecl *keyDecl = PL->get(1);
16591659

16601660
return {elementType, keyDecl};

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "swift/IDE/Utils.h"
1515
#include "swift/Sema/IDETypeChecking.h"
1616
#include "swift/AST/ASTContext.h"
17+
#include "swift/AST/ASTDemangler.h"
1718
#include "swift/AST/ASTPrinter.h"
1819
#include "swift/AST/Decl.h"
1920
#include "swift/AST/Module.h"
@@ -182,8 +183,8 @@ printTypeInterface(ModuleDecl *M, Type Ty, ASTPrinter &Printer,
182183
bool swift::ide::
183184
printTypeInterface(ModuleDecl *M, StringRef TypeUSR, ASTPrinter &Printer,
184185
std::string &TypeName, std::string &Error) {
185-
return printTypeInterface(M, getTypeFromMangledSymbolname(M->getASTContext(),
186-
TypeUSR, Error),
186+
return printTypeInterface(M, Demangle::getTypeForMangling(M->getASTContext(),
187+
TypeUSR),
187188
Printer, TypeName, Error);
188189
}
189190

lib/IDE/TypeReconstruction.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,23 +2463,3 @@ Decl *ide::getDeclFromMangledSymbolName(ASTContext &context,
24632463
}
24642464
return nullptr;
24652465
}
2466-
2467-
Type ide::getTypeFromMangledSymbolname(ASTContext &Ctx,
2468-
StringRef mangledName,
2469-
std::string &error) {
2470-
Demangle::Context DemangleCtx;
2471-
auto node = DemangleCtx.demangleSymbolAsNode(mangledName);
2472-
VisitNodeResult result;
2473-
2474-
if (node)
2475-
VisitNode(&Ctx, node, result);
2476-
error = result._error;
2477-
if (error.empty() && result._types.size() == 1) {
2478-
return result._types.front().getPointer();
2479-
} else {
2480-
error = stringWithFormat("type for symbolname '%s' was not found",
2481-
mangledName);
2482-
return Type();
2483-
}
2484-
return Type();
2485-
}

lib/IRGen/GenProto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,7 @@ void NecessaryBindings::addTypeMetadata(CanType type) {
28492849
}
28502850
if (auto fn = dyn_cast<FunctionType>(type)) {
28512851
for (const auto &elt : fn.getParams())
2852-
addTypeMetadata(elt.getOldType());
2852+
addTypeMetadata(elt.getPlainType());
28532853
addTypeMetadata(fn.getResult());
28542854
return;
28552855
}

0 commit comments

Comments
 (0)