Commit Graph

3245 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
d7dfa3e942 Bring up tests + validation tests for the 'freestanding' build and the standalone_minimal preset (#34386) 2020-10-26 16:32:36 -07:00
Azoy
df9778e2e8 [Compatibility53] Add compatibility library for 5.3 and backport tuple Equatable conformance
Fix some comments

Unnecessary cast
2020-10-22 18:27:03 -04:00
Saleem Abdulrasool
09fc82aac3 Merge pull request #34299 from compnerd/i-dont-visual-c-you
stdlib: remove `swiftMSVCRT`, replace with `swiftCRT` on Windows
2020-10-20 11:05:03 -07:00
tbkka
5d30503894 When parsing floating-point from String, underflow to 0, overflow to infinity (#34339)
Previously, overflow and underflow both caused this to return `nil`, which causes several problems:
* It does not distinguish between a large but valid input and a malformed input.  `Float("3.402824e+38")` is perfectly well-formed but returns nil
* It differs from how the compiler handles literals.  As a result, `Float(3.402824e+38)` is very different from `Float("3.402824e+38")`
* It's inconsistent with Foundation Scanner()
* It's inconsistent with other programming languages

This is exactly the same as #25313

Fixes rdar://problem/36990878
2020-10-19 09:44:57 -04:00
Saleem Abdulrasool
2fc5cbdc14 stdlib: remove swiftMSVCRT, replace with swiftCRT on Windows
This replaces swiftMSVCRT with swiftCRT.  The big difference here is
that the `visualc` module is no longer imported nor exported.  The
`visualc` module remains in use for a singular test wrt availability,
but this should effectively remove the need for the `visualc` module.

The difference between the MSVCRT and ucrt module was not well
understood by most.  MSVCRT provided ucrt AND visualc, combining pieces
of the old MSVCRT and the newer ucrt.  The ucrt module is what you
really wanted most of the time, however, would need to use MSVCRT for
the convenience aliases for type-generic math and the deprecated math
constants.

Unfortunately, we cannot shadow the `ucrt` module and create a Swift SDK
overlay for ucrt as that seems to result in circular dependencies when
processing the `_Concurrency` module.

Although this makes using the C library easier for most people, it has a
more important subtle change: it cleaves the dependency on visualc.
This means that this enables use of Swift without Visual Studio for the
singular purpose of providing 3 header files.  Additionally, it removes
the need for the installation of 2 of the 4 support files.  This greatly
simplifies the deployment process on Windows.
2020-10-15 16:02:01 -07:00
Slava Pestov
94e999a1b5 Sema: Pull availability checking out of resolveType()
We used to diagnose references to unavailable declarations in
two places:

- inside Exprs, right after type checking the expression
- inside TypeReprs, from resolveType()

In broad terms, resolveType() is called with TypeReprs
stored inside both Stmts and Decls.

To handle the first case, I added a new overload of
diagAvailability() that takes a Stmt, to be called from
typeCheckStmt(). This doesn't actually walk into any Exprs
stored inside the statement; this means it only walks
Patterns and such.

For the second case, a new DeclAvailabilityChecker is
now defined in TypeCheckAccess.cpp. It's structure is
analogous to the other three walkers there:

- AccessControlChecker
- UsableFromInlineChecker
- ExportabilityChecker

The new implementation of availability checking for types
introduces a lot more code than the old online logic
it replaces. However, I hope to consolidate some of the
code duplication among the four checkers that are defined
in TypeCheckAccess.cpp, and do some other cleanups that
will make the benefit of the new approach apparent.
2020-10-14 23:42:02 -04:00
Karoy Lorentey
d5652fa9bf [test] Don’t check for new behavior on older systems that don’t include the change 2020-10-06 12:26:47 -07:00
Xiaodi Wu
23dc001364 Merge pull request #33910 from xwu/exactness-in-little-things-a-wonderful-source-of-cheerfulness
[stdlib] Simplify 'BinaryFloatingPoint.init?<T: BinaryFloatingPoint>(exactly: T)'
2020-10-05 12:14:27 -04:00
Josh Learn
1fd6ef95ce [OSLog] Update compiler stubs and tests
The compiler stubs for testing the OSLog implementation are in need of an update. This change updates the stubs to be consistent with the current OSLog implementation, updates the existing tests, and adds new tests for String and metatype interpolations.

rdar://69719729
2020-10-01 12:14:08 -07:00
Xiaodi Wu
6216ccdcad [stdlib] Fix a Float16-to-integer conversion bug (#33893)
* [stdlib] Fix a Float16-to-integer conversion bug

* [stdlib] Add a test for 'Int(exactly: Float16.infinity)'
2020-09-16 14:53:06 -04:00
Max Desiatov
0c8b86601c test: Replace _silgen_name w/ _cdecl in CommandLineStressTest
This test abuses @_silgen_name unnecessarily according to https://forums.swift.org/t/how-can-my-c-main-function-call-swift/40244/2
2020-09-14 09:23:22 +01:00
Xiaodi Wu
26cda274ca [stdlib] Simplify 'BinaryFloatingPoint.init?<T: BinaryFloatingPoint>(exactly: T)' 2020-09-11 09:56:58 -04:00
3405691582
cd7570fdee ManagedBuffer capacity is unavailable on OpenBSD.
On OpenBSD, malloc introspection (e.g., malloc_usable_size or
malloc_size) is not provided by the platform allocator. Since allocator
introspection is currently a load-bearing piece of functionality for
ManagedBuffer and ManagedBufferPointer, pending any API changes, as a
stopgap measure, this commit marks methods in ManagedBuffer and
ManagedBufferPointer calling _swift_stdlib_malloc_size and methods
dependent thereon unavailable on OpenBSD.

This may induce some compatibility issues for some files, but at least
this change ensures that we can get stdlib to build on this platform
until the evolution process addresses this problem more thoroughly.
2020-09-09 18:57:58 -04:00
Kuba (Brecka) Mracek
73f427369f Mark Reflection_jit.swift as UNSUPPORTED for standalone stdlib builds (#33682) 2020-08-28 20:50:47 -07:00
Mike Ash
0990fa90b3 Merge pull request #33647 from mikeash/shrink-concurrentreadablehashmap
[Runtime] Shrink ConcurrentReadableHashMap a bit.
2020-08-28 14:45:17 -04:00
tbkka
524cfae1b2 [Dynamic Casting] Overhauled Runtime (#33561)
* Dynamic Cast Rework: Runtime

This is a completely refactored version of the core swift_dynamicCast
runtime method.

This fixes a number of bugs, especially in the handling of multiply-wrapped
types such as Optional within Any.  The result should be much closer to the
behavior specified by `docs/DynamicCasting.md`.

Most of the type-specific logic is simply copied over from the
earlier implementation, but the overall structure has been changed
to be uniformly recursive.  In particular, this provides uniform
handling of Optional, existentials, Any and other common "box"
types along all paths.  The consistent structure should also be
easier to update in the future with new general types.

Benchmarking does not show any noticable performance implications.

**Temporarily**, the old implementation is still available.  Setting the
environment variable `SWIFT_OLD_DYNAMIC_CAST_RUNTIME` before launching a program
will use the old runtime implementation.  This is only to facilitate testing;
once the new implementation is stable, I expect to completely remove the old
implementation.
2020-08-27 11:06:40 -07:00
Mike Ash
4cd1b715bd [Runtime] Shrink ConcurrentReadableHashMap a bit.
We're using a lot of space on the free lists. Each vector is three words, and we have two of them. Switch to a single linked list. We only need one list, as both kinds of pointers just get free()'d. A linked list optimizes for the common case where the list is empty. This takes us from six words to one.

Also make ReaderCount, ElementCount, and ElementCapacity uint32_ts. The size_ts were unnecessarily large and this saves some space on 64-bit systems.

While we're in there, add 0/NULL initialization to all elements. The current use in the runtime is unaffected (it's statically allocated) but the local variables used in the test were tripping over this.
2020-08-27 13:05:40 -04:00
Mike Ash
e13217147f [Test] Filter out a __rotate symbol and another __once_call symbol in symbol-visibility-linux.test-sh. 2020-08-20 15:55:38 -04:00
Mishal Shah
cc19330c75 Codesign the Error binary before executing 2020-08-19 17:59:59 -07:00
tbkka
7de957362e Don't verify exact NaN text for .debugDescription (#33391)
This specific check has never worked on all processors (because
some FP HW mangles NaNs) and recent LLVM changes have broken
it on the remaining platforms.

Resolves SR-13354
2020-08-10 18:40:57 -07:00
Stephen Canon
457b9990e9 Add checks that the endpoints of partial ranges are not-NaN. (#33378)
We can't actually check for NaN (because the notion doesn't exist for Comparable), but we can require that the endpoint is non-exceptional by checking if it equals itself.
2020-08-10 14:06:46 -04:00
Saleem Abdulrasool
5782dd4af3 Merge pull request #33343 from compnerd/dispatch-ASi
test: repair stdlib/Dispatch on ASi
2020-08-08 08:12:50 -07:00
Mishal Shah
bc2a8f41c1 Merge pull request #33354 from apple/shahmishal/codesign-tests
[Tests] Codesign the binary before executing the test
2020-08-07 19:33:20 -07:00
Kyle Macomber
9bbe6e7365 Merge pull request #28639 from YOCKOW/sr-10689-cherry-pick
SR-10689: Fix bugs of DataProtocol's firstRange(of:in:)/lastRange(of:in:).
2020-08-07 15:39:03 -07:00
Saleem Abdulrasool
a405c5d994 test: repair stdlib/Dispatch on ASi
The conversion of the naonseconds to Mach ticks in multiples of Mach
timebase units alters the time.  This would fail on ASi where mach ticks
are not synonymous with nanoseconds.
2020-08-07 14:58:36 -07:00
Mishal Shah
06c975cff4 Remove code sign from stdlib/Error.swift 2020-08-07 12:40:11 -07:00
Mishal Shah
a3cd8bc9e9 [Tests] Codesign the binary before executing the test 2020-08-07 00:26:07 -07:00
Saleem Abdulrasool
48b0802b63 test: swap parameters in test assertion (NFC)
Swap the parameters in `assertEqual` to improve diagnostics on failure.
This now prints as:

```
stdout>>> expected: -431 (of type Swift.int)
stdout>>> actual: -11 (of type Swift.int)
```
2020-08-06 09:04:23 -07:00
Rintaro Ishizaki
4e003dc8cc [Tests] Mark two test cases 'UNSUPPORTED: use_os_stdlib'
test/Runtime/demangleToMetadata.swift
test/stdlib/Casts.swift

rdar://problem/66394834
rdar://problem/66394791
2020-07-31 16:02:49 -07:00
eeckstein
53d3dda55e Merge pull request #33179 from eeckstein/existential-box-elimination
SILCombine: optimize casts of existential boxes.
2020-07-31 18:02:31 +02:00
Doug Gregor
e2cdc5e04b Merge pull request #33196 from DougGregor/concurrency-lib
[Concurrency] Stub out an experimental concurrency support library.
2020-07-30 11:51:27 -07:00
Erik Eckstein
5f3e79b84e StringOptimization: bug fixes
Fix some bugs in the optimization and in the test files.

rdar://problem/66283894
2020-07-30 11:32:39 +02:00
Doug Gregor
9b0266cf6a [Concurrency] Stub out an experimental concurrency support library.
The experimental concurrency model will require a supporting runtime
and possibly end-user-visible library constructs. Introduce a stub of
such a library, enabled by a new `build-script` option
`--enable-experimental-concurrency`, so we have a place to put this
work.
2020-07-29 16:32:27 -07:00
Erik Eckstein
662f03ec4c SILCombine: optimize casts of existential boxes.
Optimize the unconditional_checked_cast_addr in this pattern:

   %box = alloc_existential_box $Error, $ConcreteError
   %a = project_existential_box $ConcreteError in %b : $Error
   store %value to %a : $*ConcreteError
   %err = alloc_stack $Error
   store %box to %err : $*Error
   %dest = alloc_stack $ConcreteError
   unconditional_checked_cast_addr Error in %err : $*Error to ConcreteError in %dest : $*ConcreteError

to:
   ...
   retain_value %value : $ConcreteError
   destroy_addr %err : $*Error
   store %value to %dest $*ConcreteError

This lets the alloc_existential_box become dead and it can be removed in following optimizations.
The same optimization is also done for conditional_checked_cast_addr.

There is also an implication for debugging:
Each "throw" in the code calls the runtime function swift_willThrow. The function is used by the debugger to set a breakpoint and also add hooks.
This optimization can completely eliminate a "throw", including the runtime call.
So, with optimized code, the user might not see the program to break at a throw, whereas in the source code it is actually throwing.
On the other hand, eliminating the existential box is a significant performance win and we don't guarantee any debugging behavior for optimized code anyway. So I think this is a reasonable trade-off.
I added an option "-Xllvm -keep-will-throw-call" to keep the runtime call which can be used if someone want's to reliably break on "throw" in optimized builds.

rdar://problem/66055678
2020-07-29 21:57:51 +02:00
Doug Gregor
41817229d5 Merge pull request #33147 from DougGregor/async-function-types
[Concurrency] Add `async` to the Swift type system.
2020-07-29 08:59:34 -07:00
Doug Gregor
06d322b211 [Concurrency] Rename -enable-experimental-async.
Use the more general name `-enable-experimental-concurrency` instead,
since async is one part of the model.
2020-07-28 09:38:54 -07:00
Doug Gregor
f6e9f352f0 [Concurrency] Add async to the Swift type system.
Add `async` to the type system. `async` can be written as part of a
function type or function declaration, following the parameter list, e.g.,

  func doSomeWork() async { ... }

`async` functions are distinct from non-`async` functions and there
are no conversions amongst them. At present, `async` functions do not
*do* anything, but this commit fully supports them as a distinct kind
of function throughout:

* Parsing of `async`
* AST representation of `async` in declarations and types
* Syntactic type representation of `async`
* (De-/re-)mangling of function types involving 'async'
* Runtime type representation and reconstruction of function types
involving `async`.
* Dynamic casting restrictions for `async` function types
* (De-)serialization of `async` function types
* Disabling overriding, witness matching, and conversions with
differing `async`
2020-07-27 18:18:03 -07:00
Erik Eckstein
7f684b62e2 SIL optimizer: Add a new string optimization.
Optimizes String operations with constant operands.

Specifically:
  * Replaces x.append(y) with x = y if x is empty.
  * Removes x.append("")
  * Replaces x.append(y) with x = x + y if x and y are constant strings.
  * Replaces _typeName(T.self) with a constant string if T is statically known.

With this optimization it's possible to constant fold string interpolations, like "the \(Int.self) type" -> "the Int type"

This new pass runs on high-level SIL, where semantic calls are still in place.

rdar://problem/65642843
2020-07-27 21:32:56 +02:00
Luciano Almeida
33d23719eb [tests] Fixing pattern match of note avalable overload lists diagnostic 2020-07-24 15:01:52 -03:00
Luciano Almeida
c09af513a0 [tests] Adjusting regression tests argument mismatch diagnostics on suit 2020-07-23 20:05:27 -03:00
Holly Borla
c8e9018c4d [CSGen] Don't merge type variables for literals in computeFavoredTypeForExpr 2020-07-22 14:43:05 -07:00
Brent Royal-Gordon
4394e92c3f Merge pull request #32700 from brentdax/magical-and-evolutionary
Revise #file changes from SE-0274
2020-07-17 01:57:23 -07:00
Karoy Lorentey
8961b4ea56 [test] stdlib/DefaultIndices: Adjust test conditional
This makes it easier to find & update the availability condition if this behavior ships in an OS release.
2020-07-15 14:27:21 -07:00
Nate Chandler
a2ce157a98 [Test] Disable stdlib/DefaultIndices when use_os_stdlib.
rdar://problem/65605593
2020-07-15 09:58:36 -07:00
Karoy Lorentey
5f489fc719 [test] Fix architecture conditional
rdar://64995079
2020-07-14 18:55:41 -07:00
Stephen Canon
103961a7d5 Make Float16 unavailable on macOS and macCatalyst, mirroring Xcode's Swift. (#32868)
LLVM doesn't have a stable ABI for Float16 on x86 yet; we're working with Intel to get that fixed, but we don't want to make the type available on macOS until a stable ABI is actually available, because we'd break binaries compiled before any calling convention changes if we do.
2020-07-14 20:42:12 -04:00
Nate Cook
3af1deb447 [stdlib] Add _forEachField(of:options:body:) function (#32873)
This function walks all the fields of a struct, class, or tuple, and calls
`body` with the name, offset, and type of each field. `body` can perform
any required work or validation, returning `true` to continue walking fields
or `false` to stop immediately.
2020-07-14 16:31:32 -05:00
Karoy Lorentey
40d7da4fad Merge pull request #32019 from NevinBR/patch-1
[SR-12881] DefaultIndices dynamic dispatch
2020-07-14 12:05:12 -07:00
Brent Royal-Gordon
745dbef3ef Use file IDs in generated code
Such as force unwraps, as! casts, etc.
2020-07-13 14:05:13 -07:00
Saleem Abdulrasool
08924c476d Merge pull request #32826 from compnerd/bloating-point-operations
test: make `stdlib/Integer.swift.gyb` python 3 friendly
2020-07-13 13:46:11 -07:00