Commit Graph

6754 Commits

Author SHA1 Message Date
Joe Groff
7f9b18432a Merge pull request #71795 from jckarter/yield-read-coroutine-result
SILGen: Emit the base of a read coroutine as a borrow in a `yield`/`borrow`/noncopyable context.
2024-02-21 20:40:36 -08:00
Ben Barham
5637284e48 Merge pull request #71368 from bnbarham/std-optional-all-the-things
Migrate llvm::Optional to std::optional
2024-02-21 16:54:00 -08:00
Allan Shortlidge
898c024c2d Merge pull request #71771 from tshortli/magic-literal-unknown-loc-assert
SILGen: Avoid expanding #line directives with invalid source locations
2024-02-21 16:21:29 -08:00
Joe Groff
eca40f3d63 SILGen: Emit the base of a read coroutine as a borrow in a yield/borrow/noncopyable context. 2024-02-21 14:35:53 -08:00
Joe Groff
165b3e8e03 Merge pull request #71784 from jckarter/move-only-wrapped-yield
SILGen: Unwrap `@moveOnly` wrapped values before yielding them.
2024-02-21 13:31:39 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
John McCall
a4e92e7eb5 Merge pull request #71735 from rjmccall/isolated-any-silgen
Basic SILGen for @isolated(any); still missing closures.
2024-02-21 13:10:44 -05:00
Allan Shortlidge
cf3031794f SILGen: Avoid expanding #line directives with invalid source locations.
Synthesized stub constructors contain `#line` directives and under certain
circumstances these directives can have invalid source locations. SILGen would
trigger an assert (or invoke UB in non-asserts builds) when attempting to
expand these directives into literal values. Check the source location for
validity before translating the location to a location in the outermost source
file.

