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> {

test/SILOptimizer/inline_generics.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ sil_vtable MyNumber {}
149149
// CHECK-LABEL: sil @test_inlining : $@convention(objc_method) (@owned MyNumber) -> () {
150150
// CHECK-NOT: Generic specialization information for call-site dootherstuff <MyNumber & SomeProto> conformances <(abstract_conformance protocol="OtherProto")>
151151
// CHECK: Generic specialization information
152-
// CHECK: (normal_conformance type="MyObject" protocol="OtherProto")
152+
// CHECK: (normal_conformance type="MyObject" protocol="OtherProto"
153153
// CHECK: end sil function 'test_inlining'
154154

155155
sil @test_inlining : $@convention(objc_method) (@owned MyNumber) -> () {

test/SILOptimizer/loweraggregateinstrs_moveonly.sil

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
sil_stage canonical
44

55
import Builtin
6+
import Swift
67

78
struct S : ~Copyable {
89
deinit {}

test/SILOptimizer/sil_combine_concrete_existential.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ sil @callee2 : $@convention(thin) <τ_0_0 where τ_0_0 : SubscriptionViewControl
671671
// CHECK: [[T6:%.*]] = alloc_stack $@opened("E4D92D2A-8893-11EA-9C89-ACDE48001122", any ResourceKitProtocol) Self
672672
// CHECK: copy_addr [[T4]] to [init] [[T6]] : $*@opened("E4D92D2A-8893-11EA-9C89-ACDE48001122", any ResourceKitProtocol) Self
673673
// CHECK: Generic specialization information for call-site callee2 <any ResourceKitProtocol> conformances <(inherited_conformance type="any ResourceKitProtocol" protocol="SubscriptionViewControllerDelegate"
674-
// CHECK: (normal_conformance type="MyObject" protocol="SubscriptionViewControllerDelegate"))>:
674+
// CHECK: (normal_conformance type="MyObject" protocol="SubscriptionViewControllerDelegate"
675675
// CHECK: apply [[T5]]<@opened("E4D92D2A-8893-11EA-9C89-ACDE48001122", any ResourceKitProtocol) Self>([[T6]], [[T1]])
676676

677677
sil @test_opend_archetype_concrete_conformance_substitution : $@convention(method) (@guaranteed ResourceKitProtocol, @guaranteed ViewController) -> () {

test/SourceKit/InterfaceGen/gen_swift_type.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct S1 {
3838
// CHECK3: public func fea1()
3939
// CHECK3: public func fea2()
4040

41-
// CHECK4: public struct Array<gen_swift_type.A>
41+
// CHECK4: public struct Array<A>
4242

4343
public protocol P1 { }
4444
public class T1 : P1 { }
@@ -63,12 +63,12 @@ extension D {
6363
public func unconditionalFunc2(t : T) -> T {return t}
6464
}
6565

66-
// CHECK5: public class D<gen_swift_type.T1> {
66+
// CHECK5: public class D<T1> {
6767
// CHECK5: public func foo()
6868
// CHECK5: public func conditionalFunc1()
69-
// CHECK5: public func conditionalFunc2(t: gen_swift_type.T1) -> gen_swift_type.T1
69+
// CHECK5: public func conditionalFunc2(t: T1) -> T1
7070
// CHECK5: public func unconditionalFunc1()
71-
// CHECK5: public func unconditionalFunc2(t: gen_swift_type.T1) -> gen_swift_type.T1
71+
// CHECK5: public func unconditionalFunc2(t: T1) -> T1
7272

7373
// CHECK6: public class D<Int> {
7474
// CHECK6: public func foo()

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,9 +1372,17 @@ printCodeCompletionLookedupTypeNames(ArrayRef<NullTerminatedStringRef> names,
13721372
if (names.empty())
13731373
return;
13741374

1375+
SmallVector<NullTerminatedStringRef, 2> sortedNames;
1376+
sortedNames.append(names.begin(), names.end());
1377+
llvm::sort(sortedNames,
1378+
[](NullTerminatedStringRef a, NullTerminatedStringRef b) {
1379+
return a.compare(b) <= 0;
1380+
});
1381+
13751382
OS << "LookedupTypeNames: [";
13761383
llvm::interleave(
1377-
names.begin(), names.end(), [&](auto name) { OS << "'" << name << "'"; },
1384+
sortedNames.begin(), sortedNames.end(),
1385+
[&](auto name) { OS << "'" << name << "'"; },
13781386
[&]() { OS << ", "; });
13791387
OS << "]\n";
13801388
}

0 commit comments

Comments
 (0)