Skip to content

Commit dde37c0

Browse files
authored
Merge pull request swiftlang#81868 from hamishknight/x-of-hearts
Change InlineArray sugar separator `x` -> `of`
2 parents 5c3faaa + 5d1f219 commit dde37c0

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 () }

0 commit comments

Comments
 (0)