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

0 commit comments

Comments
 (0)