Commit Graph

403 Commits

Author SHA1 Message Date
Karoy Lorentey
1a051719e3 [runtime] Adjust file/line information in fatal error messages to follow diagnostic conventions
In debug configurations, fatal error messages include file & line number information. This update presents this information in a format matching the diagnostic conventions used by the compiler, which can be a slight productivity boost.

Code compiled with optimizations enabled (which is most production code) does not output this information, so it isn’t affected by this change.

Original format:

    Fatal error: A suffusion of yellow: file calc.swift, line 5

New format:

    calc.swift:5: Fatal error: A suffusion of yellow

Resolves rdar://68484891
2020-11-10 13:23:21 -08:00
Dave Lee
25ad42f63b missed these need_* variables 2020-11-02 08:56:35 -08:00
Dave Lee
e469ffbaf0 upcase need_* preprocessor variables 2020-11-02 08:21:37 -08:00
Dave Lee
b9c16d2a85 [stdlib] Conditionally compile swift_strto* wrappers 2020-10-30 16:55:09 -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
Kuba (Brecka) Mracek
aa0f8e670b Add a SWIFT_STDLIB_OS_VERSIONING flag to avoid querying OS version at runtime, use it in the freestanding build (#33791) 2020-09-11 08:09:14 -07:00
Dave Lee
389d099705 [stdlib] Silence a few assert related warnings 2020-09-09 09:43:56 -07:00
Mike Ash
fd6922f92d Add error reporting when looking up types by demangled name. 2020-08-28 14:43:51 -04:00
Kuba (Brecka) Mracek
9ead8d57fa Add a single-threaded stdlib mode, use it for the 'minimal' stdlib (#33437) 2020-08-25 06:03:14 -07:00
Mike Ash
da111087df [Stdlib] Handle EINTR in readLine.
rdar://problem/65366135
2020-07-13 10:58:17 -04:00
zoecarver
3e4ddb13d6 [NFC] Remove __swift_mode_t.
Removes the "__swift_mode_t" type from SwiftShims. This type is no longer used anywhere.
2020-07-10 08:38:10 -07:00
Zoe Carver
7eff49c1b6 [cxx-interop] [nfc] Remove swift namespace from SwiftShims in C++ mode. (#32715)
Most SwiftShims were put in the swift namespace in C++ mode which broke certain things when importing them in a swift file in C++ mode. This was OK when they were only imported as part of the swift runtime but, now they are used in C++ mode both in the swift runtime and when C++ interop is enabled.

This broke when C++ interop was enabled because the `Swift` module contains references to symbols in the SwiftShims headers which are built without C++ interop enabled (no "swift" namespace). But, when C++ interop is enabled, the SwiftShims headers would put everything in the swift namespace meaning the symbols couldn't be found in the global namespace. Then, the compiler would error when trying to deserialize the Swift module.
2020-07-08 08:43:26 -07:00
Saleem Abdulrasool
e258bc45d0 Merge pull request #32537 from 3405691582/StrtoSimplicity
[stdlib] Simplify the strto* platform stubs.
2020-06-30 13:22:04 -07:00
3405691582
d3a9314979 [stdlib] Simplify the strto* platform stubs.
Currently, _swift_stdlib_strtoX_clocale_impl is present here twice: one
general definition for most platforms that wraps the standard strto*
functions, and another general definition with a slightly different
implementation for Cygwin, Haiku, and Windows, using stringstreams to
achieve a similar result. Furthermore, for Windows, the stringstream
implementation isn't even used but specialized away.

Firstly: the stringstream implementation is slightly broken, since it
causes some of the unit tests to fail; secondly, there is an awful lot
of repetition here that is ripe for simplification.

Instead of duplicating twice and using template specialization to induce
platform-specific behavior, we massage the stringstream implementation
for Cygwin and Haiku into something that looks like a standard strto*
function.

Now we have one definition (for each type) of swift_strto*_l. By
default, the _swift_stdlib_strto*_clocale stubs will refer to strto*_l,
and platforms withing to make use of the swift_strto*_l stubs can make
the necessary preprocessor definitions to utilize them.
2020-06-29 16:34:24 -04:00
3405691582
3cc9d75d43 [NFC] Gather strto*_l stubs together.
Instead of putting the stubs alongside the redefinitions in each platform
preprocessor section, split these out, in anticipation for consolidation
in the next commit.
2020-06-29 16:29:46 -04:00
3405691582
311482db41 [NFC] Pull out the win32 implementation.
Here the template specializations can be adapted to a strto* wrapper, for
use with the general function-pointer implementation of
_swift_stdlib_strtoX_clocale_impl.
2020-06-29 16:29:46 -04:00
3405691582
bf0a183853 [NFC] Move the strto*_l stubs closer to use.
The includes stay at the top, while the stub definitions move closer to
_swift_stdlib_strtoX_clocale_impl.
2020-06-29 16:29:46 -04:00
Robert Widmann
3faad6a1bb Correct Windows Command Line Parsing Error Handling Paths
Returning nullptr from this function is undefined behavior. Instead,
just crash.
2020-06-25 14:19:13 -07:00
Robert Widmann
af853fd678 Correct WASI Command Line Parsing Error Handling Paths
This function may not return the null pointer. On error, just crash.
2020-06-25 14:15:53 -07:00
Robert Widmann
5dad41fb75 [NFC] Modernize Casts
C++ static_cast is far safer than C-style casts.
2020-06-25 09:07:11 -07:00
3405691582
bb2bd64594 [NFC] Run clang-format over CommandLine.cpp.
As discussed in #32514, this just runs clang-format over this file.
2020-06-24 19:38:47 -04:00
Robert Widmann
c825d7987e Merge pull request #32514 from 3405691582/OpenBSD_CommandLine
Command line routines for OpenBSD.
2020-06-24 15:28:48 -07:00
3405691582
b1f29d9617 Command line routines for OpenBSD. 2020-06-23 18:34:52 -04:00
3405691582
85c5c2ca3b [test][stdlib] Add strto*_l stubs for OpenBSD.
The template defined for Cygwin and friends does not handle failure cases
properly so the NumericParsing unit test fails.  To get the correct test
behavior, we need to use an implementation such as like in the Windows
specializations or the non-Cygwin implementation that takes a function
pointer.

However, adding additional specializations would be too wordy, and
OpenBSD doesn't have locale-dependent definitions of the relevant strto*
functions. We could add a specialization for a two-argument function
pointer, but that becomes too repetitive.

Instead, implement a few stubs and use the preprocessor, a la the
implementation for Android.
2020-06-15 17:50:25 -04:00
Mike Ash
b25dab2925 Merge pull request #32137 from mikeash/debug-environment-variables
[Runtime] Unify debug variable parsing from the environment and avoid getenv when possible.
2020-06-04 16:39:18 -04:00
Mike Ash
f2fb53967c [Runtime] Unify debug variable parsing from the environment and avoid getenv when possible.
There are a few environment variables used to enable debugging options in the
runtime, and we'll likely add more over time. These are implemented with
scattered getenv() calls at the point of use. This is inefficient, as most/all
OSes have to do a linear scan of the environment for each call. It's also not
discoverable, since the only way to find these variables is to inspect the
source.

This commit places all of these variables in a central location.
stdlib/public/runtime/EnvironmentVariables.def defines all of the debug
variables including their name, type, default value, and a help string. On OSes
which make an `environ` array available, the entire array is scanned in a single
pass the first time any debug variable is requested. By quickly rejecting
variables that do not start with `SWIFT_`, we optimize for the common case where
no debug variables are set. We also have a fallback to repeated `getenv()` calls
when a full scan is not possible.

Setting `SWIFT_HELP=YES` will print out all available debug variables along with
a brief description of what they do.
2020-06-04 10:00:06 -04:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Saleem Abdulrasool
3fa1d1fe3f runtime: ingest LLVMSupport into the runtime
This adds a new copy of LLVMSupport into the runtime.  This is the final
step before changing the inline namespace for the runtime support.  This
will allow us to avoid the ODR violations from the header definitions of
LLVMSupport.

LLVMSupport forked at: 22492eead218ec91d349c8c50439880fbeacf2b7
Changes made to LLVMSupport from that revision:
  process.inc forward declares `_beginthreadex` due to compilation issues due to custom flag handling

API changes required that we alter the `Deallocate` routine to account
for the alignment.

This is a temporary state, meant to simplify the process.  We do not use
the entire LLVMSupport library and there is no value in keeping the
entire library.  Subsequent commits will prune the library to the needs
for the runtime.
2020-05-15 09:55:36 -07:00
Saleem Abdulrasool
c721cf12f5 Merge pull request #31635 from compnerd/completely-impartial
runtime: remove use of `swift/LLVM.h` (NFC)
2020-05-09 11:28:04 -07:00
Saleem Abdulrasool
2ea11b5428 runtime: remove use of swift/LLVM.h (NFC)
Rather than using the forward declaration for the LLVMSupport types,
expect to be able to use the full declaration.  Because these are
references in the implementation, there is no reason to use a forward
declaration as the full types need to be declared for use.  The LLVM
headers will provide the declaration and definition for the types.  This
is motivated by the desire to ensure that the LLVMSupport symbols are
properly namespaced to avoid ODR violations in the runtime.
2020-05-07 13:37:31 -07:00
Saleem Abdulrasool
04eeff5b8d runtime: remove llvm/Support header usage
This reduces the dependency on `LLVMSupport`.  This is the first step
towards helping move towards a local fork of the LLVM ADT to ensure that
static linking of the Swift runtime and core library does not result in
ODR violations.
2020-05-07 13:36:13 -07:00
Arnold Schwaighofer
048e78ef79 Revert "Merge pull request #30024 from Azoy/calling-metadata-accessor-from-swift!"
This reverts commit 5fd6e98b2f, reversing
changes made to 3aee49d9d0.

Revert "XFAIL test/Interpreter/metadata_access.swift on arm64e"

This reverts commit 8fe216b004.

Revert "XFAIl test on os stdlib bots"

This reverts commit aea5fa4842.
2020-04-24 12:28:24 -07:00
David Smith
220f0ccde8 Untag tagged constant NSString pointers before we wrap them, so BridgeObject doesn't stomp the high bits 2020-04-22 16:49:23 -07:00
David Smith
e192a7ec0f Merge pull request #30966 from Catfish-Man/tagged-too
Avoid attempting to create SmallStrings for constant tagged CFStrings
2020-04-15 15:37:10 -07:00
David Smith
5ad4b15af6 Avoid attempting to create SmallStrings for constant tagged CFStrings 2020-04-15 12:30:20 -07:00
Robert Widmann
5fd6e98b2f Merge pull request #30024 from Azoy/calling-metadata-accessor-from-swift!
Runtime: Implement wrapper function to call metadata access functions
2020-04-14 19:28:47 -07:00
tbkka
110e5136c1 Float16 optimal formatting (#30862)
Extend SwiftDtoa to provide optimal formatting for Float16 and use that for `Float16.description` and `Float16.debugDescription`.

Notes on signaling NaNs: LLVM's Float16 support passes Float16s on x86
by legalizing to Float32.  This works well for most purposes but incidentally
loses the signaling marker from any NaN (because it's a conversion as far
as the hardware is concerned), with a side effect that the print code never
actually sees a true sNaN.  This is similar to what happens with Float and
Double on i386 backends.  The earlier code here tried to detect sNaN in a
different way, but that approach isn't guaranteed to work so we decided to
make this code use the correct detection logic -- sNaN printing will just be
broken until we can get a better argument passing convention.

Resolves rdar://61414101
2020-04-09 09:37:38 -04:00
Stephen Canon
248c554524 Add Float16 to stdlib (#30130)
Add Float16 (IEEE 754 binary16) to the standard library, plus assorted runtime support operations.

Swift Evolution thread: https://forums.swift.org/t/se-0277-float16/33546
2020-04-06 17:57:44 -04:00
Azoy
f35efee6dd Move metadataAccessorCall to SwiftShims 2020-04-06 17:09:21 -04:00
3405691582
5847726f51 Preliminary support for OpenBSD in the stdlib.
These should hopefully all be uncontroversial, minimal changes to deal
with progressing the build to completion on OpenBSD or addressing minor
portability issues. This is not the full set of changes to get a
successful build; other portability issues will be addressed in future
commits.

Most of this is just adding the relevant clauses to the ifdefs, but of
note in this commit:

* StdlibUnittest.swift: the default conditional in _getOSVersion assumes
  an Apple platform, therefore the explicit conditional and the relevant
  enums need filling out. The default conditional should be #error, but
  we'll fix this in a different commit.

* tgmath.swift.gyb: inexplicably, OpenBSD is missing just lgammal_r.
  Tests are updated correspondingly.

* ThreadLocalStorage.h: we use the pthread implementation, so it
  seems we should typedef __swift_thread_key_t as pthread_key_t.
  However, that's also a tweak for another commit.
2020-03-01 12:50:06 -05:00
Devin Coughlin
664e7cc00e [Availability] Make _stdlib_isOSVersionAtLeast() no longer inlinable
To make it possible to change the implementation of
_stdlib_isOSVersionAtLeast(), remove the @inlinable attribute from it.

Since it is currently inlinable and calls the helper function
_swift_stdlib_operatingSystemVersion(), we’ll have to keep the
helper around as ABI.

This change causes a minor pessimization where the LLVM optimizer can no
longer reason that, for example, a successful check for 10.12 availability
means that a later check for 10.11 will always succeed. I don't expect this
pessimization to be a problem, but if needed we could write a custom SIL
optimizer pass to claw back the performance.

<rdar://problem/59447474>
2020-02-13 20:08:48 -08:00
Max Desiatov
44a6475566 [WebAssembly] enable shims and stubs for WASI (#29505)
* [WebAssembly] enable shims and stubs for WASI

* Implement _swift_stdlib_getUnsafeArgvArgc for WASI

* Make include unconditional, add JIRA links
2020-01-28 18:29:52 -08:00
David Smith
f36a4db856 Update fast dealloc to use new-style interposing and support objc weak refs 2020-01-22 13:55:27 -08:00
David Smith
1cce12f20c Add an Array-based NSMutableArray subclass 2019-09-24 18:15:33 -07:00
Saleem Abdulrasool
64ed0a4077 stdlib: silence a unused function warning (NFC)
Pre-process away the unused function on Darwin.  NFC.
2019-09-20 17:34:17 -07:00
David Smith
1efa946caf Remove stdlib and runtime dependencies on Foundation and CF 2019-09-12 18:03:14 -07:00
Arnold Schwaighofer
fe69a86929 Revert "Remove stdlib and runtime dependencies on Foundation and CF"
It is causing bots to fail.

* Revert "The __has_include(<os/system_version.h>) branch here wasn't quite right, we'll just use the dlsym one for now"

This reverts commit f824922456.

* Revert "Remove stdlib and runtime dependencies on Foundation and CF"

This reverts commit 3fe46e3f16.

rdar://54709269
2019-08-26 13:00:08 -07:00
David Smith
f824922456 The __has_include(<os/system_version.h>) branch here wasn't quite right, we'll just use the dlsym one for now 2019-08-23 23:12:29 -07:00
swift-ci
3256392211 Merge pull request #26630 from Catfish-Man/shim-shim-sher-ee 2019-08-23 17:08:59 -07:00
David Smith
3fe46e3f16 Remove stdlib and runtime dependencies on Foundation and CF 2019-08-23 14:10:23 -07:00