Skip to content

Commit ccfb35e

Browse files
benrimmingtonando-huang
authored andcommitted
[SE-0368] StaticBigInt: support older compilers (swiftlang#62541)
1 parent 0a9b094 commit ccfb35e

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(UnsafeInheritExecutor, 0, "@_unsafeInheritExecutor
9090
SUPPRESSIBLE_LANGUAGE_FEATURE(PrimaryAssociatedTypes2, 346, "Primary associated types", true)
9191
SUPPRESSIBLE_LANGUAGE_FEATURE(UnavailableFromAsync, 0, "@_unavailableFromAsync", true)
9292
SUPPRESSIBLE_LANGUAGE_FEATURE(NoAsyncAvailability, 340, "@available(*, noasync)", true)
93+
LANGUAGE_FEATURE(BuiltinIntLiteralAccessors, 368, "Builtin.IntLiteral accessors", true)
9394

9495
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
9596
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,6 +3042,10 @@ static bool usesFeatureNoAsyncAvailability(Decl *decl) {
30423042
return decl->getAttrs().getNoAsync(decl->getASTContext()) != nullptr;
30433043
}
30443044

3045+
static bool usesFeatureBuiltinIntLiteralAccessors(Decl *decl) {
3046+
return false;
3047+
}
3048+
30453049
static bool usesFeatureConciseMagicFile(Decl *decl) {
30463050
return false;
30473051
}

stdlib/public/core/StaticBigInt.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ extension StaticBigInt {
7373
@available(SwiftStdlib 5.8, *)
7474
@inlinable
7575
internal var _isNegative: Bool {
76+
#if compiler(>=5.8) && $BuiltinIntLiteralAccessors
7677
Bool(Builtin.isNegative_IntLiteral(_value))
78+
#else
79+
fatalError("Swift compiler is incompatible with this SDK version")
80+
#endif
7781
}
7882

7983
/// Returns the minimal number of bits in this value's binary representation,
@@ -94,7 +98,11 @@ extension StaticBigInt {
9498
@available(SwiftStdlib 5.8, *)
9599
@inlinable
96100
public var bitWidth: Int {
101+
#if compiler(>=5.8) && $BuiltinIntLiteralAccessors
97102
Int(Builtin.bitWidth_IntLiteral(_value))
103+
#else
104+
fatalError("Swift compiler is incompatible with this SDK version")
105+
#endif
98106
}
99107

100108
/// Returns a 32-bit or 64-bit word of this value's binary representation.
@@ -125,9 +133,13 @@ extension StaticBigInt {
125133
guard !bitIndex.overflow, bitIndex.partialValue < bitWidth else {
126134
return _isNegative ? ~0 : 0
127135
}
136+
#if compiler(>=5.8) && $BuiltinIntLiteralAccessors
128137
return UInt(
129138
Builtin.wordAtIndex_IntLiteral(_value, wordIndex._builtinWordValue)
130139
)
140+
#else
141+
fatalError("Swift compiler is incompatible with this SDK version")
142+
#endif
131143
}
132144
}
133145

0 commit comments

Comments
 (0)