Skip to content

Commit 24a9599

Browse files
authored
Merge branch 'master' into uniterator
2 parents 103861b + 8e4503a commit 24a9599

38 files changed

+424
-457
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7259,6 +7259,7 @@ Swift 1.0
72597259
[SE-0224]: <https://github.com/apple/swift-evolution/blob/master/proposals/0224-ifswift-lessthan-operator.md>
72607260
[SE-0225]: <https://github.com/apple/swift-evolution/blob/master/proposals/0225-binaryinteger-iseven-isodd-ismultiple.md>
72617261
[SE-0226]: <https://github.com/apple/swift-evolution/blob/master/proposals/0226-package-manager-target-based-dep-resolution.md>
7262+
[SE-0227]: <https://github.com/apple/swift-evolution/blob/master/proposals/0227-identity-keypath.md>
72627263

72637264
[SR-106]: <https://bugs.swift.org/browse/SR-106>
72647265
[SR-419]: <https://bugs.swift.org/browse/SR-419>

include/swift/AST/ASTMangler.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ class ASTMangler : public Mangler {
3333
protected:
3434
CanGenericSignature CurGenericSignature;
3535
ModuleDecl *Mod = nullptr;
36-
const DeclContext *DeclCtx = nullptr;
37-
GenericEnvironment *GenericEnv = nullptr;
3836

3937
/// Optimize out protocol names if a type only conforms to one protocol.
4038
bool OptimizeProtocolNames = true;
4139

42-
/// If enabled, Arche- and Alias types are mangled with context.
40+
/// If enabled, non-canonical types are allowed and type alias types get a
41+
/// special mangling.
4342
bool DWARFMangling;
4443

4544
/// If enabled, entities that ought to have names but don't get a placeholder.
@@ -148,8 +147,7 @@ class ASTMangler : public Mangler {
148147
std::string mangleKeyPathHashHelper(ArrayRef<CanType> indices,
149148
GenericSignature *signature);
150149

151-
std::string mangleTypeForDebugger(Type decl, const DeclContext *DC,
152-
GenericEnvironment *GE);
150+
std::string mangleTypeForDebugger(Type decl, const DeclContext *DC);
153151

154152
std::string mangleDeclType(const ValueDecl *decl);
155153

@@ -269,8 +267,7 @@ class ASTMangler : public Mangler {
269267
void appendClosureEntity(const AbstractClosureExpr *closure);
270268

271269
void appendClosureComponents(Type Ty, unsigned discriminator, bool isImplicit,
272-
const DeclContext *parentContext,
273-
const DeclContext *localContext);
270+
const DeclContext *parentContext);
274271

275272
void appendDefaultArgumentEntity(const DeclContext *ctx, unsigned index);
276273

include/swift/Serialization/DeclTypeRecordNodes.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ OTHER(DEFAULT_ARGUMENT_INITIALIZER_CONTEXT, 222)
159159
OTHER(TOP_LEVEL_CODE_DECL_CONTEXT, 223)
160160

161161
OTHER(GENERIC_PARAM_LIST, 230)
162-
TRAILING_INFO(GENERIC_PARAM)
162+
OTHER(GENERIC_SIGNATURE, 231)
163163
TRAILING_INFO(GENERIC_REQUIREMENT)
164164
TRAILING_INFO(LAYOUT_REQUIREMENT)
165-
OTHER(GENERIC_SIGNATURE, 234)
165+
// 234 is unused
166166
OTHER(SIL_GENERIC_ENVIRONMENT, 235)
167167
OTHER(SUBSTITUTION_MAP, 236)
168168

include/swift/Serialization/ModuleFormat.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 463; // Last change: enable-private-imports
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 464; // Last change: simplify GenericParamLists
5656

5757
using DeclIDField = BCFixed<31>;
5858

@@ -1259,13 +1259,8 @@ namespace decls_block {
12591259
>;
12601260

12611261
using GenericParamListLayout = BCRecordLayout<
1262-
GENERIC_PARAM_LIST
1263-
// The actual parameters and requirements trail the record.
1264-
>;
1265-
1266-
using GenericParamLayout = BCRecordLayout<
1267-
GENERIC_PARAM,
1268-
DeclIDField // Typealias
1262+
GENERIC_PARAM_LIST,
1263+
BCArray<DeclIDField> // the GenericTypeParamDecls
12691264
>;
12701265

12711266
using GenericSignatureLayout = BCRecordLayout<

lib/AST/ASTMangler.cpp

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "swift/AST/ASTContext.h"
1919
#include "swift/AST/ASTVisitor.h"
2020
#include "swift/AST/ExistentialLayout.h"
21-
#include "swift/AST/GenericEnvironment.h"
21+
#include "swift/AST/GenericSignature.h"
2222
#include "swift/AST/Initializer.h"
2323
#include "swift/AST/Module.h"
2424
#include "swift/AST/Ownership.h"
@@ -378,18 +378,15 @@ std::string ASTMangler::mangleReabstractionThunkHelper(
378378
return finalize();
379379
}
380380

381-
std::string ASTMangler::mangleTypeForDebugger(Type Ty, const DeclContext *DC,
382-
GenericEnvironment *GE) {
381+
std::string ASTMangler::mangleTypeForDebugger(Type Ty, const DeclContext *DC) {
383382
PrettyStackTraceType prettyStackTrace(Ty->getASTContext(),
384383
"mangling type for debugger", Ty);
385384

386-
GenericEnv = GE;
387385
DWARFMangling = true;
388386
beginMangling();
389387

390388
if (DC)
391389
bindGenericParameters(DC);
392-
DeclCtx = DC;
393390

394391
if (auto *fnType = Ty->getAs<AnyFunctionType>()) {
395392
appendFunction(fnType, false);
@@ -682,20 +679,10 @@ static bool shouldMangleAsGeneric(Type type) {
682679
if (!type)
683680
return false;
684681

685-
TypeBase *typePtr = type.getPointer();
686-
if (auto typeAlias = dyn_cast<NameAliasType>(typePtr))
682+
if (auto typeAlias = dyn_cast<NameAliasType>(type.getPointer()))
687683
return !typeAlias->getSubstitutionMap().empty();
688684

689-
if (auto bound = dyn_cast<BoundGenericType>(typePtr))
690-
return true;
691-
692-
if (auto nominal = dyn_cast<NominalType>(typePtr))
693-
return shouldMangleAsGeneric(nominal->getParent());
694-
695-
if (auto unbound = dyn_cast<UnboundGenericType>(typePtr))
696-
return shouldMangleAsGeneric(unbound->getParent());
697-
698-
return false;
685+
return type->isSpecialized();
699686
}
700687

701688
/// Mangle a type into the buffer.
@@ -1113,15 +1100,15 @@ void ASTMangler::appendBoundGenericArgs(Type type, bool &isFirstArgList) {
11131100

11141101
if (auto *unboundType = dyn_cast<UnboundGenericType>(typePtr)) {
11151102
if (Type parent = unboundType->getParent())
1116-
appendBoundGenericArgs(parent, isFirstArgList);
1103+
appendBoundGenericArgs(parent->getDesugaredType(), isFirstArgList);
11171104
} else if (auto *nominalType = dyn_cast<NominalType>(typePtr)) {
11181105
if (Type parent = nominalType->getParent())
1119-
appendBoundGenericArgs(parent, isFirstArgList);
1106+
appendBoundGenericArgs(parent->getDesugaredType(), isFirstArgList);
11201107
} else {
11211108
auto boundType = cast<BoundGenericType>(typePtr);
11221109
genericArgs = boundType->getGenericArgs();
11231110
if (Type parent = boundType->getParent())
1124-
appendBoundGenericArgs(parent, isFirstArgList);
1111+
appendBoundGenericArgs(parent->getDesugaredType(), isFirstArgList);
11251112
}
11261113
if (isFirstArgList) {
11271114
appendOperator("y");
@@ -2060,29 +2047,24 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt) {
20602047
void ASTMangler::appendClosureEntity(
20612048
const SerializedAbstractClosureExpr *closure) {
20622049
appendClosureComponents(closure->getType(), closure->getDiscriminator(),
2063-
closure->isImplicit(), closure->getParent(),
2064-
closure->getLocalContext());
2050+
closure->isImplicit(), closure->getParent());
20652051
}
20662052

20672053
void ASTMangler::appendClosureEntity(const AbstractClosureExpr *closure) {
20682054
appendClosureComponents(closure->getType(), closure->getDiscriminator(),
2069-
isa<AutoClosureExpr>(closure), closure->getParent(),
2070-
closure->getLocalContext());
2055+
isa<AutoClosureExpr>(closure), closure->getParent());
20712056
}
20722057

20732058
void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
2074-
bool isImplicit,
2075-
const DeclContext *parentContext,
2076-
const DeclContext *localContext) {
2077-
if (!DeclCtx) DeclCtx = localContext;
2078-
2059+
bool isImplicit,
2060+
const DeclContext *parentContext) {
20792061
assert(discriminator != AbstractClosureExpr::InvalidDiscriminator
20802062
&& "closure must be marked correctly with discriminator");
20812063

20822064
appendContext(parentContext);
20832065

20842066
if (!Ty)
2085-
Ty = ErrorType::get(localContext->getASTContext());
2067+
Ty = ErrorType::get(parentContext->getASTContext());
20862068

20872069
Ty = Ty->mapTypeOutOfContext();
20882070
appendType(Ty->getCanonicalType());
@@ -2226,7 +2208,6 @@ void ASTMangler::appendAccessorEntity(StringRef accessorKindCode,
22262208

22272209
void ASTMangler::appendEntity(const ValueDecl *decl, StringRef EntityOp,
22282210
bool isStatic) {
2229-
if (!DeclCtx) DeclCtx = decl->getInnermostDeclContext();
22302211
appendContextOf(decl);
22312212
appendDeclName(decl);
22322213
appendDeclType(decl);
@@ -2236,7 +2217,6 @@ void ASTMangler::appendEntity(const ValueDecl *decl, StringRef EntityOp,
22362217
}
22372218

22382219
void ASTMangler::appendEntity(const ValueDecl *decl) {
2239-
if (!DeclCtx) DeclCtx = decl->getInnermostDeclContext();
22402220
assert(!isa<ConstructorDecl>(decl));
22412221
assert(!isa<DestructorDecl>(decl));
22422222

lib/AST/Decl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,18 +1781,18 @@ bool AbstractStorageDecl::isFormallyResilient() const {
17811781
if (getAttrs().hasAttribute<FixedLayoutAttr>())
17821782
return false;
17831783

1784-
// Private and (unversioned) internal variables always have a
1785-
// fixed layout.
1786-
if (!getFormalAccessScope(/*useDC=*/nullptr,
1787-
/*treatUsableFromInlineAsPublic=*/true).isPublic())
1788-
return false;
1789-
17901784
// If we're an instance property of a nominal type, query the type.
17911785
auto *dc = getDeclContext();
17921786
if (!isStatic())
17931787
if (auto *nominalDecl = dc->getSelfNominalTypeDecl())
17941788
return nominalDecl->isResilient();
17951789

1790+
// Non-public global and static variables always have a
1791+
// fixed layout.
1792+
if (!getFormalAccessScope(/*useDC=*/nullptr,
1793+
/*treatUsableFromInlineAsPublic=*/true).isPublic())
1794+
return false;
1795+
17961796
return true;
17971797
}
17981798

lib/AST/USRGeneration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static inline StringRef getUSRSpacePrefix() {
3535
bool ide::printTypeUSR(Type Ty, raw_ostream &OS) {
3636
assert(!Ty->hasArchetype() && "cannot have contextless archetypes mangled.");
3737
Mangle::ASTMangler Mangler;
38-
OS << Mangler.mangleTypeForDebugger(Ty->getRValueType(), nullptr, nullptr);
38+
OS << Mangler.mangleTypeForDebugger(Ty->getRValueType(), nullptr);
3939
return false;
4040
}
4141

lib/IRGen/GenDecl.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,9 +2428,11 @@ IRGenModule::getAddrOfLLVMVariableOrGOTEquivalent(LinkEntity entity,
24282428
// Handle SILFunctions specially, because unlike other entities they aren't
24292429
// variables and aren't kept in the GlobalVars table.
24302430
if (entity.isSILFunction()) {
2431-
auto fn = getAddrOfSILFunction(entity.getSILFunction(), NotForDefinition);
2432-
if (entity.getSILFunction()->isDefinition()
2433-
&& !isAvailableExternally(entity.getSILFunction()->getLinkage())) {
2431+
auto *silFn = entity.getSILFunction();
2432+
auto fn = getAddrOfSILFunction(silFn, NotForDefinition);
2433+
if (silFn->isDefinition() &&
2434+
!isAvailableExternally(silFn->getLinkage()) &&
2435+
this == IRGen.getGenModule(silFn)) {
24342436
return {fn, ConstantReference::Direct};
24352437
}
24362438

lib/IRGen/GenKeyPath.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ getAccessorForComputedComponent(IRGenModule &IGM,
120120
// If it's only externally available, we need a local thunk to relative-
121121
// reference.
122122
if (requirements.empty() &&
123-
!LinkEntity::forSILFunction(accessor, false).isAvailableExternally(IGM)) {
124-
123+
!isAvailableExternally(accessor->getLinkage()) &&
124+
&IGM == IGM.IRGen.getGenModule(accessor)) {
125125
return IGM.getAddrOfSILFunction(accessor, NotForDefinition);
126126
}
127127
auto accessorFn = IGM.getAddrOfSILFunction(accessor, NotForDefinition);
@@ -1030,33 +1030,23 @@ emitKeyPathComponent(IRGenModule &IGM,
10301030
fields.add(llvm::ConstantExpr::getTruncOrBitCast(idValue, IGM.Int32Ty));
10311031
break;
10321032
}
1033-
1034-
if (isInstantiableOnce) {
1035-
// No generic arguments or indexes, so we can invoke the
1036-
// getter/setter as is.
1033+
1034+
// Push the accessors, possibly thunked to marshal generic environment.
1035+
fields.addRelativeAddress(
1036+
getAccessorForComputedComponent(IGM, component, Getter,
1037+
genericEnv, requirements,
1038+
hasSubscriptIndices));
1039+
if (settable)
10371040
fields.addRelativeAddress(
1038-
IGM.getAddrOfSILFunction(component.getComputedPropertyGetter(),
1039-
NotForDefinition));
1040-
if (settable)
1041-
fields.addRelativeAddress(
1042-
IGM.getAddrOfSILFunction(component.getComputedPropertySetter(),
1043-
NotForDefinition));
1044-
} else {
1041+
getAccessorForComputedComponent(IGM, component, Setter,
1042+
genericEnv, requirements,
1043+
hasSubscriptIndices));
1044+
1045+
if (!isInstantiableOnce) {
10451046
// If there's generic context or subscript indexes, embed as
10461047
// arguments in the component. Thunk the SIL-level accessors to give the
10471048
// runtime implementation a polymorphically-callable interface.
1048-
1049-
// Push the accessors, possibly thunked to marshal generic environment.
1050-
fields.addRelativeAddress(
1051-
getAccessorForComputedComponent(IGM, component, Getter,
1052-
genericEnv, requirements,
1053-
hasSubscriptIndices));
1054-
if (settable)
1055-
fields.addRelativeAddress(
1056-
getAccessorForComputedComponent(IGM, component, Setter,
1057-
genericEnv, requirements,
1058-
hasSubscriptIndices));
1059-
1049+
10601050
fields.addRelativeAddress(
10611051
getLayoutFunctionForComputedComponent(IGM, component,
10621052
genericEnv, requirements));

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
651651

652652
Mangle::ASTMangler Mangler;
653653
std::string Name = Mangler.mangleTypeForDebugger(
654-
Ty, DbgTy.getDeclContext(), DbgTy.getGenericEnvironment());
654+
Ty, DbgTy.getDeclContext());
655655
return BumpAllocatedString(Name);
656656
}
657657

lib/Sema/CSBindings.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,15 +424,6 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
424424
case ConstraintKind::ArgumentConversion:
425425
case ConstraintKind::OperatorArgumentConversion:
426426
case ConstraintKind::OptionalObject: {
427-
// If there is a `bind param` constraint associated with
428-
// current type variable, result should be aware of that
429-
// fact. Binding set might be incomplete until
430-
// this constraint is resolved, because we currently don't
431-
// look-through constraints expect to `subtype` to try and
432-
// find related bindings.
433-
if (constraint->getKind() == ConstraintKind::BindParam)
434-
result.PotentiallyIncomplete = true;
435-
436427
auto binding = getPotentialBindingForRelationalConstraint(
437428
result, constraint, hasDependentMemberRelationalConstraints,
438429
hasNonDependentMemberRelationalConstraints,

lib/Sema/ConstraintSystem.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,12 +2831,6 @@ class ConstraintSystem {
28312831
/// Whether the bindings of this type involve other type variables.
28322832
bool InvolvesTypeVariables = false;
28332833

2834-
/// Whether the bindings represent (potentially) incomplete set,
2835-
/// there is no way to say with absolute certainty if that's the
2836-
/// case, but that could happen when certain constraints like
2837-
/// `bind param` are present in the system.
2838-
bool PotentiallyIncomplete = false;
2839-
28402834
/// Whether this type variable has literal bindings.
28412835
LiteralBindingKind LiteralBinding = LiteralBindingKind::None;
28422836

@@ -2881,14 +2875,9 @@ class ConstraintSystem {
28812875
if (formBindingScore(y) < formBindingScore(x))
28822876
return false;
28832877

2884-
// If there is a difference in number of default types,
2878+
// If the only difference is default types,
28852879
// prioritize bindings with fewer of them.
2886-
if (x.NumDefaultableBindings != y.NumDefaultableBindings)
2887-
return x.NumDefaultableBindings < y.NumDefaultableBindings;
2888-
2889-
// As a last resort, let's check if the bindings are
2890-
// potentially incomplete, and if so, let's de-prioritize them.
2891-
return x.PotentiallyIncomplete < y.PotentiallyIncomplete;
2880+
return x.NumDefaultableBindings < y.NumDefaultableBindings;
28922881
}
28932882

28942883
void foundLiteralBinding(ProtocolDecl *proto) {
@@ -2921,8 +2910,6 @@ class ConstraintSystem {
29212910
void dump(llvm::raw_ostream &out,
29222911
unsigned indent = 0) const LLVM_ATTRIBUTE_USED {
29232912
out.indent(indent);
2924-
if (PotentiallyIncomplete)
2925-
out << "potentially_incomplete ";
29262913
if (FullyBound)
29272914
out << "fully_bound ";
29282915
if (SubtypeOfExistentialType)

0 commit comments

Comments
 (0)