Commit Graph

9293 Commits

Author SHA1 Message Date
Michael Gottesman
92a3e53b02 Merge pull request #76434 from gottesmm/pr-3e00ab647dbc50beececb8c8cf096921bdf7acd3
[concurrency] Represent a SILFunction without isolation as std::optional<ActorIsolation> instead of ActorIsolation::Unspecified.
2024-09-19 09:17:52 -07:00
Kuba Mracek
6b9a3051e3 [embedded] Introduce class-bound existentials into Embedded Swift
Motivated by need for protocol-based dynamic dispatch, which hasn't been possible in Embedded Swift due to a full ban on existentials. This lifts that restriction but only for class-bound existentials: Class-bound existentials are already (even in desktop Swift) much more lightweight than full existentials, as they don't need type metadata, their containers are typically 2 words only (reference + wtable pointer), don't incur copies (only retains+releases).

Included in this PR:
[x] Non-generic class-bound existentials, executable tests for those.
[x] Extension methods on protocols and using those from a class-bound existential.
[x] RuntimeEffects now differentiate between Existential and ExistentialClassBound.
[x] PerformanceDiagnostics don't flag ExistentialClassBound in Embedded Swift.
[x] WTables are generated in IRGen when needed.

Left for follow-up PRs:
[ ] Generic classes support
2024-09-19 07:49:50 -07:00
Doug Gregor
5b2520e379 Remove IfConfigDecl from the AST
The swift-syntax tree retains information about the parsed #if
regions. Drop it from the semantic AST.
2024-09-18 20:51:54 -07:00
Michael Gottesman
a0088327d4 [concurrency] Represent a SILFunction without isolation as std::optional<ActorIsolation> instead of ActorIsolation::Unspecified.
The reason why is that we want to distinguish inbetween SILFunction's that are
marked as unspecified by SILGen and those that are parsed from textual SIL that
do not have any specified isolation. This will make it easier to write nice
FileCheck tests against SILGen output on what is the inferred isolation for
various items.

NFCI.
2024-09-18 11:23:22 -07:00
Doug Gregor
da0c70f301 Merge pull request #76512 from DougGregor/sourcefile-nonopt-buffer
Ensure that SourceFiles always have a backing buffer in the SourceManager
2024-09-18 10:54:52 -07:00
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Doug Gregor
49aa0e966f Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's
contents in the SourceManager, has always been optional. However, the
effectively every SourceFile actually does have a buffer ID, and the
vast majority of accesses to this information dereference the optional
without checking.

Update the handful of call sites that provided `nullopt` as the buffer
ID to provide a proper buffer instead. These were mostly unit tests
and testing programs, with a few places that passed a never-empty
optional through to the SourceFile constructor.

Then, remove optionality from the representation and accessors. It is
now the case that every SourceFile has a buffer ID, simplying a bunch
of code.
2024-09-16 21:46:42 -07:00
Slava Pestov
5147adcca5 SIL: Handle ProtocolCompositionType in SubstFunctionTypePatternVisitor
Fixes https://github.com/swiftlang/swift/issues/62061.
2024-09-16 21:20:55 -04:00
Allan Shortlidge
02dbb96b94 AST: Rename AvailabilityContext to AvailabilityRange.
The generality of the `AvailabilityContext` name made it seem like it
encapsulates more than it does. Really it just augments `VersionRange` with
additional set algebra operations that are useful for availability
computations. The `AvailabilityContext` name should be reserved for something
pulls together more than just a single version.
2024-09-13 16:25:18 -07:00
nate-chandler
40cff95549 Merge pull request #76417 from nate-chandler/bug/20240911/1
[SIL] Don't abort via llvm_unreachable.
2024-09-11 23:24:24 -07:00
Nate Chandler
66501f8993 [SIL] Don't abort via llvm_unreachable.
It is a way to indicate to the compiler that the line can't be reached.
On some configurations, it does happen to trap, as desired.  Use a
function that always traps, since that's the intent.
2024-09-11 17:05:58 -07:00
Alejandro Alonso
3b741ee488 Merge pull request #76303 from Azoy/rawlayout-fixes
[IRGen] Collect metadata from like type and add type information when GEPing into raw layouts
2024-09-11 16:25:24 -07:00
Doug Gregor
c0fea1f224 Disable printing of #ifs from the AST
The option to print #ifs defaulted to "on", but was disabled in most of
the actual compiler inputs that mattered, and the results weren't ever
actually used. Remove the option so we never print #ifs.
2024-09-08 09:52:37 -07:00
fahadnayyar
e3ea4e1b54 Merge pull request #75897 from fahadnayyar/f-dev-frt-return-ownership-annotations-pr
[cxx-interop] Add SWIFT_RETURNS_RETAINED and SWIFT_RETURNS_UNRETAINED…
2024-09-06 09:16:08 -07:00
Alejandro Alonso
7219daf418 Collect metadata from like type and add type information when GEPing into raw layouts 2024-09-05 18:04:47 -07:00
fahadnayyar
ea4328384d [cxx-interop] Add SWIFT_RETURNS_RETAINED and SWIFT_RETURNS_UNRETAINED annotations to specify ownership of FRT returned by a C++ method or function
rdar://135306908
2024-09-05 11:44:31 -07:00
Alejandro Alonso
e0f2b812e8 Add serialization and parser tests for SIL 2024-09-04 15:13:47 -07:00
Slava Pestov
1ff1b9479a AST: Pick off some usages of GenericTypeParamType::getDecl() 2024-09-04 15:13:46 -07:00
Alejandro Alonso
f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Slava Pestov
a3c0e225a7 Merge pull request #76238 from slavapestov/existential-signature-rework-part-3
Allow type variables to appear inside opened existential archetypes
2024-09-04 14:53:18 -04:00
Slava Pestov
be12788a2c SIL: Fix undefined behavior with method call on nullptr
This happened to work with a null genericEnv before, because we didn't
touch `this` when the input type didn't contain any type parameters.
2024-09-04 10:42:18 -04:00
Erik Eckstein
8b955d994e Fix a false performance error when using generic, but loadable types
For example: UnsafePointer<T>

