Skip to content

Commit 8e2aa52

Browse files
authored
Merge pull request #70667 from slavapestov/assorted-small-cleanups
Assorted small cleanups
2 parents 672386c + 47ca44c commit 8e2aa52

14 files changed

+83
-36
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6244,7 +6244,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
62446244
if (param->isParameterPack())
62456245
return false;
62466246
} else if (auto archetype = dyn_cast<ArchetypeType>(T.getPointer())) {
6247-
if (archetype->isParameterPack())
6247+
if (isa<PackArchetypeType>(archetype))
62486248
return false;
62496249
if (Options.PrintForSIL && isa<LocalArchetypeType>(archetype))
62506250
return false;
@@ -6560,7 +6560,10 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65606560

65616561
auto *typeAliasDecl = T->getDecl();
65626562
if (typeAliasDecl->isGeneric()) {
6563-
printGenericArgs(T->getExpandedGenericArgs());
6563+
if (Options.PrintTypesForDebugging)
6564+
printGenericArgs(T->getDirectGenericArgs());
6565+
else
6566+
printGenericArgs(T->getExpandedGenericArgs());
65646567
}
65656568
}
65666569

@@ -6571,7 +6574,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65716574
}
65726575

65736576
void visitPackType(PackType *T) {
6574-
if (Options.PrintExplicitPackTypes)
6577+
if (Options.PrintExplicitPackTypes || Options.PrintTypesForDebugging)
65756578
Printer << "Pack{";
65766579

65776580
auto Fields = T->getElementTypes();
@@ -6582,7 +6585,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
65826585
visit(EltType);
65836586
}
65846587

6585-
if (Options.PrintExplicitPackTypes)
6588+
if (Options.PrintExplicitPackTypes || Options.PrintTypesForDebugging)
65866589
Printer << "}";
65876590
}
65886591

@@ -6607,7 +6610,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
66076610

66086611
if (rootParameterPacks.empty() &&
66096612
(T->getCountType()->isParameterPack() ||
6610-
T->getCountType()->is<PackArchetypeType>())) {
6613+
T->getCountType()->is<PackArchetypeType>() ||
6614+
Options.PrintTypesForDebugging)) {
66116615
Printer << "/* shape: ";
66126616
visit(T->getCountType());
66136617
Printer << " */ ";
@@ -6682,7 +6686,10 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
66826686
}
66836687
printQualifiedType(T);
66846688

6685-
printGenericArgs(T->getExpandedGenericArgs());
6689+
if (Options.PrintTypesForDebugging)
6690+
printGenericArgs(T->getGenericArgs());
6691+
else
6692+
printGenericArgs(T->getExpandedGenericArgs());
66866693
}
66876694

66886695
void visitParentType(Type T) {
@@ -7749,10 +7756,20 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
77497756
// canonical types to sugared types.
77507757
if (Options.GenericSig)
77517758
T = Options.GenericSig->getSugaredType(T);
7759+
7760+
decl = T->getDecl();
77527761
}
77537762

