Skip to content

Ncgenerics test fixes kavon v8 #71540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6405,11 +6405,6 @@ class ArchetypeType : public SubstitutableType,
return *getSubclassTrailingObjects<LayoutConstraint>();
}

/// Return true if the archetype has any requirements at all.
bool hasRequirements() const {
return !getConformsTo().empty() || getSuperclass();
}

/// Retrieve the nested type with the given associated type.
Type getNestedType(AssociatedTypeDecl *assocType);

Expand Down
1 change: 1 addition & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
Type OldType = CurrentType;
if (CurrentType && (Old != nullptr || Options.PrintAsMember)) {
if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
assert(Options.CurrentModule);
auto Subs = CurrentType->getContextSubstitutionMap(
Options.CurrentModule, NTD->getDeclContext());
setCurrentType(NTD->getDeclaredInterfaceType().subst(Subs));
Expand Down
21 changes: 14 additions & 7 deletions lib/AST/ConformanceLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,21 @@ static bool isSendableFunctionType(EitherFunctionType eitherFnTy) {

/// Whether the given function type conforms to Escapable.
static bool isEscapableFunctionType(EitherFunctionType eitherFnTy) {
if (auto silFnTy = eitherFnTy.dyn_cast<const SILFunctionType *>()) {
return !silFnTy->isNoEscape();
}

auto functionType = eitherFnTy.get<const FunctionType *>();
// if (auto silFnTy = eitherFnTy.dyn_cast<const SILFunctionType *>()) {
// return !silFnTy->isNoEscape();
// }
//
// auto functionType = eitherFnTy.get<const FunctionType *>();
//
// // TODO: what about autoclosures?
// return !functionType->isNoEscape();

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

static bool isBitwiseCopyableFunctionType(EitherFunctionType eitherFnTy) {
Expand Down
1 change: 1 addition & 0 deletions lib/AST/TypeSubstitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ operator()(CanType dependentType, Type conformingReplacementType,
if (conformingReplacementType->isTypeParameter())
return ProtocolConformanceRef(conformedProtocol);

assert(M && "null module in conformance lookup");
return M->lookupConformance(conformingReplacementType,
conformedProtocol,
/*allowMissing=*/true);
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/CodeCompletionResultType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ static TypeRelation calculateTypeRelation(Type Ty, Type ExpectedTy,
bool isAny = false;
isAny |= ExpectedTy->isAny();
isAny |= ExpectedTy->is<ArchetypeType>() &&
!ExpectedTy->castTo<ArchetypeType>()->hasRequirements();
ExpectedTy->castTo<ArchetypeType>()->getExistentialType()->isAny();

if (!isAny && isConvertibleTo(Ty, ExpectedTy, /*openArchetypes=*/true,
const_cast<DeclContext &>(DC)))
Expand Down
1 change: 1 addition & 0 deletions lib/IDE/ModuleInterfacePrinting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ printTypeInterface(ModuleDecl *M, Type Ty, ASTPrinter &Printer,
PrintOptions Options = PrintOptions::printTypeInterface(
Ty.getPointer(),
Ty->getASTContext().TypeCheckerOpts.PrintFullConvention);
Options.CurrentModule = M;
ND->print(Printer, Options);
printTypeNameToString(Ty, TypeName);
return false;
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ static bool isOpenedAnyObject(Type type) {
return false;

return (archetype->requiresClass() &&
!archetype->hasRequirements());
archetype->getConformsTo().empty() &&
!archetype->getSuperclass());
}

SubstitutionMap
Expand Down
9 changes: 9 additions & 0 deletions lib/Sema/LookupVisibleDecls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ static void lookupTypeMembers(Type BaseType, NominalTypeDecl *LookupType,
assert(!BaseType->hasTypeParameter());
assert(LookupType && "should have a nominal type");

// Skip lookup on invertible protocols. They have no members.
if (auto *proto = dyn_cast<ProtocolDecl>(LookupType))
if (proto->getInvertibleProtocolKind())
return;

Consumer.onLookupNominalTypeMembers(LookupType, Reason);

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

for (auto Conformance : CurrNominal->getAllConformances()) {
auto Proto = Conformance->getProtocol();
// Skip conformances to invertible protocols. They have no members.
if (Proto->getInvertibleProtocolKind())
continue;

if (!Proto->isAccessibleFrom(FromContext))
continue;

Expand Down
18 changes: 9 additions & 9 deletions test/IDE/complete_member_basetypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ protocol DerivedPComp: BaseP1, BaseP2 {}

func testInheritedArchetype(arg: some DerivedP1) {
arg.#^TestDerivedP1^#
// TestDerivedP1: LookedupTypeNames: ['Mod.DerivedP1', 'Mod.BaseP1']
// TestDerivedP1: LookedupTypeNames: ['Mod.BaseP1', 'Mod.DerivedP1']
}

func testMultiInheritedArchetype(arg: some DerivedPComp) {
arg.#^TestDerivedPComp^#
// TestDerivedPComp: LookedupTypeNames: ['Mod.DerivedPComp', 'Mod.BaseP1', 'Mod.BaseP2']
// TestDerivedPComp: LookedupTypeNames: ['Mod.BaseP1', 'Mod.BaseP2', 'Mod.DerivedPComp']
}

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

func testDiamondProtocol(arg: some DiamondTop) {
arg.#^TestDiamondTop^#
// TestDiamondTop: LookedupTypeNames: ['Mod.DiamondTop', 'Mod.DiamondEdge1', 'Mod.DiamondRoot', 'Mod.DiamondEdge2']
// TestDiamondTop: LookedupTypeNames: ['Mod.DiamondEdge1', 'Mod.DiamondEdge2', 'Mod.DiamondRoot', 'Mod.DiamondTop']
}

func testExistential(arg: any DiamondTop) {
arg.#^TestAnyDiamondTop^#
// TestAnyDiamondTop: LookedupTypeNames: ['Mod.DiamondTop', 'Mod.DiamondEdge1', 'Mod.DiamondRoot', 'Mod.DiamondEdge2']
// TestAnyDiamondTop: LookedupTypeNames: ['Mod.DiamondEdge1', 'Mod.DiamondEdge2', 'Mod.DiamondRoot', 'Mod.DiamondTop']
}

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

func testSubClass(arg: DerivedClass) {
arg.#^TestDerivedClass^#
// TestDerivedClass: LookedupTypeNames: ['Mod.DerivedClass', 'Mod.BaseClass']
// TestDerivedClass: LookedupTypeNames: ['Mod.BaseClass', 'Mod.DerivedClass']
}

protocol BaseClassConstrainedP: BaseClass {}
protocol DerivedClassConstrainedP: DerivedClass {}

func testClassConstrainedProto(arg: some BaseClassConstrainedP) {
arg.#^TestBaseClassConstrainedP^#
// TestBaseClassConstrainedP: LookedupTypeNames: ['Mod.BaseClassConstrainedP', 'Mod.BaseClass']
// TestBaseClassConstrainedP: LookedupTypeNames: ['Mod.BaseClass', 'Mod.BaseClassConstrainedP']
}
func testClassConstriainedProto2(arg: some DerivedClassConstrainedP) {
arg.#^TestDerivedClassConstrainedP^#
// TestDerivedClassConstrainedP: LookedupTypeNames: ['Mod.DerivedClassConstrainedP', 'Mod.DerivedClass', 'Mod.BaseClass']
// TestDerivedClassConstrainedP: LookedupTypeNames: ['Mod.BaseClass', 'Mod.DerivedClass', 'Mod.DerivedClassConstrainedP']
}

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

func testDerivedClassWithProto(arg: DerivedClassWithProto) {
arg.#^TestDerivedClassWithProto^#
// TestDerivedClassWithProto: LookedupTypeNames: ['Mod.DerivedClassWithProto', 'Mod.BaseP2', 'Mod.BaseP1', 'Mod.BaseClassWithProto']
// TestDerivedClassWithProto: LookedupTypeNames: ['Mod.BaseClassWithProto', 'Mod.BaseP1', 'Mod.BaseP2', 'Mod.DerivedClassWithProto']
}

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

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

}
6 changes: 3 additions & 3 deletions test/IDE/print_type_interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ extension D {
public func unconditionalFunc2(t : T) -> T {return t}
}

// TYPE2: public class D<print_type_interface.T1> {
// TYPE2: public class D<T1> {
// TYPE2: public func foo()
// TYPE2: public func conditionalFunc1()
// TYPE2: public func conditionalFunc2(t: print_type_interface.T1) -> print_type_interface.T1
// TYPE2: public func conditionalFunc2(t: T1) -> T1
// TYPE2: public func unconditionalFunc1()
// TYPE2: public func unconditionalFunc2(t: print_type_interface.T1) -> print_type_interface.T1
// TYPE2: public func unconditionalFunc2(t: T1) -> T1
// TYPE2: }

// TYPE3: public class D<Int> {
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/inline_generics.sil
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ sil_vtable MyNumber {}
// CHECK-LABEL: sil @test_inlining : $@convention(objc_method) (@owned MyNumber) -> () {
// CHECK-NOT: Generic specialization information for call-site dootherstuff <MyNumber & SomeProto> conformances <(abstract_conformance protocol="OtherProto")>
// CHECK: Generic specialization information
// CHECK: (normal_conformance type="MyObject" protocol="OtherProto")
// CHECK: (normal_conformance type="MyObject" protocol="OtherProto"
// CHECK: end sil function 'test_inlining'

sil @test_inlining : $@convention(objc_method) (@owned MyNumber) -> () {
Expand Down
1 change: 1 addition & 0 deletions test/SILOptimizer/loweraggregateinstrs_moveonly.sil
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
sil_stage canonical

import Builtin
import Swift

struct S : ~Copyable {
deinit {}
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/sil_combine_concrete_existential.sil
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ sil @callee2 : $@convention(thin) <τ_0_0 where τ_0_0 : SubscriptionViewControl
// CHECK: [[T6:%.*]] = alloc_stack $@opened("E4D92D2A-8893-11EA-9C89-ACDE48001122", any ResourceKitProtocol) Self
// CHECK: copy_addr [[T4]] to [init] [[T6]] : $*@opened("E4D92D2A-8893-11EA-9C89-ACDE48001122", any ResourceKitProtocol) Self
// CHECK: Generic specialization information for call-site callee2 <any ResourceKitProtocol> conformances <(inherited_conformance type="any ResourceKitProtocol" protocol="SubscriptionViewControllerDelegate"
// CHECK: (normal_conformance type="MyObject" protocol="SubscriptionViewControllerDelegate"))>:
// CHECK: (normal_conformance type="MyObject" protocol="SubscriptionViewControllerDelegate"
// CHECK: apply [[T5]]<@opened("E4D92D2A-8893-11EA-9C89-ACDE48001122", any ResourceKitProtocol) Self>([[T6]], [[T1]])

sil @test_opend_archetype_concrete_conformance_substitution : $@convention(method) (@guaranteed ResourceKitProtocol, @guaranteed ViewController) -> () {
Expand Down
8 changes: 4 additions & 4 deletions test/SourceKit/InterfaceGen/gen_swift_type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct S1 {
// CHECK3: public func fea1()
// CHECK3: public func fea2()

// CHECK4: public struct Array<gen_swift_type.A>
// CHECK4: public struct Array<A>

public protocol P1 { }
public class T1 : P1 { }
Expand All @@ -63,12 +63,12 @@ extension D {
public func unconditionalFunc2(t : T) -> T {return t}
}

// CHECK5: public class D<gen_swift_type.T1> {
// CHECK5: public class D<T1> {
// CHECK5: public func foo()
// CHECK5: public func conditionalFunc1()
// CHECK5: public func conditionalFunc2(t: gen_swift_type.T1) -> gen_swift_type.T1
// CHECK5: public func conditionalFunc2(t: T1) -> T1
// CHECK5: public func unconditionalFunc1()
// CHECK5: public func unconditionalFunc2(t: gen_swift_type.T1) -> gen_swift_type.T1
// CHECK5: public func unconditionalFunc2(t: T1) -> T1

// CHECK6: public class D<Int> {
// CHECK6: public func foo()
Expand Down
2 changes: 1 addition & 1 deletion test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ subst_target_swift_frontend_mock_sdk += " -typo-correction-limit 10 "

# Enable colors if we have them.
if config.color_output:
config.target_swift_frontend += " -color-diagnostics"
config.target_swift_frontend += " -color-diagnostics "

config.substitutions.append(('%module-target-triple',
target_specific_module_triple))
Expand Down
10 changes: 9 additions & 1 deletion tools/swift-ide-test/swift-ide-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,17 @@ printCodeCompletionLookedupTypeNames(ArrayRef<NullTerminatedStringRef> names,
if (names.empty())
return;

SmallVector<NullTerminatedStringRef, 2> sortedNames;
sortedNames.append(names.begin(), names.end());
llvm::sort(sortedNames,
[](NullTerminatedStringRef a, NullTerminatedStringRef b) {
return a.compare(b) <= 0;
});

OS << "LookedupTypeNames: [";
llvm::interleave(
names.begin(), names.end(), [&](auto name) { OS << "'" << name << "'"; },
sortedNames.begin(), sortedNames.end(),
[&](auto name) { OS << "'" << name << "'"; },
[&]() { OS << ", "; });
OS << "]\n";
}
Expand Down