Commit Graph

2441 Commits

Author SHA1 Message Date
Meghana Gupta
16c277f8fb Add new api replaceAllTypeDependentUsesWith 2022-04-07 09:19:42 -07:00
Doug Gregor
fdbeb45320 SIL linker: don't try to synthesize witness tables for marker protocols.
We never have them, we never need them, and we'll crash if there were
one for a conformance of a non-nominal type to such a protocol.

Fixes rdar://91126885 .
2022-03-31 21:48:29 -07:00
Joe Groff
d451203b7f SILGen: Emit async let entry points at correct abstraction level.
Avoid a reabstraction thunk every time an async let entry point is emitted,
by setting the context abstraction level while we emit the implicit closure.
Adjust some surrounding logic that breaks when we do this:

- When lowering a non-throwing function type against a throwing abstraction
  pattern, include the error type in the lowered substituted type. Async
  throwing and nonthrowing functions would require another thunk to convert
  away the throwingness of the async context, which would defeat the purpose.
- Adjust the code in IRGen that pads the initial context size for `async let`
  entry points so that it works when the entry point has not yet emitted, by
  marking the async function pointer to be padded later if it isn't defined
  yet.
2022-03-30 14:51:46 -07:00
Erik Eckstein
6b7ae416e6 SIL: remove unused instructions thin_function_to_pointer and pointer_to_thin_function 2022-03-25 15:44:59 +01:00
Andrew Trick
1a6d7c1ba5 Merge pull request #41947 from atrick/opv-silgen
[nfc-5.7] Initial round of SILGen fixes and tests for opaque value
2022-03-23 12:01:26 -07:00
Allan Shortlidge
1dabda882e Merge pull request #41961 from tshortli/dont-serialize-back-deployed-originals
SIL: Avoid serializing the bodies of the original copies of @_backDeploy functions
2022-03-22 23:59:17 -07:00
Andrew Trick
2fd4de411e [SIL-opaque] Removed [Unconditional]CheckedCastValue 2022-03-22 17:04:13 -07:00
Allan Shortlidge
0bb6a7b9e8 SIL: Avoid serializing the bodies of the original copies of @_backDeploy functions to prevent the optimizer from inlining those bodies into their back deployment thunks. This ensures that the copy of the function in the library dylib is reliably called when it is available, both with and without optimizations enabled. Also update the attr_backDeploy_evolution test case to use precondition() instead of assert() since asserts are compiled out with optimizations enabled.
Resolves rdar://90525337
2022-03-22 15:30:42 -07:00
Andrew Trick
406aa86d2e Merge pull request #41557 from atrick/addrlower-update
Update and reimplement AddressLowering pass (for SIL opaque values).
2022-03-21 22:15:06 -07:00
Andrew Trick
e081091303 Merge pull request #41826 from atrick/fix-recursive-closure
Rewrite ClosureScopeAnalysis for generality.
2022-03-18 07:35:34 -07:00
Andrew Trick
268309e268 Add a function index
This radically simplifies the representation of function sets when
analyzing the entire module's call graph at once.
2022-03-17 17:49:50 -07:00
Pavel Yaskevich
c9a0295d6d [Distributed] Synthesis: Start using special mangling for distributed thunks 2022-03-17 14:02:42 -07:00
nate-chandler
fa9eb49cc6 Merge pull request #41806 from nate-chandler/mem_access_utils/two-new-utilities
[MemAccessUtils] Add two utilties.
2022-03-15 11:59:46 -07:00
Nate Chandler
5774e5447a [Gardening] Silenced warning. 2022-03-14 09:45:47 -07:00
Doug Gregor
4d5d9e3d56 Merge pull request #41792 from DougGregor/collapse-thunk-types 2022-03-11 19:15:43 -08:00
Doug Gregor
9c134263de Collapse the differentiation-specific thunk type generation code into the general version
We had two copies of this code that had drifted apart. Bring them back
together so there is just one place where we compute the type of a
reabstraction thunk.
2022-03-11 16:33:13 -08:00
Doug Gregor
3cb7af086d Move SILGenFunction::buildThunkType out to a utility function 2022-03-11 15:09:24 -08:00
Konrad `ktoso` Malawski
5ab8e0834d [Distributed] Reimplement distributed call thunks completely in AST (#41616)
* [Distributed] dist actor always has default executor (currently)

* [Distributed] extra test for missing makeEncoder

* [DistributedDecl] Add DistributedActorSystem to known SDK types

* [DistributedActor] ok progress on getting the system via witness

* [Distributed] allow hop-to `let any: any X` where X is DistActor

* [Distributed] AST: Add an accessor to determine whether type is distributed actor

- Classes have specialized method on their declarations
- Archetypes and existentials check their conformances for
  presence of `DistributedActor` protocol.

* [Distributed] AST: Account for distributed members declared in class extensions

`getConcreteReplacementForProtocolActorSystemType` should use `getSelfClassDecl`
otherwise it wouldn't be able to find actor if the member is declared in an extension.

* [Distributed] fix ad-hoc requirement checks for 'mutating'

[PreChecker] LookupDC might be null, so account for that

* [Distributed] Completed AST synthesis for dist thunk

* [Distributed][ASTDumper] print pretty distributed in right color in AST dumps

* wip on making the local/remote calls

* using the _local to mark the localCall as known local

* [Distributed] fix passing Never when not throwing

* fix lifetime of mangled string

* [Distributed] Implement recordGenericSubstitution

* [Distributed] Dont add .

* [Distributed] dont emit thunk when func broken

* [Distributed] fix tests; cleanups

* [Distributed] cleanup, move is... funcs to DistributedDecl

* [Distributed] Remove SILGen for distributed thunks, it is in Sema now!

* [Distributed]  no need to check stored props in protocols

* remote not used flag

* fix mangling test

* [Distributed] Synthesis: Don't re-use AST nodes for `decodeArgument` references

* [Distributed] Synthesis: Make sure that each thunk parameter has an internal name

* [Distributed/Synthesis] NFC: Add a comment regarding empty internal parameter names

* [Distributed] NFC: Adjust distributed thunk manglings in the accessor section test-cases

* cleanup

* [Distributed] NFC: Adjust distributed thunk manglings in the accessor thunk test-cases

* review follow ups

* xfail some linux tests for now so we can land the AST thunk

* Update distributed_actor_remote_functions.swift

Co-authored-by: Pavel Yaskevich <xedin@apache.org>
2022-03-10 23:58:23 +09:00
Andrew Trick
2907c61203 SILModule::hasLoweredAddress 2022-03-09 17:18:15 -08:00
Andrew Trick
8457ba30ed Add emitLoad/emitStore to OpaqueValue type lowering. 2022-03-09 17:18:15 -08:00
Andrew Trick
8a7e955b0d Move -enable-sil-opaque-value to SILOptions. 2022-03-09 17:18:15 -08:00
Robert Widmann
512ebc52a6 Merge pull request #41743 from CodaFi/existential-dread 2022-03-09 15:12:29 -08:00
Erik Eckstein
6a020f8f15 Stabilize and simplify SIL linkage and serialization
The main point of this change is to make sure that a shared function always has a body: both, in the optimizer pipeline and in the swiftmodule file.
This is important because the compiler always needs to emit code for a shared function. Shared functions cannot be referenced from outside the module.
In several corner cases we missed to maintain this invariant which resulted in unresolved-symbol linker errors.

As side-effect of this change we can drop the shared_external SIL linkage and the IsSerializable flag, which simplifies the serialization and linkage concept.
2022-03-09 15:28:05 +01:00
Robert Widmann
4efcb825f5 Unlock Opaque Types in Parameterized Protocols
Represent this in much the same way that collections do by creating an opaque value representing the source argument, and a conversion expression representing the destination argument.
2022-03-08 23:45:37 -08:00
Robert Widmann
ab44a07045 Convert DeclContext Parameters to their Associated Generic Signatures Instead 2022-03-07 22:54:23 -08:00
eeckstein
aed6c627f8 Merge pull request #41643 from eeckstein/fix-clang-imported-effects
SIL: don't add effects attributes for storage decls.
2022-03-04 13:03:00 +01:00
Alex Lorenz
ebb21d7ec1 [cxx-interop] Import const T& parameters as T.
This change allows Swift code to pass immutable values to const references in C++.
2022-03-03 14:42:27 -08:00
Erik Eckstein
08c05719e1 SIL: don't add effects attributes for storage decls.
Only for accessor functions.
This is important because the clang importer sets "readonly" attributes for a getter also on the storage decl, which would propagate to the setter.

This PR restores the old behavior which was changed by https://github.com/apple/swift/pull/40957.

Unfortunately I don't have a test case.

rdar://88876417
2022-03-03 13:31:53 +01:00
Slava Pestov
527f31ff64 AutoDiff: Another ugly hack to work around generics invariant violations 2022-03-02 17:42:40 -05:00
Allan Shortlidge
9e4ba442a2 Merge pull request #41416 from tshortli/back-deploy-thunk
Emit and call thunks for back deployed functions
2022-02-25 17:49:08 -08:00
Nate Chandler
a19ad9131e [SIL] abort_apply insts maySynchronize.
Just as a full apply may have side-effects including synchronization, so
may an abort_apply, which is lowered to the apply of a continuation.
2022-02-24 15:17:01 -08:00
Allan Shortlidge
5339dae08e SILGen: Emit a fallback variant of a back deployable function and call it when the original function is not available at run time. 2022-02-23 18:07:18 -08:00
Pavel Yaskevich
f6e573816c [SIL] Adjust lowering to account for default expr having type different from parameter
Use `getTypeOfDefaultExpr()` to fetch a type associated with default expression
if any. This could only happen in situations where it's acceptable to infer type
of generic parameter(s) associated with parameter from default expression.
2022-02-21 09:59:53 -08:00
Rintaro Ishizaki
7486cd1c21 [SwiftCompiler] Move common bridging facilities to 'Basic'
A preparation for AST/DiagnosticEngine bridging
2022-02-20 22:06:39 -08:00
Allan Shortlidge
97e8e31b5c SILGen: Emit a thunk that wraps the call to a back deployed function. The thunk calls the original function if it is available at runtime and otherwise falls back to calling a copy that is emitted into the client (not yet implemented). 2022-02-17 11:28:12 -08:00
Allan Shortlidge
ff5abc4e2f Mangling: Use 'Tw' to mangle back deployment thunks. 2022-02-17 11:28:12 -08:00
Allan Shortlidge
212043840f SIL: Add flag to SILDeclRef for back deployment thunks. 2022-02-17 11:28:12 -08:00
Arnold Schwaighofer
62ec31a462 Merge pull request #41338 from aschwaighofer/reuse_contiguous_array_storage_metadata
Reuse `_ContiguousArrayStorage<AnyObject>` metadata for any class or objc generic type
2022-02-17 12:47:23 -05:00
Andrew Trick
afde39db1b Merge pull request #41366 from atrick/addrlower-silapi
Many minor/obvious SIL API improvements that address lowering depends on
2022-02-16 17:37:12 -08:00
Anton Korobeynikov
91458b4890 Fix several issues related to captured arguments:
- Introduce a workaround while dealing with getLoweredParameterIndices() results:
    it operates on AST and therefore does not take into account captured arguments
    which are "on side" on AST and explicit in SIL
  - Ensure captured arguments (@inout_aliased) are handled in a same way as ordinary
    @inout arguments while generating a pullback type

Fixes SR-15205
2022-02-17 00:04:12 +03:00
Andrew Trick
59eea142c4 Add OwnershipForwardingMixin::hasSameRepresentation and verify
Also add OwnershipForwardingMixin::isAddressOnly.
2022-02-16 12:23:01 -08:00
Arnold Schwaighofer
9f2b6a4ebb Reuse _ContiguousArrayStorage<AnyObject> metadata for any class or objc generic type
Reduces the number of _ContiguousArrayStorage metadata.

In order to support constant time bridging we do need to set the correct
metadata when we bridge to Objective-C. This is so that the type check
succeeds when bridging back from Objective-C to reuse the storage
instance rather than bridging the elements.

To support dynamically setting the `_ContiguousArrayStorage` element
type i needed to add support for optimizing `alloc_ref_dynamic`
throughout the optimizer.

Possible future improvements:
* Use different metadata such that we can disambiguate native Swift
  classes during destruction -- allowing native release rather then unknown
  release usage.
* Optimize the newly added semantic function
  getContiguousArrayStorageType

rdar://86171143
2022-02-16 07:55:34 -08:00
Andrew Trick
f6ba6332a6 Allow SIL convention overriding in operand ownership verification
This lets the SILBuilder's verification continue to run during
address lowering before the SIL stage has been updated.
2022-02-15 13:28:47 -08:00
Andrew Trick
83b01d8ebe Improve the SILPhiArgument API
This subclass of SILArgument should be eliminated--it's not always a
phi, and whether it is a "phi argument" has nothing whatsoever to do
with the opcode. That is a property of a value's uses, not a property of the
value.

Until then, provide a logical and useful API within the type. This
often avoids the need to explicitly cast to a SILPhiArgument type and
avoids a lot of boilerplate in code that deals with phis.

Note: PhiOperand and PhiValue are improved abstractions on top of this
API. But the SILArgument-level API is still an important bridge
between SILArgument and other phi abstractions.
2022-02-15 13:28:46 -08:00
nate-chandler
23252935f6 Merge pull request #41358 from nate-chandler/lexical_lifetimes/shrink-borrow-scope/adopt-reachability
[ShrinkBorrowScope] Adopt BackwardReachability.
2022-02-15 07:07:30 -08:00
Michael Gottesman
28fb3db8b9 Merge pull request #41378 from gottesmm/pr-4f030e9c7eb178276a709f3b668f8f9f357ffb40
[move-function] Add initial debug info support to move checker passes.
2022-02-14 22:41:00 -08:00
Michael Gottesman
375ce353f2 [move-function] Add a flag to alloc_stack and debug_value that states that they describe an address/value that was moved at some point locally in the function.
The main effect of this will be that in IRGen we will use llvm.dbg.addr instead
of llvm.dbg.declare. We must do this since llvm.dbg.declare implies that the
given address is valid throughout the program.

This just adds the instructions/printing/parsing/serialization/deserialization.

rdar://85020571
2022-02-14 17:56:03 -08:00
Nate Chandler
45afec6e0a [SIL] Added SILBasicBlock::hasPhi. 2022-02-14 17:12:47 -08:00
nate-chandler
827df0110f Merge pull request #41310 from nate-chandler/lexical_lifetimes/destroy_hoisting/enable
[SILOpt] Enabled SSADestroyHoisting.
2022-02-14 15:52:48 -08:00
Nate Chandler
b516b04128 [SIL] end_apply insts maySynchronize.
Just as a full apply may have side-effects including synchronization, so
may an end_apply, which is lowered to the apply of a continuation.
2022-02-10 20:18:25 -08:00