Commit Graph

6754 Commits

Author SHA1 Message Date
Pavel Yaskevich
91042d77aa [SILGen] Make it possible to emit generator function given its body and result type
This would be used for runtime attribute generators that have to
emit `if #available(...)` block in the body which is much easier
to do during Sema.
2022-12-20 09:45:01 -08:00
Pavel Yaskevich
5442d30866 [IRGen] RuntimeMetadata: Emit runtime discoverable attributes section
Each entry relates an attribute declaration to a list of all
declarations it's associated with together with a generator
function to acquire instance of the attribute value.
2022-12-20 09:45:01 -08:00
Pavel Yaskevich
3fb69b3c3c [SIL] SILFunction: Add runtime accessible function attribute
This attribute indicates that the given SILFunction has to be
added to "accessible functions" section and could be looked up
at runtime using a special API.
2022-12-20 09:33:44 -08:00
Pavel Yaskevich
4a0f9cac72 [SILGen] TypeWrappers: force emission of wrapper initializer
Make sure that wrapper's initializer is always emitted because
it could be used by DI and IRGen later on to aid in `_storage`
initialization.
2022-12-19 14:03:48 -08:00
Pavel Yaskevich
d1bb5add17 [SILGen] TypeWrappers: Handle initialization of property wrapped fields without init exprs
Type wrapper synthesis cannot reply on `getExecutableInit` to
determine whether initialization should use backing wrapper
call or not, it has to check whether the init expression exists.
2022-12-19 13:48:40 -08:00
Doug Gregor
515715befc Merge pull request #62646 from DougGregor/global-actor-formal-metatype 2022-12-16 17:13:08 -08:00
Doug Gregor
0e8d4c470e [SILGen] Fix formal type of global actor metatype.
Fixes a crash reported in rdar://103255322 .
2022-12-16 12:33:09 -08:00
Holly Borla
d3bc4f52bc Merge pull request #62582 from hborla/pack-element-expr 2022-12-16 11:42:53 -05:00
Michael Gottesman
5fb001cb48 Merge pull request #62610 from gottesmm/pr-2fc1a68995dc3f80805e722e8419a6fcf4eb25fb
[move-only] Teach move checker that captured vars are treated like inout in the relevant closures
2022-12-15 13:46:24 -08:00
nate-chandler
5f3664ef94 Merge pull request #62563 from nate-chandler/opaque-values/1/20221212
[OpaqueValues] Initial key-path support.
2022-12-15 13:14:23 -08:00
Michael Gottesman
4901529a72 [move-only-addr] Teach move only address checker that captured vars should be treated like inout arguments.
rdar://103313357
2022-12-15 09:59:36 -08:00
nate-chandler
b8a3bbb6d4 Merge pull request #62564 from nate-chandler/opaque-values/1/20221213
[OpaqueValues] Fix @in_guaranteed loadable yields.
2022-12-15 07:09:35 -08:00
nate-chandler
1938b5c5a8 Merge pull request #62565 from nate-chandler/opaque-values/2/20221213
[OpaqueValues] Emit addr-only patterns.
2022-12-15 07:08:53 -08:00
Holly Borla
f1fd9acb23 [AST] Add 'PackElementExpr' for explicit pack elements spelled with the 'each'
keyword.
2022-12-14 20:45:51 -08:00
Michael Gottesman
9e44011e4d [sil] Add a new attribute called @closureCaptured to SILFunctionArguments that are closure capture arguments.
I am adding this to make it easy to determine if a SILFunction that is not inout
aliasable is captured. This is useful when emitting certain types of
diagnostics like I need to emit with move only.
2022-12-14 15:16:43 -08:00
Michael Gottesman
f735eda198 Merge pull request #62567 from gottesmm/pr-aff949c3a3e3aaf7839d4462bd96b8eb60c06f97
[move-only-object] Teach move only object verifier how to emit proper errors for closure/defer uses
2022-12-14 13:51:28 -08:00
Michael Gottesman
0735f9f0bb [move-only] Teach SILGen that lets captured by a closure must be no copy.
The current diagnostic that we are emitting is not perfect, but at least this
prevents us from saying that an error is not occuring here. I am going to file a
bug to track the QoI work of improving the diagnostic.

