Swift: extract parameter packs

This commit is contained in:
Alex Denisov
2023-11-09 14:31:13 +01:00
parent b611e7cebf
commit e865c3cbd3
79 changed files with 1551 additions and 41 deletions

View File

@@ -1190,11 +1190,58 @@ class OpaqueTypeArchetypeType(ArchetypeType):
See https://docs.swift.org/swift-book/LanguageGuide/OpaqueTypes.html."""
declaration: OpaqueTypeDecl
class OpenedArchetypeType(ArchetypeType):
pass
class PrimaryArchetypeType(ArchetypeType):
pass
class LocalArchetypeType(ArchetypeType):
pass
class OpenedArchetypeType(LocalArchetypeType):
pass
class ElementArchetypeType(LocalArchetypeType):
"""
An archetype type of PackElementType.
"""
pass
@qltest.test_with("PackType")
class PackArchetypeType(ArchetypeType):
"""
An archetype type of PackType.
"""
pass
class PackType(Type):
"""
An actual type of a pack expression at the instatiation point.
In the following example, PackType will appear around `makeTuple` call site as `Pack{String, Int}`:
```
func makeTuple<each T>(_ t: repeat each T) -> (repeat each T) { ... }
makeTuple("A", 2)
```
More details:
https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md
"""
elements: list[Type]
@qltest.test_with(PackType)
class PackExpansionType(Type):
"""
A type of PackExpansionExpr, see PackExpansionExpr for more information.
"""
pattern_type: Type
count_type: Type
@qltest.test_with(PackType)
class PackElementType(Type):
"""
A type of PackElementExpr, see PackElementExpr for more information.
"""
pack_type: Type
class UnarySyntaxSugarType(SyntaxSugarType):
base_type: Type
@@ -1246,3 +1293,36 @@ class SingleValueStmtExpr(Expr):
An expression that wraps a statement which produces a single value.
"""
stmt: Stmt | child
class PackExpansionExpr(Expr):
"""
A pack expansion expression.
In the following example, `repeat each t` on the second line is the pack expansion expression:
```
func makeTuple<each T>(_ t: repeat each T) -> (repeat each T) {
return (repeat each t)
}
```
More details:
https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md
"""
pattern_expr: Expr | child
@qltest.test_with(PackExpansionExpr)
class PackElementExpr(Expr):
"""
A pack element expression is a child of PackExpansionExpr.
In the following example, `each t` on the second line is the pack element expression:
```
func makeTuple<each T>(_ t: repeat each T) -> (repeat each T) {
return (repeat each t)
}
```
More details:
https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md
"""
sub_expr: Expr | child