Skip to content

Commit 6766336

Browse files
committed
Merge remote-tracking branch 'apple/swift-5.0-branch' into 5.0-branch-abi-checker
2 parents eaefa75 + 25034af commit 6766336

File tree

200 files changed

+4350
-3120
lines changed

Some content is hidden

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

200 files changed

+4350
-3120
lines changed

docs/ABI/Mangling.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,9 @@ Property behaviors are implemented using private protocol conformances.
633633
::
634634

635635
concrete-protocol-conformance ::= type protocol-conformance-ref any-protocol-conformance-list 'HC'
636-
protocol-conformance-ref ::= protocol module? 'HP'
636+
protocol-conformance-ref ::= protocol 'HP' // same module as conforming type
637+
protocol-conformance-ref ::= protocol 'Hp' // same module as protocol
638+
protocol-conformance-ref ::= protocol module // "retroactive"
637639

638640
any-protocol-conformance ::= concrete-protocol-conformance
639641
any-protocol-conformance ::= dependent-protocol-conformance
@@ -651,10 +653,13 @@ Property behaviors are implemented using private protocol conformances.
651653
dependent-associated-conformance ::= type protocol
652654

653655
A compact representation used to represent mangled protocol conformance witness
654-
arguments at runtime. The ``module`` is only specified for conformances that are
655-
"retroactive", meaning that the context in which the conformance is defined is
656-
in neither the protocol or type module. The concrete protocol conformances that
657-
follow are for the conditional conformance requirements.
656+
arguments at runtime. The ``module`` is only specified for conformances that
657+
are "retroactive", meaning that the context in which the conformance is defined
658+
is in neither the protocol or type module. For a non-retroactive conformance
659+
where both the type *and* the protocol are in the same module, or for
660+
synthesized conformances that have no owning module, the "HP" operator is
661+
preferred. The concrete protocol conformances that follow are for the
662+
conditional conformance requirements.
658663

659664
Dependent protocol conformances mangle the access path required to extract a
660665
protocol conformance from some conformance passed into the environment. The

