Skip to content

Commit c2f1193

Browse files
authored
Merge pull request #67952 from slavapestov/tuple-conformance-tbd-etc
A pile of mostly unrelated one-liners
2 parents 802e63a + bea1ba4 commit c2f1193

File tree

15 files changed

+134
-48
lines changed

15 files changed

+134
-48
lines changed

include/swift/SIL/SILWitnessTable.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,8 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
238238
/// Return the protocol for which this witness table is a conformance.
239239
ProtocolDecl *getProtocol() const;
240240

241-
/// Return the formal type which conforms to the protocol.
242-
///
243-
/// Note that this will not be a substituted type: it may only be meaningful
244-
/// in the abstract context of the conformance rather than the context of any
245-
/// particular use of it.
246-
CanType getConformingType() const;
241+
/// Return the nominal type declaration which conforms to the protocol.
242+
NominalTypeDecl *getConformingNominal() const;
247243

248244
/// Return the symbol name of the witness table that will be propagated to the
249245
/// object file level.

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,14 +3036,6 @@ static bool usesBuiltinType(Decl *decl, BuiltinTypeKind kind) {
30363036
}
30373037
}
30383038

3039-
if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
3040-
for (unsigned idx : range(patternBinding->getNumPatternEntries())) {
3041-
if (Type type = patternBinding->getPattern(idx)->getType())
3042-
if (typeMatches(type))
3043-
return true;
3044-
}
3045-
}
3046-
30473039
return false;
30483040
}
30493041

