Commit Graph

7656 Commits

Author SHA1 Message Date
eeckstein
89bdb311ab Merge pull request #81780 from eeckstein/optimize-enum-comparison
Optimize enum comparisons
2025-05-28 07:01:29 +02:00
Stephen Canon
592d72bba9 Concrete SIMD.init(repeating:) and SIMD.init(lowHalf:highHalf:) optimizations (#81766)
WIP to add more overloads to optimize SIMD codegen on concrete types.
Here we do:

- init(repeating:)
- init(lowHalf:highHalf:)

These are always inlined, even in debug, since LLVM knows how to lower
them to one or two instructions on the targets that we care about.
2025-05-27 15:15:13 -04:00
Erik Eckstein
cac594fb86 Optimizer: peephole optimization for raw-value enum comparsions
Optimize (the very inefficient) RawRepresentable comparison function call to a simple compare of enum tags.
For example,
```
  enum E: String {
    case  a, b, c
  }
```
is compared by getting the raw values of both operands and doing a string compare.
This peephole optimizations replaces the call to such a comparison function with a direct compare of the enum tags, which boils down to a single integer comparison instruction.

rdar://151788987
2025-05-27 12:11:03 +02:00
Karoy Lorentey
a7830d754a Merge pull request #80870 from lorentey/stdlib-version-6.3
[stdlib][runtime] Establish Swift Stdlib/runtime version 6.3
2025-05-21 17:48:22 -07:00
Allan Shortlidge
f8fb99320a Embedded: Suppress spurious unused result warnings.
The results of `swift_retain(object:)` and `swift_bridgeObjectRetain(object:)`
should be discardable since it's typcial to not need the pointer returned from
these calls. Suppresses unused result warnings that were generated previously.
2025-05-18 10:40:13 -07:00
Karoy Lorentey
d98002318d [stdlib][runtime] Establish Swift Stdlib/runtime version 6.3 2025-05-16 19:01:32 -07:00
Erik Eckstein
e3f25d710d stdlib: make InlineArray work with the new vector_base_addr instruction
Don't unsafe-cast from the InlineArray struct itself, but from `_storage` which is the actual array buffer.
This also requires making `_storage` a var.
2025-05-12 19:25:12 +02:00
Henrik G. Olsson
59d7d3160f [Swiftify] Emit @availability when expansions contain Span (#81320)
This prevents errors when compiling for older targets using a newer
compiler.

rdar://150740330
2025-05-08 16:13:24 -07:00
Nate Cook
e68069f891 [stdlib] Allow a default for optional interpolations (#80547)
This adds an `appendInterpolation` overload to
`DefaultStringInterpolation` that includes a parameter for providing a
default string when the value to interpolate is `nil`. This allows this
kind of usage:

```swift
let age: Int? = nil
print("Your age is \(age, default: "timeless")")
// Prints "Your age is timeless"
```

The change includes an additional fixit when optional values are
interpolated, with a suggestion to use this `default:` parameter.
2025-05-07 12:47:02 -05:00
Guillaume Lessard
d8c3942198 Merge pull request #81224 from glessard/override-lifetime-publicly
[stdlib] make `_overrideLifetime()` functions public
2025-05-06 19:56:11 -07:00
Guillaume Lessard
bc22bcd820 [stdlib] remove TODOs
These TODOs aren’t particularly actionable. What we really want is a way to define `_overrideLifetime()` in a not-unsafe way, and that will probably be a `Builtin` operation.
2025-05-06 15:19:32 -07:00
Michael Gottesman
b34e2d72fb Merge pull request #81306 from gottesmm/pr-b6ba1a771d90007a5ee6da3e4dc657bfef32b320
[swift-settings] Now that we aren't using it immediately, remove it from tree.
2025-05-06 08:21:23 -07:00
Michael Gottesman
9d59dbed17 [swift-settings] Now that we aren't using it immediately, remove it from tree.
We can always get it back from the git history.

rdar://150695113
2025-05-05 13:39:03 -07:00
Doug Gregor
f04e916dff Fix issue with older compilers not handling MutableSpan code
The use of SendableCompletionHandlers here is completely incidental,
because it happened to be introduced at roughly the same time as the
bits we needed for MutableSpan. Fixes rdar://148072153.
2025-05-05 10:12:06 -07:00
Henrik G. Olsson
bd233ea26e [Swiftify] Don't use count from Span inside withUnsafeBufferPointer call (#81267) 2025-05-04 01:52:05 -07:00
Karoy Lorentey
74efc7d354 Merge pull request #80859 from lorentey/is_same_metatype_condfail
[stdlib] Allow metatype comparisons to work with outdated compilers
2025-05-02 00:06:18 -07:00
Stephen Canon
ab2b28cc4b Add static .nanoseconds(_: Double) to Duration (#81210)
SE-0329 defines the following static factory methods:
```
public static func seconds<T: BinaryInteger>(_ seconds: T) -> Duration
public static func seconds(_ seconds: Double) -> Duration
public static func milliseconds<T: BinaryInteger>(_ milliseconds: T) -> Duration
public static func milliseconds(_ milliseconds: Double) -> Duration
public static func microseconds<T: BinaryInteger>(_ microseconds: T) -> Duration
public static func microseconds(_ microseconds: Double) -> Duration
public static func nanoseconds<T: BinaryInteger>(_ value: T) -> Duration
```
For no good reason, the obvious additional method:
```
public static func nanoseconds(_ nanoseconds: Double) -> Duration
```
was omitted. After talking this through with the LSG, we have decided
that this is simply a bug, and we will add this method without formal
evolution review.
2025-05-01 15:50:17 -04:00
Guillaume Lessard
e0cfb31fcd [stdlib] make _overrideLifetime functions public
These are discussed in the lifetime annotations pitch: https://github.com/swiftlang/swift-evolution/pull/2750

Addresses rdar://150400414
2025-04-30 15:54:41 -07:00
Meghana Gupta
ceb3264e40 Disable runtime cow verification for mutableSpan property 2025-04-30 13:38:51 -07:00
Alejandro Alonso
865aed0c38 Wrap InlineArray inlinable code in new feature 2025-04-29 10:02:15 -07:00
Andrew Trick
c25d46320c Merge pull request #81105 from atrick/rdar146319009-borrow-constraint
Fix LifetimeDependenceDiagnostics: scoped dependence on a copy
2025-04-26 08:08:15 -07:00
Doug Gregor
050a514588 [Strict memory safety] Update standard library for unsafe treated as a call effect 2025-04-25 21:54:23 -07:00
Andrew Trick
e9d11283b9 Add _overrideLifetime to Span APIs
The implementation previously took advantage of a missing diagnostic. They
returned a borrowed Span with a dependency on a copied argument. This illegally
promotes the dependency. This is what the author intended to do (the
implementation was correct) but the compiler can't know that so the code needs
to be explicit about overriding the lifetime.
2025-04-25 17:58:24 -07:00
Kuba Mracek
c0ea02f86d [embedded] Add swift_allocEmptyBox to the embedded runtime 2025-04-21 15:47:34 -07:00
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
Evan Wilde
f0430eb033 Merge pull request #80934 from etcwilde/ewilde/fix-bootstrap-builds
Fix Bootstrap: UTF8EncoddingError
2025-04-21 09:49:39 -07:00
Doug Gregor
54e4400e92 Merge pull request #80933 from DougGregor/safe-nested-in-unsafe-fixes
[Strict memory safety] Improve handling of safe types nested within unsafe ones
2025-04-20 02:31:48 -07:00
Evan Wilde
783c969e10 Fix Bootstrap: UTF8EncoddingError
The pass that annotated control-flow positions unreachable after an
infinite loop was migrated to pure Swift in PR 79186
(https://github.com/swiftlang/swift/pull/79186). As a result, the
C++-only bootstrap compiler is unable to determine that the
code-location is unreachable. Placing a fatalError after the infinite
while loop.

Fixes: rdar://149631113
2025-04-19 23:42:08 -07:00
Doug Gregor
457eb4cc64 [Strict memory safety] Update standard library for nested safe/unsafe types
Use this to mark a few internal types @safe now that it works properly.
2025-04-19 19:54:32 -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
Doug Gregor
fe6856726e [Strict memory safety] Remove now-extraneous "unsafe" from the standard libraries
Now that we aren't propagating "unsafe" to nested types, remove
unnecessary "unsafe" keywords from the standard library.
2025-04-19 08:13:05 -07:00
Guillaume Lessard
493e853039 Merge pull request #80684 from glessard/rdar137710901-addressable-utf8view-span
[SE-0456] enable span properties for the small-String representation
2025-04-17 22:52:14 -07:00
Karoy Lorentey
0c406b89e6 [stdlib] Allow metatype comparisons to work with outdated compilers
Add a new language feature to avoid the stdlib’s swiftinterface becoming unintelligible to outdated compiler builds due to the generalization of Builtin.is_same_metatype.

rdar://149396721
2025-04-16 12:45:09 -07:00
Alejandro Alonso
ace5c20b12 Merge pull request #78248 from Azoy/value-generic-static-member
[NameLookup] Allow value generics to show up as static members
2025-04-16 08:03:46 -07:00
Meghana Gupta
198a802719 Merge pull request #80767 from meg-gupta/reverttransparent
Revert #79707
2025-04-15 15:45:15 -07:00
Alejandro Alonso
b3f3dd79cf Handle dynamically accessing the static member from type(of:) 2025-04-14 15:32:46 -07:00
Guillaume Lessard
524b717944 [stdlib] work around autoclosure issues
- The move-only checker has issues with the existence of autoclosures.
- These `borrowing` accessors are within the purview of the move-only checker.
2025-04-14 10:48:42 -07:00
Guillaume Lessard
2d50c6cce9 Revert "[temporary] disable small-string support"
This reverts commit ea44ff9fc9.
2025-04-14 10:48:42 -07:00
Guillaume Lessard
1f93566d69 Merge pull request #80517 from glessard/rdar138440979-MutableSpan-mutableBytes
[SE-0467] add mutableBytes to MutableSpan
2025-04-13 10:33:09 -07:00
Michael Ilseman
e6e4bd6056 UTF8Span (#78531)
Add support for UTF8Span

Also, refactor validation and grapheme breaking
2025-04-11 16:11:11 -06: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
Guillaume Lessard
cb390140d6 [stdlib] correct MutableRawSpan sizing 2025-04-10 10:31:18 -07:00
Guillaume Lessard
53b6b45bda [stdlib] update lifetime annotation syntax 2025-04-10 10:31:18 -07:00
Guillaume Lessard
77431f5217 [stdlib] add MutableSpan.mutableBytes 2025-04-10 10:31:05 -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
Slava Pestov
822083872b Merge pull request #80678 from slavapestov/visionos-stdlib
CompatibilitySpan: Fix stdlib build on visionOS
2025-04-10 07:55:49 -04:00
Guillaume Lessard
5c54e3aea5 Merge pull request #80257 from glessard/rdar137710901-addressable-span-properties
[SE-0456, -0467] enable span properties for inline-storage types
2025-04-09 19:51:46 -07:00
Kuba Mracek
55f12fe13a [embedded] Add back LosslessStringConvertible to Bool and integer types 2025-04-09 10:08:58 -07:00