Commit Graph

31399 Commits

Author SHA1 Message Date
Holly Borla
69be7b17fc Merge pull request #40282 from hborla/existential-any
[SE-0335] Introduce existential `any`
2021-12-10 08:56:03 -08:00
swift-ci
e2f1907744 Merge pull request #40487 from rxwei/regex-integration-1 2021-12-10 00:48:09 -08:00
Holly Borla
9e3c0e6370 [Parse] Parse 'any' as a contextual keyword. 2021-12-09 23:15:02 -08:00
Holly Borla
3e936e3e67 [Sema] Require existential types with Self or associated type
requirements to be spelled with 'any' when explicit existential
types are enabled.
2021-12-09 23:15:02 -08:00
Holly Borla
37c0964d3e [Sema] Rename existentialTypeSupported to existentialRequiresAny, and
flip the return value in the implementation accordingly.
2021-12-09 23:15:02 -08:00
Holly Borla
00a4629515 Revert "NFC: Remove the now dead ProtocolDecl::existentialTypeSupported()"
This reverts commit eb1bd07bb3.
2021-12-09 23:15:02 -08:00
Holly Borla
445a856652 [Type System] Introduce a dedicated type to represent existential types.
The new type, called ExistentialType, is not yet used in type resolution.
Later, existential types written with `any` will resolve to this type, and
bare protocol names will resolve to this type depending on context.
2021-12-09 23:14:50 -08:00
Doug Gregor
5e9530429c Merge pull request #40488 from DougGregor/sendable-inherit-part-trois
Ensure that Sendable is inherited properly, take 3.
2021-12-09 19:33:10 -08:00
Michael Gottesman
aeceaf7d78 Merge pull request #40478 from gottesmm/pr-cfbd8a7087ef5ca3ec578da8993a686ad7a50077
[move-function] Add support for loadable vars
2021-12-09 16:19:39 -08:00
Richard Wei
05363cd55a Regex literal runtime plumbing.
- Frontend: Implicitly import `_StringProcessing` when frontend flag `-enable-experimental-string-processing` is set.
- Type checker: Set a regex literal expression's type as `_StringProcessing.Regex<(Substring, DynamicCaptures)>`. `(Substring, DynamicCaptures)` is a temporary `Match` type that will help get us to an end-to-end working system. This will be replaced by actual type inference based a regex's pattern in a follow-up patch (soon).
- SILGen: Lower a regex literal expression to a call to `_StringProcessing.Regex.init(_regexString:)`.
- String processing runtime: Add `Regex`, `DynamicCaptures` (matching actual APIs in apple/swift-experimental-string-processing), and `Regex(_regexString:)`.

Upcoming:
- Build `_MatchingEngine` and `_StringProcessing` modules with sources from apple/swift-experimental-string-processing.
- Replace `DynamicCaptures` with inferred capture types.
2021-12-09 16:05:34 -08:00
Slava Pestov
75ade66b21 Merge pull request #40459 from slavapestov/rqm-disabled-merged-types
RequirementMachine: Add flags to enable and disable merged associated types
2021-12-09 16:45:56 -05:00
Michael Gottesman
4a9c26ff96 [move-function] Make MandatoryInlining always convert builtin.move -> mark_unresolved_move_addr.
To give a bit more information, currently the way the move function is
implemented is that:

1. SILGen emits a builtin "move" that is called within the function _move in the
   stdlib.

2. Mandatory Inlining today if the final inlined type is address only, inlines
   builtin "move" as mark_unresolved_move_addr. Otherwise, if the inlined type
   is loadable, it performs a load [take] + move [diagnostic] + store [init].

3. In the diagnostic pipeline before any mem optimizations have run, we run the
   move checker for addresses. This eliminates /all/ mark_unresolved_move_addr
   as part of emitting diagnostics. In order to make this work, we perform a
   small optimization before the checker runs that moves the
   mark_unresolved_move_addr from being on temporary alloc_stacks to the true
   base underlying address we are trying to move. This optimization is necessary
   since _move is generic and often times SILGen will emit this temporary that
   we do not want.

4. Then after we have run the guaranteed mem optimizations, we run the object
   based move checker emitting diagnostics.

This PR changes the scheme above to the following:

1. SILGen emits a builtin "move" that is called within the function _move in the
   stdlib.

2. Mandatory Inlining inlines builtin "move" as mark_unresolved_move_addr.

3. In the diagnostic pipeline before we have run any mem optimizations and
   before we have run the actual move address checker, we massage the IR as we
   do above but in a separate pass where in addition we try to match this pattern:

     ```
     %temporary = alloc_stack $LoadableType
     store %1 to [init] %temporary : $*LoadableType
     mark_unresolved_move_addr %temporary to %otherAddr : $*LoadableType
     destroy_addr %temporary : $*LoadableType
     ```

   and transform it to:

     ```
     %temporary = alloc_stack $LoadableType
     %2 = move_value [allows_diagnostics] %1 : $*LoadableType
     store %2 to [init] %temporary : $*LoadableType
     destroy_addr %temporary : $*LoadableType
     ```

   ensuring that the object move checker will handle this.