Resolves rdar://121971741
2024-02-20 20:07:16 -08:00
Joe Groff
88192ffb70 SILGen: Unwrap @moveOnly wrapped values before yielding them. 2024-02-20 16:40:36 -08:00
Joe Groff
0491755de9 Consume switch subjects under an opaque sub-access.
This prevents the move-only checker from trying to analyze the bindings
as partial consumptions, which ought to be unnecessary since SILGen
will always fully consume the subject as part of forming the bindings.
2024-02-20 16:35:39 -08:00
John McCall
68806b4ff5 Merge branch 'main' into isolated-any-silgen 2024-02-20 12:54:12 -05:00
John McCall
868fc6ad46 Basic SILGen for @isolated(any).
The main piece that's still missing here is support for closures;
they actually mostly work, but they infer the wrong isolation for
actor-isolated closures (it's not expressed in the type, so obviously
they're non-isolated), so it's not really functional.  We also have
a significant problem where reabstraction thunks collide incorrectly
because we don't mangle (or represent!) formal isolation into
SILFunctionType; that's another follow-up.  Otherwise, I think SILGen
is working.
2024-02-19 21:21:03 -05:00
Joe Groff
01405ba2e8 Fixes for compound payloads in borrowing switches.
Fill in a missing path for destructuring loadable elements from
address-only tuples in a borrowing context. Enclose projections in their
own separate accesses so that they are analyzed independently by the
move checker.
2024-02-19 17:37:34 -08:00
nate-chandler
1ecd9388ec Merge pull request #71673 from nate-chandler/bitwise-copyable/opt-store-bytes
[BitwiseCopyable] Optimize storeBytes overload.
2024-02-16 07:20:17 -08:00
Kavon Farvardin
8b79101698 Merge pull request #71674 from kavon/ncgenerics-test-fixes-kavon-v16 2024-02-15 22:04:38 -08:00
Kavon Farvardin
da5f716f2f NCGenerics: fix @UIApplicationMain 2024-02-15 18:26:57 -08:00
Nate Chandler
3f729c9121 [SILGen] Add Builtin.storeRaw.
The new builtin performs a store to unaligned memory.
2024-02-15 18:05:16 -08:00
Nate Chandler
1a2af606b0 [NFC] SILGen: Extracted emitBuiltinStore.
In preparation to reuse the code for a different sort of store.
2024-02-15 18:05:16 -08:00
John McCall
c9dac8d0b3 [NFC] Extract executor-handling stuff into SILGenConcurrency.cpp 2024-02-15 20:02:53 -05:00
John McCall
4e518463ea Merge pull request #71641 from rjmccall/emit-enum-args-into-context
Emit enum element arguments directly into the enum payload
2024-02-15 18:13:49 -05:00
Joe Groff
3decd816ed Merge pull request #71630 from jckarter/emit-value-as-borrow
SILGen: Handle emitting borrowed lvalues from value bindings.
2024-02-15 07:46:19 -08:00
John McCall
2d71c604ed Emit enum element arguments directly into the enum payload.
This generates significantly better code directly out of SILGen, at
the cost of having to reimplement a little bit of the argument-emission
logic to handle default arguments.  But it also neatly sidesteps the
problems we have with splitting tuple RValues when the tuple contains
a pack expansion, which will require some significant surgery to RValue
to fix.  That, in turn, fixes rdar://121489308.
2024-02-15 01:09:12 -05:00
Michael Gottesman
23ab974574 Merge pull request #71567 from gottesmm/transferring-param
[transferring] Implement transferring result and clean up transferring param support by making transferring a bit on param instead of a ParamSpecifier.
2024-02-14 17:54:48 -08:00
Doug Gregor
81ffafdc6a Merge pull request #70602 from ApolloZhu/macro/expression-as-default-argument
[Macros] Expression macro as caller-side default argument
2024-02-14 16:10:11 -08:00
Joe Groff
7fed21ae98 SILGen: Handle emitting borrowed lvalues from value bindings.
Replace the "must be an address" assertion with an implementation
that emits and borrows the base value. Fixes #71598.
2024-02-14 16:09:14 -08:00
Michael Gottesman
1f0527d47f [ast] Rename ParamSpecifier::{Transferring,ImplicitlyCopyableConsuming}.
The reason why I am doing this is that I am going to be changing transferring to
not be a true ParamSpecifier. Instead, it is going to be a bit on Param that
changes the default ParamSpecifier used. That being said, I cannot use consuming
for this purpose since consuming today implies no implicit copy semantics, which
we do not want unless the user specifically asks for it by writing consuming.
2024-02-14 13:04:21 -08:00
Ellie Shin
f5150e7265 Remove AbstractStorageDecl::isFormallyResilient.
Update DeclContext::bypassResilienceInPackage.
2024-02-13 19:09:31 -08:00
John McCall
b23bc82cdb Merge pull request #71574 from rjmccall/isolation-any-sil-irgen
SIL and IRGen support for `@isolated(any)` function types
2024-02-13 11:57:16 -05:00
Doug Gregor
eeeb8c3f18 Merge pull request #71577 from DougGregor/silgen-no-peeping-typed-throws-closures
[SILGen] Don't peephole closures with abstraction differences in the thrown error
2024-02-13 08:53:45 -08:00
Joe Groff
2170b4e725 Merge pull request #71489 from jckarter/borrowing-switch-8
MoveOnlyAddressUtils: Fixes for borrowing switch over address-only types.
2024-02-13 07:51:40 -08:00
John McCall
d5142668f4 SIL and IRGen support for @isolated(any). SILGen to come. 2024-02-13 03:04:13 -05:00
Doug Gregor
3edbb06632 [SILGen] Don't peephole closures with abstraction differences in the thrown error
The prolog and epilog code in SILGen is not set up to deal with
abstraction differences in the thrown error type of closures, so disable
the peephole optimization for closure literals.

Fixes https://github.com/apple/swift/issues/71401 / rdar://122366566,
which I've stared at for waaaaay too many hours.
2024-02-12 23:15:07 -08:00
Joe Groff
0365c6abba MoveOnlyAddressUtils: Fixes for borrowing switch over address-only types.
Relax some existing pattern matches and add some unhandled instructions to the
walkers so that borrowing switches over address-only enums are properly analyzed
for incorrect consumption. Add a `[strict]` flag to `mark_unresolved_move_only_value`
to indicate a borrow access that should remain a borrow access even if the subject
is later stack-promoted from a box.
2024-02-12 20:20:50 -08:00
Allan Shortlidge
2990c65457 NFC: Address some unused variable warnings. 2024-02-12 12:23:42 -08:00
Slava Pestov
6027bf46a6 AST: Simplify collectExistentialConformances() 2024-02-10 09:36:37 -05:00
Kavon Farvardin
74a3839cf3 Merge pull request #71515 from kavon/ncgenerics-test-fixes-kavon-v7
Ncgenerics test fixes kavon v7
2024-02-09 19:39:18 -08:00
Slava Pestov
06b1aee360 Evaluator: Cache circular evaluation to avoid redundant diagnostics
Previously, if a request R evaluated itself N times, we would emit N
"circular reference" diagnostics. These add no value, so instead let's
cache the user-provided default value on the first circular evaluation.

This changes things slightly so that instead of returning an
llvm::Expected<Request::OutputType>, various evaluator methods take
a callback which can produce the default value.

The existing evaluateOrDefault() interface is unchanged, and a new
evaluateOrFatal() entry point replaces
llvm::cantFail(ctx.evaluator(...)).

Direct callers of the evaluator's operator() were updated to pass in
the callback. The benefit of the callback over evaluateOrDefault() is
that if the default value is expensive to constuct, like a dummy
generic signature, we will only construct it in the case where a
cycle actually happened, otherwise we just delete the callback.

(cherry picked from commit b8fcf1c709efa6cd28e1217bd0efe876f7c0d2b7)
2024-02-09 16:02:24 -08:00
Kavon Farvardin
73e176cfdb NCGenerics: fix createInitExistentialAddr call 2024-02-09 11:14:06 -08:00
Andrew Trick
da3f583492 Add mark_dependence [unresolved]
In preparation for inserting mark_dependence instructions for lifetime
dependencies early, immediately after SILGen. That will simplify the
implementation of borrowed arguments.

Marking them unresolved is needed to make OSSA verification
conservative until lifetime dependence diagnostics runs.
2024-02-08 22:53:16 -08:00
Ellie Shin
1adfb7a6a1 Merge pull request #71446 from apple/revert-69843-end-apply-result
Revert "Allow normal function results of @yield_once coroutines"
2024-02-08 13:39:27 +09:00
Ian Anderson
c73497559e Merge pull request #71424 from ian-twilightcoder/fix-exit-crash
[Concurrency] SILGenModule::emitEntryPoint crashes when `exit` hasn't been imported
2024-02-07 16:44:28 -08:00
Joe Groff
c28b352b4c Merge pull request #71431 from jckarter/borrowing-switch-6
SILGen: Improve handling of copyable subpatterns in borrowing switches.
2024-02-07 15:12:22 -08:00
Ian Anderson
e7f1ea5848 [Concurrency] SILGenModule::emitEntryPoint crashes when exit hasn't been imported
If `exit` hasn't been imported, SILGenModule::emitEntryPoint crashes because it doesn't synthesize an exit function like SILGenFunction::emitCallToMain does. Make it do so.

rdar://122413238
2024-02-07 14:08:30 -08:00
Nate Cook
e317febc9d Revert "Allow normal function results of @yield_once coroutines (#69843)"
This reverts commit aa5b505014.
2024-02-07 14:57:31 -06:00
John McCall
60807a76a4 Merge pull request #71433 from rjmccall/isolated-any-typechecking
Experimental type-checking support for `@isolated(any)` function types.
2024-02-07 14:07:53 -05:00
Joe Groff
e46168c626 SILGen: Improve handling of copyable subpatterns in borrowing switches.
A `let` binding of a copyable subpattern can create an independent variable
which should be copyable and consumable without affecting a borrowed
move-only base. In the same way that `borrowing` parameters are
no-implicit-copy, though, explicitly `_borrowing` subpatterns of
copyable type should be no-implicit-copy as well.
2024-02-07 07:21:11 -08:00
Anton Korobeynikov
aa5b505014 Allow normal function results of @yield_once coroutines (#69843)
This adds SIL-level support and LLVM codegen for normal results of a coroutine.

The main user of this will be autodiff as VJP of a coroutine must be a coroutine itself (in order to produce the yielded result) and return a pullback closure as a normal result.

For now only direct results are supported, but this seems to be enough for autodiff purposes.
2024-02-06 22:13:15 -08:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Ellie Shin
e38bc9756c Merge pull request #71083 from apple/es-sil-pkg
Support a package SILLinkage
2024-02-07 09:10:13 +09:00
Apollo Zhu
b09a22a9a0 Somewhat working
Test shadowed variable of same type

Fully type check caller side macro expansion

Skip macro default arg caller side expr at decl primary

Test macro expand more complex expressions

Set synthesized expression as implicit

Add test case for with argument, not compiling currently

Test with swiftinterface

Always use the string representation of the default argument

Now works across module boundary

Check works for multiple files

Make default argument expression work in single file

Use expected-error

Disallow expression macro as default argument

Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
2024-02-06 15:02:11 -08:00