Skip to content

Commit 13f082e

Browse files
committed
---
yaml --- r: 319293 b: refs/heads/master-rebranch c: 696e9a9 h: refs/heads/master i: 319291: e3a8f99
1 parent eb46ac7 commit 13f082e

19 files changed

+388
-122
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,4 +1457,4 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14571457
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14581458
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14591459
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1460-
refs/heads/master-rebranch: 5c1ad46472ccd2be646a36e434e27a5c83a75b6e
1460+
refs/heads/master-rebranch: 696e9a957030d3108352dafe5cf58527e999e1ac

branches/master-rebranch/include/swift/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5323,6 +5323,8 @@ class ParamDecl : public VarDecl {
53235323

53245324
SourceRange getSourceRange() const;
53255325

5326+
AnyFunctionType::Param toFunctionParam(Type type = Type()) const;
5327+
53265328
// Implement isa/cast/dyncast/etc.
53275329
static bool classof(const Decl *D) {
53285330
return D->getKind() == DeclKind::Param;

branches/master-rebranch/include/swift/AST/ParameterList.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ class alignas(ParamDecl *) ParameterList final :
127127
/// based on the interface types of the parameters in this list.
128128
void getParams(SmallVectorImpl<AnyFunctionType::Param> &params) const;
129129

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;
134-
135-
136130
/// Return the full source range of this parameter.
137131
SourceRange getSourceRange() const;
138132
SourceLoc getStartLoc() const { return getSourceRange().Start; }

branches/master-rebranch/include/swift/AST/ProtocolConformanceRef.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ class ProtocolConformanceRef {
138138
static Type
139139
getTypeWitnessByName(Type type,
140140
ProtocolConformanceRef conformance,
141-
Identifier name,
142-
LazyResolver *resolver);
141+
Identifier name);
143142

144143
/// Determine whether this conformance is canonical.
145144
bool isCanonical() const;
@@ -154,11 +153,6 @@ class ProtocolConformanceRef {
154153
/// Get any additional requirements that are required for this conformance to
155154
/// be satisfied.
156155
ArrayRef<Requirement> getConditionalRequirements() const;
157-
158-
/// If this is a conformance reference for a protocol that inherits other
159-
/// protocols, get a reference to the related conformance for the inherited
160-
/// protocol.
161-
ProtocolConformanceRef getInheritedConformanceRef(ProtocolDecl *base) const;
162156
};
163157

164158
} // end namespace swift

branches/master-rebranch/lib/AST/ASTContext.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4225,13 +4225,8 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
42254225
*bridgedValueType = type;
42264226

42274227
// Find the Objective-C class type we bridge to.
4228-
if (conformance->isConcrete()) {
4229-
return ProtocolConformanceRef::getTypeWitnessByName(
4230-
type, *conformance, Id_ObjectiveCType,
4231-
getLazyResolver());
4232-
} else {
4233-
return type->castTo<ArchetypeType>()->getNestedType(Id_ObjectiveCType);
4234-
}
4228+
return ProtocolConformanceRef::getTypeWitnessByName(
4229+
type, *conformance, Id_ObjectiveCType);
42354230
}
42364231

42374232
// Do we conform to Error?

branches/master-rebranch/lib/AST/Decl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5673,6 +5673,21 @@ Type ParamDecl::getVarargBaseTy(Type VarArgT) {
56735673
return T;
56745674
}
56755675

