diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 8e76b7c63460a..5c40e4118fcbd 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -5387,9 +5387,8 @@ ERROR(invalid_expansion_argument,none, ERROR(expansion_not_variadic,none, "pack expansion %0 must contain at least one pack reference", (Type)) ERROR(pack_reference_outside_expansion,none, - "pack reference %0 can only appear in pack expansion " - "%select{or generic requirement|}1", - (Type, /*inExpression*/ bool)) + "pack reference %0 can only appear in pack expansion ", + (Type)) ERROR(each_non_pack,none, "'each' cannot be applied to non-pack type %0", (Type)) diff --git a/include/swift/AST/GenericParamList.h b/include/swift/AST/GenericParamList.h index 48a529101cacb..fc3ebe33941cf 100644 --- a/include/swift/AST/GenericParamList.h +++ b/include/swift/AST/GenericParamList.h @@ -58,6 +58,7 @@ class RequirementRepr { SourceLoc SeparatorLoc; RequirementReprKind Kind : 2; bool Invalid : 1; + bool IsExpansionPattern : 1; TypeRepr *FirstType; /// The second element represents the right-hand side of the constraint. @@ -72,13 +73,17 @@ class RequirementRepr { StringRef AsWrittenString; RequirementRepr(SourceLoc SeparatorLoc, RequirementReprKind Kind, - TypeRepr *FirstType, TypeRepr *SecondType) + TypeRepr *FirstType, TypeRepr *SecondType, + bool IsExpansionPattern) : SeparatorLoc(SeparatorLoc), Kind(Kind), Invalid(false), + IsExpansionPattern(IsExpansionPattern), FirstType(FirstType), SecondType(SecondType) { } RequirementRepr(SourceLoc SeparatorLoc, RequirementReprKind Kind, - TypeRepr *FirstType, LayoutConstraintLoc SecondLayout) + TypeRepr *FirstType, LayoutConstraintLoc SecondLayout, + bool IsExpansionPattern) : SeparatorLoc(SeparatorLoc), Kind(Kind), Invalid(false), + IsExpansionPattern(IsExpansionPattern), FirstType(FirstType), SecondLayout(SecondLayout) { } public: @@ -92,8 +97,10 @@ class RequirementRepr { /// subject must conform, or superclass from which the subject must inherit. static RequirementRepr getTypeConstraint(TypeRepr *Subject, SourceLoc ColonLoc, - TypeRepr *Constraint) { - return { ColonLoc, RequirementReprKind::TypeConstraint, Subject, Constraint }; + TypeRepr *Constraint, + bool IsExpansionPattern) { + return { ColonLoc, RequirementReprKind::TypeConstraint, Subject, Constraint, + IsExpansionPattern }; } /// Construct a new same-type requirement. @@ -104,8 +111,10 @@ class RequirementRepr { /// \param SecondType The second type. static RequirementRepr getSameType(TypeRepr *FirstType, SourceLoc EqualLoc, - TypeRepr *SecondType) { - return { EqualLoc, RequirementReprKind::SameType, FirstType, SecondType }; + TypeRepr *SecondType, + bool IsExpansionPattern) { + return { EqualLoc, RequirementReprKind::SameType, FirstType, SecondType, + IsExpansionPattern }; } /// Construct a new layout-constraint requirement. @@ -118,9 +127,10 @@ class RequirementRepr { /// subject must conform. static RequirementRepr getLayoutConstraint(TypeRepr *Subject, SourceLoc ColonLoc, - LayoutConstraintLoc Layout) { + LayoutConstraintLoc Layout, + bool IsExpansionPattern) { return {ColonLoc, RequirementReprKind::LayoutConstraint, Subject, - Layout}; + Layout, IsExpansionPattern}; } /// Determine the kind of requirement @@ -129,6 +139,12 @@ class RequirementRepr { /// Determine whether this requirement is invalid. bool isInvalid() const { return Invalid; } + /// Whether this requirement repr is the pattern of a requirement + /// expansion, e.g. `repeat G == (each U).A` + bool isExpansionPattern() const { + return IsExpansionPattern; + } + /// Mark this requirement invalid. void setInvalid() { Invalid = true; } diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 6e6104071ba3e..fa432eefbe007 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -1842,16 +1842,23 @@ void PrintAST::printRequirement(const Requirement &req) { Printer << ")) : Any"; return; case RequirementKind::Layout: + if (req.getFirstType()->hasParameterPack()) + Printer << "repeat "; printTransformedType(req.getFirstType()); Printer << " : "; req.getLayoutConstraint()->print(Printer, Options); return; case RequirementKind::Conformance: case RequirementKind::Superclass: + if (req.getFirstType()->hasParameterPack()) + Printer << "repeat "; printTransformedType(req.getFirstType()); Printer << " : "; break; case RequirementKind::SameType: + if (req.getFirstType()->hasParameterPack() || + req.getSecondType()->hasParameterPack()) + Printer << "repeat "; printTransformedType(req.getFirstType()); Printer << " == "; break; diff --git a/lib/AST/CASTBridging.cpp b/lib/AST/CASTBridging.cpp index f92eb505bbf7e..e9ad486caecc6 100644 --- a/lib/AST/CASTBridging.cpp +++ b/lib/AST/CASTBridging.cpp @@ -559,12 +559,12 @@ void *GenericParamList_create(void *ctx, void *lAngleLoc, case BridgedRequirementReprKindTypeConstraint: requirements.push_back(RequirementRepr::getTypeConstraint( (TypeRepr *)req.FirstType, getSourceLocFromPointer(req.SeparatorLoc), - (TypeRepr *)req.SecondType)); + (TypeRepr *)req.SecondType, /*isExpansionPattern*/false)); break; case BridgedRequirementReprKindSameType: requirements.push_back(RequirementRepr::getSameType( (TypeRepr *)req.FirstType, getSourceLocFromPointer(req.SeparatorLoc), - (TypeRepr *)req.SecondType)); + (TypeRepr *)req.SecondType, /*isExpansionPattern*/false)); break; case BridgedRequirementReprKindLayoutConstraint: llvm_unreachable("cannot handle layout constraints!"); diff --git a/lib/Parse/ParseGeneric.cpp b/lib/Parse/ParseGeneric.cpp index 80fb939af5d3e..779772bbdb31b 100644 --- a/lib/Parse/ParseGeneric.cpp +++ b/lib/Parse/ParseGeneric.cpp @@ -288,6 +288,13 @@ ParserStatus Parser::parseGenericWhereClause( break; } + // Parse the 'repeat' keyword for requirement expansions. + bool isRequirementExpansion = false; + if (Tok.is(tok::kw_repeat)) { + consumeToken(); + isRequirementExpansion = true; + } + // Parse the leading type. It doesn't necessarily have to be just a type // identifier if we're dealing with a same-type constraint. ParserResult FirstType = parseType(); @@ -326,7 +333,8 @@ ParserStatus Parser::parseGenericWhereClause( // Add the layout requirement. Requirements.push_back(RequirementRepr::getLayoutConstraint( FirstType.get(), ColonLoc, - LayoutConstraintLoc(Layout, LayoutLoc))); + LayoutConstraintLoc(Layout, LayoutLoc), + isRequirementExpansion)); } } else { // Parse the protocol or composition. @@ -337,7 +345,7 @@ ParserStatus Parser::parseGenericWhereClause( // Add the requirement. Requirements.push_back(RequirementRepr::getTypeConstraint( - FirstType.get(), ColonLoc, Protocol.get())); + FirstType.get(), ColonLoc, Protocol.get(), isRequirementExpansion)); } } else if ((Tok.isAnyOperator() && Tok.getText() == "==") || Tok.is(tok::equal)) { @@ -367,15 +375,18 @@ ParserStatus Parser::parseGenericWhereClause( // completion token in the TypeRepr. Requirements.push_back(RequirementRepr::getTypeConstraint( FirstType.get(), EqualLoc, - new (Context) ErrorTypeRepr(SecondType.get()->getLoc()))); + new (Context) ErrorTypeRepr(SecondType.get()->getLoc()), + isRequirementExpansion)); } else { Requirements.push_back(RequirementRepr::getSameType( - FirstType.get(), EqualLoc, SecondType.get())); + FirstType.get(), EqualLoc, SecondType.get(), + isRequirementExpansion)); } } else if (FirstType.hasCodeCompletion()) { // Recover by adding dummy constraint. Requirements.push_back(RequirementRepr::getTypeConstraint( - FirstType.get(), PreviousLoc, new (Context) ErrorTypeRepr(PreviousLoc))); + FirstType.get(), PreviousLoc, new (Context) ErrorTypeRepr(PreviousLoc), + isRequirementExpansion)); } else { diagnose(Tok, diag::expected_requirement_delim); Status.setIsParseError(); diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 2f6112766a0c1..aabf2ec54e560 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -6043,7 +6043,7 @@ bool InvalidPackElement::diagnoseAsError() { bool InvalidPackReference::diagnoseAsError() { emitDiagnostic(diag::pack_reference_outside_expansion, - packType, /*inExpression*/true); + packType); return true; } diff --git a/lib/Sema/TypeCheckGeneric.cpp b/lib/Sema/TypeCheckGeneric.cpp index b64235f6fdacf..dd7ccfbd75551 100644 --- a/lib/Sema/TypeCheckGeneric.cpp +++ b/lib/Sema/TypeCheckGeneric.cpp @@ -1028,7 +1028,8 @@ RequirementRequest::evaluate(Evaluator &evaluator, context = TypeResolverContext::GenericRequirement; } auto options = TypeResolutionOptions(context); - options |= TypeResolutionFlags::AllowPackReferences; + if (reqRepr.isExpansionPattern()) + options |= TypeResolutionFlags::AllowPackReferences; if (owner.dc->isInSpecializeExtensionContext()) options |= TypeResolutionFlags::AllowUsableFromInline; Optional resolution; diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index 375367216644c..b0b32b4443e10 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -4637,7 +4637,7 @@ NeverNullType TypeResolver::resolvePackElement(PackElementTypeRepr *repr, if (!options.contains(TypeResolutionFlags::AllowPackReferences)) { ctx.Diags.diagnose(repr->getLoc(), diag::pack_reference_outside_expansion, - packReference, /*inExpression*/false); + packReference); return ErrorType::get(ctx); } diff --git a/test/Constraints/pack-expansion-expressions.swift b/test/Constraints/pack-expansion-expressions.swift index f15f73ecfe6b2..2dcbeed11a5fe 100644 --- a/test/Constraints/pack-expansion-expressions.swift +++ b/test/Constraints/pack-expansion-expressions.swift @@ -52,11 +52,11 @@ protocol P { func f(_ self: Self) -> Self } -func outerArchetype(t: repeat each T, u: U) where each T: P { +func outerArchetype(t: repeat each T, u: U) where repeat each T: P { let _: (repeat (each T.A, U)) = (repeat ((each t).value, u)) } -func sameElement(t: repeat each T, u: U) where each T: P, each T == U { +func sameElement(t: repeat each T, u: U) where repeat each T: P, repeat each T == U { // expected-error@-1{{same-element requirements are not yet supported}} // FIXME: Opened element archetypes in diagnostics @@ -65,7 +65,7 @@ func sameElement(t: repeat each T, u: U) where each T: P, each T == U } func forEachEach(c: repeat each C, function: (U) -> Void) - where each C: Collection, each C.Element == U { + where repeat each C: Collection, repeat (each C).Element == U { // expected-error@-1{{same-element requirements are not yet supported}} // FIXME: Opened element archetypes in diagnostics @@ -73,7 +73,7 @@ func forEachEach(c: repeat each C, function: (U) -> Void) // expected-error@-1 {{cannot convert value of type '(U) -> Void' to expected argument type '(τ_1_0.Element) throws -> Void'}} } -func typeReprPacks(_ t: repeat each T) where each T: ExpressibleByIntegerLiteral { +func typeReprPacks(_ t: repeat each T) { _ = (repeat Array()) _ = (repeat 1 as each T) diff --git a/test/Constraints/pack_expansion_types.swift b/test/Constraints/pack_expansion_types.swift index 31bc1b78a74f8..581d3ad4bebeb 100644 --- a/test/Constraints/pack_expansion_types.swift +++ b/test/Constraints/pack_expansion_types.swift @@ -264,7 +264,8 @@ func patternInstantiationConcreteInvalid() { let _: (Array, Set) = patternInstantiationTupleTest1() // expected-error {{type of expression is ambiguous without more context}} } -func patternInstantiationGenericValid(t: repeat each T, u: repeat each U) where (repeat (each T, each U)): Any, each T: Hashable { +func patternInstantiationGenericValid(t: repeat each T, u: repeat each U) + where (repeat (each T, each U)): Any, repeat each T: Hashable { let _: (repeat Array) = patternInstantiationTupleTest1() let _: (repeat Array, Array) = patternInstantiationTupleTest1() let _: (Array, repeat Array) = patternInstantiationTupleTest1() @@ -286,7 +287,7 @@ func patternInstantiationGenericValid(t: repeat each T, u: repea let _: (Dictionary, repeat Dictionary, Dictionary) -> () = patternInstantiationFunctionTest2() } -func patternInstantiationGenericInvalid(t: repeat each T) where each T: Hashable { +func patternInstantiationGenericInvalid(t: repeat each T) { let _: (repeat Set) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(repeat Array)' to specified type '(repeat Set)}} // expected-error@-1 {{generic parameter 'T' could not be inferred}} diff --git a/test/Constraints/variadic_generic_constraints.swift b/test/Constraints/variadic_generic_constraints.swift index df193aea4e608..c85ae64a3331a 100644 --- a/test/Constraints/variadic_generic_constraints.swift +++ b/test/Constraints/variadic_generic_constraints.swift @@ -47,9 +47,11 @@ takesAnyObject(C(), S(), C()) // expected-error {{type of expression is ambiguo // Same-type requirements -func takesParallelSequences(t: repeat each T, u: repeat each U) where each T: Sequence, each U: Sequence, each T.Element == each U.Element {} -// expected-note@-1 {{where 'T.Element' = 'String', 'U.Element' = 'Int'}} - +// expected-note@+1 {{where 'T.Element' = 'String', 'U.Element' = 'Int'}} +func takesParallelSequences(t: repeat each T, u: repeat each U) + where repeat each T: Sequence, + repeat each U: Sequence, + repeat (each T).Element == (each U).Element {} takesParallelSequences() // ok takesParallelSequences(t: Array(), u: Set()) // ok takesParallelSequences(t: Array(), Set(), u: Set(), Array()) // ok diff --git a/test/Constraints/variadic_generic_functions.swift b/test/Constraints/variadic_generic_functions.swift index de1441fff09ce..6506c9204ea18 100644 --- a/test/Constraints/variadic_generic_functions.swift +++ b/test/Constraints/variadic_generic_functions.swift @@ -3,7 +3,7 @@ // REQUIRES: asserts func debugPrint(_ items: repeat each T) - where each T: CustomDebugStringConvertible + where repeat each T: CustomDebugStringConvertible { /*for (item: T) in items { stdout.write(item.debugDescription) @@ -11,7 +11,7 @@ func debugPrint(_ items: repeat each T) } func max(_ values: repeat each T) -> (repeat each T)? - where each T: Comparable + where repeat each T: Comparable { return nil } diff --git a/test/Frontend/experimental_feature.swift b/test/Frontend/experimental_feature.swift index a88a3d1e55577..2337a1e3c5b2c 100644 --- a/test/Frontend/experimental_feature.swift +++ b/test/Frontend/experimental_feature.swift @@ -11,6 +11,6 @@ let x = BOOM // Use variadic generics func debugPrint(_ items: repeat each T) - where each T: CustomDebugStringConvertible + where repeat each T: CustomDebugStringConvertible { } diff --git a/test/Generics/pack-shape-requirements.swift b/test/Generics/pack-shape-requirements.swift index e7d2b199c275e..f3067c985cdfb 100644 --- a/test/Generics/pack-shape-requirements.swift +++ b/test/Generics/pack-shape-requirements.swift @@ -12,9 +12,9 @@ func inferSameShape(ts t: repeat each T, us u: repeat each U) wh } // CHECK-LABEL: desugarSameShape(ts:us:) -// CHECK-NEXT: Generic signature: -func desugarSameShape(ts t: repeat each T, us u: repeat each U) where each T: P, each U: P, (repeat (each T.A, each U.A)): Any { -} +// CHECK-NEXT: Generic signature: +func desugarSameShape(ts t: repeat each T, us u: repeat each U) + where repeat each T: P, repeat each U: P, (repeat (each T.A, each U.A)): Any {} // CHECK-LABEL: multipleSameShape1(ts:us:vs:) // CHECK-NEXT: Generic signature: @@ -49,14 +49,14 @@ func multipleSameShape6(ts t: repeat each T, us u: repea struct Ts { struct Us { // CHECK-LABEL: Ts.Us.packEquality() - // CHECK-NEXT: Generic signature: - func packEquality() where each T == each U, (repeat (each T, each U)): Any { + // CHECK-NEXT: Generic signature: + func packEquality() where repeat each T == each U, (repeat (each T, each U)): Any { } struct Vs { // CHECK-LABEL: Ts.Us.Vs.packEquality() - // CHECK-NEXT: Generic signature: - func packEquality() where each T == each U, (repeat (each U, each V)): Any { + // CHECK-NEXT: Generic signature: + func packEquality() where repeat each T == each U, (repeat (each U, each V)): Any { } } } diff --git a/test/Generics/tuple-conformances.swift b/test/Generics/tuple-conformances.swift index 6fdd5fa4c0518..431c2aa6b1513 100644 --- a/test/Generics/tuple-conformances.swift +++ b/test/Generics/tuple-conformances.swift @@ -11,7 +11,7 @@ protocol P { func f() } -extension Builtin.TheTupleType: P where each Elements: P { +extension Builtin.TheTupleType: P where repeat each Elements: P { typealias A = (repeat each Elements.A) typealias B = Float func f() {} diff --git a/test/Generics/variadic_generic_requirements.swift b/test/Generics/variadic_generic_requirements.swift index 52b942b8476ec..dcc79447c2f5d 100644 --- a/test/Generics/variadic_generic_requirements.swift +++ b/test/Generics/variadic_generic_requirements.swift @@ -22,7 +22,7 @@ _ = Layout.self // ok _ = Layout.self // expected-error {{'Layout' requires that 'Int' be a class type}} struct Outer { - struct Inner where each T.Element == each U.Element {} + struct Inner where repeat each T.Element == each U.Element {} // expected-note@-1 {{requirement specified as 'T.Element' == 'U.Element' [with each T = Array, Array; each U = Set, Set]}} // expected-note@-2 {{requirement specified as 'T.Element' == 'U.Element' [with each T = Array; each U = Set, Set]}} @@ -36,4 +36,4 @@ _ = Outer, Array>.Inner, Set>.self // expec _ = Outer>.Inner, Set>.self // expected-error {{'Outer>.Inner' requires the types 'Pack{Int}' and 'Pack{Int, String}' be equivalent}} _ = Outer, Array>.InnerShape, Set>.self // ok -_ = Outer>.InnerShape, Set>.self // expected-error {{'Outer>.InnerShape' requires the type packs 'Pack{Array}' and 'Pack{Set, Set}' have the same shape}} \ No newline at end of file +_ = Outer>.InnerShape, Set>.self // expected-error {{'Outer>.InnerShape' requires the type packs 'Pack{Array}' and 'Pack{Set, Set}' have the same shape}} diff --git a/test/IRGen/run_variadic_generics.sil b/test/IRGen/run_variadic_generics.sil index f524aabed6836..7d28724fc68ca 100644 --- a/test/IRGen/run_variadic_generics.sil +++ b/test/IRGen/run_variadic_generics.sil @@ -626,7 +626,7 @@ entry(%intIndex : $Builtin.Word): return %t : $() } -sil @unwrap_from_PA : $ (Builtin.Word) -> () { +sil @unwrap_from_PA : $ (Builtin.Word) -> () { entry(%intIndex : $Builtin.Word): %direct_access_from_parameter_with_conformance = function_ref @direct_access_from_parameter_with_conformance : $@convention(thin) (Builtin.Word) -> () apply %direct_access_from_parameter_with_conformance}>(%intIndex) : $@convention(thin) (Builtin.Word) -> () @@ -637,7 +637,7 @@ entry(%intIndex : $Builtin.Word): sil @extract_associatedtype_with_conformance : $ (Builtin.Word) -> () { entry(%intIndex : $Builtin.Word): %innerIndex = dynamic_pack_index %intIndex of $Pack{repeat each T_1} - %token = open_pack_element %innerIndex of at >}>, shape $U_1, uuid "01234567-89AB-CDEF-0123-000000000005" + %token = open_pack_element %innerIndex of at >}>, shape $U_1, uuid "01234567-89AB-CDEF-0123-000000000005" %metatype_1 = metatype $@thick (@pack_element("01234567-89AB-CDEF-0123-000000000005") U_1).Type %printGenericType = function_ref @printGenericType : $@convention(thin) (@thick T.Type) -> () apply %printGenericType<(@pack_element("01234567-89AB-CDEF-0123-000000000005") U_1)>(%metatype_1) : $@convention(thin) (@thick T.Type) -> () @@ -653,7 +653,7 @@ sil @extract_associatedtype_with_conformance2 : $>>>, repeat GenAssocPA>>>} %token = open_pack_element %innerIndex - of + of at < Pack{repeat GenAssocPA>>>, repeat GenAssocPA>>>}, GenAssocPA>>>, diff --git a/test/IRGen/variadic_generic_captures.swift b/test/IRGen/variadic_generic_captures.swift index 8e1a0dac968d7..74cfd368b1a3b 100644 --- a/test/IRGen/variadic_generic_captures.swift +++ b/test/IRGen/variadic_generic_captures.swift @@ -82,6 +82,6 @@ public func has_witness_table_pack(t: repeat each T) -> () -> } public func has_witness_table_pack2(t: repeat each T) -> () -> () - where each T.Element: Sequence { + where repeat each T.Element: Sequence { return { _ = (repeat (each T).Element.Element).self } } diff --git a/test/IRGen/variadic_generic_functions.sil b/test/IRGen/variadic_generic_functions.sil index e62c4f01e53f0..1ae95c2db8d5b 100644 --- a/test/IRGen/variadic_generic_functions.sil +++ b/test/IRGen/variadic_generic_functions.sil @@ -76,14 +76,14 @@ sil @fc : $ () -> () {} // CHECK-SAME: i8*** %T.PA, // CHECK-SAME: i8*** %T.A.P) // CHECK: call swiftcc void @f1c([[INT]] %0, %swift.type** %T, i8*** %T.PA, i8*** %T.A.P) -sil @f1 : $ () -> () { - %f1c = function_ref @f1c : $@convention(thin) () -> () - apply %f1c() : $@convention(thin) () -> () +sil @f1 : $ () -> () { + %f1c = function_ref @f1c : $@convention(thin) () -> () + apply %f1c() : $@convention(thin) () -> () %ret = tuple () return %ret : $() } -sil @f1c : $ () -> () {} +sil @f1c : $ () -> () {} // Construct associatedtype metadata pack, forward root wtable pack. // CHECK-LABEL: define {{.*}}@associatedtype_with_added_conformance( @@ -96,7 +96,7 @@ sil @f1c : $ () -> () {} // CHECK-SAME: [[INT]] [[SHAPE]], // CHECK-SAME: %swift.type** [[ASSOCIATEDTYPES]], // CHECK-SAME: i8*** [[ASSOCIATEDTYPES_CONFORMANCES_TO_Q]]) -sil @associatedtype_with_added_conformance : $ () -> () { +sil @associatedtype_with_added_conformance : $ () -> () { %callee = function_ref @associatedtype_with_added_conformance_callee : $@convention(thin) () -> () apply %callee() : $@convention(thin) () -> () %ret = tuple () @@ -116,7 +116,7 @@ sil @associatedtype_with_added_conformance_callee : $ () -> () {} // CHECK-SAME: [[INT]] [[SHAPE]], // CHECK-SAME: %swift.type** [[ASSOCIATEDTYPES]], // CHECK-SAME: i8*** [[ASSOCIATEDTYPES_CONFORMANCES_TO_Q]]) -sil @associatedtype_with_added_conformance_2 : $ () -> () { +sil @associatedtype_with_added_conformance_2 : $ () -> () { %j = function_ref @associatedtype_with_added_conformance_2_callee : $@convention(thin) () -> () apply %j() : $@convention(thin) () -> () %ret = tuple () @@ -157,13 +157,13 @@ sil @associatedtype_with_forwarded_conformance_1_callee : $ () -> () // CHECK-SAME: %swift.type** [[GEN1_TYPES]], // CHECK-SAME: i8*** [[GEN1_CONFORMANCES_TO_PA]], // CHECK-SAME: i8*** %T.A.Q) -sil @generictype_with_forwarded_conformance_2 : $() -> () { - %callee = function_ref @generictype_with_forwarded_conformance_2_callee : $@convention(thin) () -> () - apply %callee}>() : $@convention(thin) () -> () +sil @generictype_with_forwarded_conformance_2 : $() -> () { + %callee = function_ref @generictype_with_forwarded_conformance_2_callee : $@convention(thin) () -> () + apply %callee}>() : $@convention(thin) () -> () %ret = tuple () return %ret : $() } -sil @generictype_with_forwarded_conformance_2_callee : $ () -> () {} +sil @generictype_with_forwarded_conformance_2_callee : $ () -> () {} // Construct a pack of generic types of generic types which "forward" conformance to a protocol with an associatedtype which itself conforms to a protocol. // CHECK-LABEL: define {{.*}}@generic_with_forwarded_conformance_3( @@ -178,12 +178,12 @@ sil @generictype_with_forwarded_conformance_2_callee : $ () -> () { - %callee = function_ref @generic_with_forwarded_conformance_3_callee : $@convention(thin) () -> () - apply %callee>}>() : $@convention(thin) () -> () +sil @generic_with_forwarded_conformance_3 : $ () -> () { + %callee = function_ref @generic_with_forwarded_conformance_3_callee : $@convention(thin) () -> () + apply %callee>}>() : $@convention(thin) () -> () %ret = tuple () return %ret : $() } -sil @generic_with_forwarded_conformance_3_callee : $ () -> () { +sil @generic_with_forwarded_conformance_3_callee : $ () -> () { } diff --git a/test/Interpreter/variadic_generic_captures.swift b/test/Interpreter/variadic_generic_captures.swift index c64da4f30d02b..d504fcee6e25c 100644 --- a/test/Interpreter/variadic_generic_captures.swift +++ b/test/Interpreter/variadic_generic_captures.swift @@ -31,7 +31,7 @@ types.test("WitnessTable") { expectEqual((Int, String, Bool).self, hasWitnessTablePack([1], ["hi"], [false])()) } -func hasWitnessTablePack2(_: repeat each T) -> () -> Any.Type where (each T).Element: Sequence { +func hasWitnessTablePack2(_: repeat each T) -> () -> Any.Type where repeat (each T).Element: Sequence { return { return (repeat (each T).Element.Element).self } } @@ -56,4 +56,4 @@ types.test("Lifetime") { expectEqual((Int, Double).self, fn2()) } -runAllTests() \ No newline at end of file +runAllTests() diff --git a/test/Interpreter/variadic_generic_types.swift b/test/Interpreter/variadic_generic_types.swift index 23d04c6a25f21..c21f8f10111d0 100644 --- a/test/Interpreter/variadic_generic_types.swift +++ b/test/Interpreter/variadic_generic_types.swift @@ -104,7 +104,7 @@ types.test("LayoutReq") { } public struct OuterSeq { - public struct InnerSeq where each T.Element == each U.Element {} + public struct InnerSeq where repeat each T.Element == each U.Element {} } types.test("SameTypeReq") { @@ -156,4 +156,4 @@ types.test("SequenceElementTuple") { returnSize((Int8, Int16, Int32, Int64).self)) } -runAllTests() \ No newline at end of file +runAllTests() diff --git a/test/SILGen/variadic_generic_types.swift b/test/SILGen/variadic_generic_types.swift index 9dd9058b5e2cb..b5202a3c1fb7c 100644 --- a/test/SILGen/variadic_generic_types.swift +++ b/test/SILGen/variadic_generic_types.swift @@ -3,6 +3,6 @@ // Because of -enable-experimental-feature VariadicGenerics // REQUIRES: asserts -struct Variadic where each T: Equatable {} +struct Variadic where repeat each T: Equatable {} _ = Variadic() diff --git a/test/TypeDecoder/variadic_nominal_types.swift b/test/TypeDecoder/variadic_nominal_types.swift index bbcc5dc7489bd..e1ba27f3b8936 100644 --- a/test/TypeDecoder/variadic_nominal_types.swift +++ b/test/TypeDecoder/variadic_nominal_types.swift @@ -12,7 +12,7 @@ struct Variadic { struct Inner {} } -extension Variadic where each T: Equatable { +extension Variadic where repeat each T: Equatable { struct Constrained {} } @@ -54,4 +54,4 @@ do { // CHECK-TYPE: Variadic.Constrained // DEMANGLE-TYPE: $s22variadic_nominal_types8VariadicVAASQRzrlE11ConstrainedVySi_SSQPSf_GD -// CHECK-TYPE: Variadic.Constrained \ No newline at end of file +// CHECK-TYPE: Variadic.Constrained diff --git a/test/type/pack_expansion.swift b/test/type/pack_expansion.swift index 44a11a8e761a0..231f9ec930191 100644 --- a/test/type/pack_expansion.swift +++ b/test/type/pack_expansion.swift @@ -49,7 +49,6 @@ enum E { } func withWhereClause(_ x: repeat each T) where repeat each T: P {} -// expected-error@-1 {{pack expansion 'repeat each T' can only appear in a function parameter list, tuple element, or generic argument list}} struct Outer { struct Bad { @@ -65,9 +64,9 @@ struct Outer { } } -func packRef(_: repeat each T) where each T: P {} +func packRef(_: repeat each T) where repeat each T: P {} -func packMemberRef(_: repeat each T.T) where each T: P {} +func packMemberRef(_: repeat each T.T) where repeat each T: P {} // expected-error@+1 {{'each' cannot be applied to non-pack type 'Int'}}{{31-35=}} func invalidPackRefEachInt(_: each Int) {} @@ -90,6 +89,12 @@ func packRefOutsideExpansion(_: (each T)) {} // expected-error@+1 {{pack reference 'T' requires expansion using keyword 'repeat'}} func packRefOutsideExpansion(_: each T.Type) {} +// expected-error@+1 {{pack reference 'T' requires expansion using keyword 'repeat'}} +func packRefOutsideExpansionRequirement1(_: repeat each T) where each T: P {} + +// expected-error@+1 {{pack reference 'T' requires expansion using keyword 'repeat'}} +func packRefOutsideExpansionRequirement2(_: repeat each T) where G: P {} + // coverage to ensure a 'repeat each' type is considered Copyable func golden(_ z: Z) {} func hour(_ t: repeat each T) {