Commit Graph

2448 Commits

Author SHA1 Message Date
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
zoecarver
a1f9aae63f [cxx-interop] Fix integer substitution on watchOS.
Basically watchOS had the same issue as Windows.
2022-02-15 16:51:14 -08:00
zoecarver
283fc782ec Revert "Revert "[cxx-interop] A few cleanups and fixes for function templates.""
This reverts commit 5de09631ff.
2022-02-15 13:30:10 -08:00
Zoe Carver
5de09631ff Revert "[cxx-interop] A few cleanups and fixes for function templates." 2022-02-13 09:54:39 -08:00
Zoe Carver
0e7af7a7cd Merge pull request #41217 from zoecarver/cleanup-and-fixes-for-function-templates 2022-02-12 14:10:41 -08:00
zoecarver
83e465f763 Move up the Windows hack and fix it for static members/inits. 2022-02-11 20:51:11 -08:00
zoecarver
4cb1704b0e [nfc] Clang format the PR. 2022-02-11 13:57:31 -08:00
zoecarver
6da5e7ee06 [cxx-interop] Fix (U)Int substituted params on Windows.
Re-write the parameter list to use (U)Int if that was one of the substituted parameters. This is required because Windows will incorrectly map Int -> long long -> Int64.
2022-02-11 13:57:04 -08:00
Hamish Knight
aa6942e462 [CS] Simplify visitCoerceExpr slightly
Remove the unused `choice` parameter.
2022-02-10 19:06:47 +00:00
Pavel Yaskevich
f1e602f98d Merge pull request #41189 from xedin/trailing-closures-with-callAsFunction
[ConstraintSystem] Match trailing closures to implicit `.callAsFunction` when necessary
2022-02-08 17:44:55 -08:00
zoecarver
daceecfc75 [cxx-interop] Remove generateSpecializedCXXFunctionTemplate and just import the decl directly.
1) This unifies two code paths that do essentially the same thing.
2) This fixes how we import certain types (such as return types).
2022-02-04 16:18:02 -08:00
Anthony Latsis
91bd2b1803 AST: Remove OpenedArchetypeType::getOpenedExistentialType()
Clients can explicitly ask for the opened existential type on the archetype's generic environment,
or use `getExistentialType` to obtain a specific archetype's upper bounds.
2022-02-04 16:22:50 +03:00
Pavel Yaskevich
36c02e4291 [CSApply] Implement support for implicit .callAsFunction after init with trailing closures
Situations like `T(...) { ... }` where `T` is a callable type
and trailing closure belongs to `.callAsFunction` should be
rewritten as `T.init().callAsFunction { ... }`.
2022-02-03 15:36:18 -08:00
Slava Pestov
aa67c8bf8a Parametrized => parameterized 2022-02-03 13:27:24 -05:00
Anthony Latsis
c7fd60f2dd Merge pull request #39492 from AnthonyLatsis/se-309-2
SE-309: Covariant erasure for dependent member types
2022-02-02 07:07:17 +03:00
Anthony Latsis
24c19d4ad4 Sema: Enable covariant erasure for dependent member types 2022-02-02 02:10:05 +03:00
Anthony Latsis
b3ee4b0718 AST, Sema: Use the opened archetype's generic signature to determine existential member availability 2022-02-02 02:09:59 +03:00
Pavel Yaskevich
48ffeddbc7 [CSApply] Result coercion check should always use resolved type
`shouldCoerceToContextualType` used `solution.getType(ASTNode)`
which returns a type that has type variables in it. To properly
check whether result type needs a coercion it has to be resolved
first which is done via `solution.getResultType(ASTNode)`.

Resolves: rdar://88285682
2022-01-31 14:42:27 -08:00
Slava Pestov
e7e536705e AST: Introduce ParametrizedProtocolType 2022-01-26 00:11:38 -05:00
Holly Borla
76e6156857 [Sema] Construct OpenedArchetypeType with a canonical existential type.
Opened archetypes can be created in the constraint system, and the
existential type it wraps can contain type variables. This can happen
when the existential type is inferred through a typealias inside a
generic type, and a member reference whose base is the opened existential
gets bound before binding the generic arguments of the parent type.

However, simplifying opened archetypes to replace type variables is
not yet supported, which leads to type variables escaping the constraint
system. We can support cases where the underlying existential type doesn't
depend on the type variables by canonicalizing it when opening the
existential. Cases where the underlying type requires resolved generic
arguments are still unsupported for now.
2022-01-19 22:53:52 -08:00
Doug Gregor
452eccab83 Remove NestedArchetypeType.
Nested archetypes are represented by their base archetype kinds (primary,
opened, or opaque type) with an interface type that is a nested type,
as represented by a DependentMemberType. This provides a more uniform
representation of archetypes throughout the frontend.
2022-01-14 21:28:21 -08:00
Holly Borla
d971d489d6 [Type System] With explicit existential types, make sure existential
metatypes always wrap the constraint type directly, and the instance
type of an existential metatype is an existential type.
2022-01-13 19:30:44 -08:00
Evan Wilde
89af8c9d24 Removing unused ctx variable
Cleaning up build warning for unused ctx variable in CSApply.cpp.
2022-01-11 09:16:09 -08:00
Doug Gregor
7a37ad3105 Ensure that we set opaque type substitutions on local variables.
We were never setting these opaque type substitutions, but code
generation was silently failing. Now we assert, so move the code into
the proper common location so we always set opaque type substitutions
on properties.

Fixes rdar://86800325.
2022-01-10 15:32:42 -08:00
Pavel Yaskevich
9f7d3fccad Merge pull request #40708 from xedin/disable-multi-stmt-inference-inside-result-builder-bodies
[ConstraintSystem] SE-0326: Temporarily prevent multi-statement closure inference in result builder contexts
2022-01-06 01:04:22 -08:00
Doug Gregor
b97ef02d85 Opaque opaque types and compute substitutions in the constraint system
Opaque opaque types and record them within the "opened types" of the
constraint system, then use that information to compute the set of
substitutions needed for the opaque type declaration using the normal
mechanism of the constraint solver. Record these substitutions within
the underlying-to-opaque conversion.

Use the recorded substitutions in the underlying-to-opaque conversion
to set the underlying substitutions for the opaque type declaration
itself, rather than reconstructing the substitutions in an ad hoc manner
that does not account for structural opaque result types.
2021-12-26 20:33:58 -08:00
Pavel Yaskevich
bbdbb47b25 [CSApply] Switch delayed closure processing to use participatesInInference
Instead of checking the frontend flag directly, let's use dedicated
method on a constraint system to determine whether closure did
participate in inference or not.
2021-12-25 17:08:58 -08:00