Skip to content

Commit 5d1f219

Browse files
committed
Change InlineArray sugar separator x -> of
1 parent 8ce5f2b commit 5d1f219

17 files changed

+96
-96
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ struct PrintOptions {
601601
bool AlwaysDesugarArraySliceTypes = false;
602602

603603
/// Whether to always desugar inline array types from
604-
/// `[<count> x <element>]` to `InlineArray<count, element>`
604+
/// `[<count> of <element>]` to `InlineArray<count, element>`
605605
bool AlwaysDesugarInlineArrayTypes = false;
606606

607607
/// Whether to always desugar dictionary types

include/swift/AST/TypeRepr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ class ArrayTypeRepr : public TypeRepr {
641641
friend class TypeRepr;
642642
};
643643

644-
/// An InlineArray type e.g `[2 x Foo]`, sugar for `InlineArray<2, Foo>`.
644+
/// An InlineArray type e.g `[2 of Foo]`, sugar for `InlineArray<2, Foo>`.
645645
class InlineArrayTypeRepr : public TypeRepr {
646646
TypeRepr *Count;
647647
TypeRepr *Element;

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6299,7 +6299,7 @@ class ArraySliceType : public UnarySyntaxSugarType {
62996299
}
63006300
};
63016301

6302-
/// An InlineArray type e.g `[2 x Foo]`, sugar for `InlineArray<2, Foo>`.
6302+
/// An InlineArray type e.g `[2 of Foo]`, sugar for `InlineArray<2, Foo>`.
63036303
class InlineArrayType : public SyntaxSugarType {
63046304
Type Count;
63056305
Type Elt;

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ EXPERIMENTAL_FEATURE(CustomAvailability, true)
497497
/// Syntax sugar features for concurrency.
498498
EXPERIMENTAL_FEATURE(ConcurrencySyntaxSugar, true)
499499

500-
/// Enable syntax sugar type '[3 x Int]' for Inline Array
500+
/// Enable syntax sugar type '[3 of Int]' for Inline Array
501501
EXPERIMENTAL_FEATURE(InlineArrayTypeSugar, false)
502502

503503
/// Allow declaration of compile-time values

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7115,7 +7115,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
71157115
} else {
71167116
Printer << "[";
71177117
visit(T->getCountType());
7118-
Printer << " x ";
7118+
Printer << " of ";
71197119
visit(T->getElementType());
71207120
Printer << "]";
71217121
}

lib/AST/TypeRepr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ void InlineArrayTypeRepr::printImpl(ASTPrinter &Printer,
484484
const PrintOptions &Opts) const {
485485
Printer << "[";
486486
printTypeRepr(getCount(), Printer, Opts);
487-
Printer << " x ";
487+
Printer << " of ";
488488
printTypeRepr(getElement(), Printer, Opts);
489489
Printer << "]";
490490
}

lib/Demangling/NodePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3316,7 +3316,7 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
33163316
case Node::Kind::SugaredInlineArray: {
33173317
Printer << "[";
33183318
print(Node->getChild(0), depth + 1);
3319-
Printer << " x ";
3319+
Printer << " of ";
33203320
print(Node->getChild(1), depth + 1);
33213321
Printer << "]";
33223322
return nullptr;

lib/Parse/ParseType.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,13 +1322,13 @@ ParserResult<TypeRepr> Parser::parseTypeInlineArray(SourceLoc lSquare) {
13221322

13231323
ParserStatus status;
13241324

1325-
// 'isStartOfInlineArrayTypeBody' means we should at least have a type and 'x'
1326-
// to start with.
1325+
// 'isStartOfInlineArrayTypeBody' means we should at least have a type and
1326+
// 'of' to start with.
13271327
auto count = parseTypeOrValue();
13281328
auto *countTy = count.get();
13291329
status |= count;
13301330

1331-
// 'x'
1331+
// 'of'
13321332
consumeToken(tok::identifier);
13331333

13341334
// Allow parsing a value for better recovery, Sema will diagnose any
@@ -1827,16 +1827,16 @@ bool Parser::canParseStartOfInlineArrayType() {
18271827
if (!Context.LangOpts.hasFeature(Feature::InlineArrayTypeSugar))
18281828
return false;
18291829

1830-
// We must have at least '[<type> x', which cannot be any other kind of
1830+
// We must have at least '[<type> of', which cannot be any other kind of
18311831
// expression or type. We specifically look for any type, not just integers
1832-
// for better recovery in e.g cases where the user writes '[Int x 2]'. We
1833-
// only do type-scalar since variadics would be ambiguous e.g 'Int...x'.
1832+
// for better recovery in e.g cases where the user writes '[Int of 2]'. We
1833+
// only do type-scalar since variadics would be ambiguous e.g 'Int...of'.
18341834
if (!canParseTypeScalar())
18351835
return false;
18361836

18371837
// For now we don't allow multi-line since that would require
18381838
// disambiguation.
1839-
if (Tok.isAtStartOfLine() || !Tok.isContextualKeyword("x"))
1839+
if (Tok.isAtStartOfLine() || !Tok.isContextualKeyword("of"))
18401840
return false;
18411841

18421842
consumeToken();

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5379,7 +5379,7 @@ TypeResolver::resolveInlineArrayType(InlineArrayTypeRepr *repr,
53795379
auto argOptions = options.withoutContext().withContext(
53805380
TypeResolverContext::ValueGenericArgument);
53815381

5382-
// It's possible the user accidentally wrote '[Int x 4]', correct that here.
5382+
// It's possible the user accidentally wrote '[Int of 4]', correct that here.
53835383
auto *countRepr = repr->getCount();
53845384
auto *eltRepr = repr->getElement();
53855385
if (!isa<IntegerTypeRepr>(countRepr) && isa<IntegerTypeRepr>(eltRepr)) {

test/ASTGen/types.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ let optionalIntArray: Array<_> = [42]
8484

8585
@available(SwiftStdlib 9999, *)
8686
func testInlineArray() {
87-
let _: [3 x Int] = [1, 2, 3]
88-
let _: [_ x _] = [1, 2]
89-
let _ = [3 x Int](repeating: 0)
90-
let _ = [3 x _](repeating: 0)
87+
let _: [3 of Int] = [1, 2, 3]
88+
let _: [_ of _] = [1, 2]
89+
let _ = [3 of Int](repeating: 0)
90+
let _ = [3 of _](repeating: 0)
9191
}
9292

9393
func testNamedOpaqueReturnTy() -> <T> T { return () }

test/DebugInfo/sugar_inline_array.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
// REQUIRES: swift_feature_InlineArrayTypeSugar
44

5-
let a: ([3 x Int], InlineArray<3, Int>) = ([1, 2, 3], [1, 2, 3])
6-
let b: ([3 x [1 x String]], InlineArray<3, InlineArray<1, String>>) = ([[""], [""], [""]], [[""], [""], [""]])
5+
let a: ([3 of Int], InlineArray<3, Int>) = ([1, 2, 3], [1, 2, 3])
6+
let b: ([3 of [1 of String]], InlineArray<3, InlineArray<1, String>>) = ([[""], [""], [""]], [[""], [""], [""]])
77

88
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$s$2_SiXSA_s11InlineArrayVy$2_SiGtD", {{.*}})
99
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$s$2_$0_SSXSAXSA_s11InlineArrayVy$2_ABy$0_SSGGtD", {{.*}})
1010

1111
// RUN: swift-demangle 's$2_SiXSA_s11InlineArrayVy$2_SiGtD' | %FileCheck %s --check-prefix SIMPLE
12-
// SIMPLE: ([3 x Swift.Int], Swift.InlineArray<3, Swift.Int>)
12+
// SIMPLE: ([3 of Swift.Int], Swift.InlineArray<3, Swift.Int>)
1313

1414
// RUN: swift-demangle 's$2_$0_SSXSAXSA_s11InlineArrayVy$2_ABy$0_SSGGtD' | %FileCheck %s --check-prefix NESTED
15-
// NESTED: ([3 x [1 x Swift.String]], Swift.InlineArray<3, Swift.InlineArray<1, Swift.String>>)
15+
// NESTED: ([3 of [1 of Swift.String]], Swift.InlineArray<3, Swift.InlineArray<1, Swift.String>>)

test/IDE/complete_inline_array.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
struct FooBar {}
66

7-
[3 x #^COMPLETE_TOPLEVEL?check=COMPLETE^#
8-
let _: [3 x #^COMPLETE_TYPE?check=COMPLETE^#
7+
[3 of #^COMPLETE_TOPLEVEL?check=COMPLETE^#
8+
let _: [3 of #^COMPLETE_TYPE?check=COMPLETE^#
99
// COMPLETE: Decl[Struct]/CurrModule: FooBar[#FooBar#]; name=FooBar

test/Sema/inline_array_availability.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ func foo(x: InlineArray<3, Int>) {}
77
// expected-error@-1 {{'InlineArray' is only available in}}
88
// expected-note@-2 {{add '@available' attribute to enclosing global function}}
99

10-
func bar(x: [3 x Int]) {}
10+
func bar(x: [3 of Int]) {}
1111
// expected-error@-1 {{'InlineArray' is only available in}}
1212
// expected-note@-2 {{add '@available' attribute to enclosing global function}}
1313

1414
@available(SwiftStdlib 9999, *)
1515
func baz(x: InlineArray<3, Int>) {}
1616

1717
@available(SwiftStdlib 9999, *)
18-
func qux(x: [3 x Int]) {}
18+
func qux(x: [3 of Int]) {}

test/Sema/inlinearray.swift

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ let f: InlineArray<_, Int> = ["hello"] // expected-error {{cannot convert value
1313

1414
let g: InlineArray<1, 1> // expected-error {{cannot use value type '1' for generic argument 'Element'}}
1515

16-
let _: [3 x Int] = [1, 2, 3] // Ok, InlineArray<3, Int>
17-
let _: [_ x Int] = [1, 2, 3] // Ok, InlineArray<3, Int>
18-
let _: [3 x _] = [1, 2, 3] // Ok, InlineArray<3, Int>
19-
let _: [_ x _] = ["", "", ""] // Ok, InlineArray<3, String>
16+
let _: [3 of Int] = [1, 2, 3] // Ok, InlineArray<3, Int>
17+
let _: [_ of Int] = [1, 2, 3] // Ok, InlineArray<3, Int>
18+
let _: [3 of _] = [1, 2, 3] // Ok, InlineArray<3, Int>
19+
let _: [_ of _] = ["", "", ""] // Ok, InlineArray<3, String>
2020

21-
let _: [3 x [3 x Int]] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
22-
let _: [3 x [3 x Int]] = [[1, 2], [3, 4, 5, 6]]
21+
let _: [3 of [3 of Int]] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
22+
let _: [3 of [3 of Int]] = [[1, 2], [3, 4, 5, 6]]
2323
// expected-error@-1 {{'3' elements in inline array literal, but got '2'}}
24-
// expected-error@-2 2{{cannot convert value of type '[Int]' to expected element type '[3 x Int]'}}
24+
// expected-error@-2 2{{cannot convert value of type '[Int]' to expected element type '[3 of Int]'}}
2525

26-
let _ = [3 x [3 x Int]](repeating: [1, 2]) // expected-error {{expected '3' elements in inline array literal, but got '2'}}
27-
let _ = [3 x [_ x Int]](repeating: [1, 2])
26+
let _ = [3 of [3 of Int]](repeating: [1, 2]) // expected-error {{expected '3' elements in inline array literal, but got '2'}}
27+
let _ = [3 of [_ of Int]](repeating: [1, 2])
2828

29-
let _: [Int x 10] = [1, 2] // expected-error {{element count must precede inline array element type}} {{15-17=Int}} {{9-12=10}}
29+
let _: [Int of 10] = [1, 2] // expected-error {{element count must precede inline array element type}} {{16-18=Int}} {{9-12=10}}
3030
// expected-error@-1 {{expected '10' elements in inline array literal, but got '2'}}
3131

32-
let _: [4 x _] = [1, 2, 3] // expected-error {{expected '4' elements in inline array literal, but got '3'}}
33-
let _: [3 x Int] = [1, 2, 3, 4] // expected-error {{expected '3' elements in inline array literal, but got '4'}}
34-
let _: [3 x String] = [1, 2, 3] // expected-error 3{{cannot convert value of type 'Int' to expected element type 'String'}}
35-
let _: [3 x String] = [1] // expected-error {{cannot convert value of type 'Int' to expected element type 'String'}}
32+
let _: [4 of _] = [1, 2, 3] // expected-error {{expected '4' elements in inline array literal, but got '3'}}
33+
let _: [3 of Int] = [1, 2, 3, 4] // expected-error {{expected '3' elements in inline array literal, but got '4'}}
34+
let _: [3 of String] = [1, 2, 3] // expected-error 3{{cannot convert value of type 'Int' to expected element type 'String'}}
35+
let _: [3 of String] = [1] // expected-error {{cannot convert value of type 'Int' to expected element type 'String'}}
3636
// expected-error@-1 {{expected '3' elements in inline array literal, but got '1'}}
3737

3838
func takeVectorOf2<T>(_: InlineArray<2, T>) {}
@@ -63,10 +63,10 @@ takeVectorOf2Int(["hello", "world"]) // expected-error {{cannot convert value of
6363

6464
takeVectorOf2Int(["hello", "world", "!"]) // expected-error {{cannot convert value of type '[String]' to expected argument type 'InlineArray<2, Int>'}}
6565

66-
func takeSugarVectorOf2<T>(_: [2 x T], ty: T.Type = T.self) {}
66+
func takeSugarVectorOf2<T>(_: [2 of T], ty: T.Type = T.self) {}
6767
takeSugarVectorOf2([1, 2])
6868
takeSugarVectorOf2(["hello"]) // expected-error {{expected '2' elements in inline array literal, but got '1'}}
69-
takeSugarVectorOf2(["hello"], ty: Int.self) // expected-error {{cannot convert value of type '[String]' to expected argument type '[2 x Int]'}}
69+
takeSugarVectorOf2(["hello"], ty: Int.self) // expected-error {{cannot convert value of type '[String]' to expected argument type '[2 of Int]'}}
7070
takeSugarVectorOf2(["hello", "hi"], ty: Int.self) // expected-error 2{{cannot convert value of type 'String' to expected element type 'Int'}}
7171

7272

@@ -112,15 +112,15 @@ extension InlineArray where Element: ~Copyable {
112112
}
113113
}
114114

115-
extension [3 x Int] { // expected-note 2{{where 'count' = '2'}} expected-note {{where 'Element' = 'String'}}
115+
extension [3 of Int] { // expected-note 2{{where 'count' = '2'}} expected-note {{where 'Element' = 'String'}}
116116
func methodOnSugar() {}
117117
}
118118

119119
func testExtension(
120-
_ a: [3 x Int],
120+
_ a: [3 of Int],
121121
_ b: InlineArray<3, Int>,
122-
_ c: [2 x Int],
123-
_ d: [2 x String]
122+
_ c: [2 of Int],
123+
_ d: [2 of String]
124124
) {
125125
a.enumerated { _, _ in }
126126
a.methodOnSugar()
@@ -133,24 +133,24 @@ func testExtension(
133133
}
134134

135135
func redecl(_ x: InlineArray<2, Int>) {} // expected-note {{'redecl' previously declared here}}
136-
func redecl(_ x: [2 x Int]) {} // expected-error {{invalid redeclaration of 'redecl'}}
136+
func redecl(_ x: [2 of Int]) {} // expected-error {{invalid redeclaration of 'redecl'}}
137137

138138
func noRedecl(_ x: InlineArray<2, Int>) {}
139-
func noRedecl(_ x: [3 x Int]) {}
140-
func noRedecl(_ x: [2 x String]) {}
141-
func noRedecl(_ x: [3 x String]) {}
139+
func noRedecl(_ x: [3 of Int]) {}
140+
func noRedecl(_ x: [2 of String]) {}
141+
func noRedecl(_ x: [3 of String]) {}
142142

143-
func testMismatches(_ x: [3 x Int], _ y: InlineArray<3, Int>) {
143+
func testMismatches(_ x: [3 of Int], _ y: InlineArray<3, Int>) {
144144
let _: InlineArray<3, Int> = x
145-
let _: InlineArray<4, Int> = x // expected-error {{cannot assign value of type '[3 x Int]' to type 'InlineArray<4, Int>'}}
145+
let _: InlineArray<4, Int> = x // expected-error {{cannot assign value of type '[3 of Int]' to type 'InlineArray<4, Int>'}}
146146
// expected-note@-1 {{arguments to generic parameter 'count' ('3' and '4') are expected to be equal}}
147-
let _: InlineArray<3, String> = x // expected-error {{cannot assign value of type '[3 x Int]' to type 'InlineArray<3, String>'}}
147+
let _: InlineArray<3, String> = x // expected-error {{cannot assign value of type '[3 of Int]' to type 'InlineArray<3, String>'}}
148148
// expected-note@-1 {{arguments to generic parameter 'Element' ('Int' and 'String') are expected to be equal}}
149149

150-
let _: [3 x Int] = y
151-
let _: [4 x Int] = y // expected-error {{cannot assign value of type 'InlineArray<3, Int>' to type '[4 x Int]'}}
150+
let _: [3 of Int] = y
151+
let _: [4 of Int] = y // expected-error {{cannot assign value of type 'InlineArray<3, Int>' to type '[4 of Int]'}}
152152
// expected-note@-1 {{arguments to generic parameter 'count' ('3' and '4') are expected to be equal}}
153-
let _: [3 x String] = y // expected-error {{cannot assign value of type 'InlineArray<3, Int>' to type '[3 x String]'}}
153+
let _: [3 of String] = y // expected-error {{cannot assign value of type 'InlineArray<3, Int>' to type '[3 of String]'}}
154154
// expected-note@-1 {{arguments to generic parameter 'Element' ('Int' and 'String') are expected to be equal}}
155155
}
156156

test/Serialization/value_generics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ extension Vector where Count == 2 {
2222
// CHECK: func something<let N : Int>(_: borrowing Vector<Int, N>)
2323
func something<let N: Int>(_: borrowing Vector<Int, N>) {}
2424

25-
// CHECK: func hello(_: [4 x Int])
26-
func hello(_: [4 x Int]) {}
25+
// CHECK: func hello(_: [4 of Int])
26+
func hello(_: [4 of Int]) {}

0 commit comments

Comments
 (0)