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

0 commit comments

Comments
 (0)