Skip to content

Commit 0cd644d

Browse files
committed
[SE-0111] Suppress the printing of argument labels in function types.
Argument labels still persist on the function types of declarations, so suppress them entirely when printing function types.
1 parent 8cfbdec commit 0cd644d

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3821,14 +3821,28 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
38213821

38223822
printFunctionExtInfo(T->getExtInfo());
38233823

3824+
// If we're stripping argument labels from types, do it when printing.
3825+
Type inputType = T->getInput();
3826+
if (inputType->getASTContext().LangOpts.SuppressArgumentLabelsInTypes) {
3827+
if (auto tupleTy = dyn_cast<TupleType>(inputType.getPointer())) {
3828+
SmallVector<TupleTypeElt, 4> elements;
3829+
elements.reserve(tupleTy->getNumElements());
3830+
for (const auto &elt : tupleTy->getElements()) {
3831+
elements.push_back(TupleTypeElt(elt.getType(), Identifier(),
3832+
elt.isVararg()));
3833+
}
3834+
inputType = TupleType::get(elements, inputType->getASTContext());
3835+
}
3836+
}
3837+
38243838
bool needsParens =
3825-
!isa<ParenType>(T->getInput().getPointer()) &&
3826-
!T->getInput()->is<TupleType>();
3839+
!isa<ParenType>(inputType.getPointer()) &&
3840+
!inputType->is<TupleType>();
38273841

38283842
if (needsParens)
38293843
Printer << "(";
38303844

3831-
visit(T->getInput());
3845+
visit(inputType);
38323846

38333847
if (needsParens)
38343848
Printer << ")";

test/SILGen/argument_labels.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend -emit-silgen -suppress-argument-labels-in-types %s | FileCheck %s
2+
3+
public struct X { }
4+
public struct Y { }
5+
6+
public class Foo {
7+
func doSomething(x: X, y: Y) { }
8+
func doSomethingElse(x: X) { }
9+
}
10+
11+
// CHECK-LABEL: sil hidden @_TF15argument_labels7testFoo
12+
func testFoo(foo: Foo, x: X, y: Y) {
13+
// CHECK: class_method %0 : $Foo, #Foo.doSomething!1 : (Foo) -> (X, Y) -> ()
14+
foo.doSomething(x: x, y: y)
15+
16+
// CHECK: class_method %0 : $Foo, #Foo.doSomethingElse!1 : (Foo) -> (X) -> ()
17+
foo.doSomethingElse(x: x)
18+
}
19+

0 commit comments

Comments
 (0)