5676+
AnyFunctionType::Param ParamDecl::toFunctionParam(Type type) const {
5677+
if (!type)
5678+
type = getInterfaceType();
5679+
5680+
if (isVariadic())
5681+
type = ParamDecl::getVarargBaseTy(type);
5682+
5683+
auto label = getArgumentName();
5684+
auto flags = ParameterTypeFlags::fromParameterType(type,
5685+
isVariadic(),
5686+
isAutoClosure(),
5687+
getValueOwnership());
5688+
return AnyFunctionType::Param(type, label, flags);
5689+
}
5690+
56765691
void ParamDecl::setDefaultValue(Expr *E) {
56775692
if (!DefaultValueAndFlags.getPointer()) {
56785693
if (!E) return;

branches/master-rebranch/lib/AST/GenericSignatureBuilder.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,13 +2057,6 @@ TypeDecl *EquivalenceClass::lookupNestedType(
20572057
!= proto->getParentModule())
20582058
continue;
20592059

2060-
// Resolve the signature of this type.
2061-
if (!type->hasInterfaceType()) {
2062-
type->getASTContext().getLazyResolver()->resolveDeclSignature(type);
2063-
if (!type->hasInterfaceType())
2064-
continue;
2065-
}
2066-
20672060
concreteDecls.push_back(type);
20682061
continue;
20692062
}

branches/master-rebranch/lib/AST/Parameter.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,8 @@ ParameterList *ParameterList::clone(const ASTContext &C,
8989

9090
void ParameterList::getParams(
9191
SmallVectorImpl<AnyFunctionType::Param> &params) const {
92-
getParams(params,
93-
[](ParamDecl *decl) { return decl->getInterfaceType(); });
94-
}
95-
96-
void ParameterList::getParams(
97-
SmallVectorImpl<AnyFunctionType::Param> &params,
98-
llvm::function_ref<Type(ParamDecl *)> getType) const {
99-
if (size() == 0)
100-
return;
101-
102-
for (auto P : *this) {
103-
auto type = getType(P);
104-
105-
if (P->isVariadic())
106-
type = ParamDecl::getVarargBaseTy(type);
107-
108-
auto label = P->getArgumentName();
109-
auto flags = ParameterTypeFlags::fromParameterType(type,
110-
P->isVariadic(),
111-
P->isAutoClosure(),
112-
P->getValueOwnership());
113-
params.emplace_back(type, label, flags);
114-
}
92+
for (auto P : *this)
93+
params.push_back(P->toFunctionParam());
11594
}
11695

11796

branches/master-rebranch/lib/AST/ProtocolConformance.cpp

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ ProtocolConformanceRef::subst(Type origType,
144144
Type
145145
ProtocolConformanceRef::getTypeWitnessByName(Type type,
146146
ProtocolConformanceRef conformance,
147-
Identifier name,
148-
LazyResolver *resolver) {
147+
Identifier name) {
149148
assert(!conformance.isInvalid());
150149

151150
// Find the named requirement.
151+
ProtocolDecl *proto = conformance.getRequirement();
152152
AssociatedTypeDecl *assocType = nullptr;
153-
auto members = conformance.getRequirement()->lookupDirect(name);
153+
auto members = proto->lookupDirect(name);
154154
for (auto member : members) {
155155
assocType = dyn_cast<AssociatedTypeDecl>(member);
156156
if (assocType)
@@ -161,21 +161,8 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type,
161161
if (!assocType)
162162
return nullptr;
163163

164-
if (conformance.isAbstract()) {
165-
// For an archetype, retrieve the nested type with the appropriate
166-
// name. There are no conformance tables.
167-
if (auto archetype = type->getAs<ArchetypeType>()) {
168-
return archetype->getNestedType(name);
169-
}
170-
171-
return DependentMemberType::get(type, assocType);
172-
}
173-
174-
auto concrete = conformance.getConcrete();
175-
if (!concrete->hasTypeWitness(assocType, resolver)) {
176-
return nullptr;
177-
}
178-
return concrete->getTypeWitness(assocType, resolver);
164+
return assocType->getDeclaredInterfaceType().subst(
165+
SubstitutionMap::getProtocolSubstitutions(proto, type, conformance));
179166
}
180167

181168
void *ProtocolConformance::operator new(size_t bytes, ASTContext &context,
@@ -500,37 +487,6 @@ ProtocolConformanceRef::getConditionalRequirements() const {
500487
return {};
501488
}
502489

503-
ProtocolConformanceRef
504-
ProtocolConformanceRef::getInheritedConformanceRef(ProtocolDecl *base) const {
505-
if (isAbstract()) {
506-
assert(getRequirement()->inheritsFrom(base));
507-
return ProtocolConformanceRef(base);
508-
}
509-
510-
auto concrete = getConcrete();
511-
auto proto = concrete->getProtocol();
512-
auto path =
513-
proto->getGenericSignature()->getConformanceAccessPath(
514-
proto->getSelfInterfaceType(), base);
515-
ProtocolConformanceRef result = *this;
516-
Type resultType = concrete->getType();
517-
bool first = true;
518-
for (const auto &step : path) {
519-
if (first) {
520-
assert(step.first->isEqual(proto->getSelfInterfaceType()));
521-
assert(step.second == proto);
522-
first = false;
523-
continue;
524-
}
525-
526-
result =
527-
result.getAssociatedConformance(resultType, step.first, step.second);
528-
resultType = result.getAssociatedType(resultType, step.first);
529-
}
530-
531-
return result;
532-
}
533-
534490
void NormalProtocolConformance::differenceAndStoreConditionalRequirements()
535491
const {
536492
switch (CRState) {

branches/master-rebranch/lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
13801380
Type objcType = ProtocolConformanceRef::getTypeWitnessByName(
13811381
nominal->getDeclaredType(),
13821382
ProtocolConformanceRef(conformance),
1383-
ctx.Id_ObjectiveCType,
1384-
nullptr);
1383+
ctx.Id_ObjectiveCType);
13851384
if (!objcType) return nullptr;
13861385

13871386
// Dig out the Objective-C class.

branches/master-rebranch/lib/SIL/Bridging.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ Type TypeConverter::getLoweredCBridgedType(AbstractionPattern pattern,
225225
Type bridgedTy =
226226
ProtocolConformanceRef::getTypeWitnessByName(
227227
t, ProtocolConformanceRef(conformance),
228-
M.getASTContext().Id_ObjectiveCType,
229-
M.getASTContext().getLazyResolver());
228+
M.getASTContext().Id_ObjectiveCType);
230229
assert(bridgedTy && "Missing _ObjectiveCType witness?");
231230
if (purpose == BridgedTypePurpose::ForResult && clangTy)
232231
bridgedTy = OptionalType::get(bridgedTy);

branches/master-rebranch/lib/Sema/CSDiag.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ static Type isRawRepresentable(Type fromType, const ConstraintSystem &CS) {
17411741
return Type();
17421742

17431743
Type rawTy = ProtocolConformanceRef::getTypeWitnessByName(
1744-
fromType, *conformance, CS.getASTContext().Id_RawValue, &CS.TC);
1744+
fromType, *conformance, CS.getASTContext().Id_RawValue);
17451745
return rawTy;
17461746
}
17471747

@@ -2120,8 +2120,8 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
21202120
Type errorCodeType = CS.getType(expr);
21212121
Type errorType =
21222122
ProtocolConformanceRef::getTypeWitnessByName(errorCodeType, *conformance,
2123-
TC.Context.Id_ErrorType,
2124-
&TC)->getCanonicalType();
2123+
TC.Context.Id_ErrorType)
2124+
->getCanonicalType();
21252125
if (errorType) {
21262126
auto diag = diagnose(expr->getLoc(), diag::cannot_throw_error_code,
21272127
errorCodeType, errorType);
@@ -6255,7 +6255,7 @@ bool FailureDiagnosis::visitArrayExpr(ArrayExpr *E) {
62556255
Type contextualElementType =
62566256
ProtocolConformanceRef::getTypeWitnessByName(
62576257
contextualType, *Conformance,
6258-
CS.getASTContext().Id_ArrayLiteralElement, &CS.TC)
6258+
CS.getASTContext().Id_ArrayLiteralElement)
62596259
->getDesugaredType();
62606260

62616261
// Type check each of the subexpressions in place, passing down the contextual
@@ -6344,12 +6344,12 @@ bool FailureDiagnosis::visitDictionaryExpr(DictionaryExpr *E) {
63446344

63456345
contextualKeyType =
63466346
ProtocolConformanceRef::getTypeWitnessByName(
6347-
contextualType, *Conformance, CS.getASTContext().Id_Key, &CS.TC)
6347+
contextualType, *Conformance, CS.getASTContext().Id_Key)
63486348
->getDesugaredType();
63496349

63506350
contextualValueType =
63516351
ProtocolConformanceRef::getTypeWitnessByName(
6352-
contextualType, *Conformance, CS.getASTContext().Id_Value, &CS.TC)
6352+
contextualType, *Conformance, CS.getASTContext().Id_Value)
63536353
->getDesugaredType();
63546354

63556355
assert(contextualKeyType && contextualValueType &&

branches/master-rebranch/lib/Sema/CSGen.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,8 @@ namespace {
20362036
SmallVectorImpl<AnyFunctionType::Param> &params) {
20372037
auto *paramList = closureExpr->getParameters();
20382038
unsigned i = 0;
2039-
paramList->getParams(params, [&](ParamDecl *param) {
2039+
2040+
for (auto *param : *paramList) {
20402041
auto *locator = CS.getConstraintLocator(
20412042
closureExpr, LocatorPathElt::getTupleElement(i++));
20422043
Type paramType, internalType;
@@ -2058,8 +2059,8 @@ namespace {
20582059
locator);
20592060
}
20602061
CS.setType(param, internalType);
2061-
return paramType;
2062-
});
2062+
params.push_back(param->toFunctionParam(paramType));
2063+
}
20632064
}
20642065

20652066
/// Produces a type for the given pattern, filling in any missing

branches/master-rebranch/lib/Sema/TypeCheckProtocol.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4326,7 +4326,7 @@ void TypeChecker::useBridgedNSErrorConformances(DeclContext *dc, Type type) {
43264326
// protocol, also use the RawRepresentable and _ErrorCodeProtocol
43274327
// conformances on the Code associated type witness.
43284328
if (auto codeType = ProtocolConformanceRef::getTypeWitnessByName(
4329-
type, *conformance, Context.Id_Code, this)) {
4329+
type, *conformance, Context.Id_Code)) {
43304330
(void)conformsToProtocol(codeType, errorCodeProto, dc,
43314331
ConformanceCheckFlags::Used);
43324332
(void)conformsToProtocol(codeType, rawProto, dc,
@@ -4341,7 +4341,7 @@ void TypeChecker::useBridgedNSErrorConformances(DeclContext *dc, Type type) {
43414341
ConformanceCheckFlags::Used));
43424342
if (conformance && conformance->isConcrete()) {
43434343
if (Type errorType = ProtocolConformanceRef::getTypeWitnessByName(
4344-
type, *conformance, Context.Id_ErrorType, this)) {
4344+
type, *conformance, Context.Id_ErrorType)) {
43454345
(void)conformsToProtocol(errorType, bridgedStoredNSError, dc,
43464346
ConformanceCheckFlags::Used);
43474347
}
@@ -5663,8 +5663,7 @@ Type TypeChecker::getWitnessType(Type type, ProtocolDecl *protocol,
56635663
ProtocolConformanceRef conformance,
56645664
Identifier name,
56655665
Diag<> brokenProtocolDiag) {
5666-
Type ty = ProtocolConformanceRef::getTypeWitnessByName(type, conformance,
5667-
name, this);
5666+
Type ty = ProtocolConformanceRef::getTypeWitnessByName(type, conformance, name);
56685667
if (!ty &&
56695668
!(conformance.isConcrete() && conformance.getConcrete()->isInvalid()))
56705669
diagnose(protocol->getLoc(), brokenProtocolDiag);

branches/master-rebranch/lib/Sema/TypeCheckType.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,13 @@ Type TypeResolution::resolveDependentMemberType(
228228
auto lazyResolver = ctx.getLazyResolver();
229229
if (lazyResolver)
230230
lazyResolver->resolveDeclSignature(concrete);
231-
if (!concrete->hasInterfaceType())
231+
if (!concrete->hasInterfaceType()) {
232+
ctx.Diags.diagnose(ref->getIdLoc(), diag::recursive_decl_reference,
233+
concrete->getDescriptiveKind(), concrete->getName());
234+
concrete->diagnose(diag::kind_declared_here,
235+
DescriptiveDeclKind::Type);
232236
return ErrorType::get(ctx);
237+
}
233238

234239
// Make sure that base type didn't get replaced along the way.
235240
assert(baseTy->isTypeParameter());

branches/master-rebranch/test/IDE/complete_from_swiftonly_systemmodule.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// RUN: %t/SomeModule.swift
1111

1212
// RUN: %target-swift-ide-test -code-completion -sdk %t/SDK -iframework %t/SDK/Frameworks -source-filename %t/main.swift -code-completion-token=GLOBAL | %FileCheck --check-prefix GLOBAL %s
13+
// RUN: %target-swift-ide-test -code-completion -sdk %t/SDK -iframework %t/SDK/Frameworks -source-filename %t/main.swift -code-completion-token=GLOBAL_TYPE | %FileCheck --check-prefix GLOBAL_TYPE %s
1314
// RUN: %target-swift-ide-test -code-completion -sdk %t/SDK -iframework %t/SDK/Frameworks -source-filename %t/main.swift -code-completion-token=INSTANCE | %FileCheck --check-prefix INSTANCE %s
1415
// RUN: %target-swift-ide-test -code-completion -sdk %t/SDK -iframework %t/SDK/Frameworks -source-filename %t/main.swift -code-completion-token=INITIALIZER | %FileCheck --check-prefix INITIALIZER %s
1516

@@ -36,6 +37,10 @@ internal func internalFunc() {}
3637
public func _secretFunc() {}
3738
public func publicFunc() {}
3839

40+
internal class InternalClass {}
41+
public class _SecretClass {}
42+
public class PublicClass {}
43+
3944
// BEGIN main.swift
4045
import SomeModule
4146

@@ -44,10 +49,21 @@ func test(value: SomeValue) {
4449
// GLOBAL: Begin completions
4550
// GLOBAL-NOT: _secretFunc
4651
// GLOBAL-NOT: internalFunc
52+
// GLOBAL-NOT: _SecretClass
53+
// GLOBAL-NOT: InternalClass
4754
// GLOBAL-DAG: Decl[Struct]/OtherModule[SomeModule]: SomeValue[#SomeValue#];
4855
// GLOBAL-DAG: Decl[FreeFunction]/OtherModule[SomeModule]: publicFunc()[#Void#];
56+
// GLOBAL-DAG: Decl[Class]/OtherModule[SomeModule]: PublicClass[#PublicClass#]; name=PublicClass
4957
// GLOBAL: End completions
5058

59+
let _: #^GLOBAL_TYPE^#
60+
// GLOBAL_TYPE: Begin completions
61+
// GLOBAL_TYPE-NOT: InternalClass
62+
// GLOBAL_TYPE-NOT: _SecretClass
63+
// GLOBAL-TYPE-DAG: Decl[Struct]/OtherModule[SomeModule]: SomeValue[#SomeValue#];
64+
// GLOBAL-TYPE-DAG: Decl[Class]/OtherModule[SomeModule]: PublicClass[#PublicClass#];
65+
// GLOBAL_TYPE: End completions
66+
5167
let _ = value.#^INSTANCE^#
5268
// INSTANCE: Begin completions, 3 items
5369
// INSTANCE-DAG: Keyword[self]/CurrNominal: self[#SomeValue#];

0 commit comments

Comments
 (0)