Skip to content

Commit 4fc2fe9

Browse files
authored
Merge pull request #71540 from kavon/ncgenerics-test-fixes-kavon-v8
Ncgenerics test fixes kavon v8
2 parents 009a93a + 648ac8a commit 4fc2fe9

15 files changed

+57
-33
lines changed

include/swift/AST/Types.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6405,11 +6405,6 @@ class ArchetypeType : public SubstitutableType,
64056405
return *getSubclassTrailingObjects<LayoutConstraint>();
64066406
}
64076407

6408-
/// Return true if the archetype has any requirements at all.
6409-
bool hasRequirements() const {
6410-
return !getConformsTo().empty() || getSuperclass();
6411-
}
6412-
64136408
/// Retrieve the nested type with the given associated type.
64146409
Type getNestedType(AssociatedTypeDecl *assocType);
64156410

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
10931093
Type OldType = CurrentType;
10941094
if (CurrentType && (Old != nullptr || Options.PrintAsMember)) {
10951095
if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
1096+
assert(Options.CurrentModule);
10961097
auto Subs = CurrentType->getContextSubstitutionMap(
10971098
Options.CurrentModule, NTD->getDeclContext());
10981099
setCurrentType(NTD->getDeclaredInterfaceType().subst(Subs));

lib/AST/ConformanceLookup.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,21 @@ static bool isSendableFunctionType(EitherFunctionType eitherFnTy) {
280280

281281
/// Whether the given function type conforms to Escapable.
282282
static bool isEscapableFunctionType(EitherFunctionType eitherFnTy) {
283-
if (auto silFnTy = eitherFnTy.dyn_cast<const SILFunctionType *>()) {
284-
return !silFnTy->isNoEscape();
285-
}
286-
287-
auto functionType = eitherFnTy.get<const FunctionType *>();
283+
// if (auto silFnTy = eitherFnTy.dyn_cast<const SILFunctionType *>()) {
284+
// return !silFnTy->isNoEscape();
285+
// }
286+
//
287+
// auto functionType = eitherFnTy.get<const FunctionType *>();
288+
//
289+
// // TODO: what about autoclosures?
290+
// return !functionType->isNoEscape();
288291

289-
// TODO: what about autoclosures?
290-
return !functionType->isNoEscape();
292+
// FIXME: unify TypeBase::isNoEscape with TypeBase::isEscapable
293+
// LazyConformanceEmitter::visitDestroyValueInst chokes on these instructions
294+
// destroy_value %2 : $@convention(block) @noescape () -> ()
295+
//
296+
// Wrongly claim that all functions today conform to Escapable for now:
297+
return true;
291298
}
292299

293300
static bool isBitwiseCopyableFunctionType(EitherFunctionType eitherFnTy) {

lib/AST/TypeSubstitution.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ operator()(CanType dependentType, Type conformingReplacementType,
211211
if (conformingReplacementType->isTypeParameter())
212212
return ProtocolConformanceRef(conformedProtocol);
213213

214+
assert(M && "null module in conformance lookup");
214215
return M->lookupConformance(conformingReplacementType,
215216
conformedProtocol,
216217
/*allowMissing=*/true);

lib/IDE/CodeCompletionResultType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static TypeRelation calculateTypeRelation(Type Ty, Type ExpectedTy,
396396
bool isAny = false;
397397
isAny |= ExpectedTy->isAny();
398398
isAny |= ExpectedTy->is<ArchetypeType>() &&
399-
!ExpectedTy->castTo<ArchetypeType>()->hasRequirements();
399+
ExpectedTy->castTo<ArchetypeType>()->getExistentialType()->isAny();
400400

401401
if (!isAny && isConvertibleTo(Ty, ExpectedTy, /*openArchetypes=*/true,
402402
const_cast<DeclContext &>(DC)))

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ printTypeInterface(ModuleDecl *M, Type Ty, ASTPrinter &Printer,
177177
PrintOptions Options = PrintOptions::printTypeInterface(
178178
Ty.getPointer(),
179179
Ty->getASTContext().TypeCheckerOpts.PrintFullConvention);
180+
Options.CurrentModule = M;
180181
ND->print(Printer, Options);
181182
printTypeNameToString(Ty, TypeName);
182183
return false;

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ static bool isOpenedAnyObject(Type type) {
7878
return false;
7979

8080
return (archetype->requiresClass() &&
81-
!archetype->hasRequirements());
81+
archetype->getConformsTo().empty() &&
82+
!archetype->getSuperclass());
8283
}
8384

8485
SubstitutionMap

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ static void lookupTypeMembers(Type BaseType, NominalTypeDecl *LookupType,
271271
assert(!BaseType->hasTypeParameter());
272272
assert(LookupType && "should have a nominal type");
273273

274+
// Skip lookup on invertible protocols. They have no members.
275+
if (auto *proto = dyn_cast<ProtocolDecl>(LookupType))
276+
if (proto->getInvertibleProtocolKind())
277+
return;
278+
274279
Consumer.onLookupNominalTypeMembers(LookupType, Reason);
275280

276281
SmallVector<ValueDecl*, 2> FoundDecls;
@@ -444,6 +449,10 @@ static void lookupDeclsFromProtocolsBeingConformedTo(
444449

445450
for (auto Conformance : CurrNominal->getAllConformances()) {
446451
auto Proto = Conformance->getProtocol();
452+
// Skip conformances to invertible protocols. They have no members.
453+
if (Proto->getInvertibleProtocolKind())
454+
continue;
455+
447456
if (!Proto->isAccessibleFrom(FromContext))
448457
continue;
449458

test/IDE/complete_member_basetypes.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ protocol DerivedPComp: BaseP1, BaseP2 {}
1616

1717
func testInheritedArchetype(arg: some DerivedP1) {
1818
arg.#^TestDerivedP1^#
19-
// TestDerivedP1: LookedupTypeNames: ['Mod.DerivedP1', 'Mod.BaseP1']
19+
// TestDerivedP1: LookedupTypeNames: ['Mod.BaseP1', 'Mod.DerivedP1']
2020
}
2121

2222
func testMultiInheritedArchetype(arg: some DerivedPComp) {
2323
arg.#^TestDerivedPComp^#
24-
// TestDerivedPComp: LookedupTypeNames: ['Mod.DerivedPComp', 'Mod.BaseP1', 'Mod.BaseP2']
24+
// TestDerivedPComp: LookedupTypeNames: ['Mod.BaseP1', 'Mod.BaseP2', 'Mod.DerivedPComp']
2525
}
2626

2727
func testCompositionArchetype(arg: some BaseP1 & BaseP2) {
@@ -36,12 +36,12 @@ protocol DiamondTop: DiamondEdge1, DiamondEdge2 {}
3636

3737
func testDiamondProtocol(arg: some DiamondTop) {
3838
arg.#^TestDiamondTop^#
39-
// TestDiamondTop: LookedupTypeNames: ['Mod.DiamondTop', 'Mod.DiamondEdge1', 'Mod.DiamondRoot', 'Mod.DiamondEdge2']
39+
// TestDiamondTop: LookedupTypeNames: ['Mod.DiamondEdge1', 'Mod.DiamondEdge2', 'Mod.DiamondRoot', 'Mod.DiamondTop']
4040
}
4141

4242
func testExistential(arg: any DiamondTop) {
4343
arg.#^TestAnyDiamondTop^#
44-
// TestAnyDiamondTop: LookedupTypeNames: ['Mod.DiamondTop', 'Mod.DiamondEdge1', 'Mod.DiamondRoot', 'Mod.DiamondEdge2']
44+
// TestAnyDiamondTop: LookedupTypeNames: ['Mod.DiamondEdge1', 'Mod.DiamondEdge2', 'Mod.DiamondRoot', 'Mod.DiamondTop']
4545
}
4646

4747
class BaseClass {}
@@ -54,19 +54,19 @@ func testBasicClass(arg: BaseClass) {
5454

5555
func testSubClass(arg: DerivedClass) {
5656
arg.#^TestDerivedClass^#
57-
// TestDerivedClass: LookedupTypeNames: ['Mod.DerivedClass', 'Mod.BaseClass']
57+
// TestDerivedClass: LookedupTypeNames: ['Mod.BaseClass', 'Mod.DerivedClass']
5858
}
5959

6060
protocol BaseClassConstrainedP: BaseClass {}
6161
protocol DerivedClassConstrainedP: DerivedClass {}
6262

6363
func testClassConstrainedProto(arg: some BaseClassConstrainedP) {
6464
arg.#^TestBaseClassConstrainedP^#
65-
// TestBaseClassConstrainedP: LookedupTypeNames: ['Mod.BaseClassConstrainedP', 'Mod.BaseClass']
65+
// TestBaseClassConstrainedP: LookedupTypeNames: ['Mod.BaseClass', 'Mod.BaseClassConstrainedP']
6666
}
6767
func testClassConstriainedProto2(arg: some DerivedClassConstrainedP) {
6868
arg.#^TestDerivedClassConstrainedP^#
69-
// TestDerivedClassConstrainedP: LookedupTypeNames: ['Mod.DerivedClassConstrainedP', 'Mod.DerivedClass', 'Mod.BaseClass']
69+
// TestDerivedClassConstrainedP: LookedupTypeNames: ['Mod.BaseClass', 'Mod.DerivedClass', 'Mod.DerivedClassConstrainedP']
7070
}
7171

7272
class BaseClassWithProto: BaseP1 {}
@@ -79,7 +79,7 @@ func testBaseClassWithProto(arg: BaseClassWithProto) {
7979

8080
func testDerivedClassWithProto(arg: DerivedClassWithProto) {
8181
arg.#^TestDerivedClassWithProto^#
82-
// TestDerivedClassWithProto: LookedupTypeNames: ['Mod.DerivedClassWithProto', 'Mod.BaseP2', 'Mod.BaseP1', 'Mod.BaseClassWithProto']
82+
// TestDerivedClassWithProto: LookedupTypeNames: ['Mod.BaseClassWithProto', 'Mod.BaseP1', 'Mod.BaseP2', 'Mod.DerivedClassWithProto']
8383
}
8484

8585
struct GenericS<T> {}
@@ -92,6 +92,6 @@ func testConditionalConformanceNo(arg: GenericS<String>) {
9292

9393
func testConditionalConformanceYes(arg: GenericS<Int>) {
9494
arg.#^TestConditionalConformanceYes^#
95-
// TestConditionalConformanceYes: LookedupTypeNames: ['Mod.GenericS', 'Mod.BaseP1', 'Swift.Sendable']
95+
// TestConditionalConformanceYes: LookedupTypeNames: ['Mod.BaseP1', 'Mod.GenericS', 'Swift.Sendable']
9696

9797
}

test/IDE/print_type_interface.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ extension D {
5454
public func unconditionalFunc2(t : T) -> T {return t}
5555
}
5656

57-
// TYPE2: public class D<print_type_interface.T1> {
57+
// TYPE2: public class D<T1> {
5858
// TYPE2: public func foo()
5959
// TYPE2: public func conditionalFunc1()
60-
// TYPE2: public func conditionalFunc2(t: print_type_interface.T1) -> print_type_interface.T1
60+
// TYPE2: public func conditionalFunc2(t: T1) -> T1
6161
// TYPE2: public func unconditionalFunc1()
62-
// TYPE2: public func unconditionalFunc2(t: print_type_interface.T1) -> print_type_interface.T1
62+
// TYPE2: public func unconditionalFunc2(t: T1) -> T1
6363
// TYPE2: }
6464

6565
// TYPE3: public class D<Int> {

0 commit comments

Comments
 (0)