Skip to content

[SE-0368] StaticBigInt: support older compilers #62541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(UnsafeInheritExecutor, 0, "@_unsafeInheritExecutor
SUPPRESSIBLE_LANGUAGE_FEATURE(PrimaryAssociatedTypes2, 346, "Primary associated types", true)
SUPPRESSIBLE_LANGUAGE_FEATURE(UnavailableFromAsync, 0, "@_unavailableFromAsync", true)
SUPPRESSIBLE_LANGUAGE_FEATURE(NoAsyncAvailability, 340, "@available(*, noasync)", true)
LANGUAGE_FEATURE(BuiltinIntLiteralAccessors, 368, "Builtin.IntLiteral accessors", true)

UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3042,6 +3042,10 @@ static bool usesFeatureNoAsyncAvailability(Decl *decl) {
return decl->getAttrs().getNoAsync(decl->getASTContext()) != nullptr;
}

static bool usesFeatureBuiltinIntLiteralAccessors(Decl *decl) {
return false;
}

static bool usesFeatureConciseMagicFile(Decl *decl) {
return false;
}
Expand Down
12 changes: 12 additions & 0 deletions stdlib/public/core/StaticBigInt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ extension StaticBigInt {
@available(SwiftStdlib 5.8, *)
@inlinable
internal var _isNegative: Bool {
#if compiler(>=5.8) && $BuiltinIntLiteralAccessors
Bool(Builtin.isNegative_IntLiteral(_value))
#else
fatalError("Swift compiler is incompatible with this SDK version")
#endif
}

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

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

Expand Down