Commit Graph

76 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
1281f5910a Merge pull request #80682 from kubamracek/embedded-lossless-convertible
[embedded] Add back LosslessStringConvertible to Bool and integer types
2025-04-21 14:50:57 -07:00
Meghana Gupta
b76047a846 Merge pull request #80930 from meg-gupta/relandpr
Reland #79707
2025-04-21 11:19:33 -07:00
Meghana Gupta
d81b5f7e27 Reland #79707
Revert "Merge pull request #80767 from meg-gupta/reverttransparent"

This reverts commit 198a802719, reversing
changes made to 8eb43af590.
2025-04-19 09:55:06 -07:00
Meghana Gupta
a0fc6e2eaf Merge pull request #80712 from meg-gupta/fixoslog
Add  @_transparent to some more Integer operations
2025-04-19 09:51:07 -07:00
Meghana Gupta
f462bc5d93 Revert "Merge pull request #79707 from DougGregor/transparent-integer-conversions"
This reverts commit 9c2c4ea07f, reversing
changes made to 829e03c104.
2025-04-11 10:42:17 -07:00
Meghana Gupta
fc90619254 Add @_transparent to some integer operations in the stdlib
@_transparent will ensure there are inlined in MandatoryInlining which runs before OSLogOptimization.

OSLogOptimization does not look through their calls because they are not marked with
@_semantics("constant_evaluable") which requires them to also be annotated as @_optimize(none)

rdar://148256435
2025-04-10 07:24:02 -07:00
Kuba Mracek
55f12fe13a [embedded] Add back LosslessStringConvertible to Bool and integer types 2025-04-09 10:08:58 -07:00
Erik Eckstein
3f6f163598 stdlib: annotate some floating point functions with "optimize.sil.inline.constant.arguments" 2025-04-01 18:12:45 +02:00
Doug Gregor
ad626f9c0e [Stdlib performance] Make integer conversion operations transparent
The integer conversion operations were inlinable, but aren't getting
inlined in debug builds, which results in unreasonably poor
performance. Mark them as transparent so we don't end up with
unspecialized generic code in the hot path.

