Skip to content

Commit b9c5aca

Browse files
committed
Enable SE-0413 "Typed Throws" by default
1 parent 06a9e13 commit b9c5aca

16 files changed

+16
-50
lines changed

Diff for: include/swift/AST/DiagnosticsSema.def

-3
Original file line numberDiff line numberDiff line change
@@ -5231,9 +5231,6 @@ WARNING(no_throw_in_try,none,
52315231
WARNING(no_throw_in_do_with_catch,none,
52325232
"'catch' block is unreachable because no errors are thrown in 'do' block", ())
52335233

5234-
ERROR(experimental_typed_throws,none,
5235-
"typed throws is an experimental feature", ())
5236-
52375234
ERROR(thrown_type_not_error,none,
52385235
"thrown type %0 does not conform to the 'Error' protocol", (Type))
52395236

Diff for: include/swift/Basic/Features.def

+1-3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ LANGUAGE_FEATURE(ParameterPacks, 393, "Value and type parameter packs", true)
116116
SUPPRESSIBLE_LANGUAGE_FEATURE(LexicalLifetimes, 0, "@_eagerMove/@_noEagerMove/@_lexicalLifetimes annotations", true)
117117
LANGUAGE_FEATURE(FreestandingMacros, 397, "freestanding declaration macros", true)
118118
SUPPRESSIBLE_LANGUAGE_FEATURE(RetroactiveAttribute, 364, "@retroactive", true)
119+
LANGUAGE_FEATURE(TypedThrows, 413, "Typed throws", true)
119120

120121
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
121122
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)
@@ -249,9 +250,6 @@ EXPERIMENTAL_FEATURE(Embedded, true)
249250
/// Enables noncopyable generics
250251
EXPERIMENTAL_FEATURE(NoncopyableGenerics, false)
251252

252-
/// Enables typed throws.
253-
EXPERIMENTAL_FEATURE(TypedThrows, true)
254-
255253
/// Allow destructuring stored `let` bindings in structs.
256254
EXPERIMENTAL_FEATURE(StructLetDestructuring, true)
257255

Diff for: lib/ASTGen/Sources/ASTGen/SourceFile.swift

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ extension Parser.ExperimentalFeatures {
5252
}
5353
}
5454
mapFeature(.ThenStatements, to: .thenStatements)
55-
mapFeature(.TypedThrows, to: .typedThrows)
5655
mapFeature(.DoExpressions, to: .doExpressions)
5756
mapFeature(.NonescapableTypes, to: .nonescapableTypes)
5857
}

