@@ -26,13 +26,14 @@ using namespace swift;
2626// 〚`name: T` (atom)〛 ==> .atom, `name`, '\0'
2727// 〚`[T]`〛 ==> 〚`T`〛, .formArray
2828// 〚`T?`〛 ==> 〚`T`〛, .formOptional
29+ // 〚`(T0, T1, ...)` (top level)〛 ==> 〚`T0`〛, 〚`T1`〛, ...
2930// 〚`(T0, T1, ...)`〛 ==> .beginTuple, 〚`T0`〛, 〚`T1`〛, ..., .endTuple
3031//
3132// For details, see apple/swift-experimental-string-processing.
3233bool swift::decodeRegexCaptureTypes (ASTContext &ctx,
3334 ArrayRef<uint8_t > serialization,
3435 Type atomType,
35- SmallVectorImpl<TupleTypeElt > &result) {
36+ SmallVectorImpl<Type > &result) {
3637 using Version = RegexLiteralExpr::CaptureStructureSerializationVersion;
3738 static const Version implVersion = 1 ;
3839 unsigned size = serialization.size ();
@@ -45,7 +46,7 @@ bool swift::decodeRegexCaptureTypes(ASTContext &ctx,
4546 if (version != implVersion)
4647 return true ;
4748 // Read contents.
48- SmallVector<SmallVector<TupleTypeElt , 4 >, 4 > scopes (1 );
49+ SmallVector<SmallVector<Type , 4 >, 4 > scopes (1 );
4950 unsigned offset = sizeof (Version);
5051 auto consumeCode = [&]() -> Optional<RegexCaptureStructureCode> {
5152 auto rawValue = serialization[offset];
@@ -72,26 +73,34 @@ bool swift::decodeRegexCaptureTypes(ASTContext &ctx,
7273 if (length >= size - offset)
7374 return true ; // Unterminated string.
7475 StringRef name (namePtr, length);
75- scopes.back ().push_back (TupleTypeElt (atomType, ctx.getIdentifier (name)));
76+ // The name is currently unused becuase we are forming a nominal
77+ // `Tuple{n}` type. We will switch back to native tuples when there is
78+ // variadic generics.
79+ (void )name;
80+ scopes.back ().push_back (atomType);
7681 offset += length + /* NUL*/ 1 ;
7782 break ;
7883 }
7984 case RegexCaptureStructureCode::FormArray: {
8085 auto &type = scopes.back ().back ();
81- type = TupleTypeElt ( ArraySliceType::get (type. getRawType ()) );
86+ type = ArraySliceType::get (type);
8287 break ;
8388 }
8489 case RegexCaptureStructureCode::FormOptional: {
8590 auto &type = scopes.back ().back ();
86- type = TupleTypeElt ( OptionalType::get (type. getRawType ()) );
91+ type = OptionalType::get (type);
8792 break ;
8893 }
8994 case RegexCaptureStructureCode::BeginTuple:
9095 scopes.push_back ({});
9196 break ;
9297 case RegexCaptureStructureCode::EndTuple: {
9398 auto children = scopes.pop_back_val ();
94- scopes.back ().push_back (TupleType::get (children, ctx));
99+ if (children.size () > ctx.getStringProcessingTupleDeclMaxArity ())
100+ return true ;
101+ auto tupleDecl = ctx.getStringProcessingTupleDecl (children.size ());
102+ auto type = BoundGenericStructType::get (tupleDecl, Type (), children);
103+ scopes.back ().push_back (type);
95104 break ;
96105 }
97106 case RegexCaptureStructureCode::CaseCount:
0 commit comments