include/swift/AST/DiagnosticsSema.def

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,11 +1700,11 @@ ERROR(type_witness_not_accessible_type,none,
17001700
"matches a requirement in protocol %3",
17011701
(DescriptiveDeclKind, DeclName, AccessLevel, DeclName))
17021702
ERROR(witness_not_usable_from_inline,none,
1703-
"%0 %1 must be declared '@usableFromInline' because "
1703+
"%0 %1 must be declared '@usableFromInline' "
17041704
"because it matches a requirement in protocol %2",
17051705
(DescriptiveDeclKind, DeclName, DeclName))
17061706
WARNING(witness_not_usable_from_inline_warn,none,
1707-
"%0 %1 should be declared '@usableFromInline' because "
1707+
"%0 %1 should be declared '@usableFromInline' "
17081708
"because it matches a requirement in protocol %2",
17091709
(DescriptiveDeclKind, DeclName, DeclName))
17101710
ERROR(type_witness_objc_generic_parameter,none,
@@ -3942,6 +3942,10 @@ ERROR(dynamic_replacement_function_not_found, none,
39423942
"replaced function %0 could not be found", (DeclName))
39433943
ERROR(dynamic_replacement_accessor_not_found, none,
39443944
"replaced accessor for %0 could not be found", (DeclName))
3945+
ERROR(dynamic_replacement_accessor_ambiguous, none,
3946+
"replaced accessor for %0 occurs in multiple places", (DeclName))
3947+
NOTE(dynamic_replacement_accessor_ambiguous_candidate, none,
3948+
"candidate accessor found in module %0", (DeclName))
39453949
ERROR(dynamic_replacement_function_of_type_not_found, none,
39463950
"replaced function %0 of type %1 could not be found", (DeclName, Type))
39473951
NOTE(dynamic_replacement_found_function_of_type, none,
@@ -4276,6 +4280,10 @@ WARNING(non_exhaustive_switch_warn,none, "switch must be exhaustive", ())
42764280
WARNING(override_nsobject_hashvalue,none,
42774281
"override of 'NSObject.hashValue' is deprecated; "
42784282
"override 'NSObject.hash' to get consistent hashing behavior", ())
4283+
WARNING(hashvalue_implementation,none,
4284+
"'Hashable.hashValue' is deprecated as a protocol requirement; "
4285+
"conform type %0 to 'Hashable' by implementing 'hash(into:)' instead",
4286+
(Type))
42794287

42804288
#ifndef DIAG_NO_UNDEF
42814289
# if defined(DIAG)

include/swift/AST/KnownIdentifiers.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ IDENTIFIER(appendInterpolation)
175175
IDENTIFIER_WITH_NAME(dollarInterpolation, "$interpolation")
176176
IDENTIFIER(arrayLiteral)
177177
IDENTIFIER(dictionaryLiteral)
178-
IDENTIFIER_(getBuiltinLogicValue)
179178
IDENTIFIER(className)
180179

181180
IDENTIFIER_(ErrorType)

include/swift/Demangling/DemangleNodes.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ NODE(PropertyDescriptor)
156156
CONTEXT_NODE(Protocol)
157157
CONTEXT_NODE(ProtocolSymbolicReference)
158158
NODE(ProtocolConformance)
159-
NODE(ProtocolConformanceRef)
159+
NODE(ProtocolConformanceRefInTypeModule)
160+
NODE(ProtocolConformanceRefInProtocolModule)
161+
NODE(ProtocolConformanceRefInOtherModule)
160162
NODE(ProtocolDescriptor)
161163
NODE(ProtocolConformanceDescriptor)
162164
NODE(ProtocolList)

include/swift/Demangling/Demangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ class Demangler : public NodeFactory {
458458
NodePointer getDependentGenericParamType(int depth, int index);
459459
NodePointer demangleGenericParamIndex();
460460
NodePointer popProtocolConformance();
461-
NodePointer demangleProtocolConformanceRef();
461+
NodePointer demangleRetroactiveProtocolConformanceRef();
462462
NodePointer popAnyProtocolConformance();
463463
NodePointer demangleConcreteProtocolConformance();
464464
NodePointer popDependentProtocolConformance();

include/swift/Demangling/TypeDecoder.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,15 @@ class TypeDecoder {
163163
case NodeKind::BoundGenericClass:
164164
{
165165
#if SWIFT_OBJC_INTEROP
166-
if (Node->getNumChildren() == 2)
167-
if (auto mangledName = getObjCClassOrProtocolName(Node->getChild(0)))
166+
if (Node->getNumChildren() >= 2) {
167+
auto ChildNode = Node->getChild(0);
168+
if (ChildNode->getKind() == NodeKind::Type &&
169+
ChildNode->getNumChildren() > 0)
170+
ChildNode = ChildNode->getChild(0);
171+
172+
if (auto mangledName = getObjCClassOrProtocolName(ChildNode))
168173
return Builder.createObjCClassType(mangledName->str());
174+
}
169175
#endif
170176
LLVM_FALLTHROUGH;
171177
}

include/swift/IDE/Utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,16 @@ enum class LabelRangeEndAt: int8_t {
598598
struct CallArgInfo {
599599
Expr *ArgExp;
600600
CharSourceRange LabelRange;
601+
bool IsTrailingClosure;
601602
CharSourceRange getEntireCharRange(const SourceManager &SM) const;
602603
};
603604

604605
std::vector<CallArgInfo>
605606
getCallArgInfo(SourceManager &SM, Expr *Arg, LabelRangeEndAt EndKind);
606607

607608
// Get the ranges of argument labels from an Arg, either tuple or paren.
609+
// This includes empty ranges for any unlabelled arguments, and excludes
610+
// trailing closures.
608611
std::vector<CharSourceRange>
609612
getCallArgLabelRanges(SourceManager &SM, Expr *Arg, LabelRangeEndAt EndKind);
610613

include/swift/Parse/Parser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,7 @@ class Parser {
13331333
ParserResult<Expr> parseExprCallSuffix(ParserResult<Expr> fn,
13341334
bool isExprBasic);
13351335
ParserResult<Expr> parseExprCollection();
1336-
ParserResult<Expr> parseExprArray(SourceLoc LSquareLoc);
1337-
ParserResult<Expr> parseExprDictionary(SourceLoc LSquareLoc);
1336+
ParserResult<Expr> parseExprCollectionElement(Optional<bool> &isDictionary);
13381337
ParserResult<Expr> parseExprPoundAssert();
13391338
ParserResult<Expr> parseExprPoundUnknown(SourceLoc LSquareLoc);
13401339
ParserResult<Expr>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is processed by CMake.
2+
// See https://cmake.org/cmake/help/v3.0/command/configure_file.html.
3+
4+
#ifndef SWIFT_RUNTIME_CMAKECONFIG_H
5+
6+
#cmakedefine01 SWIFT_DARWIN_ENABLE_STABLE_ABI_BIT
7+
8+
#endif

include/swift/Runtime/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
configure_file(CMakeConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeConfig.h
2+
ESCAPE_QUOTES @ONLY)

include/swift/Runtime/Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef SWIFT_RUNTIME_CONFIG_H
1818
#define SWIFT_RUNTIME_CONFIG_H
1919

20+
#include "swift/Runtime/CMakeConfig.h"
21+
2022
/// \macro SWIFT_RUNTIME_GNUC_PREREQ
2123
/// Extend the default __GNUC_PREREQ even if glibc's features.h isn't
2224
/// available.

include/swift/SILOptimizer/Utils/CastOptimizer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ class CastOptimizer {
129129
SILValue Dest, CanType Source,
130130
CanType Target, SILBasicBlock *SuccessBB,
131131
SILBasicBlock *FailureBB);
132+
133+
SILInstruction *
134+
optimizeMetatypeConversion(ConversionInst *MCI,
135+
MetatypeRepresentation Representation);
132136
};
133137

134138
} // namespace swift

lib/AST/ASTMangler.cpp

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,48 +1110,69 @@ void ASTMangler::appendBoundGenericArgs(Type type, bool &isFirstArgList) {
11101110
}
11111111
}
11121112

1113-
/// Determine whether the given protocol conformance is itself retroactive,
1114-
/// meaning that there might be multiple conflicting conformances of the
1115-
/// same type to the same protocol.
1116-
static bool isRetroactiveConformance(const RootProtocolConformance *root) {
1113+
static bool conformanceHasIdentity(const RootProtocolConformance *root) {
11171114
auto conformance = dyn_cast<NormalProtocolConformance>(root);
11181115
if (!conformance) {
11191116
assert(isa<SelfProtocolConformance>(root));
1120-
return false; // self-conformances are never retroactive.
1117+
return true;
11211118
}
11221119

1123-
/// Non-retroactive conformances are... never retroactive.
1124-
if (!conformance->isRetroactive())
1125-
return false;
1126-
1127-
/// Synthesized non-unique conformances all get collapsed together at run
1128-
/// time.
1120+
// Synthesized non-unique conformances all get collapsed together at run time.
11291121
if (conformance->isSynthesizedNonUnique())
11301122
return false;
11311123

1132-
/// Objective-C protocol conformances don't have identity.
1124+
// Objective-C protocol conformances are checked by the ObjC runtime.
11331125
if (conformance->getProtocol()->isObjC())
11341126
return false;
11351127

11361128
return true;
11371129
}
11381130

1131+
/// Determine whether the given protocol conformance is itself retroactive,
1132+
/// meaning that there might be multiple conflicting conformances of the
1133+
/// same type to the same protocol.
1134+
static bool isRetroactiveConformance(const RootProtocolConformance *root) {
1135+
auto conformance = dyn_cast<NormalProtocolConformance>(root);
1136+
if (!conformance) {
1137+
assert(isa<SelfProtocolConformance>(root));
1138+
return false; // self-conformances are never retroactive.
1139+
}
1140+
1141+
return conformance->isRetroactive();
1142+
}
1143+
11391144
/// Determine whether the given protocol conformance contains a retroactive
11401145
/// protocol conformance anywhere in it.
11411146
static bool containsRetroactiveConformance(
11421147
const ProtocolConformance *conformance,
11431148
ModuleDecl *module) {
11441149
// If the root conformance is retroactive, it's retroactive.
1145-
if (isRetroactiveConformance(conformance->getRootConformance()))
1150+
const RootProtocolConformance *rootConformance =
1151+
conformance->getRootConformance();
1152+
if (isRetroactiveConformance(rootConformance) &&
1153+
conformanceHasIdentity(rootConformance))
11461154
return true;
11471155

1148-
// If any of the substitutions used to form this conformance are retroactive,
1149-
// it's retroactive.
1156+
// If the conformance is conditional and any of the substitutions used to
1157+
// satisfy the conditions are retroactive, it's retroactive.
11501158
auto subMap = conformance->getSubstitutions(module);
1151-
for (auto conformance : subMap.getConformances()) {
1152-
if (conformance.isConcrete() &&
1153-
containsRetroactiveConformance(conformance.getConcrete(), module))
1159+
for (auto requirement : rootConformance->getConditionalRequirements()) {
1160+
if (requirement.getKind() != RequirementKind::Conformance)
1161+
continue;
1162+
ProtocolDecl *proto =
1163+
requirement.getSecondType()->castTo<ProtocolType>()->getDecl();
1164+
Optional<ProtocolConformanceRef> conformance =
1165+
subMap.lookupConformance(requirement.getFirstType()->getCanonicalType(),
1166+
proto);
1167+
if (!conformance) {
1168+
// This should only happen when mangling invalid ASTs, but that happens
1169+
// for indexing purposes.
1170+
continue;
1171+
}
1172+
if (conformance->isConcrete() &&
1173+
containsRetroactiveConformance(conformance->getConcrete(), module)) {
11541174
return true;
1175+
}
11551176
}
11561177

11571178
return false;
@@ -2289,12 +2310,19 @@ void ASTMangler::appendProtocolConformanceRef(
22892310
appendProtocolName(conformance->getProtocol());
22902311

22912312
// For retroactive conformances, add a reference to the module in which the
2292-
// conformance resides. For @objc protocols, there is no point: conformances
2293-
// are global anyway.
2294-
if (isRetroactiveConformance(conformance))
2313+
// conformance resides. Otherwise, use an operator to indicate which known
2314+
// module it's associated with.
2315+
if (!conformanceHasIdentity(conformance)) {
2316+
// Same as "conformance module matches type", below.
2317+
appendOperator("HP");
2318+
} else if (isRetroactiveConformance(conformance)) {
22952319
appendModule(conformance->getDeclContext()->getParentModule());
2296-
2297-
appendOperator("HP");
2320+
} else if (conformance->getDeclContext()->getParentModule() ==
2321+
conformance->getType()->getAnyNominal()->getParentModule()) {
2322+
appendOperator("HP");
2323+
} else {
2324+
appendOperator("Hp");
2325+
}
22982326
}
22992327

23002328
/// Retrieve the index of the conformance requirement indicated by the

lib/AST/ASTVerifier.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ class Verifier : public ASTWalker {
996996
case StmtConditionElement::CK_Boolean: {
997997
auto *E = elt.getBoolean();
998998
if (shouldVerifyChecked(E))
999-
checkSameType(E->getType(), BuiltinIntegerType::get(1, Ctx),
999+
checkSameType(E->getType(), Ctx.getBoolDecl()->getDeclaredType(),
10001000
"condition type");
10011001
break;
10021002
}
@@ -2070,8 +2070,8 @@ class Verifier : public ASTWalker {
20702070
PrettyStackTraceExpr debugStack(Ctx, "verifying IfExpr", E);
20712071

20722072
auto condTy = E->getCondExpr()->getType();
2073-
if (!condTy->isBuiltinIntegerType(1)) {
2074-
Out << "IfExpr condition is not an i1\n";
2073+
if (!condTy->isBool()) {
2074+
Out << "IfExpr condition is not Bool\n";
20752075
abort();
20762076
}
20772077

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4801,8 +4801,12 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenTypeParameters(
48014801
auto T1 = OrigT1->getRepresentative();
48024802
auto T2 = OrigT2->getRepresentative();
48034803

4804-
// Pick representative based on the canonical ordering of the type parameters.
4805-
if (compareDependentTypes(depType2, depType1) < 0) {
4804+
// Decide which potential archetype is to be considered the representative.
4805+
// We prefer potential archetypes with lower nesting depths, because it
4806+
// prevents us from unnecessarily building deeply nested potential archetypes.
4807+
unsigned nestingDepth1 = T1->getNestingDepth();
4808+
unsigned nestingDepth2 = T2->getNestingDepth();
4809+
if (nestingDepth2 < nestingDepth1) {
48064810
std::swap(T1, T2);
48074811
std::swap(OrigT1, OrigT2);
48084812
std::swap(equivClass, equivClass2);
@@ -6833,6 +6837,14 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
68336837
auto locA = (*a)->constraint.source->getLoc();
68346838
auto locB = (*b)->constraint.source->getLoc();
68356839

6840+
// Put invalid locations after valid ones.
6841+
if (locA.isInvalid() || locB.isInvalid()) {
6842+
if (locA.isInvalid() != locB.isInvalid())
6843+
return locA.isValid() ? 1 : -1;
6844+
6845+
return 0;
6846+
}
6847+
68366848
auto bufferA = sourceMgr.findBufferContainingLoc(locA);
68376849
auto bufferB = sourceMgr.findBufferContainingLoc(locB);
68386850

lib/AST/SubstitutionMap.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,19 +353,17 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
353353
return None;
354354
};
355355

356+
// Check whether the superclass conforms.
357+
if (auto superclass = genericSig->getSuperclassBound(type)) {
358+
LookUpConformanceInSignature lookup(*getGenericSignature());
359+
if (auto conformance = lookup(type->getCanonicalType(), superclass, proto))
360+
return conformance;
361+
}
362+
356363
// If the type doesn't conform to this protocol, the result isn't formed
357364
// from these requirements.
358-
if (!genericSig->conformsToProtocol(type, proto)) {
359-
// Check whether the superclass conforms.
360-
if (auto superclass = genericSig->getSuperclassBound(type)) {
361-
return LookUpConformanceInSignature(*getGenericSignature())(
362-
type->getCanonicalType(),
363-
superclass,
364-
proto);
365-
}
366-
365+
if (!genericSig->conformsToProtocol(type, proto))
367366
return None;
368-
}
369367

370368
auto accessPath =
371369
genericSig->getConformanceAccessPath(type, proto);

0 commit comments

Comments
 (0)