Skip to content

Commit dbda273

Browse files
hborlasimanerush
authored andcommitted
[Features] Gate same-element requirements behind an experimental feature flag.
1 parent e6eb5da commit dbda273

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ EXPERIMENTAL_FEATURE(CodeItemMacros, false)
232232
EXPERIMENTAL_FEATURE(PreambleMacros, false)
233233
EXPERIMENTAL_FEATURE(TupleConformances, false)
234234
EXPERIMENTAL_FEATURE(FullTypedThrows, false)
235+
EXPERIMENTAL_FEATURE(SameElementRequirements, false)
235236

236237
// Whether to enable @_used and @_section attributes
237238
EXPERIMENTAL_FEATURE(SymbolLinkageMarkers, true)

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ UNINTERESTING_FEATURE(StaticExclusiveOnly)
134134
UNINTERESTING_FEATURE(ExtractConstantsFromMembers)
135135
UNINTERESTING_FEATURE(FixedArrays)
136136
UNINTERESTING_FEATURE(GroupActorErrors)
137+
UNINTERESTING_FEATURE(SameElementRequirements)
137138

138139
static bool usesFeatureSendingArgsAndResults(Decl *decl) {
139140
auto isFunctionTypeWithSending = [](Type type) {

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,17 @@ static void desugarSameTypeRequirement(
220220
break;
221221
}
222222

223+
auto &ctx = firstType->getASTContext();
224+
if (!ctx.LangOpts.hasFeature(Feature::SameElementRequirements)) {
225+
// If one side is a parameter pack, this is a same-element requirement, which
226+
// is not yet supported.
227+
if (firstType->isParameterPack() != secondType->isParameterPack()) {
228+
errors.push_back(RequirementError::forSameElement(
229+
{kind, sugaredFirstType, secondType}, loc));
230+
return true;
231+
}
232+
}
233+
223234
if (firstType->isTypeParameter() && secondType->isTypeParameter()) {
224235
result.emplace_back(kind, sugaredFirstType, secondType);
225236
return true;

test/Constraints/pack-expansion-expressions.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,16 @@ func outerArchetype<each T, U>(t: repeat each T, u: U) where repeat each T: P {
6363
}
6464

6565
func sameElement<each T, U>(t: repeat each T, u: U) where repeat each T: P, repeat each T == U {
66-
let _ = (repeat (each t).f(u))
66+
// expected-error@-1{{same-element requirements are not yet supported}}
67+
let _: (repeat each T) = (repeat (each t).f(u))
68+
// expected-error@-1 {{cannot convert value of type 'U' to expected argument type 'each T'}}
6769
}
6870

6971
func forEachEach<each C, U>(c: repeat each C, function: (U) -> Void)
7072
where repeat each C: Collection, repeat (each C).Element == U {
71-
repeat (each c).forEach(function)
73+
// expected-error@-1{{same-element requirements are not yet supported}}
74+
_ = (repeat (each c).forEach(function))
75+
// expected-error@-1 {{cannot convert value of type '(U) -> Void' to expected argument type '((each C).Element) throws -> Void'}}
7276
}
7377

7478
func typeReprPacks<each T: ExpressibleByIntegerLiteral>(_ t: repeat each T) {

test/Generics/parameter-pack-same-element-requirements.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-availability-checking 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -enable-experimental-feature SameElementRequirements -disable-availability-checking 2>&1 | %FileCheck %s
22

33
// REQUIRES: asserts
44

0 commit comments

Comments
 (0)