Skip to content

A pile of mostly unrelated one-liners #67952

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 10 commits into from
Aug 18, 2023
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
8 changes: 2 additions & 6 deletions include/swift/SIL/SILWitnessTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,8 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
/// Return the protocol for which this witness table is a conformance.
ProtocolDecl *getProtocol() const;

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

/// Return the symbol name of the witness table that will be propagated to the
/// object file level.
Expand Down
8 changes: 0 additions & 8 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3041,14 +3041,6 @@ static bool usesBuiltinType(Decl *decl, BuiltinTypeKind kind) {
}
}

if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
for (unsigned idx : range(patternBinding->getNumPatternEntries())) {
if (Type type = patternBinding->getPattern(idx)->getType())
if (typeMatches(type))
return true;
}
}

return false;
}

Expand Down
1 change: 1 addition & 0 deletions lib/AST/RequirementMachine/RequirementBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ void RequirementBuilder::addTypeAliasRules(ArrayRef<unsigned> rules) {

auto &component = Components[rule.getRHS()];
assert(!component.ConcreteType);
(void) component;
Components[rule.getRHS()].ConcreteType = concreteType;
} else {
Components[rule.getRHS()].Aliases.push_back(name);
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "swift/AST/Module.h"
#include "swift/AST/PackConformance.h"
#include "swift/AST/ParameterList.h"
#include "swift/AST/PrettyStackTrace.h"
#include "swift/AST/ProtocolConformance.h"
#include "swift/AST/SILLayout.h"
#include "swift/AST/SubstitutionMap.h"
Expand Down Expand Up @@ -1748,6 +1749,9 @@ CanType TypeBase::computeCanonicalType() {
case TypeKind::GenericFunction: {
AnyFunctionType *funcTy = cast<AnyFunctionType>(this);

PrettyStackTraceType trace(funcTy->getResult()->getASTContext(),
"computing canonical type for ", this);

CanGenericSignature genericSig;
if (auto *genericFnTy = dyn_cast<GenericFunctionType>(this))
genericSig = genericFnTy->getGenericSignature().getCanonicalSignature();
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/FrontendOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,6 @@ bool FrontendOptions::canActionEmitInterface(ActionType action) {
switch (action) {
case ActionType::NoneAction:
case ActionType::Parse:
case ActionType::ResolveImports:
case ActionType::DumpParse:
case ActionType::DumpInterfaceHash:
case ActionType::DumpAST:
Expand All @@ -727,6 +726,7 @@ bool FrontendOptions::canActionEmitInterface(ActionType action) {
case ActionType::ScanDependencies:
case ActionType::PrintFeature:
return false;
case ActionType::ResolveImports:
case ActionType::Typecheck:
case ActionType::MergeModules:
case ActionType::EmitModuleOnly:
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4080,8 +4080,8 @@ void IRGenModule::appendLLVMUsedConditionalEntry(
auto *protocol = getAddrOfProtocolDescriptor(conformance->getProtocol())
->stripPointerCasts();
auto *type = getAddrOfTypeContextDescriptor(
conformance->getType()->getAnyNominal(), DontRequireMetadata)
->stripPointerCasts();
conformance->getDeclContext()->getSelfNominalTypeDecl(),
DontRequireMetadata)->stripPointerCasts();

llvm::Metadata *metadata[] = {
// (1) which variable is being conditionalized, "target"
Expand Down
7 changes: 4 additions & 3 deletions lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ namespace {
// Add a relative reference to the type, with the type reference
// kind stored in the flags.
auto ref = IGM.getTypeEntityReference(
Conformance->getType()->getAnyNominal());
Conformance->getDeclContext()->getSelfNominalTypeDecl());
B.addRelativeAddress(ref.getValue());
Flags = Flags.withTypeReferenceKind(ref.getKind());
}
Expand Down Expand Up @@ -2474,8 +2474,9 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
// Record this conformance descriptor.
addProtocolConformance(std::move(description));

IRGen.noteUseOfTypeContextDescriptor(conf->getType()->getAnyNominal(),
RequireMetadata);
IRGen.noteUseOfTypeContextDescriptor(
conf->getDeclContext()->getSelfNominalTypeDecl(),
RequireMetadata);
}

/// True if a function's signature in LLVM carries polymorphic parameters.
Expand Down
5 changes: 1 addition & 4 deletions lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,10 +1284,7 @@ bool IRGenerator::canEmitWitnessTableLazily(SILWitnessTable *wt) {
if (wt->getLinkage() == SILLinkage::Shared)
return true;

NominalTypeDecl *ConformingTy =
wt->getConformingType()->getNominalOrBoundGenericNominal();

switch (ConformingTy->getEffectiveAccess()) {
switch (wt->getConformingNominal()->getEffectiveAccess()) {
case AccessLevel::Private:
case AccessLevel::FilePrivate:
return true;
Expand Down
31 changes: 16 additions & 15 deletions lib/IRGen/Linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,16 +748,17 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
case Kind::OpaqueTypeDescriptor: {
auto *opaqueType = cast<OpaqueTypeDecl>(getDecl());

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

return getSILLinkage(getDeclLinkage(opaqueType), forDefinition);
}
Expand Down Expand Up @@ -803,15 +804,15 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {

case Kind::ProtocolWitnessTableLazyAccessFunction:
case Kind::ProtocolWitnessTableLazyCacheVariable: {
auto ty = getType();
ValueDecl *nominal = nullptr;
if (auto *otat = ty->getAs<OpaqueTypeArchetypeType>()) {
nominal = otat->getDecl();
TypeDecl *typeDecl = nullptr;
if (auto *otat = getType()->getAs<OpaqueTypeArchetypeType>()) {
typeDecl = otat->getDecl();
} else {
nominal = ty->getAnyNominal();
typeDecl = getProtocolConformance()->getDeclContext()
->getSelfNominalTypeDecl();
}
assert(nominal);
if (getDeclLinkage(nominal) == FormalLinkage::Private ||
assert(typeDecl);
if (getDeclLinkage(typeDecl) == FormalLinkage::Private ||
getLinkageAsConformance() == SILLinkage::Private) {
return SILLinkage::Private;
} else {
Expand Down
9 changes: 2 additions & 7 deletions lib/SIL/IR/SILSymbolVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
addSymbolIfNecessary(getter, witnessDecl);
}
}
});
}, /*useResolver=*/true);
}
}

Expand Down Expand Up @@ -594,13 +594,8 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
if (!Ctx.getOpts().VisitMembers)
return;

for (auto member : D->getMembers()) {
member->visitAuxiliaryDecls([&](Decl *decl) {
visit(decl);
});

for (auto member : D->getABIMembers())
visit(member);
}
}

void visitNominalTypeDecl(NominalTypeDecl *NTD) {
Expand Down
4 changes: 2 additions & 2 deletions lib/SIL/IR/SILWitnessTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ ProtocolDecl *SILWitnessTable::getProtocol() const {
return getConformance()->getProtocol();
}

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

void SILWitnessTable::addWitnessTable() {
Expand Down
6 changes: 6 additions & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,7 @@ NamingPatternRequest::evaluate(Evaluator &evaluator, VarDecl *VD) const {
}
}
assert(foundVarDecl && "VarDecl not declared in its parent?");
(void) foundVarDecl;
} else {
// We have some other parent stmt. Type check it completely.
if (auto CS = dyn_cast<CaseStmt>(parentStmt))
Expand Down Expand Up @@ -2780,6 +2781,11 @@ static ArrayRef<Decl *> evaluateMembersRequest(
// We need to add implicit initializers because they
// affect vtable layout.
TypeChecker::addImplicitConstructors(nominal);

// Destructors don't affect vtable layout, but TBDGen needs to
// see them, so we also force the destructor here.
if (auto *classDecl = dyn_cast<ClassDecl>(nominal))
(void) classDecl->getDestructor();
}

// Force any conformances that may introduce more members.
Expand Down
34 changes: 34 additions & 0 deletions test/IRGen/tuple_conformances.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %target-swift-frontend -emit-ir -parse-stdlib -primary-file %s -enable-experimental-feature TupleConformances -parse-as-library | %FileCheck %s

import Swift

protocol P {
func f()
}

extension P {
func f() {}
}

extension Builtin.TheTupleType: P where repeat each Elements: P {
}

func takesP<T: P>(_ t: T) {
t.f()
}

struct S: P {}

func use() {
takesP((S(), S()))
}

// CHECK-LABEL: define internal swiftcc void @"$sxxQp_t18tuple_conformances1PA2aBP1fyyFTW"({{i32|i64}} %0, ptr %"{{.*}}", ptr {{.*}} swiftself %1, ptr %Self, ptr %SelfWitnessTable) {{.*}} {

// CHECK-LABEL: define hidden swiftcc void @"$s18tuple_conformances3useyyF"() {{.*}} {
// CHECK: call ptr @"$s18tuple_conformances1SV_ACtxxQp_tAA1PAAWl"()
// CHECK: ret void

// CHECK-LABEL: define linkonce_odr hidden ptr @"$s18tuple_conformances1SV_ACtxxQp_tAA1PAAWl"() {{.*}} {


25 changes: 25 additions & 0 deletions test/ModuleInterface/resolve-imports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -resolve-imports %s -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution
// RUN: %FileCheck %s < %t/main.swiftinterface

// CHECK: import Swift

// CHECK: public func f() -> Swift.Int
public func f() -> Int {}

// Deliberate semantic errors to ensure private and internal declarations don't
// get type checked.
private func bad1(_: NotAThing) -> DoesNotExist {}

internal typealias Bad1 = NotEvenReal.DefinitelyNot

// Destructors
public class C {}

// CHECK: public class C {
// CHECK: deinit
// CHECK: }

// Globals
public var year = 2023
34 changes: 34 additions & 0 deletions test/TBD/resolve_imports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -resolve-imports -emit-tbd -emit-tbd-path %t/resolve_imports.tbd %s -disable-availability-checking
// RUN: %FileCheck %s < %t/resolve_imports.tbd

// REQUIRES: OS=macosx

// Correct linkage for opaque type descriptor.
@_alwaysEmitIntoClient public var x: some Any {
get {
if #available(macOS 20, *) {
return 3
} else {
return "hi"
}
}
}

// Make sure we emit all ABI members.
public class C {}

// Edge case where protocol witness thunk is public.
protocol PrivateProto: Equatable {}

extension PrivateProto {
public static func ==(lhs: Self, rhs: Self) -> Bool { return false }
}

public struct S: PrivateProto {}

// CHECK: symbols: [ '_$s15resolve_imports1CCMa', '_$s15resolve_imports1CCMm',
// CHECK-NEXT: '_$s15resolve_imports1CCMn', '_$s15resolve_imports1CCN', '_$s15resolve_imports1CCfD',
// CHECK-NEXT: '_$s15resolve_imports1CCfd', '_$s15resolve_imports1SVMa',
// CHECK-NEXT: '_$s15resolve_imports1SVMn', '_$s15resolve_imports1SVN', '_$s15resolve_imports1SVSQAAMc',
// CHECK-NEXT: '_$s15resolve_imports1SVSQAASQ2eeoiySbx_xtFZTW', _main ]