Fixes https://github.com/swiftlang/swift/issues/78501
2025-03-12 07:40:49 -07:00
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Ben Rimmington
3c855da45d [stdlib] Fix coding style of AdditiveArithmetic (#75461)
Use explicit access modifiers instead of `public extension` inheritance.
2024-07-25 11:30:14 -04:00
Ben Rimmington
fc8cc33777 [stdlib] Update documentation of integer types (#74973)
* [stdlib] Remove docs from default implementations

Customized docs were not removed:

  public static var isSigned: Bool
  public static var max: Self
  public static var min: Self
  public var description: String
  public var magnitude: Self
  public init<T: BinaryInteger>(_ source: T)
  public func distance(to other: Self) -> Int
  public func advanced(by n: Int) -> Self

* [stdlib] Remove unused docs for "unsafe" methods

* [stdlib] Remove inherited "ReportingOverflow" docs

* [stdlib] Remove inherited docs for operators

Customized docs were not removed.
(`+`, `-`, `*`, `+=`, `-=`, `*=`)

Non-inherited docs were not removed.
(`&+`, `&-`, `&+=`, `&-=`, `&*=`)

* [stdlib] Reattach doc comments to their APIs

Use `rstrip()` to remove the trailing newline.
<https://docs.python.org/3/library/stdtypes.html#str.rstrip>

* [stdlib] Remove inherited docs from integer types

* [stdlib] Remove FIXME(ABI) comments

* [stdlib] Remove unused docs for operators

* [stdlib] Update example code for `-=` and `*=`

* [stdlib] Update internal gyb comments

* [stdlib] Move docs to BinaryInteger overrides

* [stdlib] Remove unused gyb code

* [stdlib] Fix `&-` and `&*` examples
2024-07-24 17:31:15 -05:00
Alexander Cyon
c21b1e68fd [stdlib] Fix typos 2024-07-06 13:09:57 +02:00
Kuba Mracek
7ae20b7039 [embedded] Port Swift.String to embedded Swift 2024-05-08 11:11:37 -07:00
Stephen Canon
a381589524 SE-0425 implementation (#72139) 2024-04-02 16:24:41 -04:00
Nate Chandler
73231b185b [BitwiseCopyable] Don't apply to FixedWidthInteger.
Per LWG feedback.

This reverts commit c8119e3c01.
2024-03-06 08:12:54 -08:00
Oscar Byström Ericsson
d7b3d3e319 Minor advanced(by:) enhancement. 2024-02-03 15:18:02 +01:00
Oscar Byström Ericsson
17187e38f5 This patch fixes two unnecessary traps in BinaryInteger's advanced(to:) method.
- `Int8.min.advanced(by: 128)`, etc.
- `UInt.max.advanced(by: Int.min)`, etc.
2024-02-03 13:56:33 +01:00
Nate Chandler
c8119e3c01 [stdlib] FixedWidthInteger is BitwiseCopyable. 2024-01-30 14:38:07 -08:00
Kuba Mracek
bd5913a176 [embedded] Make RNG APIs available on embedded Swift 2024-01-17 14:53:24 -08:00
Stephen Canon
7a0c4b5e4a Add default implementations for FixedWidthInteger.dividingFullWidth (#70823)
These are provided for FixedWidthInteger & UnsignedInteger (the base implementation, following Knuth's Algorithm D) and SignedInteger (converting to magnitudes and calling the former). Previously no default implementations were available, requiring every type to implement these operations.

These defaults will not be optimal for large fixed-width integers, so types vending Int512 or similar integers should still provide their own implementations, but they are unconditionally available as a fallback, which simplifies the process of writing such types, and work well enough as a fallback for modest fixed-width integer types like Int64 or 32b or smaller platforms or Int128 on 64b platforms.

Additionally rework the concrete implementations to guarantee that we always trap when the quotient is not representable, and to improve performance for 64b integers on arm64_32, and added some new test coverage for these operations.
2024-01-12 15:25:01 -05:00
Philippe Hausler
7a2c21d312 [Embedded] enable random APIs if a RandomNumberGenerator is provided, but leave system random number generators unavailable (#69645) 2023-11-03 21:12:22 -07:00
Kuba Mracek
3646c32b45 [embedded] Move _CustomStringConvertibleOrNone/_LosslessStringConvertibleOrNone to avoid detaching doccomments from their declarations 2023-10-13 15:31:30 -07:00
Kuba Mracek
169ed58bee [embedded] Revert change on FixedWidthInteger protocol requirements, use an empty protocol instead 2023-09-17 17:23:08 -07:00
Kuba Mracek
92b075b518 [embedded] Drop several #ifs and fatalError()s by adding an unavailable ExpressibleByStringInterpolation String conformance 2023-09-16 13:40:25 -07:00
Kuba Mracek
cba7cdfad6 [embedded] Drop an unnecessary change in Integers.swift 2023-09-16 13:25:21 -07:00
Kuba Mracek
ae2e903574 [embedded] Build an initial embedded Swift standard library
This isn't a "complete" port of the standard library for embedded Swift, but
something that should serve as a starting point for further iterations on the
stdlib.

- General CMake logic for building a library as ".swiftmodule only" (ONLY_SWIFTMODULE).
- CMake logic in stdlib/public/core/CMakeLists.txt to start building the embedded stdlib for a handful of hardcoded target triples.
- Lots of annotations throughout the standard library to make types, functions, protocols unavailable in embedded Swift (@_unavailableInEmbedded).
- Mainly this is about stdlib functionality that relies on existentials, type erasure, metatypes, reflection, string interpolations.
- We rely on function body removal of unavailable functions to eliminate the actual problematic SIL code (existentials).
- Many .swift files are not included in the compilation of embedded stdlib at all, to simplify the scope of the annotations.
- EmbeddedStubs.swift is used to stub out (as unavailable and fatalError'd) the missing functionality.
2023-09-16 12:38:46 -07:00
Xiaodi Wu
df6a56ecbc [stdlib] Make a stylistic change per reviewer feedback. 2023-01-17 19:39:59 -05:00
Xiaodi Wu
f671e50265 [stdlib] Further optimize heterogeneous binary integer comparison 2023-01-15 13:32:24 -05:00
Xiaodi Wu
d6ac4e3476 [stdlib] Improve performance of generic binary integer == and < 2023-01-15 13:32:24 -05:00
Alex Martini
950b7160c2 Correct the expected output in an example. 2022-05-12 10:35:55 -07:00
Josh Soref
a0d2cabda6 Spelling stdlib/public/core (#42441)
* spelling: available

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: components

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conjunction

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conversion

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: enforce

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: guarantee

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interchangeable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: satisfied

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: superfluous

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-19 14:02:24 -07:00
Stephen Canon
a3ba517837 Mark legacy overloads of &+ and &- unavailable. (#38723)
These were defined for both FixedWidthInteger and FixedWidthInteger & SignedInteger for source compatibility with Swift 3; the latter set probably should have been removed when we stabilized the ABI, but were not. We can't easily remove them entirely (because we need them for ABI stability now), but we can mark them unavailable so that the typechecker doesn't have to consider them..
2021-08-05 21:18:48 -04:00
Stephen Canon
ce122dbb81 Clarify the documentation of SignedNumeric.
Previously we said that a type conforming to SignedNumeric allows positive and negative values, but that's nonsense. A type conforms to signed numeric if it has a negate() operation; it doesn't even have to have a notion of positive or negative values (for examples, see complex numbers, quaternions, integers mod n, etc).
2021-08-04 23:03:33 -04:00
Alex Martini
1c5c111aab Merge pull request #36709 from amartini51/main
Doc comment corrections
2021-04-05 15:46:31 -07:00
Meghana Gupta
dbea482085 Refactor FixedWidthInteger init (#36485) 2021-03-18 13:47:12 -07:00
Alex Martini
0b9ae84d66 Remove misleading comment about .zero.
There's nothing useful to say about the type of .zero -- it's
constrained by the protocol to Self, so you don't have any choice what
it is when conforming to AdditiveArithmetic.

Fixes <rdar://problem/72592923> (SR-13983).
2021-02-17 15:09:49 -08:00
Patrick Pijnappel
8ecd884b62 [stdlib] Expand integer conversion comment 2020-10-19 17:55:50 +11:00
Patrick Pijnappel
87c177c4b6 [stdlib] Change misleading comment 2020-10-19 10:51:18 +11:00
Stephen Canon
294bde951b Documentation fix: remainder matches sign of lhs, not rhs. 2020-08-31 08:46:24 -04:00
Nate Cook
2938466ecb Update docs for numericCast (#31464)
Drops outdated random number generation example and simplifies a bit.

Fixes <rdar://problem/57888487>
2020-05-01 15:14:33 -05:00
Ben Rimmington
682c1672b6 [stdlib] Update file headers of de-gybbed files 2020-04-01 22:14:03 +01:00
Alex Martini
c0e2f08818 Add missing backtick.
Fixes rdar://problem/58855960
2020-03-05 11:17:50 -08:00
NevinBR
a7f28785c9 Fixes for FixedWidthInteger.random(in: ClosedRange<Self>, using:) (#29633)
Allow the closed-range version of `FixedWidthInteger.random(in:using:)` to work for types larger than 64 bits when the entire valid range (`.min ... .max`) is passed in.

Also, closed ranges are never empty, so the unnecessary `!isEmpty` precondition has been removed.
2020-02-05 17:17:20 +01:00
Ravi Kandhadai
c198c1a2aa [Constant Evaluator] Add support for BinaryInteger.description which
converts an integer to a string. This patch adds a @_semantics
annotation to the BinaryInteger.description function.
2020-01-27 21:13:50 -08:00
Luciano Almeida
392baefc47 [stdlib][Qol] SR-11295 Removing stdlib unnecessary coercions (#27165)
* Removing unnecessary casts from stdlib

* Minor adjustments

* [stdlib][qol] Clean up error variable assign NSError

* Removing unnecessary coercions after removing DeclRefExpr restriction.
2019-12-11 07:30:25 -08:00
Paul Hudson
06f82a53b5 Replaced the majority of ' : ' with ': '. 2019-07-18 20:46:07 +01:00
Richard Wei
259571a7f7 Add default implementations for AdditiveArithmetic.{+=, -=}. (#25321)
This patch defines a default implementation for `+=` and `-=` in `extension AdditiveArithmetic` implemented in terms of `+` and `-`.
2019-07-04 22:57:27 -07:00
Stephen Canon
166d0fa961 FloatingPoint.radix should be transparent. (#25789)
* FloatingPoint.radix should be inlinable.

* Switch transparent to inlinable+inline(__always).
2019-06-26 18:20:27 -04:00
t.ae
f96cbb8a36 Make AdditiveArithmetic.zero @_transparent (#25658) 2019-06-26 09:07:30 -04:00