rdar://135231581
2024-09-04 10:55:14 +02:00
Alex Hoppen
c5aa49ba64 Revert "Isolated synchronous deinit" 2024-09-03 18:11:26 -07:00
eeckstein
a4a157c775 Merge pull request #76221 from eeckstein/fix-oss-lt-completion
OSSALifetimeCompletion: need to look through borrowed-from when creating an end_borrow
2024-09-03 22:21:05 +02:00
Allan Shortlidge
3f626f50fe Merge pull request #76203 from tshortli/availability-context-cleanup
AST: Clean up `AvailabilityContext` and uses
2024-09-03 09:42:25 -07:00
Erik Eckstein
abbd9d3fd6 OSSALifetimeCompletion: need to look through borrowed-from when creating an end_borrow
Fixes a verifier crash

rdar://134728428
2024-09-03 14:46:13 +02:00
Allan Shortlidge
0bf3aa9df0 AST: Add AvailabilityContext::getVersionString() for debugging and diagnostics.
NFC (except for debug output).
2024-09-02 16:47:14 -07:00
Allan Shortlidge
8052e3f9dc AST: Remove 'OS' from AvailabilityContext member names.
An `AvailabilityContext` represents an abstract version range in which
something is available. In the future, these version ranges may not necessarily
always correspond to operating system version ranges.

NFC.
2024-09-02 16:47:14 -07:00
Konrad `ktoso` Malawski
c55ad6fa88 Merge branch 'main' into mpokhylets/isolated-deinit 2024-09-02 23:16:17 +09:00
Slava Pestov
44dbebdd9e Merge pull request #76200 from slavapestov/type-subst-invariant
AST: Type substitution can skip subtrees that won't change
2024-09-01 17:55:11 -04:00
nate-chandler
b3fd194e56 Merge pull request #76095 from nate-chandler/lifetime-completion/20240826/1
[LifetimeCompletion] Avoid instruction list walk.
2024-08-30 12:35:06 -07:00
Slava Pestov
e79763b590 AST: Factor out mapLocalArchetypesOutOfContext() utility function 2024-08-30 15:24:00 -04:00
Slava Pestov
52ce02eb96 AST: Remove ArchetypeType::getRoot() 2024-08-30 15:24:00 -04:00
Allan Shortlidge
ec8f091f8c Merge pull request #76158 from tshortli/backdeployed-thunk-sil-printing
SIL: Print thunk kind attribute for `@backDeployed` thunks
2024-08-29 21:48:27 -07:00
Slava Pestov
d36dcea88d Merge pull request #76154 from slavapestov/combine-substitution-maps
Move combineSubstitutionMaps() to SILOptimizer and fix an assertion
2024-08-29 20:51:49 -04:00
Allan Shortlidge
8502c89234 SIL: Print thunk kind attribute for @backDeployed thunks.
As promised in the FIXME, update the SIL printer and parser to handle the new
thunk kind for `@backDeployed` thunks.

Follow up to https://github.com/swiftlang/swift/pull/76135.
2024-08-29 17:26:06 -07:00
Slava Pestov
b68a78cd54 SIL: Track local environments instead of root local archetypes 2024-08-29 16:18:13 -04:00
Allan Shortlidge
789b795cec SILOptimizer: Allow inlining of transparent functions in @backDeployed thunks.
In order for availability checks in iOS apps to be evaluated correctly when
running on macOS, the application binary must call a copy of
`_stdlib_isOSVersionAtLeast_AEIC()` that was emitted into the app, instead of
calling the `_stdlib_isOSVersionAtLeast()` function provided by the standard
library. This is because the call to the underlying compiler-rt function
`__isPlatformVersionAtLeast()` must be given the correct platform identifier
argument; if the call is not emitted into the client, then the macOS platform
identifier is used and the iOS version number will be mistakenly interpreted as
a macOS version number at runtime.