Diff for: lib/Sema/ConstraintSystem.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,6 @@ void ConstraintSystem::recordPotentialThrowSite(
373373
ConstraintLocatorBuilder locator) {
374374
ASTContext &ctx = getASTContext();
375375

376-
// Only record potential throw sites when typed throws is enabled.
377-
if (!ctx.LangOpts.hasFeature(Feature::TypedThrows))
378-
return;
379-
380376
// Catch node location is determined by the source location.
381377
auto sourceLoc = locator.getAnchor().getStartLoc();
382378
if (!sourceLoc)

Diff for: lib/Sema/TypeCheckEffects.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,7 @@ static Expr *removeErasureToExistentialError(Expr *expr) {
663663
return expr;
664664

665665
ASTContext &ctx = type->getASTContext();
666-
if (!ctx.LangOpts.hasFeature(Feature::FullTypedThrows) ||
667-
!ctx.LangOpts.hasFeature(Feature::TypedThrows))
666+
if (!ctx.LangOpts.hasFeature(Feature::FullTypedThrows))
668667
return expr;
669668

670669
// Look for an outer erasure expression.

Diff for: lib/Sema/TypeCheckType.cpp

-23
Original file line numberDiff line numberDiff line change
@@ -3715,11 +3715,6 @@ NeverNullType TypeResolver::resolveASTFunctionType(
37153715
Type thrownTy;
37163716
if (auto thrownTypeRepr = repr->getThrownTypeRepr()) {
37173717
ASTContext &ctx = getASTContext();
3718-
if (!ctx.LangOpts.hasFeature(Feature::TypedThrows)) {
3719-
diagnoseInvalid(
3720-
thrownTypeRepr, thrownTypeRepr->getLoc(), diag::experimental_typed_throws);
3721-
}
3722-
37233718
auto thrownTypeOptions = options.withoutContext();
37243719
thrownTy = resolveType(thrownTypeRepr, thrownTypeOptions);
37253720
if (thrownTy->hasError()) {
@@ -5691,10 +5686,6 @@ Type ExplicitCaughtTypeRequest::evaluate(
56915686
}
56925687

56935688
// We have an explicit thrown error type, so resolve it.
5694-
if (!ctx.LangOpts.hasFeature(Feature::TypedThrows)) {
5695-
ctx.Diags.diagnose(thrownTypeRepr->getLoc(), diag::experimental_typed_throws);
5696-
}
5697-
56985689
auto options = TypeResolutionOptions(TypeResolverContext::None);
56995690
if (func->preconcurrency())
57005691
options |= TypeResolutionFlags::Preconcurrency;
@@ -5710,11 +5701,6 @@ Type ExplicitCaughtTypeRequest::evaluate(
57105701
if (auto closure = catchNode.dyn_cast<ClosureExpr *>()) {
57115702
// Explicit thrown error type.
57125703
if (auto thrownTypeRepr = closure->getExplicitThrownTypeRepr()) {
5713-
if (!ctx.LangOpts.hasFeature(Feature::TypedThrows)) {
5714-
ctx.Diags.diagnose(thrownTypeRepr->getLoc(),
5715-
diag::experimental_typed_throws);
5716-
}
5717-
57185704
return TypeResolution::resolveContextualType(
57195705
thrownTypeRepr, closure,
57205706
TypeResolutionOptions(TypeResolverContext::None),
@@ -5736,18 +5722,9 @@ Type ExplicitCaughtTypeRequest::evaluate(
57365722
// A do..catch block with no explicit 'throws' annotation will infer
57375723
// the thrown error type.
57385724
if (doCatch->getThrowsLoc().isInvalid()) {
5739-
// Prior to typed throws, the do..catch always throws 'any Error'.
5740-
if (!ctx.LangOpts.hasFeature(Feature::TypedThrows))
5741-
return ctx.getErrorExistentialType();
5742-
57435725
return Type();
57445726
}
57455727

5746-
if (!ctx.LangOpts.hasFeature(Feature::TypedThrows)) {
5747-
ctx.Diags.diagnose(doCatch->getThrowsLoc(), diag::experimental_typed_throws);
5748-
return ctx.getErrorExistentialType();
5749-
}
5750-
57515728
auto typeRepr = doCatch->getCaughtTypeRepr();
57525729

57535730
// If there is no explicitly-specified thrown error type, it's 'any Error'.

Diff for: test/Generics/typed_throws.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -enable-experimental-feature TypedThrows 2>&1 | %FileCheck %s
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures 2>&1 | %FileCheck %s
22

33
protocol P1 {
44
associatedtype A

Diff for: test/IRGen/typed_throws.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-experimental-feature TypedThrows -disable-availability-checking -runtime-compatibility-version none -target %module-target-future | %FileCheck %s --check-prefix=CHECK-MANGLE
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -disable-availability-checking -runtime-compatibility-version none -target %module-target-future | %FileCheck %s --check-prefix=CHECK-MANGLE
22

3-
// RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-experimental-feature TypedThrows -disable-availability-checking -runtime-compatibility-version 5.8 -disable-concrete-type-metadata-mangled-name-accessors | %FileCheck %s --check-prefix=CHECK-NOMANGLE
3+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -disable-availability-checking -runtime-compatibility-version 5.8 -disable-concrete-type-metadata-mangled-name-accessors | %FileCheck %s --check-prefix=CHECK-NOMANGLE
44

5-
// RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-experimental-feature TypedThrows | %FileCheck %s --check-prefix=CHECK
5+
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s --check-prefix=CHECK
66

77
// XFAIL: CPU=arm64e
88
// REQUIRES: PTRSIZE=64

Diff for: test/IRGen/typed_throws_exec.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift -module-name=test -enable-experimental-feature TypedThrows %s -o %t/a.out
2+
// RUN: %target-build-swift -module-name=test %s -o %t/a.out
33
// RUN: %target-codesign %t/a.out
44
// RUN: %target-run %t/a.out | %FileCheck %s
55
// REQUIRES: executable_test

Diff for: test/IRGen/typed_throws_thunks.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -primary-file %s -emit-irgen -enable-experimental-feature TypedThrows -disable-availability-checking -runtime-compatibility-version none -target %module-target-future -enable-library-evolution | %FileCheck %s --check-prefix=CHECK
1+
// RUN: %target-swift-frontend -primary-file %s -emit-irgen -disable-availability-checking -runtime-compatibility-version none -target %module-target-future -enable-library-evolution | %FileCheck %s --check-prefix=CHECK
22

33
// REQUIRES: PTRSIZE=64
44
// UNSUPPORTED: CPU=arm64e

Diff for: test/Runtime/demangleToMetadata.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -parse-stdlib -enable-experimental-feature TypedThrows %s -module-name main -o %t/a.out
2+
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -parse-stdlib %s -module-name main -o %t/a.out
33
// RUN: %target-codesign %t/a.out
44
// RUN: %target-run %t/a.out
55
// REQUIRES: executable_test

Diff for: test/SILGen/typed_throws.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-silgen %s -enable-experimental-feature TypedThrows | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
22

33
enum MyError: Error {
44
case fail

Diff for: test/SILGen/typed_throws_generic.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-silgen %s -enable-experimental-feature TypedThrows -enable-experimental-feature FullTypedThrows | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen %s -enable-experimental-feature FullTypedThrows | %FileCheck %s
22

33
public func genericThrow<E>(e: E) throws(E) {
44
throw e

Diff for: test/embedded/throw-typed.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %target-run-simple-swift(%S/Inputs/print.swift -enable-experimental-feature Embedded -enable-experimental-feature TypedThrows -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
2-
// RUN: %target-run-simple-swift(%S/Inputs/print.swift -O -enable-experimental-feature Embedded -enable-experimental-feature TypedThrows -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
3-
// RUN: %target-run-simple-swift(%S/Inputs/print.swift -Osize -enable-experimental-feature Embedded -enable-experimental-feature TypedThrows -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
1+
// RUN: %target-run-simple-swift(%S/Inputs/print.swift -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
2+
// RUN: %target-run-simple-swift(%S/Inputs/print.swift -O -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
3+
// RUN: %target-run-simple-swift(%S/Inputs/print.swift -Osize -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
44

55
// REQUIRES: swift_in_compiler
66
// REQUIRES: executable_test

Diff for: test/stmt/typed_throws.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature TypedThrows -enable-upcoming-feature FullTypedThrows
1+
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature FullTypedThrows
22

33
enum MyError: Error {
44
case failed

Diff for: test/stmt/typed_throws_ast.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -enable-experimental-feature TypedThrows %s -dump-ast | %FileCheck %s
1+
// RUN: %target-swift-frontend %s -dump-ast | %FileCheck %s
22

33
enum MyError: Error {
44
case failed

0 commit comments

Comments
 (0)