Commit Graph

2424 Commits

Author SHA1 Message Date
Anthony Latsis
c9c5fe2345 CSApply: Handle unbound references to methods found via dynamic lookup 2022-04-12 05:12:28 +03:00
Anthony Latsis
3593f1b987 [NFC] CSApply: 'isPartialApplication' → 'needsCurryThunk' which is more accurate 2022-04-12 05:12:23 +03:00
Anthony Latsis
4c4e2b4f84 CSApply: Fix unbound ref to class method on protocol composition metatype 2022-04-12 05:10:58 +03:00
Doug Gregor
4c77d71f60 Reseat the "is distributed thunk" check onto actor reference checking.
Rather than write an appoximation of the "is distributed thunk" check
within the type checker, use the new actor reference checking logic with
a referenced actor that is synthesized from the information in the
constraint system.
2022-04-07 10:46:52 -07:00
Doug Gregor
eef2704c86 Reimplement actor isolation checking for referencing a declaration.
Start collapsing the several implementations of actor isolation checking
into a single place that determines what it means to reference a declaration
from a given context, potentially supplying an instance for an actor. This
is partly cleanup, and partly staging for the implementation of the
Sendable restrictions introduced in SE-0338. The result of this check
falls into one of three categories:

* Reference occurs within the same concurrency domain (actor/task)
* Reference leaves an actor context to a nonisolated context (SE-0338)
* Reference enters the context of the actor, which might require a
combination of implicit async, implicit throws, and a "distributed" check.

Throughout this change I've sought to maintain the existing semantics,
even where I believe they are incorrect. The changes to the test cases
are not semantic changes, but reflect the unification of some
diagnostic paths that changed the diagnostic text but not when or how
those diagnostics are produced. Additionally, SE-0338 has not yet been
implemented, although this refactoring makes it easier to implement
SE-0338.

Use this new actor isolation checking scheme to implement the most
common actor-isolation check, which occurs when accessing a member of
an instance.
2022-04-07 09:07:36 -07:00
Pavel Yaskevich
8b8ccb488a [ConstraintSystem] Cache types of ~= components
While synthesizing `~=` application for multi-statement closures or
result builder, solver shouldn't set types directly to newly
created AST nodes because they might not be fully resolved, instead
such types have to be recorded in the constraint system and then
set during solution application.