77547763
// Print opaque types as "some ..."
77557764
if (decl && decl->isOpaqueType()) {
7765+
// For SIL, we print opaque parameter types as canonical types, and parse
7766+
// them that way too (because they're printed in this way in the SIL
7767+
// generic parameter list).
7768+
if (Options.PrintInSILBody) {
7769+
Printer.printName(cast<GenericTypeParamType>(T->getCanonicalType())->getName());
7770+
return;
7771+
}
7772+
77567773
// If we have and should print based on the type representation, do so.
77577774
if (auto opaqueRepr = decl->getOpaqueTypeRepr()) {
77587775
if (willUseTypeReprPrinting(opaqueRepr, Type(), Options)) {

lib/AST/ASTVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ class Verifier : public ASTWalker {
622622
if (!(countType->is<PackType>() ||
623623
countType->is<PackArchetypeType>() ||
624624
countType->isRootParameterPack())) {
625-
Out << "non-pack shape type" << countType->getString() << "\n";
625+
Out << "non-pack shape type: " << countType->getString() << "\n";
626626
abort();
627627
}
628628
}

lib/AST/ProtocolConformance.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ void Witness::dump() const { dump(llvm::errs()); }
7171
void Witness::dump(llvm::raw_ostream &out) const {
7272
out << "Witness: ";
7373
if (auto decl = this->getDecl()) {
74-
decl->print(out);
74+
decl->dumpRef(out);
75+
out << "\n";
7576
} else {
7677
out << "<no decl>\n";
7778
}

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,20 +2712,20 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
27122712
llvm::errs()
27132713
<< "Instruction missing on-stack pack metadata cleanups!\n";
27142714
I.print(llvm::errs());
2715-
llvm::errs() << "\n In function";
2715+
llvm::errs() << "\n In function:\n";
27162716
CurSILFn->print(llvm::errs());
2717-
llvm::errs() << "Allocated the following on-stack pack metadata:";
2717+
llvm::errs() << "Allocated the following on-stack pack metadata:\n";
27182718
for (auto pair : OutstandingStackPackAllocs) {
27192719
StackAddress addr;
27202720
llvm::Value *shape;
27212721
uint8_t kind;
27222722
std::tie(addr, shape, kind) = pair;
27232723
switch ((GenericRequirement::Kind)kind) {
27242724
case GenericRequirement::Kind::MetadataPack:
2725-
llvm::errs() << "Metadata Pack: ";
2725+
llvm::errs() << "- Metadata Pack: ";
27262726
break;
27272727
case GenericRequirement::Kind::WitnessTablePack:
2728-
llvm::errs() << "Witness Table Pack: ";
2728+
llvm::errs() << "- Witness Table Pack: ";
27292729
break;
27302730
default:
27312731
llvm_unreachable("bad requirement in stack pack alloc");

lib/SIL/IR/SIL.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,14 @@ bool SILModule::isTypeMetadataForLayoutAccessible(SILType type) {
296296
return ::isTypeMetadataForLayoutAccessible(*this, type);
297297
}
298298

299-
static bool isUnsupportedKeyPathValueType(Type ty, GenericEnvironment *env) {
299+
static bool isUnsupportedKeyPathValueType(Type ty) {
300300
// Visit lowered positions.
301301
if (auto tupleTy = ty->getAs<TupleType>()) {
302302
for (auto eltTy : tupleTy->getElementTypes()) {
303303
if (eltTy->is<PackExpansionType>())
304304
return true;
305305

306-
if (isUnsupportedKeyPathValueType(eltTy, env))
306+
if (isUnsupportedKeyPathValueType(eltTy))
307307
return true;
308308
}
309309

@@ -321,19 +321,19 @@ static bool isUnsupportedKeyPathValueType(Type ty, GenericEnvironment *env) {
321321
if (paramTy->is<PackExpansionType>())
322322
return true;
323323

324-
if (isUnsupportedKeyPathValueType(paramTy, env))
324+
if (isUnsupportedKeyPathValueType(paramTy))
325325
return true;
326326
}
327327

328-
if (isUnsupportedKeyPathValueType(funcTy->getResult(), env))
328+
if (isUnsupportedKeyPathValueType(funcTy->getResult()))
329329
return true;
330330
}
331331

332332
// Noncopyable types aren't supported by key paths in their current form.
333333
// They would also need a new ABI that's yet to be implemented in order to
334334
// be properly supported, so let's suppress the descriptor for now if either
335335
// the container or storage type of the declaration is non-copyable.
336-
if (ty->isNoncopyable(env))
336+
if (ty->isNoncopyable())
337337
return true;
338338

339339
return false;
@@ -398,8 +398,9 @@ bool AbstractStorageDecl::exportsPropertyDescriptor() const {
398398
llvm_unreachable("should be definition linkage?");
399399
}
400400

401-
auto *env = getDeclContext()->getGenericEnvironmentOfContext();
402-
if (isUnsupportedKeyPathValueType(getValueInterfaceType(), env)) {
401+
auto typeInContext = getInnermostDeclContext()->mapTypeIntoContext(
402+
getValueInterfaceType());
403+
if (isUnsupportedKeyPathValueType(typeInContext)) {
403404
return false;
404405
}
405406

lib/SIL/IR/SILPrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,12 @@ static void printSILFunctionNameAndType(
528528
for (auto *paramTy : genSig.getGenericParams()) {
529529
// Get a uniqued sugared name for the generic parameter type.
530530
auto sugaredTy = genEnv->getGenericSignature()->getSugaredType(paramTy);
531+
532+
// Opaque parameter types are printed as their canonical types and not
533+
// the unparseable "<anonymous>".
534+
if (sugaredTy->getDecl() && sugaredTy->getDecl()->isOpaqueType())
535+
continue;
536+
531537
Identifier name = sugaredTy->getName();
532538
while (!usedNames.insert(name).second) {
533539
disambiguatedNameBuf.clear();

lib/SIL/IR/SILTypeSubstitution.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ class SILTypeSubstituter :
348348
[&](Type substExpansionShape) {
349349
CanType substComponentType = visit(origType.getPatternType());
350350
if (substExpansionShape) {
351+
if (auto packArchetype = substExpansionShape->getAs<PackArchetypeType>())
352+
substExpansionShape = packArchetype->getReducedShape();
351353
substComponentType = CanPackExpansionType::get(substComponentType,
352354
substExpansionShape->getCanonicalType());
353355
}

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,8 +1823,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
18231823

18241824
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures)) {
18251825
// All global functions should be @Sendable
1826-
if (!funcDecl->getDeclContext()->isTypeContext() &&
1827-
!funcDecl->getDeclContext()->isLocalContext()) {
1826+
if (funcDecl->getDeclContext()->isModuleScopeContext()) {
18281827
funcType =
18291828
funcType->withExtInfo(funcType->getExtInfo().withConcurrent());
18301829
}
@@ -1849,7 +1848,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
18491848
if (isForCodeCompletion() && openedType->hasError()) {
18501849
// In code completion, replace error types by placeholder types so we can
18511850
// match the types we know instead of bailing out completely.
1852-
openedType = replaceParamErrorTypeByPlaceholder(openedType, value, /*hasAppliedSelf=*/true);
1851+
openedType = replaceParamErrorTypeByPlaceholder(
1852+
openedType, value, /*hasAppliedSelf=*/true);
18531853
}
18541854

18551855
// If we opened up any type variables, record the replacements.

lib/Sema/TypeCheckInvertible.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ bool StorageVisitor::visit(NominalTypeDecl *nominal, DeclContext *dc) {
342342
// Walk the stored properties of classes and structs.
343343
if (isa<StructDecl>(nominal) || isa<ClassDecl>(nominal)) {
344344
for (auto property : nominal->getStoredProperties()) {
345-
auto propertyType = dc->mapTypeIntoContext(property->getInterfaceType())
346-
->getRValueType()->getReferenceStorageReferent();
345+
auto propertyType = dc->mapTypeIntoContext(
346+
property->getValueInterfaceType());
347347
if ((*this)(property, propertyType))
348348
return true;
349349
}

test/Constraints/pack-expansion-expressions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func forEachEach<each C, U>(c: repeat each C, function: (U) -> Void)
7474
// expected-error@-1{{same-element requirements are not yet supported}}
7575

7676
_ = (repeat (each c).forEach(function))
77-
// expected-error@-1 {{cannot convert value of type '(U) -> Void' to expected argument type '(each C.Element) throws -> Void'}}
77+
// expected-error@-1 {{cannot convert value of type '(U) -> Void' to expected argument type '((each C).Element) throws -> Void'}}
7878
}
7979

8080
func typeReprPacks<each T: ExpressibleByIntegerLiteral>(_ t: repeat each T) {

test/IRGen/variadic_generic_functions.sil

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ sil @fc : $<each T : P> () -> () {}
7070
// CHECK-SAME: [[INT]] %0,
7171
// CHECK-SAME: ptr %"each T",
7272
// CHECK-SAME: ptr %"each T.PA",
73-
// CHECK-SAME: ptr %"each T.A.P")
74-
// CHECK: call swiftcc void @f1c([[INT]] %0, ptr %"each T", ptr %"each T.PA", ptr %"each T.A.P")
73+
// CHECK-SAME: ptr %"(each T).A.P")
74+
// CHECK: call swiftcc void @f1c([[INT]] %0, ptr %"each T", ptr %"each T.PA", ptr %"(each T).A.P")
7575
sil @f1 : $<each T : PA where repeat (each T).A : P> () -> () {
7676
%f1c = function_ref @f1c : $@convention(thin) <each T : PA where repeat (each T).A : P> () -> ()
7777
apply %f1c<Pack{repeat each T}>() : $@convention(thin) <each T : PA where repeat (each T).A : P> () -> ()
@@ -105,7 +105,7 @@ sil @associatedtype_with_added_conformance_callee : $<each T : Q> () -> () {}
105105
// CHECK-SAME: [[INT]] [[SHAPE:%[^,]+]],
106106
// CHECK-SAME: ptr %"each T",
107107
// CHECK-SAME: ptr %"each T.PA",
108-
// CHECK-SAME: ptr %"each T.A.QA",
108+
// CHECK-SAME: ptr %"(each T).A.QA",
109109
// CHECK-SAME: ptr [[ASSOCIATEDTYPES_CONFORMANCES_TO_Q:%[^,]+]])
110110
// CHECK: [[ASSOCIATEDTYPES:%[^,]+]] = alloca ptr, [[INT]] [[SHAPE]]
111111
// CHECK: call swiftcc void @associatedtype_with_added_conformance_2_callee(
@@ -147,15 +147,15 @@ sil @associatedtype_with_forwarded_conformance_1_callee : $<each T : Q> () -> ()
147147
// CHECK-SAME: [[INT]] [[SHAPE:%[^,]+]],
148148
// CHECK-SAME: ptr %"each T",
149149
// CHECK-SAME: ptr %"each T.PA",
150-
// CHECK-SAME: ptr %"each T.A.Q")
150+
// CHECK-SAME: ptr %"(each T).A.Q")
151151
// CHECK: [[GEN1_TYPES:%[^,]+]] = alloca ptr, [[INT]] [[SHAPE]]
152152
// CHECK: [[STORED_STACK_LOC:%[^,]+]] = call ptr @llvm.stacksave()
153153
// CHECK: [[GEN1_CONFORMANCES_TO_PA:%[^,]+]] = alloca ptr, [[INT]] [[SHAPE]]
154154
// CHECK: call swiftcc void @generictype_with_forwarded_conformance_2_callee(
155155
// CHECK-SAME: [[INT]] [[SHAPE]],
156156
// CHECK-SAME: ptr [[GEN1_TYPES]],
157157
// CHECK-SAME: ptr [[GEN1_CONFORMANCES_TO_PA]],
158-
// CHECK-SAME: ptr %"each T.A.Q")
158+
// CHECK-SAME: ptr %"(each T).A.Q")
159159
// CHECK: call void @llvm.stackrestore(ptr [[STORED_STACK_LOC]])
160160
sil @generictype_with_forwarded_conformance_2 : $<each T : PA where repeat (each T).A : Q>() -> () {
161161
%callee = function_ref @generictype_with_forwarded_conformance_2_callee : $@convention(thin) <each T : PA where repeat (each T).A : Q> () -> ()
@@ -170,15 +170,15 @@ sil @generictype_with_forwarded_conformance_2_callee : $<each T : PA where repea
170170
// CHECK-SAME: [[INT]] [[SHAPE:%[^,]+]],
171171
// CHECK-SAME: ptr %"each T",
172172
// CHECK-SAME: ptr %"each T.PA",
173-
// CHECK-SAME: ptr %"each T.A.Q")
173+
// CHECK-SAME: ptr %"(each T).A.Q")
174174
// CHECK: [[GEN1_GEN1_TYPES:%[^,]+]] = alloca ptr, [[INT]] [[SHAPE]]
175175
// CHECK: [[STORED_STACK_LOC:%[^,]+]] = call ptr @llvm.stacksave()
176176
// CHECK: [[GEN1_GEN1_CONFORMANCES_TO_PA:%[^,]+]] = alloca ptr, [[INT]] [[SHAPE]]
177177
// CHECK: call swiftcc void @generic_with_forwarded_conformance_3_callee(
178178
// CHECK-SAME: [[INT]] [[SHAPE]],
179179
// CHECK-SAME: ptr [[GEN1_GEN1_TYPES]],
180180
// CHECK-SAME: ptr [[GEN1_GEN1_CONFORMANCES_TO_PA]],
181-
// CHECK-SAME: ptr %"each T.A.Q")
181+
// CHECK-SAME: ptr %"(each T).A.Q")
182182
// CHECK: call void @llvm.stackrestore(ptr [[STORED_STACK_LOC]])
183183
sil @generic_with_forwarded_conformance_3 : $<each T : PA where repeat (each T).A : Q> () -> () {
184184
%callee = function_ref @generic_with_forwarded_conformance_3_callee : $@convention(thin) <each T : PA where repeat (each T).A : Q> () -> ()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
// RUN: %target-swift-frontend -emit-silgen %s | %target-sil-opt | %FileCheck %s
3+
4+
protocol P {}
5+
6+
func bar(_: some P) {}
7+
8+
func foo(_ x: some P) {
9+
bar(x)
10+
}
11+
12+
// CHECK-LABEL: sil hidden [ossa] @$s26opaque_parameter_roundtrip3fooyyxAA1PRzlF : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> () {
13+
// CHECK: bb0(%0 : $*τ_0_0):
14+
// CHECK-NEXT: debug_value %0 : $*τ_0_0, let, name "x", argno 1, expr op_deref
15+
// CHECK-NEXT: // function_ref bar<A>(_:)
16+
// CHECK-NEXT: [[FN:%.*]] = function_ref @$s26opaque_parameter_roundtrip3baryyxAA1PRzlF : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
17+
// CHECK-NEXT: apply [[FN]]<τ_0_0>(%0) : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
18+
// CHECK-NEXT: [[RESULT:%.*]] = tuple ()
19+
// CHECK-NEXT: return [[RESULT]] : $()
20+
// CHECK-NEXT: } // end sil function '$s26opaque_parameter_roundtrip3fooyyxAA1PRzlF'

test/SILGen/objc_async.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ extension OptionalMemberLookups {
303303
}
304304

305305

306-
// CHECK-LABEL: sil {{.*}} @$s10objc_async12checkHotdogsySSSgx_So8NSObjectCtYaKSo16HotdogCompetitorRzlF
306+
// CHECK-LABEL: sil {{.*}} @$s10objc_async12checkHotdogsySSSgx_So8NSObjectCtYaKSo16HotdogCompetitorRzlF : $@convention(thin) @async <τ_0_0 where τ_0_0 : HotdogCompetitor> (@guaranteed τ_0_0, @guaranteed NSObject) -> (@owned Optional<String>, @error any Error) {
307307
// CHECK: hop_to_executor {{.*}} : $MainActor
308-
// CHECK: [[AUTO_REL_STR:%.*]] = apply {{.*}}<some HotdogCompetitor>({{.*}}) : $@convention(objc_method)
308+
// CHECK: [[AUTO_REL_STR:%.*]] = apply {{.*}}<τ_0_0>({{.*}}) : $@convention(objc_method)
309309
// CHECK: [[UNMANAGED_OPTIONAL:%.*]] = load [trivial] {{.*}} : $*@sil_unmanaged Optional<NSError>
310310
// CHECK: [[MANAGED_OPTIONAL:%.*]] = unmanaged_to_ref [[UNMANAGED_OPTIONAL]] : $@sil_unmanaged Optional<NSError> to $Optional<NSError>
311311
// CHECK: [[RETAINED_OPTIONAL:%.*]] = copy_value [[MANAGED_OPTIONAL]] : $Optional<NSError>

test/SILGen/variadic-generic-tuples.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ func testStructOfLoadableTuple() -> StructOfLoadableTuple<Int> {
358358
// The verifier had some home-grown type-lowering logic that didn't
359359
// know about pack expansions.
360360
// CHECK-LABEL: sil {{.*}}@$s4main22testExistentialErasureyyxxQpRvzlF1gL_yyqd__qd__QpRvzRvd__r__lF :
361-
// CHECK: [[T0:%.*]] = init_existential_addr {{.*}} : $*Any, $(repeat each T.Type)
362-
// CHECK: tuple_pack_element_addr {{.*}} of [[T0]] : $*(repeat @thick each T.Type) as $*@thick (@pack_element("{{.*}}") each T).Type
361+
// CHECK: [[T0:%.*]] = init_existential_addr {{.*}} : $*Any, $(repeat (each T).Type)
362+
// CHECK: tuple_pack_element_addr {{.*}} of [[T0]] : $*(repeat @thick (each T).Type) as $*@thick (@pack_element("{{.*}}") each T).Type
363363
func testExistentialErasure<each T>(_: repeat each T) {
364364
func g<each U>(_: repeat each U) {
365365
print((repeat (each T).self))

0 commit comments

Comments
 (0)