Skip to content

Commit 451e725

Browse files
committed
Add ValueGenerics experimental feature
1 parent 9903d71 commit 451e725

File tree

14 files changed

+43
-18
lines changed

14 files changed

+43
-18
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8024,6 +8024,8 @@ ERROR(value_generic_unexpected,none,
80248024
"using value generic %0 here is not allowed", (Type))
80258025
ERROR(missing_value_generic_type,none,
80268026
"value generic %0 must have an explicit value type declared", (Identifier))
8027+
ERROR(value_generics_missing_feature,none,
8028+
"value generics require '-enable-experimental-feature ValueGenerics'", ())
80278029

80288030
#define UNDEFINE_DIAGNOSTIC_MACROS
80298031
#include "DefineDiagnosticMacros.h"

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(AllowUnsafeAttribute, true)
408408
/// Warn on use of unsafe constructs.
409409
EXPERIMENTAL_FEATURE(WarnUnsafe, true)
410410

411+
// Enable values in generic signatures, e.g. <let N: Int>
412+
EXPERIMENTAL_FEATURE(ValueGenerics, true)
413+
411414
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
412415
#undef EXPERIMENTAL_FEATURE
413416
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "swift/AST/Decl.h"
1616
#include "swift/AST/ExistentialLayout.h"
17+
#include "swift/AST/GenericParamList.h"
1718
#include "swift/AST/NameLookup.h"
1819
#include "swift/AST/ParameterList.h"
1920
#include "swift/AST/Pattern.h"
@@ -232,6 +233,22 @@ static bool usesFeatureAllowUnsafeAttribute(Decl *decl) {
232233

233234
UNINTERESTING_FEATURE(WarnUnsafe)
234235

236+
static bool usesFeatureValueGenerics(Decl *decl) {
237+
auto genericContext = decl->getAsGenericContext();
238+
239+
if (!genericContext || !genericContext->getGenericParams())
240+
return false;
241+
242+
for (auto param : genericContext->getGenericParams()->getParams()) {
243+
if (param->isValue())
244+
return true;
245+
246+
continue;
247+
}
248+
249+
return false;
250+
}
251+
235252
// ----------------------------------------------------------------------------
236253
// MARK: - FeatureSet
237254
// ----------------------------------------------------------------------------

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ InferredGenericSignatureRequest::evaluate(
825825
"Parsed an empty generic parameter list?");
826826

827827
for (auto *gpDecl : *gpList) {
828+
if (gpDecl->isValue() &&
829+
!gpDecl->getASTContext().LangOpts.hasFeature(Feature::ValueGenerics))
830+
gpDecl->diagnose(diag::value_generics_missing_feature);
831+
828832
auto *gpType = gpDecl->getDeclaredInterfaceType()
829833
->castTo<GenericTypeParamType>();
830834
genericParams.push_back(gpType);

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ namespace {
761761
// parameter doesn't declare a value type and we're going to diagnose it
762762
// later.
763763
if (!paramType->getValueType() || !secondType->getValueType())
764-
return false;
764+
return true;
765765

766766
// Otherwise, these are both value parameters and check that both their
767767
// value types are the same.

test/ASTGen/decls.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
// RUN: %empty-directory(%t)
3-
// RUN: %target-swift-frontend %s -dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-feature ParserASTGen > %t/astgen.ast.raw
4-
// RUN: %target-swift-frontend %s -dump-parse -disable-availability-checking -enable-experimental-move-only > %t/cpp-parser.ast.raw
3+
// RUN: %target-swift-frontend %s -dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-feature ParserASTGen -enable-experimental-feature ValueGenerics > %t/astgen.ast.raw
4+
// RUN: %target-swift-frontend %s -dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-feature ValueGenerics > %t/cpp-parser.ast.raw
55

66
// Filter out any addresses in the dump, since they can differ.
77
// RUN: sed -E 's#0x[0-9a-fA-F]+##g' %t/cpp-parser.ast.raw > %t/cpp-parser.ast
88
// RUN: sed -E 's#0x[0-9a-fA-F]+##g' %t/astgen.ast.raw > %t/astgen.ast
99

1010
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
1111

12-
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -enable-experimental-feature SwiftParser -enable-experimental-feature ParserASTGen)
12+
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -enable-experimental-feature SwiftParser -enable-experimental-feature ParserASTGen -enable-experimental-feature ValueGenerics)
1313

1414
// REQUIRES: executable_test
1515
// REQUIRES: swift_swift_parser

test/IRGen/raw_layout.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/chex.py < %s > %t/raw_layout.sil
3-
// RUN: %target-swift-frontend -enable-experimental-feature RawLayout -emit-ir -disable-availability-checking -I %S/Inputs -cxx-interoperability-mode=upcoming-swift %t/raw_layout.sil | %FileCheck %t/raw_layout.sil --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
3+
// RUN: %target-swift-frontend -enable-experimental-feature RawLayout -enable-experimental-feature ValueGenerics -emit-ir -disable-availability-checking -I %S/Inputs -cxx-interoperability-mode=upcoming-swift %t/raw_layout.sil | %FileCheck %t/raw_layout.sil --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
44

55
import Builtin
66
import Swift
@@ -428,7 +428,7 @@ entry(%0 : $*Cell<T>):
428428

429429
// CHECK-LABEL: define {{.*}} void @"$s10raw_layout18ConcreteMoveAsLikeVwxx"(ptr {{.*}} %object, ptr %ConcreteMoveAsLike)
430430
// CHECK: [[OBJ_CELL:%.*]] = getelementptr inbounds %T10raw_layout18ConcreteMoveAsLikeV, ptr %object, i32 0, i32 0
431-
// CHECK: {{invoke void|invoke ptr|call void}} @{{.*}}(ptr [[OBJ_CELL]])
431+
// CHECK: {{invoke void|invoke ptr|call void|call ptr}} @{{.*}}(ptr [[OBJ_CELL]])
432432

433433
//===----------------------------------------------------------------------===//
434434
// ConcreteMoveAsLike initializeWithTake
@@ -555,7 +555,7 @@ entry(%0 : $*Cell<T>):
555555
// CHECK: [[NEW_I:%.*]] = add {{i64|i32}} [[I]], 1
556556
// CHECK: store {{i64|i32}} [[NEW_I]], ptr [[I_ALLOCA]]
557557
// CHECK: [[OBJECT:%.*]] = getelementptr inbounds %TSo24NonBitwiseTakableCXXTypeV, ptr [[OBJ_VECTOR]], {{i64|i32}} [[I]]
558-
// CHECK-NEXT: {{invoke void|invoke ptr|call void}} @{{.*}}(ptr [[OBJECT]])
558+
// CHECK-NEXT: {{invoke void|invoke ptr|call void|call ptr}} @{{.*}}(ptr [[OBJECT]])
559559

560560
// This may or may not be in the loop_br
561561
// CHECK: [[EQ_CMP:%.*]] = icmp eq {{i64|i32}} [[NEW_I]], 2
@@ -747,7 +747,7 @@ entry(%0 : $*Cell<T>):
747747
// CHECK: [[NEW_I:%.*]] = add {{i64|i32}} [[I]], 1
748748
// CHECK: store {{i64|i32}} [[NEW_I]], ptr [[I_ALLOCA]]
749749
// CHECK: [[OBJECT:%.*]] = getelementptr inbounds %TSo24NonBitwiseTakableCXXTypeV, ptr [[OBJ_VECTOR]], {{i64|i32}} [[I]]
750-
// CHECK-NEXT: {{invoke void|invoke ptr|call void}} @{{.*}}(ptr [[OBJECT]])
750+
// CHECK-NEXT: {{invoke void|invoke ptr|call void|call ptr}} @{{.*}}(ptr [[OBJECT]])
751751

752752
// This may or may not be in the loop_br
753753
// CHECK: [[EQ_CMP:%.*]] = icmp eq {{i64|i32}} [[NEW_I]], 4

test/Interpreter/value_generics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift | %FileCheck %s
1+
// RUN: %target-run-simple-swift(-enable-experimental-feature ValueGenerics) | %FileCheck %s
22

33
// REQUIRES: executable_test
44

test/ModuleInterface/value_generics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name ValueGeneric
2+
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name ValueGeneric -enable-experimental-feature ValueGenerics
33
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name ValueGeneric
44
// RUN: %FileCheck %s < %t.swiftinterface
55

test/SIL/Parser/basic2.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt %s | %target-sil-opt | %FileCheck %s
1+
// RUN: %target-sil-opt %s -enable-experimental-feature ValueGenerics | %target-sil-opt -enable-experimental-feature ValueGenerics | %FileCheck %s
22

33
import Builtin
44
import Swift

0 commit comments

Comments
 (0)