rdar://103313305
2022-12-14 10:57:34 -08:00
Nate Chandler
d2af3435bb [OpaqueValues] Emit addr-only patterns.
When opaque values are enabled, pattern match emission now emits a copy
and a store to the destination rather than a copy-addr to it.
2022-12-13 18:09:25 -08:00
Nate Chandler
626e708c41 [OpaqueValues] Fix @in_guaranteed loadable yields.
When opaque values are enabled, when yielding a value with an indirect
convention, a value whose type's category is "object" must be yielded.
Previously, if a value's type was loadable, an attempt was made to yield
a value whose type's category was "address".  Here, that's fixed.
Additionally, handling for trivial types yielded via @in_guaranteed is
added.
2022-12-13 18:07:52 -08:00
Nate Chandler
cd03615a1a [OpaqueValues] Initial key-path support.
Enough support for emitting key-paths SIL to build _Regex and
_StringProcessing.
2022-12-13 18:06:56 -08:00
Andrew Trick
f9861ec9c0 Add APIs for terminator results that forward ownership.
Add TermInst::forwardedOperand.

Add SILArgument::forwardedTerminatorResultOperand. This API will be
moved into a proper TerminatorResult abstraction.

Remove getSingleTerminatorOperand, which could be misused because it's
not necessarilly forwarding ownership.

Remove the isTransformationTerminator API, which is not useful or well
defined.

Rewrite several instances of complex logic to handle block arguments
with the simple terminator result API. This defines away potential
bugs where we don't detect casts that perform implicit conversion.

Replace uses of the SILPhiArgument type and code that explicitly
handle block arguments. Control flow is irrelevant in these
situations. SILPhiArgument needs to be deleted ASAP. Instead, use
simple APIs like SILArgument::isTerminatorResult(). Eventually this
will be replaced by a TerminatorResult type.
2022-12-12 12:37:35 -08:00
Nate Chandler
8d8577e5b0 [SIL] Removed Indirect_In_Constant convention.
It is no different from @in.

Continue parse @in_constant in textual and serialized SIL, but just as
an alias for @in.
2022-12-09 21:54:00 -08:00
nate-chandler
599cd1fad6 Merge pull request #62468 from nate-chandler/opaque-values/3/20221207
[OpaqueValues] Handle indirect resilient switch.
2022-12-09 07:03:48 -08:00
Joe Groff
deab4cbf21 Merge pull request #62183 from ellishg/objc-direct-constructor
Allow Swift to call objc_direct constructors
2022-12-08 15:13:21 -08:00
Nate Chandler
eae4a8b013 [OpaqueValues] Handle indirect resilient switch.
For a switch on an indirect enum whose case is resilient, SILGen now
produces a load_borrow just as it does for cases which are loadable.
2022-12-08 12:30:58 -08:00
Allan Shortlidge
95a9310e11 SILGen: Fix 'multiple definitions of symbol' error for functions with @_backDeploy containing defer blocks.
If the emission of a function is delayed via `emitOrDelayFunction()`, then the function is recorded on a list of delayed functions. If the delayed function is later referenced, then the function moves from the delayed list to the "forced" list which will cause it to actually be emitted later. The implementation of `emitOrDelayFunction()` had a bug when called twice for the same delayable function - it would emit that function prematurely if the function moved to the forced list between the two invocations. Later, during forced function emission a multiple definitions of symbol diagnostic would be emitted since the function was not empty.

This issue could be triggered by `@_backDeploy` functions that have auxilary delayable helper functions (e.g. defer blocks). SILGen visits `@_backDeploy` functions twice (once for the copy of the function emitted into the client and once for the resilient copy of the function) so `emitOrDelayFunction()` is called twice for each of the helper functions and the helper functions could become referenced between the two calls.

The fix is to check for an existing entry in the forced functions list before delaying or emitting a delayable function.

Resolves rdar://102909684
2022-12-07 20:51:39 -08:00
Steven Wu
a98e830b0a [Profile] Update swift after LLVM API update
Related to rdar://102581439
2022-12-02 15:12:40 -08:00
Joe Groff
d9c4bed487 Merge pull request #62312 from jckarter/mix-read-or-address-with-setter-reabstraction
SILGen: Match up abstraction level when materializing mixed set and read/unsafeAddress properties.
2022-11-30 14:51:22 -08:00
Joe Groff
d1a9f9a6b3 SILGen: Match up abstraction level when materializing mixed set and read/unsafeAddress properties.
Addresses part of rdar://102525437.
2022-11-29 21:24:32 -08:00
Michael Gottesman
d03ee03eb9 Merge pull request #62287 from gottesmm/pr-74833c7154cdbcf5812c7deb2677c4e1f78607a2
[move-only] Borrow copyable typed arguments contained within a move only struct/enum.
2022-11-29 04:46:46 -08:00
Michael Gottesman
ec9db3ffbb [move-only] Borrow copyable typed arguments contained within a move only struct/enum.
Otherwise, we down the normal load [copy] path which will cause us to have a
tight exclusivity scope.

One thing to note is that if one accesses a field of a moveonly class one will
still get the tight exclusivity scope issue since SILGenLValue will emit the
moveonly class as a base of the field causing us to use the non-borrow codegen.

