Commit Graph

30 Commits

Author SHA1 Message Date
Hamish Knight
91ae5d6345 [AST] NFC: Rename getArgumentInterfaceType -> getPayloadInterfaceType
IMO this is a slightly clearer name, many of its
uses already use the term "payload".
2024-09-29 17:05:14 +01:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Slava Pestov
977b444eb3 AST: Add a new overload of getContextSubstitutionMap() 2024-07-10 13:28:26 -04:00
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Allan Shortlidge
15d9f4c8ce SILGen: Ignore invalid associated conformances.
With lazy type checking, invalid conformances can make it all the way to
SILGen. As a result, `SILGenModule::useConformance()` needs to handle invalid
conformances more gracefully by ignoring them instead of asserting.

Resolves rdar://128286622
2024-06-20 20:08:55 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Slava Pestov
4aa0008d74 SILGen: Rewrite captured local archetypes into primary archetypes
This implements support for autoclosures, closures and local functions
nested within a pack iteration for loop.

The combination of explicit closure expressions and pack expansion
expressions still needs some work.

Fixes #66917.
Fixes #69947.
Fixes rdar://113505724.
Fixes rdar://122293832.
Fixes rdar://124329076.
2024-05-17 17:45:05 -04:00
Doug Gregor
97ea19d191 Introduce a builtin and API for getting the local actor from a distributed one
When an actual instance of a distributed actor is on the local node, it is
has the capabilities of `Actor`. This isn't expressible directly in the type
system, because not all `DistributedActor`s are `Actor`s, nor is the
opposite true.

Instead, provide an API `DistributedActor.asLocalActor` that can only
be executed when the distributed actor is known to be local (because
this API is not itself `distributed`), and produces an existential
`any Actor` referencing that actor. The resulting existential value
carries with it a special witness table that adapts any type
conforming to the DistributedActor protocol into a type that conforms
to the Actor protocol. It is "as if" one had written something like this:

    extension DistributedActor: Actor { }

which, of course, is not permitted in the language. Nonetheless, we
lovingly craft such a witness table:

* The "type" being extended is represented as an extension context,
rather than as a type context. This hasn't been done before, all Swift
runtimes support it uniformly.

* A special witness is provided in the Distributed library to implement
the `Actor.unownedExecutor` operation. This witness back-deploys to the
Swift version were distributed actors were introduced (5.7). On Swift
5.9 runtimes (and newer), it will use
`DistributedActor.unownedExecutor` to support custom executors.

* The conformance of `Self: DistributedActor` is represented as a
conditional requirement, which gets satisfied by the witness table
that makes the type a `DistributedActor`. This makes the special
witness work.

* The witness table is *not* visible via any of the normal runtime
lookup tables, because doing so would allow any
`DistributedActor`-conforming type to conform to `Actor`, which would
break the safety model.

* The witness table is emitted on demand in any client that needs it.
In back-deployment configurations, there may be several witness tables
for the same concrete distributed actor conforming to `Actor`.
However, this duplication can only be observed under fairly extreme
circumstances (where one is opening the returned existential and
instantiating generic types with the distributed actor type as an
`Actor`, then performing dynamic type equivalence checks), and will
not be present with a new Swift runtime.

All of these tricks together mean that we need no runtime changes, and
`asLocalActor` back-deploys as far as distributed actors, allowing it's
use in `#isolation` and the async for...in loop.
2024-01-22 17:27:31 -08:00
Slava Pestov
de94a460c8 SILGen: Handle PackConformance in SILGenModule::useConformance() 2023-02-25 16:19:07 -05:00
Slava Pestov
9d96ed940f AST: Rename 'canonical wrt. generic signature' to 'reduced'
We had two notions of canonical types, one is the structural property
where it doesn't contain sugared types, the other one where it does
not contain reducible type parameters with respect to a generic
signature.

Rename the second one to a 'reduced type'.
2022-08-09 12:46:31 -04:00
Slava Pestov
1d8b0f25ac SILGen: Simplify SILGenModule::useConformance() 2022-08-03 00:28:43 -04:00
Slava Pestov
69bb2a797f SILGen: Crash better when useConformance() is handed an invalid conformance 2022-07-29 11:59:17 -04:00
Andrew Trick
2fd4de411e [SIL-opaque] Removed [Unconditional]CheckedCastValue 2022-03-22 17:04:13 -07:00
Slava Pestov
a1c03db381 AST: Generalize ProtocolDecl::getRequirementSignature() to a new RequirementSignature type
The RequirementSignature generalizes the old ArrayRef<Requirement>
which stores the minimal requirements that a conforming type's
witnesses must satisfy, to also record the protocol typealiases
defined in the protocol.
2022-02-13 00:24:23 -05:00
Michael Gottesman
d74299e68d [move-function] Add a new instruction called mark_unresolved_move_addr.
This instruction is similar to a copy_addr except that it marks a move of an
address that has to be checked. In order to keep the memory lifetime verifier
happy, the semantics before the checker runs are the mark_unresolved_move_addr is
equivalent to copy_addr [init] (not copy_addr [take][init]).

