Commit Graph

10155 Commits

Author SHA1 Message Date
Saleem Abdulrasool
d4757d4b7a Merge pull request #22857 from compnerd/foreign-imports
IRGen: lazy initialize ForeignClassMetadata
2019-03-07 21:34:31 -08:00
Karoy Lorentey
5b9ab59515 [Foundation] NSSet, NSDictionary: Use as! casts to force-bridge elements
This traps with a clear runtime error on failure, rather than simply crashing in the runtime.
2019-03-07 19:57:13 -08:00
Andrew Trick
404cf73ca6 Merge pull request #23111 from atrick/dominating-access-algo
Change the algorithm for the AccessEnforcementDom pass.
2019-03-07 16:51:18 -08:00
Saleem Abdulrasool
3f829c28d2 IRGen: lazy initialize ForeignClassMetadata
This is needed for Windows which does not support cross-module data
references without indirection.  By lazy initializing the data, we can
indirect through the IAT for the data pointer and fill in the parent
pointer.
2019-03-07 16:19:07 -08:00
Saleem Abdulrasool
68cb52a351 Merge pull request #23168 from compnerd/invalid-invalid
WinSDK: overwrite `INVALID_FILE_ATTRIBUTES`
2019-03-07 15:14:50 -08:00
swift-ci
74d1322a72 Merge pull request #23119 from ravikandhadai/array-init-semantics 2019-03-07 14:17:34 -08:00
Andrew Trick
3da2cc9e06 Clarify comments. 2019-03-07 13:48:41 -08:00
Mike Ash
c4434fe2a9 Merge pull request #23064 from mikeash/dynamically-select-is-swift-bit
[Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
2019-03-07 16:48:15 -05:00
Saleem Abdulrasool
52054d2443 WinSDK: overwrite INVALID_FILE_ATTRIBUTES
`INVALID_FILE_ATTRIBUTES` is imported as a signed value which will
overflow the unsigned usage.  Explicitly create it in the SDK overlay.
2019-03-07 13:30:47 -08:00
Andrew Trick
f4c7d4611f Change the algorithm for the AccessEnforcementDom pass.
This adds a mostly flow-insensitive analysis that runs before the
dominator-based transformations. The analysis is simple and efficient
because it only needs to track data flow of currently in-scope
accesses. The original dominator tree walk remains simple, but it now
checks the flow insensitive analysis information to determine general
correctness. This is now correct in the presence of all kinds of nested
static and dynamic nested accesses, call sites, coroutines, etc.

This is a better compromise than:

(a) disabling the pass and taking a major performance loss.

(b) converting the pass itself to full-fledged data flow driven
optimization, which would be more optimal because it could remove
accesses when nesting is involved, but would be much more expensive
and complicated, and there's no indication that it's useful.

The new approach is also simpler than adding more complexity to
independently handle to each of many issues:

- Nested reads followed by a modify without a false conflict.
- Reads nested within a function call without a false conflict.
- Conflicts nested within a function call without dropping enforcement.
- Accesses within a generalized accessor.
- Conservative treatment of invalid storage locations.
- Conservative treatment of unknown apply callee.
- General analysis invalidation.

Some of these issues also needed to be considered in the
LoopDominatingAccess sub-pass. Rather than fix that sub-pass, I just
integrated it into the main pass. This is a simplification, is more
efficient, and also handles nested loops without creating more
redundant accesses. It is also generalized to:
- hoist non-uniquely identified accesses.
- Avoid unnecessarily promoting accesses inside the loop.

With this approach we can remove the scary warnings and caveats in the
comments.

While doing this I also took the opportunity to eliminate quadratic
behavior, make the domtree walk non-recursive, and eliminate cutoff
thresholds.

Note that simple nested dynamic reads to identical storage could very
easily be removed via separate logic, but it does not fit with the
dominator-based algorithm. For example, during the analysis phase, we
could simply mark the "fully nested" read scopes, then convert them to
[static] right after the analysis, removing them from the result
map. I didn't do this because I don't know if it happens in practice.
2019-03-07 12:39:53 -08:00
Mike Ash
fbe990481b [Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
Recent Swift uses 2 as the is-Swift bit when running on newer versions, and 1 on older versions. Since it's difficult or impossible to know what we'll be running on at build time, make the selection at runtime.
2019-03-07 10:12:27 -05:00
simon gladman
df1d85f6df [Accelerate] [vDSP] Large Vector Type Conversion Operations
This PR contains a suite of overlays to the vDSP conversion functions.
2019-03-07 13:53:14 +00:00
Erik Eckstein
0dd2495815 runtime: bail in createBoundGenericType if the number of generic parameters and arguments don't match.
This can happen if _typeByName() is called with an invalid mangled type name.
2019-03-06 14:37:03 -08:00
Erik Eckstein
d7fd45d74a Remangler: Use a bump-pointer allocated string instead of std::string
Done by replacing DemanglerPrinter with a bump-pointer allocated CharVector buffer.
This avoids malloc calls.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08:00
Erik Eckstein
a60086f1dd Runtime: use lambdas to avoid allocations in std::function
Instead of capturing SubstGenericParametersFromMetadata and SubstGenericParametersFromWrittenArgs by value, capture by reference.
This avoids those instances to be copied and thus avoids a lot of mallocs.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08:00
Erik Eckstein
3bd7f027f8 Runtime: use SmallVector instead of std::vector to avoid memory allocations in most cases.
This dramatically reduces the number of needed malloc calls.
Unfortunately I had to add the implementation of SmallVectorBase::grow_pod to the runtime, as we don't link LLVM. This is a bad hack, but better than re-inventing a new SmallVector implementation.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08:00
David Smith
909868fd67 Merge pull request #21845 from numist/numist/diffing
Ordered Collection Diffing
2019-03-05 23:08:03 -08:00
Ravi Kandhadai
6c662f7a6c [stdlib][Semantics annotation] Add ".empty" suffix to the semantics attribute of
array.init() and add semantics annotation to the compiler-intrinsic:
Array._allocateUninitializedArray
2019-03-05 17:09:34 -08:00
Max Moiseev
041eda1f27 Merge pull request #23105 from moiseev/max-datagram-size-abi
Add availability annotations to NWConnection.maximumDatagramSize
2019-03-05 15:04:41 -08:00
Maxim Moiseev
52c6e03c44 Add availability annotations to NWConnection.maximumDatagramSize
Since it did not exist pre-ABI.
<rdar://problem/48314607>
2019-03-05 10:55:14 -08:00
Scott Perry
fcf6550506 Merge branch 'master' into numist/diffing 2019-03-04 21:29:12 -08:00
Patrick Pijnappel
24282df850 [stdlib] Fix typo in comment 2019-03-05 12:05:00 +11:00
Saleem Abdulrasool
618d525b91 runtime: enable stack traces on Windows
We would not previously symbolicate the stack trace and as a result
would not display the stack trace.  Add symbolication support to the
runtime to actually make use of the captured stack trace.  This allows
us to get a stack trace when the standard library or swift code reports
a fatal error.
2019-03-04 10:39:10 -08:00
Michael Ilseman
dc89cc06e6 Merge pull request #23026 from milseman/client_helper_emitted
[stdlib] Some cleanup enabled by _alwaysEmitIntoClient.
2019-03-04 07:40:17 -08:00
Michael Ilseman
19014a85af [stdlib] Some cleanup enabled by _alwaysEmitIntoClient.
Refactor some copy-pasted code into a helper computed variable and
outline some cold paths.
2019-03-03 14:10:01 -08:00
Saleem Abdulrasool
a19a62351d Merge pull request #23029 from compnerd/list-the-ways-that-everything-is-terrible
stdlib: use the correct va_list type on Windows
2019-03-01 21:22:41 -08:00
Saleem Abdulrasool
08cf801152 Merge pull request #23030 from compnerd/this-shall-be-part-of-my-legacy
stdlib: link against legacy_stdio_definitions on Windows
2019-03-01 21:22:12 -08:00
Saleem Abdulrasool
c826deadb4 stdlib: link against legacy_stdio_definitions on Windows
Because Microsoft inlines the definitions of the printf family of
functions, we end up with undefined references to them.  Add an explicit
request to link against the `legacy_stdio_definitions` library when
`ucrt.C.stdio` is used which provides out-of-line definitions for them.
This fixes the building of the `stdlib/VarArgs' test.
2019-03-01 14:50:46 -08:00
Saleem Abdulrasool
75e31751ba stdlib: use the correct va_list type on Windows
Windows uses `char *` for the `va_list` type even on x86_64.  Restore
the correct selection of `__VaListBuilder` for Windows x86_64.  This
partially fixes variadic functions.
2019-03-01 14:25:26 -08:00
Saleem Abdulrasool
45fa39c855 Merge pull request #23001 from compnerd/shims
SwiftShims: update shims copying logic
2019-03-01 11:03:35 -08:00
Saleem Abdulrasool
6da949dda7 stdlib: address a compiler warning
Explicit template specialization may not have a storage class.  Remove
the extraneous storage class.
2019-02-28 23:56:12 -08:00
Saleem Abdulrasool
a227273ff4 stdlib: correct floating point parsing behaviour
These are supposed to be processed in the C locale always, irrespective
of the current locale.  We were not doing this and so we would parse the
value incorrectly.
2019-02-28 23:56:12 -08:00
Saleem Abdulrasool
d26ca1cd3c SwiftShims: update shims copying logic
Update the shims logic to make sure that it works for Xcode as well.
Rather than adding additional rules, just simplify it down to the one
canonical way in modern LLVM land.  The headers are always installed to
the LLVM_LIBRARY_OUTPUT_INTDIR which will be defined for us in both the
standalone and unified build mode.  This allows us to just remove all
the work to find the headers since they will always be in one location.
2019-02-28 17:11:30 -08:00
Michael Ilseman
438010d366 [gardening] Dead File Elimination 2019-02-28 10:11:11 -08:00
Max Moiseev
c903186fa4 Merge pull request #22885 from moiseev/os-log-unshadow
[os_log] Un-shadow buffer so the correct copy happens
2019-02-28 10:07:16 -08:00
Max Moiseev
3bc9ce123a Merge pull request #22964 from moiseev/nil-unwrap-location
Print nil unwrap location in no-assert builds of stdlib
2019-02-28 10:06:40 -08:00
Saleem Abdulrasool
48d8ebd1b0 Merge pull request #21606 from compnerd/you-may-not-assert
stdlib: remove some static assertions which may not hold
2019-02-28 09:49:48 -08:00
Maxim Moiseev
2ce0630b58 Print nil unwrap location in no-assert builds of stdlib
We've been collecting the location info for some time now, but
apparently never printed it in no-assert builds of the stdlib, which
means this functionality was never available to the users.

With this change, the location will be printed depending on the
debug/release build configuration of the program, not stdlib.

Somewhat addresses: <rdar://problem/42980523>
2019-02-27 16:04:30 -08:00
Saleem Abdulrasool
0983ea66ae stdlib: use placement new on Windows, disable asserts
The assertions here are based around the idea that `std::atomic` is
trivially constructible which is not a guarantee that the standard fully
provides.  The default initialization of the `std::atomic` type may
leave it in an undetermined state.  These were caught using the Visual
C++ preview runtime.

Ideally, the object constructor would use a placement new operator.
However, prior to C++17, the C++ standard mandated that there be a
NULL pointer check in the placement new operator.  This is something
which is no longer the case with C++17.  Switch to the placement new
operator for C++17 and newer and enable that codepath for Windows as
well (which seemingly elides the null-pointer check with clang-cl).
2019-02-27 15:29:06 -08:00
Scott Perry
6e3139b5da Incorporate feedback from @lorentey and @moiseev 2019-02-27 14:05:06 -08:00
Daniel Rodríguez Troitiño
3f76e63b6e Merge pull request #22899 from drodriguez/reflection-context-fix-2
Reflection: try holding 32/64 address offset in target machine pointers.
2019-02-27 11:34:36 -08:00
Daniel Rodríguez Troitiño
8bee95d232 Reflection: try holding 32/64 address offset in type big enough for all architectures.
When compiling for a 32 bit machine, uintptr_t from ReflectionInfo will
be the integer sized to hold a 32 bit pointer, so a 64 bit pointer might
not fit.

This commit removes the solution in
0f20c486e0 and does a runtime check that
the calculated offset will fit into the target machine uintptr_t, which
might not be true for 32 bits machines trying to read 64 bits images,
which should not be that common (and those images have to have offsets
bigger than what a 32 bits number can hold).
2019-02-26 13:31:35 -08:00
Max Moiseev
67f62a14f0 Merge pull request #22272 from moiseev/intents-warnings
Remove access specifiers on some extensions to avoid warnings
2019-02-25 12:53:31 -08:00
Maxim Moiseev
a0326f6514 Un-shadow buffer so the correct copy happens
Fixes: rdar://problem/48299301
2019-02-25 11:19:53 -08:00
Saleem Abdulrasool
90fd8a5d34 stdlib: define and use SWIFT_{,UN}LIKELY
Rather than directly using the extension `__builtin_expect`, use a macro
to permit the removal of the builtin on compilers which do not support
this (i.e. cl).  This permits us to build the swift compiler with MSVC
again.
2019-02-24 13:58:18 -08:00
Karoy Lorentey
fd32a3d14e [stdlib] Set availability of diffing APIs 2019-02-22 14:28:15 -08:00
Karoy Lorentey
57f4afbf84 [stdlib] Update diffing code to match stdlib coding conventions
- Add an underscore to private/internal symbols
- Make access levels explicit, even when they’re implied from context
- Conform to max line length of 80 characters
- Conformances declared on separate extensions that implement them
- Arrange member declarations so that stored properties appear first
- Expand single-letter function and type parameter names where there is an obvious name that’s more descriptive
- RangeReplaceableCollection.fastApplicationEnumeration → CollectionDifference._fastEnumeratedApply
2019-02-22 14:27:45 -08:00
Saleem Abdulrasool
3df60b4a84 SwiftRemoteMirror: fix static library builds for Windows
We were previously treating all the builds as shared, which is not the
case for the host library build of SwiftRemoteMirror.  The warnings were
lost in the interminable spew from the build which is now fixed and this
stands out.
2019-02-22 10:46:32 -08:00
Saleem Abdulrasool
0cfb54dbfa stdlib: make cl based compilation reasonable
`-Wall` with the clang-cl interface gives us `-Weverything` effectively,
which really reduces the effectiveness of the warnings.  Switch to `/W3`
which is roughly equivalent to `-Wall` in clang mode.
2019-02-21 22:38:02 -08:00
Saleem Abdulrasool
f58155924c stdlib: repair the Windows build
The recent change to enable the stack traces requires a dependency on
DbgHelp which we were not linking against.  Add the link.
2019-02-21 16:03:53 -08:00