Resolves: rdar://91145060.
2022-04-01 14:00:43 -07:00
Anthony Latsis
4c2e88b207 Merge pull request #41849 from AnthonyLatsis/dyn_unbound_ref
CS: Handle unbound references to @objc optional methods
2022-03-31 04:01:20 +03:00
Anthony Latsis
324913055d CS: Handle unbound references to @objc optional methods 2022-03-30 19:11:29 +03:00
Pavel Yaskevich
a5a50a3658 [AST] NFC: Rename underlying type accessors of OpaqueTypeDecl
Adds a `Unique` component to the accessor names to draw the
distinction between unique and conditionally available substitutions.
2022-03-28 16:22:08 -07:00
Pavel Yaskevich
0c2b8419f6 [CSApply] NFC: Remove unused cs variable
After switching to use a declaration context of rewriter,
variable `cs` became obsolete.
2022-03-28 09:47:14 -07:00
Anthony Latsis
d877ff9e0d [NFC] CSApply: Delete the now dead 'buildCurryThunk' 2022-03-26 18:28:24 +03:00
Anthony Latsis
87bdddd681 CSApply: Supplant 'buildCurryThunk' with a routine that builds a double curry thunk from scratch 2022-03-26 18:28:24 +03:00
Anthony Latsis
b06b66d28e CSApply: Use 'buildSingleCurryThunk' instead of 'buildCurryThunk' where a double thunk is not needed 2022-03-26 18:28:24 +03:00
Anthony Latsis
9dccd3374d [NFC] CSApply: Delete the now dead 'buildPropertyWrapperFnThunk' 2022-03-26 18:28:24 +03:00
Anthony Latsis
89667f8783 CSApply: Refactor 'buildCurryThunk' to use 'buildSingleCurryThunk' 2022-03-26 18:28:24 +03:00
Anthony Latsis
5a9010819d CSApply: Replace some 'buildPropertyWrapperFnThunk' calls with the new 'buildSingleCurryThunk' 2022-03-26 18:28:24 +03:00
Anthony Latsis
969324d9b6 [NFC] CSApply: Introduce generalized and convenience routines for building single curry thunks 2022-03-26 18:28:24 +03:00
Anthony Latsis
f25725279e [NFC] CSApply: Introduce a generalized routine for building single curry thunk bodies 2022-03-26 18:28:20 +03:00
Pavel Yaskevich
be08bac7e7 [CSApply] Use declaration context associated with rewriter
`ExprRewriter` could be created for a solution application target,
which could have its own declaration context if it's e.g. an inner
statement or a pattern binding.
2022-03-23 15:18:35 -07:00
Pavel Yaskevich
c6de8088c6 Merge pull request #41960 from xedin/csgen-casts-without-reprs
[CSGen/CSApply] Don't expect implicit casts to have type reprs
2022-03-23 12:26:19 -07:00
Pavel Yaskevich
15772e4a72 [CSApply] Ajust expression rewriter to handle casts without reprs
Implicit casts are allowed to provide cast type directly without
a type repr, adjust solution application logic to handle this just
like constraint generator does. Also fix a couple of places where
declaration context from constraint system was used instead
of one associated with the expression rewriter.
2022-03-23 00:18:55 -07:00
Alex Hoppen
e2a62f1a60 [CodeCompletion] Migrate expression completions to solver-based 2022-03-21 13:00:33 +01:00
Robert Widmann
363954a416 Put Variadic Generics Behind a Flag 2022-03-16 14:22:03 -07:00
Pavel Yaskevich
894c932ad0 [CSApply] Use decl context of target when applying solution to it
Solution application target can have its declaration context differ
from one used for constraint system, since target could be e.g. a
pattern associated with pattern binding declaration, a statement or
a sub-element of one (e.g. where clause) used in a closure etc.
2022-03-14 10:09:35 -07: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
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
Robert Widmann
d6186c9cfb Add a DeclContext Parameter to Opened Archetype Construction
This ensures that opened archetypes always inherit any outer generic parameters from the context in which they reside. This matters because class bounds may bind generic parameters from these outer contexts, and without the outer context you can wind up with ill-formed generic environments like

<τ_0_0, where τ_0_0 : C<T>, τ_0_0 : P>

Where T is otherwise unbound because there is no entry for it among the generic parameters of the environment's associated generic signature.
2022-03-07 22:54:22 -08:00
Zoe Carver
d3c40ef9f1 Merge pull request #41624 from zoecarver/cache-thunks-for-spec
[cxx-interop] Cache specialized function templates.
2022-03-03 14:15:44 -08:00
Pavel Yaskevich
26d85520a2 Merge pull request #41589 from xedin/handle-expr-patterns-in-the-solver
[ConstraintSystem] Support solving expression patterns via injecting call to `~=` operator
2022-03-02 16:33:52 -08:00
zoecarver
680d5d2cc8 [nfc] [cxx-interop] Move function template specialization logic into clang-module-loader. 2022-03-02 10:58:14 -08:00
swift-ci
ad903094c0 Merge pull request #41386 from beccadax/your-library-is-overdue
Weaken some type checks for @preconcurrency decls
2022-03-01 16:13:59 -08:00
Pavel Yaskevich
59154d6d71 [ConstraintSystem] Support solving expression patterns via injecting call to ~= operator
Augment the constraint solver to fallback to implicit `~=` application
when member couldn't be found for `EnumElement` patterns because
`case` statement should be able to match enum member directly, as well
as through an implicit `~=` operator application.
2022-02-28 17:02:28 -08:00
Pavel Yaskevich
50d0508a4b [ConstraintSystem] Add a new contextual type purpose - expression pattern
This makes it possible to associate expression with its parent pattern.
2022-02-25 12:30:22 -08:00
Zoe Carver
5974cd0908 Merge pull request #41466 from zoecarver/support-basic-inout-case 2022-02-18 22:03:25 -08:00
Doug Gregor
e3af684772 Merge pull request #41183 from DougGregor/implicitly-open-existentials 2022-02-18 18:04:04 -08:00
zoecarver
f73e20b795 [cxx-interop] Fix crash when inout parameter is used in some "template contexts".
We used to incorrectly forward inout paramters in the thunk for both template paramters that aren't used in the signature and in the thunk for dependent types as Any.