The use of this instruction is that Mandatory Inlining converts builtin "move"
to a mark_unresolved_move_addr when inlining the function "_move" (the only
place said builtin is invoked).

This is then run through a special checker (that is later in this PR) that
either proves that the mark_unresolved_move_addr can actually be a move in which
case it converts it to copy_addr [take][init] or if it can not be a move, emit
an error and convert the instruction to a copy_addr [init]. After this is done
for all instructions, we loop back through again and emit an error on any
mark_unresolved_move_addr that were not processed earlier allowing for us to
know that we have completeness.

NOTE: The move kills checker for addresses is going to run after Mandatory
Inlining, but before predictable memory opts and friends.
2021-12-06 12:47:29 -08:00
Erik Eckstein
7849f09e52 SIL: remove the unused alloc_value_buffer, project_value_buffer and dealloc_value_buffer instructions.
Those instructions were use for the materializeForSet implementation, which was replaced by modify-coroutines.
2021-10-07 07:41:54 +02:00
Robert Widmann
1491eb0ca3 [NFC] Drop Some Superfluous Null Signature Guards 2021-07-22 23:27:06 -07:00
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
2021-07-22 23:27:05 -07:00
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Azoy
f21a306ae5 [AST] Introduce BuiltinProtocolConformance 2020-10-22 18:24:27 -04:00
Slava Pestov
53bfc767a3 SIL: Track target formal type for casts
SIL type lowering erases DynamicSelfType, so we generate
incorrect code when casting to DynamicSelfType. Fixing this
requires a fair amount of plumbing, but most of the
changes are mechanical.

Note that the textual SIL syntax for casts has changed
slightly; the target type is now a formal type without a '$',
not a SIL type.

Also, the unconditional_checked_cast_value and
checked_cast_value_br instructions now take the _source_
formal type as well, just like the *_addr forms they are
intended to replace.
2019-11-20 21:30:28 -05:00
Robert Widmann
b849e51768 Use operator bool to claw back some readability 2019-10-29 16:56:21 -07:00
Robert Widmann
3e1a61f425 [NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
ProtocolConformanceRef already has an invalid state.  Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it.  Mechanically
translate all of the callers and callsites to use this new
representation.
2019-10-29 16:55:56 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
John Holdsworth
fe32ba1a86 Add missing newlines 2019-06-10 22:12:24 +01:00
Slava Pestov
04db869d80 SILGen: Simplify delayed conformance emission
Instead of visiting all types in the ExternalDefinitions list and
queuing up their conformances, just emit conformances as needed
when they are first referenced.
2019-05-18 11:35:05 -04:00
Slava Pestov
a0197b38ea SILGen: Some fixes for lazy conformance emission
- Don't forget to walk the top-level 'main' function

- Force _ObjectiveCBridgeable and _BridgedStoredNSError conformances
  for types mentioned in apply instructions, existential erasure and
  casts

- Only walk each unique CanType once, and skip non-ClangImporter
  synthesized conformances completely

- Add a few missing cases
2019-04-25 22:27:16 -04:00
Slava Pestov
cf60ed5bf0 SILGen: Force lazy conformances referenced from various places in the AST
SILGen has the ability to lazily emit ClangImporter-synthesized
conformances. Sema builds a per-SourceFile list of "used" conformances,
which are forced to be emitted by SILGen. All other conformances can be
emitted lazily.

Some of these "used" conformances are in fact not referenced by SILGen
at all, but must exist for emission by IRGen so that they can be
referenced from type metadata accessors, as well as available at
runtime for the dynamic cast machinery.

To handle these cases, add an AST walk to SILGen which emits the types
of stored properties, the superclass of a class, and a few other
things that might not be referenced directly from SIL.

For now, this is all redundant because Sema forces the right
conformances anyway, but that's going to change soon.
2019-04-25 22:22:58 -04:00
Slava Pestov
8a74e52273 SILGen: Add post-processing pass to lazily emit ClangImproter-synthesized conformances 2019-04-25 02:05:20 -04:00