Skip to content

Commit 531a1ab

Browse files
committed
Temporarily put uses of "Span" and "RawSpan" behind an experimental feature flag
While Span is present, we don't yet have an official way to create Span instances. Until then, put uses of Span and RawSpan behind an experimental feature flag (`Span`) that must be set to use these. Addresses rdar://139308307.
1 parent 4bb507d commit 531a1ab

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7912,6 +7912,10 @@ ERROR(noncopyable_cannot_have_read_set_accessor,none,
79127912
ERROR(nonescapable_types_attr_disabled,none,
79137913
"attribute requires '-enable-experimental-feature NonescapableTypes'", ())
79147914

7915+
ERROR(span_requires_feature_flag,none,
7916+
"'%0' requires -enable-experimental-feature Span",
7917+
(StringRef))
7918+
79157919
//------------------------------------------------------------------------------
79167920
// MARK: Init accessors
79177921
//------------------------------------------------------------------------------

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ EXPERIMENTAL_FEATURE(MacrosOnImports, true)
234234
EXPERIMENTAL_FEATURE(TupleConformances, false)
235235
EXPERIMENTAL_FEATURE(FullTypedThrows, false)
236236
EXPERIMENTAL_FEATURE(SameElementRequirements, false)
237+
EXPERIMENTAL_FEATURE(Span, true)
237238

238239
// Whether to enable @_used and @_section attributes
239240
EXPERIMENTAL_FEATURE(SymbolLinkageMarkers, true)

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ UNINTERESTING_FEATURE(GroupActorErrors)
197197
UNINTERESTING_FEATURE(SameElementRequirements)
198198
UNINTERESTING_FEATURE(UnspecifiedMeansMainActorIsolated)
199199
UNINTERESTING_FEATURE(GenerateForceToMainActorThunks)
200+
UNINTERESTING_FEATURE(Span)
200201

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

lib/Sema/TypeCheckType.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,32 @@ static void diagnoseGenericArgumentsOnSelf(const TypeResolution &resolution,
17191719
}
17201720
}
17211721

1722+
/// Diagnose when this is one of the Span types, which currently requires
1723+
/// an experimental feature to use.
1724+
static void diagnoseSpanType(TypeDecl *typeDecl, SourceLoc loc,
1725+
const DeclContext *dc) {
1726+
if (loc.isInvalid())
1727+
return;
1728+
1729+
if (!typeDecl->isStdlibDecl())
1730+
return;
1731+
1732+
ASTContext &ctx = typeDecl->getASTContext();
1733+
if (ctx.LangOpts.hasFeature(Feature::Span))
1734+
return;
1735+
1736+
auto nameString = typeDecl->getName().str();
1737+
if (nameString != "Span" && nameString != "RawSpan")
1738+
return;
1739+
1740+
// Don't require this in the standard library or _Concurrency library.
1741+
auto module = dc->getParentModule();
1742+
if (module->isStdlibModule() || module->getName().str() == "_Concurrency")
1743+
return;
1744+
1745+
ctx.Diags.diagnose(loc, diag::span_requires_feature_flag, nameString);
1746+
}
1747+
17221748
/// Resolve the given identifier type representation as an unqualified type,
17231749
/// returning the type it references.
17241750
/// \param silContext Used to look up generic parameters in SIL mode.
@@ -1854,6 +1880,9 @@ resolveUnqualifiedIdentTypeRepr(const TypeResolution &resolution,
18541880
repr->setInvalid();
18551881
return ErrorType::get(ctx);
18561882
}
1883+
1884+
diagnoseSpanType(currentDecl, repr->getLoc(), DC);
1885+
18571886
repr->setValue(currentDecl, currentDC);
18581887
return current;
18591888
}
@@ -2074,6 +2103,8 @@ static Type resolveQualifiedIdentTypeRepr(const TypeResolution &resolution,
20742103
member = memberTypes.back().Member;
20752104
inferredAssocType = memberTypes.back().InferredAssociatedType;
20762105
repr->setValue(member, nullptr);
2106+
2107+
diagnoseSpanType(member, repr->getLoc(), DC);
20772108
}
20782109

20792110
return maybeDiagnoseBadMemberType(member, memberType, inferredAssocType);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-typecheck-verify-swift -verify-additional-prefix missing-
2+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Span
3+
// REQUIRES: swift_feature_Span
4+
5+
@available(SwiftStdlib 6.1, *)
6+
func f(_: Span<Int>) { }
7+
// expected-missing-error@-1{{'Span' requires -enable-experimental-feature Span}}
8+
9+
10+
@available(SwiftStdlib 6.1, *)
11+
func g(_: RawSpan) { }
12+
// expected-missing-error@-1{{'RawSpan' requires -enable-experimental-feature Span}}

0 commit comments

Comments
 (0)