The `_stdlib_isOSVersionAtLeast()` function in the standard library is marked
`@_transparent` on iOS so that its call to `_stdlib_isOSVersionAtLeast_AEIC()`
is always inlined into the client. This works for the code generated by normal
`if #available` checks, but for the `@backDeployed` function thunks, the calls
to `_stdlib_isOSVersionAtLeast()` were not being inlined and that was causing
calls to `@backDeployed` functions to crash in iOS apps running on macOS since
their availability checks were being misevaluated.

The SIL optimizer has a heuristic which inhibits mandatory inlining in
functions that are classified as thunks, in order to save code size. This
heuristic needs to be relaxed in `@backDeployed` thunks, so that mandatory
inlining of `_stdlib_isOSVersionAtLeast()` can behave as expected. The change
should be safe since the only `@_transparent` function a `@backDeployed` thunk
is ever expected to call is `_stdlib_isOSVersionAtLeast()`.

Resolves rdar://134793410.
2024-08-29 08:43:07 -07:00
Mykola Pokhylets
e0ad7bde82 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	include/swift/Basic/Features.def
#	lib/AST/ASTPrinter.cpp
#	lib/AST/FeatureSet.cpp
2024-08-29 11:28:43 +02:00
Slava Pestov
f2fff10cc9 SIL: Synchronous local functions don't need to capture the isolation parameter
Also, move this rule from the computation of lowered captures in SIL,
to the computation of AST captures in Sema. This allows us to
correctly handle the case where an async function nests inside a
sync function. It also removes a special case that was added recently
to cope with a generic `self` type.

Fixes rdar://129366819.
2024-08-28 17:03:49 -04:00
Nate Chandler
d669c1d220 [LifetimeCompletion] Avoid instruction list walk.
When computing the available region, a forward walk is done from the
non-lifetime-ending boundary of the live region.  That boundary consists
of (1) the target blocks of boundary edges, (2) dead defs, and (3) last
users which are non-consuming.  This forward walk is done at the block
level, so neither the specific dead def (for (2)) nor specific last
non-consuming user (for (3)) is required to perform the walk; indeed
currently these are computed and then immediately used only to obtain
the blocks in which they appear and then discarded.  Avoid computing the
specific dead defs and specific last non-consuming users by switching to
a lower-fidelity liveness boundary computation via
`PrunedLivenessBlockBoundary`.
2024-08-26 16:24:51 -07:00
Nate Chandler
86cd9603da [PrunedLiveness] Add lower detail boundary.
To enable those clients which care only about _blocks_ whose
instructions or dead-defs make up the liveness boundary to avoid
iterating instruction lists, enhance boundary computation with a second
type (`PrunedLivenessBlockBoundary`) and migrate some methods from
liveness onto the boundary types to enable dispatching on the boundary
type to do only the amount of analysis that's necessary.
2024-08-26 16:04:57 -07:00
Erik Eckstein
c8e74b8393 Generic specialization: change the mangling for dropped metatype arguments
Instead of adding a "flag" (`m` in `...Tgm5`) make it more generic to allow to drop any unused argument.
Add all dropped arguments with a `t<n-1>` (where `<n-1>` is empty for n === 0). For example `...Ttt2g5`.
2024-08-26 10:43:15 +02:00
Michael Gottesman
00519669af Merge pull request #76076 from gottesmm/rdar134623227
[region-isolation] Treat sending indirect_results as disconnected even if it is a return value of an actor isolated function.
2024-08-25 08:02:25 -04:00
Michael Gottesman
da597be76d Merge pull request #76075 from gottesmm/rdar133531625
[region-isolation] Treat as Sendable values that are meant to be ignored since they are marked with preconcurrency
2024-08-24 22:26:00 -04:00
Slava Pestov
8315120eaf Merge pull request #76051 from slavapestov/archetype-get-parent
AST: Remove ArchetypeType::getParent()
2024-08-24 15:31:01 -04:00
Michael Gottesman
3e27bfc03b [region-isolation] Treat sending indirect_results as disconnected even if it is a return value of an actor isolated function.
rdar://134623227
2024-08-24 14:02:41 -04:00
Michael Gottesman
49eee05647 [region-isolation] Treat as Sendable values that are meant to be ignored since they are marked with preconcurrency
rdar://133531625
2024-08-24 13:14:39 -04:00
Slava Pestov
cf784f980e AST: Remove SubstFlags::AllowLoweredTypes 2024-08-23 13:14:05 -04:00