4. Then after we have run the guaranteed mem optimizations, we run the object
   based move checker emitting diagnostics.
2021-12-09 12:48:29 -08:00
Doug Gregor
61e907498c Ensure that Sendable is inherited properly, take 3.
Extend the implicit Sendable request to produce an inherited
conformance when queried, rather than depending on the conformance
lookup table to always have the right entries. This acknowledges that
implicit Sendable needs to happen more at the type checking level than
the name-binding level, which is needed to eliminate cyclic
dependencies.
2021-12-09 11:06:13 -08:00
Slava Pestov
d9fd6cbdbf Merge pull request #40482 from slavapestov/rqm-verify-protocol-signatures
AST: Use RequirementMachine to verify protocol requirement signatures
2021-12-09 13:51:31 -05:00
Holly Borla
3ab0a78383 [AST] Introduce ExistentialTypeRepr, which is the type repr for an
existential type spelled with `any`.
2021-12-09 09:26:12 -08:00
Holly Borla
7cdda6dc80 [FrontendOptions] Add a frontend flag -enable-explicit-existential-types
to enable the 'any' keyword.
2021-12-09 09:26:12 -08:00
nate-chandler
6a34f04f3f Merge pull request #40473 from nate-chandler/lexical_lifetimes/enable-with-copy-propagation
Enabling copy propagation enables lexical lifetimes.
2021-12-09 08:06:47 -08:00
Slava Pestov
589fc40d5a AST: Use RequirementMachine to verify protocol requirement signatures 2021-12-08 23:07:48 -05:00
Nate Chandler
ea42e2f334 Enabling copy propagation enables lexical lifetimes.
The effect of passing -enable-copy-propagation is both to enable the
CopyPropagation pass to shorten object lifetimes and also to enable
lexical lifetimes to ensure that object lifetimes aren't shortened while
a variable is still in scope and used.

Add a new flag, -enable-lexical-borrow-scopes=true to override
-enable-copy-propagation's effect (setting it to ::ExperimentalLate) on
SILOptions::LexicalLifetimes that sets it to ::Early even in the face of
-enable-copy-propagation.  The old flag -disable-lexical-lifetimes is
renamed to -enable-lexical-borrow-scopes=false but continues to set that
option to ::Off even when -enable-copy-propagation is passed.
2021-12-08 19:13:21 -08:00
Slava Pestov
c1339240cd RequirementMachine: Add flags to enable and disable merged associated types
On by default, no change from current behavior. I'm going to try turning
this off (and hopefully ripping it out entirely) once I fix a few bugs.
2021-12-08 21:32:42 -05:00
Evan Wilde
a3cc692f01 Merge pull request #40378 from etcwilde/ewilde/concurrency/unavailablefromasync-messages
Adding optional message to `_unavailableFromAsync`
2021-12-08 17:30:50 -08:00
Slava Pestov
cfd8dbf272 Merge pull request #40465 from slavapestov/rqm-protocol-minimization-fixes
RequirementMachine: Protocol requirement signature minimization fixes
2021-12-08 17:19:21 -05:00
Evan Wilde
691cf1925d Merge branch 'main' into ewilde/concurrency/unavailablefromasync-messages 2021-12-08 11:41:14 -08:00
Zoe Carver
a46a3c525a Merge pull request #39605 from zoecarver/cxx-interop-import-as-class
[cxx-interop] Implement foreign reference types.
2021-12-08 19:33:50 +00:00
Evan Wilde
aa9085a3d8 Handle attr parse failures
Adding nice error messages for when things go wrong.
2021-12-08 09:39:24 -08:00
Evan Wilde
3a13721eae Add optional message to unavailablefromasync
Adding the ability to add an optional message to the unavailable from
async attribute. This can be used to indicate other possible API to use,
or help explain why it's unavailable.
2021-12-08 09:39:24 -08:00
zoecarver
fc3b3a1d71 [cxx-interop] Implement foreign reference types.
This is an expiremental feature to allow an attribute, `import_as_ref`, to import a C++ record as a non-reference-counted reference type in Swift.
2021-12-08 15:35:18 +00:00
nate-chandler
f95748ceba Merge pull request #40461 from nate-chandler/lexical_lifetimes/remove-simple-lexical-borrow-if-redundant
[CanonicalizeInst] Remove redundant lexical bbis.
2021-12-08 07:21:14 -08:00
Augusto Noronha
beb99a432e Merge pull request #40452 from augusto2112/refl-dump-use-stream
Modify reflection dumping to use std::ostream instead of FILE *
2021-12-08 09:29:03 -03:00
Ellie Shin
d95d0a0a7d Merge pull request #40450 from apple/es-index
[Indexing] If module aliasing is used, store module real names to index unit/record files
Resolves rdar://82896373
2021-12-07 23:49:01 -08:00
Slava Pestov
044611dddc RequirementMachine: Another cycle-breaking hack for associated type inference 2021-12-08 00:53:35 -05:00
Nate Chandler
f0bd5839a2 [OwnershipUtils] Extracted utility for common use.
Promoted isRedundantLexicalBeginBorrow function to OwnershipUtils so
that it can be used in more than just SemanticARCOpts.
2021-12-07 17:51:18 -08:00
Michael Gottesman
1ed3ce3b6f Merge pull request #40453 from gottesmm/pr-a85fbe6f331638d8fc105031e934d0516c72122f
[move-function] Implement move function support for address only vars.
2021-12-07 16:01:21 -08:00
Augusto Noronha
981c358ca1 Merge pull request #40432 from augusto2112/lazy-typeref-caching
Make caching the typeref builder cache lazier
2021-12-07 20:25:23 -03:00
Ellie Shin
e358302f54 Always print real module name via printModuleUSR 2021-12-07 14:43:41 -08:00
Michael Gottesman
2e018aff5b [move-function] Implement move function support for address only vars.
I have to make a few other changes to make this work for loadable vars, but I
wanted to get this in.