lib/AST/RequirementMachine/RequirementBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ void RequirementBuilder::addTypeAliasRules(ArrayRef<unsigned> rules) {
312312

313313
auto &component = Components[rule.getRHS()];
314314
assert(!component.ConcreteType);
315+
(void) component;
315316
Components[rule.getRHS()].ConcreteType = concreteType;
316317
} else {
317318
Components[rule.getRHS()].Aliases.push_back(name);

lib/AST/Type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "swift/AST/Module.h"
3232
#include "swift/AST/PackConformance.h"
3333
#include "swift/AST/ParameterList.h"
34+
#include "swift/AST/PrettyStackTrace.h"
3435
#include "swift/AST/ProtocolConformance.h"
3536
#include "swift/AST/SILLayout.h"
3637
#include "swift/AST/SubstitutionMap.h"
@@ -1748,6 +1749,9 @@ CanType TypeBase::computeCanonicalType() {
17481749
case TypeKind::GenericFunction: {
17491750
AnyFunctionType *funcTy = cast<AnyFunctionType>(this);
17501751

1752+
PrettyStackTraceType trace(funcTy->getResult()->getASTContext(),
1753+
"computing canonical type for ", this);
1754+
17511755
CanGenericSignature genericSig;
17521756
if (auto *genericFnTy = dyn_cast<GenericFunctionType>(this))
17531757
genericSig = genericFnTy->getGenericSignature().getCanonicalSignature();

lib/Frontend/FrontendOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,6 @@ bool FrontendOptions::canActionEmitInterface(ActionType action) {
705705
switch (action) {
706706
case ActionType::NoneAction:
707707
case ActionType::Parse:
708-
case ActionType::ResolveImports:
709708
case ActionType::DumpParse:
710709
case ActionType::DumpInterfaceHash:
711710
case ActionType::DumpAST:
@@ -727,6 +726,7 @@ bool FrontendOptions::canActionEmitInterface(ActionType action) {
727726
case ActionType::ScanDependencies:
728727
case ActionType::PrintFeature:
729728
return false;
729+
case ActionType::ResolveImports:
730730
case ActionType::Typecheck:
731731
case ActionType::MergeModules:
732732
case ActionType::EmitModuleOnly:

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,8 +4080,8 @@ void IRGenModule::appendLLVMUsedConditionalEntry(
40804080
auto *protocol = getAddrOfProtocolDescriptor(conformance->getProtocol())
40814081
->stripPointerCasts();
40824082
auto *type = getAddrOfTypeContextDescriptor(
4083-
conformance->getType()->getAnyNominal(), DontRequireMetadata)
4084-
->stripPointerCasts();
4083+
conformance->getDeclContext()->getSelfNominalTypeDecl(),
4084+
DontRequireMetadata)->stripPointerCasts();
40854085

40864086
llvm::Metadata *metadata[] = {
40874087
// (1) which variable is being conditionalized, "target"

lib/IRGen/GenProto.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@ namespace {
19841984
// Add a relative reference to the type, with the type reference
19851985
// kind stored in the flags.
19861986
auto ref = IGM.getTypeEntityReference(
1987-
Conformance->getType()->getAnyNominal());
1987+
Conformance->getDeclContext()->getSelfNominalTypeDecl());
19881988
B.addRelativeAddress(ref.getValue());
19891989
Flags = Flags.withTypeReferenceKind(ref.getKind());
19901990
}
@@ -2474,8 +2474,9 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
24742474
// Record this conformance descriptor.
24752475
addProtocolConformance(std::move(description));
24762476

2477-
IRGen.noteUseOfTypeContextDescriptor(conf->getType()->getAnyNominal(),
2478-
RequireMetadata);
2477+
IRGen.noteUseOfTypeContextDescriptor(
2478+
conf->getDeclContext()->getSelfNominalTypeDecl(),
2479+
RequireMetadata);
24792480
}
24802481

24812482
/// True if a function's signature in LLVM carries polymorphic parameters.

lib/IRGen/IRGenModule.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,10 +1280,7 @@ bool IRGenerator::canEmitWitnessTableLazily(SILWitnessTable *wt) {
12801280
if (wt->getLinkage() == SILLinkage::Shared)
12811281
return true;
12821282

1283-
NominalTypeDecl *ConformingTy =
1284-
wt->getConformingType()->getNominalOrBoundGenericNominal();
1285-
1286-
switch (ConformingTy->getEffectiveAccess()) {
1283+
switch (wt->getConformingNominal()->getEffectiveAccess()) {
12871284
case AccessLevel::Private:
12881285
case AccessLevel::FilePrivate:
12891286
return true;

lib/IRGen/Linking.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -743,16 +743,17 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
743743
case Kind::OpaqueTypeDescriptor: {
744744
auto *opaqueType = cast<OpaqueTypeDecl>(getDecl());
745745

746-
// The opaque result type descriptor with availability conditions
747-
// has to be emitted into a client module when associated with
746+
// With conditionally available substitutions, the opaque result type
747+
// descriptor has to be emitted into a client module when associated with
748748
// `@_alwaysEmitIntoClient` declaration which means it's linkage
749749
// has to be "shared".
750-
if (opaqueType->hasConditionallyAvailableSubstitutions()) {
751-
if (auto *srcDecl = opaqueType->getNamingDecl()) {
752-
if (srcDecl->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>())
753-
return SILLinkage::Shared;
754-
}
755-
}
750+
//
751+
// If we don't have conditionally available substitutions, we won't emit
752+
// the descriptor at all, but still make sure we report "shared" linkage
753+
// so that TBD files don't include a bogus symbol.
754+
auto *srcDecl = opaqueType->getNamingDecl();
755+
if (srcDecl->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>())
756+
return SILLinkage::Shared;
756757

757758
return getSILLinkage(getDeclLinkage(opaqueType), forDefinition);
758759
}
@@ -798,15 +799,15 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
798799

799800
case Kind::ProtocolWitnessTableLazyAccessFunction:
800801
case Kind::ProtocolWitnessTableLazyCacheVariable: {
801-
auto ty = getType();
802-
ValueDecl *nominal = nullptr;
803-
if (auto *otat = ty->getAs<OpaqueTypeArchetypeType>()) {
804-
nominal = otat->getDecl();
802+
TypeDecl *typeDecl = nullptr;
803+
if (auto *otat = getType()->getAs<OpaqueTypeArchetypeType>()) {
804+
typeDecl = otat->getDecl();
805805
} else {
806-
nominal = ty->getAnyNominal();
806+
typeDecl = getProtocolConformance()->getDeclContext()
807+
->getSelfNominalTypeDecl();
807808
}
808-
assert(nominal);
809-
if (getDeclLinkage(nominal) == FormalLinkage::Private ||
809+
assert(typeDecl);
810+
if (getDeclLinkage(typeDecl) == FormalLinkage::Private ||
810811
getLinkageAsConformance() == SILLinkage::Private) {
811812
return SILLinkage::Private;
812813
} else {

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
303303
addSymbolIfNecessary(getter, witnessDecl);
304304
}
305305
}
306-
});
306+
}, /*useResolver=*/true);
307307
}
308308
}
309309

@@ -580,13 +580,8 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
580580
if (!Ctx.getOpts().VisitMembers)
581581
return;
582582

583-
for (auto member : D->getMembers()) {
584-
member->visitAuxiliaryDecls([&](Decl *decl) {
585-
visit(decl);
586-
});
587-
583+
for (auto member : D->getABIMembers())
588584
visit(member);
589-
}
590585
}
591586

592587
void visitNominalTypeDecl(NominalTypeDecl *NTD) {

lib/SIL/IR/SILWitnessTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ ProtocolDecl *SILWitnessTable::getProtocol() const {
4343
return getConformance()->getProtocol();
4444
}
4545

46-
CanType SILWitnessTable::getConformingType() const {
47-
return getConformance()->getType()->getCanonicalType();
46+
NominalTypeDecl *SILWitnessTable::getConformingNominal() const {
47+
return getConformance()->getDeclContext()->getSelfNominalTypeDecl();
4848
}
4949

5050
void SILWitnessTable::addWitnessTable() {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,6 +2671,7 @@ NamingPatternRequest::evaluate(Evaluator &evaluator, VarDecl *VD) const {
26712671
}
26722672
}
26732673
assert(foundVarDecl && "VarDecl not declared in its parent?");
2674+
(void) foundVarDecl;
26742675
} else {
26752676
// We have some other parent stmt. Type check it completely.
26762677
if (auto CS = dyn_cast<CaseStmt>(parentStmt))
@@ -2780,6 +2781,11 @@ static ArrayRef<Decl *> evaluateMembersRequest(
27802781
// We need to add implicit initializers because they
27812782
// affect vtable layout.
27822783
TypeChecker::addImplicitConstructors(nominal);
2784+
2785+
// Destructors don't affect vtable layout, but TBDGen needs to
2786+
// see them, so we also force the destructor here.
2787+
if (auto *classDecl = dyn_cast<ClassDecl>(nominal))
2788+
(void) classDecl->getDestructor();
27832789
}
27842790

27852791
// Force any conformances that may introduce more members.

test/IRGen/tuple_conformances.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-frontend -emit-ir -parse-stdlib -primary-file %s -enable-experimental-feature TupleConformances -parse-as-library | %FileCheck %s
2+
3+
import Swift
4+
5+
protocol P {
6+
func f()
7+
}
8+
9+
extension P {
10+
func f() {}
11+
}
12+
13+
extension Builtin.TheTupleType: P where repeat each Elements: P {
14+
}
15+
16+
func takesP<T: P>(_ t: T) {
17+
t.f()
18+
}
19+
20+
struct S: P {}
21+
22+
func use() {
23+
takesP((S(), S()))
24+
}
25+
26+
// CHECK-LABEL: define internal swiftcc void @"$sxxQp_t18tuple_conformances1PA2aBP1fyyFTW"({{i32|i64}} %0, ptr %"{{.*}}", ptr {{.*}} swiftself %1, ptr %Self, ptr %SelfWitnessTable) {{.*}} {
27+
28+
// CHECK-LABEL: define hidden swiftcc void @"$s18tuple_conformances3useyyF"() {{.*}} {
29+
// CHECK: call ptr @"$s18tuple_conformances1SV_ACtxxQp_tAA1PAAWl"()
30+
// CHECK: ret void
31+
32+
// CHECK-LABEL: define linkonce_odr hidden ptr @"$s18tuple_conformances1SV_ACtxxQp_tAA1PAAWl"() {{.*}} {
33+
34+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -resolve-imports %s -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution
4+
// RUN: %FileCheck %s < %t/main.swiftinterface
5+
6+
// CHECK: import Swift
7+
8+
// CHECK: public func f() -> Swift.Int
9+
public func f() -> Int {}
10+
11+
// Deliberate semantic errors to ensure private and internal declarations don't
12+
// get type checked.
13+
private func bad1(_: NotAThing) -> DoesNotExist {}
14+
15+
internal typealias Bad1 = NotEvenReal.DefinitelyNot
16+
17+
// Destructors
18+
public class C {}
19+
20+
// CHECK: public class C {
21+
// CHECK: deinit
22+
// CHECK: }
23+
24+
// Globals
25+
public var year = 2023

test/TBD/resolve_imports.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -resolve-imports -emit-tbd -emit-tbd-path %t/resolve_imports.tbd %s -disable-availability-checking
3+
// RUN: %FileCheck %s < %t/resolve_imports.tbd
4+
5+
// REQUIRES: OS=macosx
6+
7+
// Correct linkage for opaque type descriptor.
8+
@_alwaysEmitIntoClient public var x: some Any {
9+
get {
10+
if #available(macOS 20, *) {
11+
return 3
12+
} else {
13+
return "hi"
14+
}
15+
}
16+
}
17+
18+
// Make sure we emit all ABI members.
19+
public class C {}
20+
21+
// Edge case where protocol witness thunk is public.
22+
protocol PrivateProto: Equatable {}
23+
24+
extension PrivateProto {
25+
public static func ==(lhs: Self, rhs: Self) -> Bool { return false }
26+
}
27+
28+
public struct S: PrivateProto {}
29+
30+
// CHECK: symbols: [ '_$s15resolve_imports1CCMa', '_$s15resolve_imports1CCMm',
31+
// CHECK-NEXT: '_$s15resolve_imports1CCMn', '_$s15resolve_imports1CCN', '_$s15resolve_imports1CCfD',
32+
// CHECK-NEXT: '_$s15resolve_imports1CCfd', '_$s15resolve_imports1SVMa',
33+
// CHECK-NEXT: '_$s15resolve_imports1SVMn', '_$s15resolve_imports1SVN', '_$s15resolve_imports1SVSQAAMc',
34+
// CHECK-NEXT: '_$s15resolve_imports1SVSQAASQ2eeoiySbx_xtFZTW', _main ]

0 commit comments

Comments
 (0)