rdar://102746971
2022-11-28 20:32:15 -08:00
Pavel Yaskevich
c17d35dc3e Merge pull request #62146 from xedin/rdar-102085039
[AST] `getParameterAt` should check index before retrieving it
2022-11-28 10:01:51 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Xi Ge
c5a7eff0c9 Merge pull request #62147 from tshortli/has-symbol-sil-instruction 2022-11-18 04:34:24 -08:00
Ellis Hoag
693a049fe4 Allow Swift to call objc_direct constructors 2022-11-17 17:05:45 -08:00
Michael Gottesman
427a5558f7 [move-only-address] When emitting a simple assignment, make sure to consume the move only type.
This was an oversight since I thought that `let _ = x` and `_ = x` were
codegened in the same way.

rdar://102491017
2022-11-17 16:25:11 -08:00
Pavel Yaskevich
77fb90ee19 [Sema/SILGen] Add asserts to getParameterAt call sites that expect non-null parameter 2022-11-17 11:52:00 -08:00
Allan Shortlidge
efd5c1ecfc SIL: Move the implementation of Lowering::usesObjCAllocator() to the SIL library.
The definition of `Lowering::usesObjCAllocator()` was previously implemented in SILGen, which does not match the library membership of the declaration. The implementation of `SILSymbolVisitor` in the SIL library uses this and since SIL is a dependency of SILGen instead of vice-versa this resulted in a linker error.
2022-11-16 17:25:27 -08:00
Allan Shortlidge
abdc4d9112 SILGen: Use has_symbol instruction in SILGen. 2022-11-16 16:07:29 -08:00
Michael Gottesman
48987de3d3 Merge pull request #62104 from gottesmm/pr-0e98608fa6aa0c166d5ba2affb5145d241fd7682
[move-only] Mark self of move only struct/enum types in deinits as being move-only.
2022-11-14 23:35:14 -08:00
eeckstein
f78f302ffc Merge pull request #62100 from eeckstein/fix-future-warnings
Some fixes for "future" warnings
2022-11-15 08:28:47 +01:00
Slava Pestov
34c9daa635 Merge pull request #62076 from slavapestov/no-assert-test-hang-fix
Disable 0022-rdar21625478.swift entirely on noassert builds
2022-11-14 19:52:45 -05:00
Michael Gottesman
6f7961b63c [move-only] Mark self of move only struct/enum types in deinits as being move-only.
This ensures that if we try to escape self or assign it to a variable, we
error since at the end of the deinit we always consume self and clean up its
variables.

I did not handle unique classes since it would have required a bit more surgery
around how deinits are handled and we do not need unique classes for our MVP.

rdar://102339259
2022-11-14 14:47:37 -08:00
Erik Eckstein
1f4ac2b542 A few more deprecated iterator fixes
std::iterator is deprecated in C++17
2022-11-14 20:37:00 +01:00
Doug Gregor
5ab6b72604 [Macros] Turn Macro into a declaration node.
Although the declaration of macros doesn't appear in Swift source code
that uses macros, they still operate as declarations within the
language. Rework `Macro` as `MacroDecl`, a generic value declaration,
which appropriate models its place in the language.

The vast majority of this change is in extending all of the various
switches on declaration kinds to account for macros.
2022-11-13 12:21:29 -08:00
Slava Pestov
87844648ba SILGen: Add a couple of assertions 2022-11-11 23:31:06 -05:00
Michael Gottesman
525ba8c07b [move-only] When passing a move only struct address, pass it as a true borrowed parameter.
This ensures that the address move checker does not have to perform any unsound
access scope expansions. One note is that the current approach does not work for
class member refs since in SILGenLValue, a class is considered a base of the
SILGenLValue access which is immediately evaluated (causing a copy) rather than
evaluated later at formal evaluation time. I have a few ways of working around
this issue but am going to fix it in a subsequent commit when I fix this for
classes and also read coroutines.

rdar://99616492
2022-11-10 17:20:32 -08:00
Michael Gottesman
36306c6a45 [move-only] Treat black hole initialization as a consuming operation.
Otherwise, we don't treat `let _ = x` as a consuming operation.

rdar://102196620
2022-11-10 09:40:32 -08:00
Michael Gottesman
1084d892bd Merge pull request #62021 from gottesmm/pr-88e3b82d31a08823ec6704d7d190b78b233ac27e
[move-only] Two more small fixes
2022-11-10 07:07:14 -08:00
swift-ci
fd6fd76dae Merge pull request #42513 from jsoref/spelling-silgen
Spelling silgen
2022-11-09 23:28:43 -08:00