Now this works in the simple case. We'll need to do something more complicated when we have an `inout Any` for dependent types because we will need to somehow cast without copying. This will probably require synthesising the SIL of the thunk manually.
2022-02-18 15:11:14 -08:00
Becca Royal-Gordon
c2ccb874ab Soften actor isolation in closures passed to @preconcurrency
When a closure is not properly actor-isolated, but we know that we inferred its isolation from a `@preconcurrency` declaration, we now emit the errors as warnings in Swift 5 mode to avoid breaking source compatibility if the isolation was added retroactively.
2022-02-18 14:29:16 -08:00
Doug Gregor
e30c8a5c09 Allow opening existentials for inout parameters. 2022-02-18 11:22:57 -08:00
Doug Gregor
1e1b3427c3 Experimental support for implicitly opening existential arguments.
When calling a generic function with an argument of existential type,
implicitly "open" the existential type into a concrete archetype, which
can then be bound to the generic type. This extends the implicit
opening that is performed when accessing a member of an existential
type from the "self" parameter to all parameters. For example:

    func unsafeFirst<C: Collection>(_ c: C) -> C.Element { c.first! }

    func g(c: any Collection) {
      unsafeFirst(c)   // currently an error
                       // with this change, succeeds and produces an 'Any'
    }

This avoids many common sources of errors of the form

    protocol 'P' as a type cannot conform to the protocol itself

which come from calling generic functions with an existential, and
allows another way "out" if one has an existention and needs to treat
it generically.

This feature is behind a frontend flag
`-enable-experimental-opened-existential-types`.
2022-02-18 11:22:56 -08:00
Zoe Carver
4a67288168 Merge pull request #41440 from zoecarver/members-with-dependent-types
[cxx-interop] Fix calling methods with dependent types.
2022-02-18 11:06:16 -08:00
zoecarver
47064a0eda [cxx-interop] Fix calling methods with dependent types.
Both instance members and static methods.
2022-02-18 09:21:55 -08:00
zoecarver
970489b72f [cxx-interop] [nfc] Don't emit a cast if the cast is a no-op. 2022-02-18 09:19:43 -08:00
zoecarver
0d60c2e25d Revert "Revert "[cxx-interop] Start to import dependent types as Any""
This reverts commit fdb417a2e5.
2022-02-17 13:23:14 -08:00
Saleem Abdulrasool
fdb417a2e5 Revert "[cxx-interop] Start to import dependent types as Any" 2022-02-16 20:20:36 -08:00
zoecarver
9ff5bb1f45 [cxx-interop] Add support for dependent types as Any.
Dependent types are going to be very hard to support, especially in complex cases. This PR adds a workaround that people can use: `Any`. This requires manual type casting, but it does work.
2022-02-16 12:44:14 -08:00
zoecarver
02a621962c [nfc] Re-factor logic in resolveConcreteDeclRef into separate static functions. 2022-02-16 12:43:48 -08:00
Zoe Carver
b60dcc1d24 Merge pull request #41394 from zoecarver/revert-revert-cleanup-and-fixes-for-function-templates 2022-02-16 08:30:16 -08:00
Anthony Latsis
352b3a2f6d Merge pull request #41201 from AnthonyLatsis/opened-root
AST: Remove OpenedArchetypeType::getOpenedExistentialType()
2022-02-16 09:07:30 +03:00
zoecarver
83e3f9657d [nfc] Re-factor logic in resolveConcreteDeclRef into separate static functions. 2022-02-15 20:09:15 -08:00