Commit Graph

53 Commits

Author SHA1 Message Date
Gabor Horvath
402ad33463 [StrictMemorySafety] Check the safety of return types of calls
Previously, we skipped checking the return type of a function for safety
as we expected to warn at the use of the returned value:

  let x = returnsUnsafe()
  usesUnsafe(x) // warn here

Unfortunately, this resulted in missing some unsafe constructs that can
introduce memory safety issues when the use of the return value had a
different shape resulting in false negatives for cases like:

  return returnsUnsafe()

or

  usesUnsafe(returnsUnsafe())

This PR changes the analysis to always take return types of function
calls into account.

rdar://157237301
2025-08-05 12:16:44 +01: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
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Alejandro Alonso
d3146e37b3 Update Scalar names for Unicode 16 2025-01-15 14:08:30 -08:00
Kuba Mracek
7ae20b7039 [embedded] Port Swift.String to embedded Swift 2024-05-08 11:11:37 -07:00
Alejandro Alonso
cc62bb1ddc Update copyright years 2023-03-29 10:35:30 -07:00
Alejandro Alonso
f16f0c3c23 Update the stdlib to use Unicode 15 data 2023-03-29 10:18:16 -07:00
Ole Begemann
46c472f408 Reintroduce intentional typo in Unicode doc comment
This reintroduces an intentionally misspelled word in a doc comment for the `Unicode.Scalar.Properties.nameAlias` property. This "typo" was accidentally "fixed" in be13b470aa.
2022-05-13 22:23:17 +02:00
Josh Soref
644c18ca9b Spelling stdlib (#42444)
* spelling: against

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

* spelling: algorithmic

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

* spelling: alignment

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

* spelling: anything

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

* spelling: architectural

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

* spelling: architecture

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

* spelling: are

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

* spelling: artificial

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

* spelling: aside

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

* spelling: available

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

* spelling: being

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

* spelling: bidirectional

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

* spelling: characters

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

* spelling: circular

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

* spelling: compatibility

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

* spelling: compiled

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

* spelling: correctly

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

* spelling: covers

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

* spelling: declaration

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

* spelling: dependencies

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

* spelling: descriptor

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

* spelling: dictionaries

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

* spelling: dynamic

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

* spelling: greater

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

* spelling: hierarchy

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

* spelling: immortal

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

* spelling: initialize

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

* spelling: initializes

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

* spelling: iterable

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

* spelling: message

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

* spelling: minimum

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

* spelling: multiple

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

* spelling: originally

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

* spelling: simplified

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

* spelling: sophisticated

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

* spelling: trivia

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

* spelling: wasn't

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:43 -07:00
Alejandro Alonso
76fbb3c139 Some fixes for scalar names 2021-12-20 13:51:45 -08:00
Alejandro Alonso
ac6c08f157 [stdlib] Make the rest of the scalar properties native (#40233)
* Factor out the scalar bit array index mechanism

* Implement native numeric scalar properties

* Implement native scalar name aliases

* Implement native scalar mappings

* Implement native scalar names

* Implement native scalar age

* Implement native scalar general category

* Address Michael's and others comments

fix special mappings

fix bug
2021-11-30 12:40:32 -08:00
Alejandro Alonso
3b402f0179 [stdlib] Implement native Unicode.Scalar binary properties (#39597)
* Generate Unicode data for Scalar Binary Properties

* Use native scalar binary property lookup

* Add _BinaryProperties to Scalar Properties

narrow access control

* Upgrade the notice to a warning in UnicodeScalarProperties
2021-11-15 15:20:46 -08:00
Alejandro Alonso
98aaa157ec Implement native normalization for String
use >/< instead of !=

fix some bugs

fix
2021-09-29 14:20:21 -07:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Doug Gregor
1a1f79c0de Introduce safety checkin for ConcurrentValue conformance.
Introduce checking of ConcurrentValue conformances:
- For structs, check that each stored property conforms to ConcurrentValue
- For enums, check that each associated value conforms to ConcurrentValue
- For classes, check that each stored property is immutable and conforms
  to ConcurrentValue

Because all of the stored properties / associated values need to be
visible for this check to work, limit ConcurrentValue conformances to
be in the same source file as the type definition.

This checking can be disabled by conforming to a new marker protocol,
UnsafeConcurrentValue, that refines ConcurrentValue.
UnsafeConcurrentValue otherwise his no specific meaning. This allows
both "I know what I'm doing" for types that manage concurrent access
themselves as well as enabling retroactive conformance, both of which
are fundamentally unsafe but also quite necessary.

The bulk of this change ended up being to the standard library, because
all conformances of standard library types to the ConcurrentValue
protocol needed to be sunk down into the standard library so they
would benefit from the checking above. There were numerous little
mistakes in the initial pass through the stsandard library types that
have now been corrected.
2021-02-04 03:45:09 -08:00
Matt Zanchelli
be13b470aa Fix typos
becuase -> because
preceeds -> precedes
initalizer -> initializer
intialize -> initialize
libary -> library
notfication -> notification
reciever -> receiver
collecton -> collection
exlcusive -> exclusive
techincal -> technical
compatability -> compatibility
setps -> steps
accomodate -> accommodate
brakcet -> bracket
fraciton -> fraction
programm -> program
concequently -> consequently
ecoding -> encoding
timeIntervalforSelfEnd -> timeIntervalForSelfEnd
2020-12-21 18:44:03 -05:00
Valeriy Van
dd237b984b Eliminates redundant buffer zeroing in internal func in UnicodeScalarProperties by using init(unsafeUninitializedCapacity:initializingWith:) 2020-06-11 12:51:18 +02:00
Valeriy Van
b5392e8fb3 Refactors internal func _applyMapping using _FixedArray16 2020-05-26 02:00:30 +02:00
Valeriy Van
1e9bc9f408 Fixes example snippets in UnicodeScalarProperties.swift (#31514) 2020-05-04 12:49:28 -05:00
Nate Cook
f19aca6cb0 [WIP] Revise documentation for Swift 5 stdlib additions (#21333)
* Revise the Unicode scalar/Character properties
* Minor revisions to `compactMapValues` docs.
* Add documentation for AdditiveArithmetic, revise Numeric
* Apply minor style updates to count(where:).
* Revise string interpolation docs.

- Convert table of interpolation examples to a list of examples. Tables
aren't supported by Swift markup, so this wouldn't render properly in
Xcode or on the web.
- Add a description of what a user must implement in a custom
string interpolation type to get the behavior they want.

* Revise isMultiple(of:) docs.

- In particular, add emphasis to mathematical symbols and equations to
match how we document such things elsewhere.
- I'm using asterisks for single symbols, and underscores for equations
because it's easier to read in-source when you don't have to escape
multiplication within emphasis.

* Add some abstracts to the SIMD vector types.

- Adds a dictionary of spelled out numbers. Only numbers < 10
  should be spelled out according to editorial.
- Adds abstracts to some of the basic members.
- Includes parameter descriptions for the xyzw properties and inits,
but not for the unlabeled initializers. Combined with the protocol
extension method abstracts, this should complete coverage of the concrete
types.
2019-01-03 18:19:20 -06:00
Karoy Lorentey
545fa5e640 [stdlib] Re-add previously synthesized hashing definitions 2018-11-22 17:15:36 +00:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
Michael Ilseman
f9e6df312a Implement SE-0221: Character Properties (#20520)
Provide convenience properties on Character.
2018-11-15 14:03:49 -08:00
Michael Ilseman
948655e850 [String] Cleanups, comments, documentation
After rebasing on master and incorporating more 32-bit support,
perform a bunch of cleanup, documentation updates, comments, move code
back to String declaration, etc.
2018-11-04 10:42:42 -08:00
Michael Ilseman
fe7c3ce2e4 [String] Refactorings and cleanup
* Refactor out RRC implementation into dedicated file.

* Change our `_invariantCheck` pattern to generate efficient code in
  asserts builds and make the optimizer job's easier.

* Drop a few Bidi shims we no longer need.

* Restore View decls to String, workaround no longer needed

* Cleaner unicode helper facilities
2018-11-04 10:42:40 -08:00
Michael Ilseman
f23a3c19b8 [String] Bounds checking and Index cleanup 2018-11-04 10:42:40 -08:00
Michael Ilseman
4ab45dfe20 [String] Drop in initial UTF-8 String prototype
This is a giant squashing of a lot of individual changes prototyping a
switch of String in Swift 5 to be natively encoded as UTF-8. It
includes what's necessary for a functional prototype, dropping some
history, but still leaves plenty of history available for future
commits.

My apologies to anyone trying to do code archeology between this
commit and the one prior. This was the lesser of evils.
2018-11-04 10:42:40 -08:00
Ben Rimmington
cec9faf1c0 [SE-0211] Emoji properties require ICU 57 or later 2018-09-13 18:18:33 +01:00
Michael Ilseman
b93a351c89 Merge branch 'master' into patch-1 2018-08-11 18:51:29 -07:00
Thomas Roughton
839d92b247 [stdlib] UnicodeScalarProperties: use RawValue over UInt32
On Windows, `__swift_stdlib_UNumericType` and `__swift_stdlib_UCharCategory` are imported as `Int32`s rather than `UInt32`. Change the constructors to use the type's inferred `RawValue` rather than always `UInt32`.
2018-08-11 12:01:19 +12:00
Michael Ilseman
9f6eecb1ef [string] Internal Unicode.Scalar.withUTF16CodeUnits
Clean up Unicode.Scalar.Properties a bit and add internal methods to
access UTF-16 and UTF-8 code units by pointer. NFC.
2018-08-10 16:22:49 -07:00
swift-ci
4edbd83576 Merge pull request #17923 from allevato/unicode-properties-docs 2018-07-24 17:45:06 -07:00
Tony Allevato
5352545f9c Apply review feedback 2018-07-16 18:00:39 -07:00
Ben Cohen
b77b544cdc Remove remaining @ininable from @_transparent (#17968) 2018-07-16 08:12:52 -07:00
Tony Allevato
f99109c552 [stdlib] NFC: Unicode.Scalar.Properties documentation fixes 2018-07-12 21:32:05 -07:00
Tony Allevato
b454e8d0f4 Make emoji properties Darwin only.
Ubuntu 16.04 doesn't have a recent enough ICU to support these; we need a better long-term solution, such as bundling ICU with the toolchain.
2018-07-09 18:42:42 -07:00
Tony Allevato
d0e93acb00 Various fixes to Unicode.Scalar.Properties.
- numericValue returns nil instead of .nan for non-numerics
- Remove small-string optimizations from _scalarName that failed on 32-bit archs
- Put case mappings back into U.S.Properties
- Added more sanity tests
2018-07-05 20:42:56 -07:00
Tony Allevato
54f4c77ce7 [stdlib] Revert hasNormalizationBoundaryBefore
This property is too specific in that it forces a particular normalization; let's not expose it this way, but instead in the future with a full normalization API.
2018-04-22 12:01:03 -07:00
Tony Allevato
95dc229d17 [stdlib] Fix age property and update case mappings
Using &foo.0 is not a suitable shortcut for getting a mutable
pointer to the first element of a tuple.
2018-04-06 06:29:50 -07:00
Tony Allevato
f06af77e01 [stdlib] Lift case mappings directly into Unicode.Scalar 2018-04-03 23:02:15 -07:00
Tony Allevato
56d04befd1 [stdlib] Rewrite _scalarName to fully use a small string 2018-04-03 19:20:38 -07:00
Tony Allevato
47deadc2fb [stdlib] Compute scalar's UTF-16 on demand instead of caching 2018-04-02 21:38:54 -07:00
Tony Allevato
5a7d7d3929 [stdlib] Update case mappings to use small strings if possible 2018-04-02 21:12:08 -07:00
Tony Allevato
4a1794074a [stdlib] Update documentation for case mappings 2018-04-01 19:41:43 -07:00
Tony Allevato
5807bb9436 [stdlib] Fix _scalarName to use small string if possible 2018-04-01 19:29:26 -07:00
Tony Allevato
3a2ad05092 [stdlib] Add "isDefined", "hasNormalizationBoundaryBefore" to Unicode.Scalar.Properties 2018-03-28 06:40:25 -07:00
Tony Allevato
354f2ad66e [stdlib] Add "numeric{Type,Value}" to Unicode.Scalar.Properties 2018-03-27 21:07:27 -07:00
Tony Allevato
e7078a473b [stdlib] Add "canonicalCombiningClass" to Unicode.Scalar.Properties 2018-03-26 06:38:55 -07:00
Tony Allevato
e7fa49984a [stdlib] Add "{lower,title,upper}caseMapping" to Unicode.Scalar.Properties 2018-03-26 06:38:55 -07:00
Tony Allevato
9858d4edfb [stdlib] Add "name", "nameAlias" to Unicode.Scalar.Properties 2018-03-26 06:38:55 -07:00