Behind a flag.
2021-12-07 12:03:01 -08:00
Augusto Noronha
d200a06ae2 Make caching the typeref builder cache lazier 2021-12-07 16:25:59 -03:00
Augusto Noronha
385d91aeb8 Modify reflection dumping to use std::ostream instead of FILE * 2021-12-07 16:05:20 -03:00
Nate Chandler
cde250a3e3 [CopyPropagation] Add ShrinkBorrowScope.
During copy propagation (for which -enable-copy-propagation must still
be passed), also try to shrink borrow scopes by hoisting end_borrows
using the newly added ShrinkBorrowScope utility.

Allow end_borrow instructions to be hoisted over instructions that are
not deinit barriers for the value which is borrowed.  Deinit barriers
include uses of the value, loads of memory, loads of weak references
that may be zeroed during deinit, and "synchronization points".

rdar://79149830
2021-12-07 09:43:57 -08:00
Alex Hoppen
1739c23a9b Merge pull request #40158 from ahoppen/pr/cancel-code-completion
[SourceKit] Support cancellation of code completion like requests
2021-12-07 17:10:05 +01:00
Ellie Shin
0ff713d44c [Indexing] Use module real name in case module aliasing is used
Resolves rdar://82896373
2021-12-07 02:22:36 -08:00
Hamish Knight
23a8bf0bec Merge pull request #40367 from hamishknight/pitter-patter 2021-12-07 10:15:44 +00:00
swift-ci
fe4d9af277 Merge pull request #40404 from nate-chandler/lexical_lifetimes/renamed_flag 2021-12-06 20:12:59 -08:00
Michael Gottesman
9069cc7b7d Merge pull request #40423 from gottesmm/address-only-let-checker
[move-function] Implement move checking for address only lets
2021-12-06 18:16:18 -08:00
Doug Gregor
600fd1775a Merge pull request #40434 from DougGregor/capture-sendable-checking
Diagnose non-sendable captures more directly.
2021-12-06 15:46:15 -08:00
Hamish Knight
37f16520e6 Prototype regex literal AST and emission
With `-enable-experimental-string-processing`,
start lexing `'` delimiters as regex literals (this
is just a placeholder delimiter for now). The
contents of which gets passed to the libswift
library, which can return an error string to be
emitted, or null for success.

The libswift side isn't yet hooked up to the Swift
regex parser, so for now just emit a dummy
diagnostic for regexes starting with quantifiers.

If successful, build an AST node which will be
emitted as an implicit call to an
`init(_regexString:)` initializer of an in-scope
`Regex` decl (which will eventually be a known
stdlib decl).
2021-12-06 21:16:14 +00:00
Michael Gottesman
f3801c2453 Fix diagnostic to use proper grammar. 2021-12-06 12:47:31 -08:00
Michael Gottesman
e3f9eaca58 [move-function] Implement the move-function checker for address only lets. 2021-12-06 12:47:31 -08:00
Michael Gottesman
8f22966ff7 [move-function] Emit mark_unresolved_move_addr when we inline Builtin._move in a generic context.
This turns off the diagnostic that prevented the user from calling _move in such
contexts. I left that in for _copy.
2021-12-06 12:47:31 -08: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