Commit Graph

1433 Commits

Author SHA1 Message Date
Doug Gregor
5004a5447b [Concurrency] Make "self" parameter of actor-isolated functions 'isolated'.
The notion of "actor-isolated" currently exists at the declaration level.
For functions, it is going to be captured in the function type itself,
where 'self' is declared to be 'isolated'. Model isolation both
ways: the 'self' of a method that is isolated to an actor instance
will be 'isolated' as well.

We are still using declaration-based checking of actor isolation.
However, by mirroring this information we can move more incrementally
over to doing checking based on 'isolated' parameters.
2021-06-07 23:59:38 -07:00
Doug Gregor
bd8626fa1b [Concurrency] Parse and add 'isolated' parameters to the type system. 2021-06-07 23:59:38 -07:00
Doug Gregor
59b6563b68 Define "Actors2" feature to cope with short-term backward compatibility 2021-06-03 12:13:34 -07:00
Doug Gregor
9411baab9f Add feature for _implicitSelfCapture attribute.
Fixes rdar://77681413.
2021-05-07 19:53:31 -07:00
Alex Hoppen
7462a62b37 Merge pull request #37238 from ahoppen/pr/dont-print-dollar-internal-labels
[AST] Don’t print internal function labels if they start with '$'
2021-05-04 18:34:20 +02:00
Alex Hoppen
66e416b604 [AST] Don’t print internal function labels if they start with '$'
We might infer internal function labels as `$0` from a closure with which a variable is initialised. But we don’t want to print the function signature as `(_ $0: Int) -> Int` because `$0` is not a valid variable name to declare.

So, in the case described above, only print the type.

Fixes rdar://77462547
2021-05-04 12:42:58 +02:00
Kavon Farvardin
c5ec5bf5b1 fix feature guards in swiftinterface for eff. props 2021-04-30 17:07:18 -07:00
John McCall
186c53000d Introduce basic support for custom executors.
- Introduce an UnownedSerialExecutor type into the concurrency library.
- Create a SerialExecutor protocol which allows an executor type to
  change how it executes jobs.
- Add an unownedExecutor requirement to the Actor protocol.
- Change the ABI for ExecutorRef so that it stores a SerialExecutor
  witness table pointer in the implementation field.  This effectively
  makes ExecutorRef an `unowned(unsafe) SerialExecutor`, except that
  default actors are represented without a witness table pointer (just
  a bit-pattern).
- Synthesize the unownedExecutor method for default actors (i.e. actors
  that don't provide an unownedExecutor property).
- Make synthesized unownedExecutor properties `final`, and give them
  a semantics attribute specifying that they're for default actors.
- Split `Builtin.buildSerialExecutorRef` into a few more precise
  builtins.  We're not using the main-actor one yet, though.

Pitch thread:
  https://forums.swift.org/t/support-custom-executors-in-swift-concurrency/44425
2021-04-30 03:11:56 -04:00
Kavon Farvardin
c1f48c6855 fix missing effects specifiers on eff props in swiftinterface
I missed the case where the body is also being printed in the
interface file.
2021-04-29 20:29:50 -07:00
Alex Hoppen
41777b9d01 [AST] Remove a call to mapOutOfContext in ASTPrinter
It appears that the call is not necessary anymore.
2021-04-27 08:35:54 +02:00
Alex Hoppen
4a98a29d0d Merge pull request #36989 from ahoppen/pr/check-may-have-members
[SourceKit] Don’t transform type when printing if CurrentType can’t have members
2021-04-27 07:48:13 +02:00
swift-ci
a11acd3140 Merge pull request #37023 from DougGregor/builtin-executor-feature 2021-04-22 19:24:28 -07:00
Doug Gregor
0d5ec20549 [Concurrency] Put Builtin.Executor type behind a feature flag.
Fixes rdar://77041644.
2021-04-22 16:25:11 -07:00
Doug Gregor
cdd6ad8bfd Introduce a feature for @_inheritActorContext
Add a feature for this new attribute, and make sure we use the feature
guard for functions that use it, e.g., the new `async`.

Finishes rdar://76927008.
2021-04-22 15:49:48 -07:00
Alex Hoppen
6b5c03208d [SourceKit] Don’t transform type when printing if CurrentType can’t have members
Since 9ba892c we always transform `CurrentType` in `ASTPrinter` to be an interface type.

This causes issues when the variable type is a generic parameter type. Previously we had `CurrentType` set to a `PrimaryArchetypeType`. With the fix in d93ae06, we are mapping the archetype out of context to a `GenericParamType`. A `GenericParamType`, however, can’t have members, so we’re hitting an assertion when creating a `TypeTransformContext`. Since the entire type transformation in `printTransformedTypeWithOptions` is only affecting type members, we should be able to safely skip over the transformation if `CurrentType` can’t have any members.

Fixes rdar://76750555 [SR-14497]
2021-04-21 11:53:06 +02:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
Ben Barham
c1cb50f40b Merge pull request #36920 from bnbarham/cleanup-rawcomment
[Gardening] Do not store start/end line in SingleRawComment
2021-04-16 14:19:53 +10:00
Ben Barham
52de30ce1f [Gardening] Do not store start/end line in SingleRawComment
The start and end lines were only used while constructing the comments,
so move the line tracking into that method instead of storing it in each
comment.
2021-04-16 08:10:49 +10:00
Alex Hoppen
7123d2614b Merge pull request #36880 from ahoppen/pr/cursor-info-protocol-var
[ASTPrinter] Don't transform type if current type can't have members
2021-04-15 08:20:25 +02:00
Alex Hoppen
d93ae06f50 [ASTPrinter] Don't transform type if current type can't have members
Since 9ba892c5af we always transform `CurrentType` in `ASTPrinter` to be an interface type.

This causes issues for variables that whose type is a protocol. Previously, when printing the type, we had `CurrentType` set to an `OpenedArchetypeType`. Now we replace the archetype by a `GenericTypeParamType`, which may not have members, so we are hitting an assertion in `ASTPrinter.cpp:270`.
To resolve this, replace any `OpenedArchetypeType`s with their protocol type before calling `mapTypeOutOfContext`.

Resolves rdar://76580851 [SR-14479]
2021-04-13 20:29:06 +02:00
Alex Hoppen
62aabece62 Merge pull request #36866 from ahoppen/pr/serialize-internal-closure-name
[Serialization] Serialize internal closure labels
2021-04-13 18:49:58 +02:00
Alex Hoppen
380db634fa [Serialization] Serialize internal closure labels
Since 865e80f9c4 we are keeping track of internal closure labels in the closure’s type. With this change, wer are also serializing them to the swiftmodules.

Furthermore, this change adjusts the printing behaviour to print the parameter labels in the swiftinterfaces.

Resolves rdar://63633158
2021-04-13 08:53:46 +02:00
Alex Hoppen
9ba892c5af [ASTPrinter] Fix issue printing Self resolved to a generic type
When printing a type in type through `ASTPrinter::printTransformedTypeWithOptions`, we are removing any contextual types by mapping the type out of context. However, when substituting `Self` (or any other type member) with their concrete type from `CurrentType`, we might re-introduce contextual types.

To fix this, make sure that `CurrentType` is always an interface type that has all contextual types removed.

Fixes rdar://76021569
2021-04-12 10:39:09 +02:00
John McCall
efeb818161 Clean up the TaskGroup ABI:
- stop storing the parent task in the TaskGroup at the .swift level
- make sure that swift_taskGroup_isCancelled is implied by the parent
  task being cancelled
- make the TaskGroup structs frozen
- make the withTaskGroup functions inlinable
- remove swift_taskGroup_create
- teach IRGen to allocate memory for the task group
- don't deallocate the task group in swift_taskGroup_destroy

To achieve the allocation change, introduce paired create/destroy builtins.

Furthermore, remove the _swiftRetain and _swiftRelease functions and
several calls to them.  Replace them with uses of the appropriate builtins.
I should probably change the builtins to return retained, since they're
working with a managed type, but I'll do that in a separate commit.
2021-04-09 03:06:31 -04:00
Alex Hoppen
fd8e34913a Merge pull request #36551 from ahoppen/pr/internal-labels-in-closures
[CodeComplete] Default parameter names of completed closure to internal names
2021-04-06 15:30:26 +02:00
Alex Hoppen
865e80f9c4 [CodeComplete] Default parameter names of completed closure to internal names
If have a function that takes a trailing closure as follows
```
func sort(callback: (_ left: Int, _ right: Int) -> Bool) {}
```
completing a call to `sort` and expanding the trailing closure results in
```
sort { <#Int#>, <#Int#> in
  <#code#>
}
```

We should be doing a better job here and defaulting the trailing closure's to the internal names specified in the function signature. I.e. the final result should be
```
sort { left, right in
  <#code#>
}
```

This commit does exactly that.

Firstly, it keeps track of the closure's internal names (as specified in the declaration of `sort`) in the closure's type through a new `InternalLabel` property in `AnyFunctionType::Param`. Once the type containing the parameter gets canonicalized, the internal label is dropped.

Secondly, it adds a new option to `ASTPrinter` to always try and print parameter labels. With this option set to true, it will always print external paramter labels and, if they are present, print the internal parameter label as `_ <internalLabel>`.

Finally, we can use this new printing mode to print the trailing closure’s type as
```
<#T##callback: (Int, Int) -> Bool##(_ left: Int, _ right: Int) -> Bool#>
```

This is already correctly expanded by code-expand to the desired result. I also added a test case for that behaviour.
2021-04-01 19:14:19 +02:00
Doug Gregor
492bca113d [Module interface] Retain #if's with feature checks in inline bodies. 2021-03-30 17:56:42 -07:00
John McCall
0f152af85f Add a Builtin.Executor type to abstract executor references. 2021-03-28 04:31:49 -04:00
Kavon Farvardin
f9452b23f4 implement parsing for effects specifiers on 'get' accessors
An effectful 'get' accessor must be the only accessor for the
property.
2021-03-26 07:54:53 -07:00
David Zarzycki
00533e8712 [NFC] Change magic emoji to __ 2021-03-23 13:41:16 -04:00
Doug Gregor
52096a640e SE-0302: Rename ConcurrentValue/@concurrent to Sendable/@Sendable. 2021-03-18 23:48:21 -07:00
Doug Gregor
3a357e9978 Add global actor-qualified function types.
Introduce the notion of global actor-qualified function types, e.g.,

    @MainActor () -> Void

to describe synchronous functions that must execute on a particular
global actor.
2021-03-17 00:51:16 -07:00
Doug Gregor
2b72725d32 Special-case the relationship of Error and CodingKey to ConcurrentValue 2021-03-15 13:39:19 -07:00
Doug Gregor
fb968ca638 Merge pull request #36415 from DougGregor/module-interface-more-ifs
[Module interfaces] More aggressively #if-out declarations.
2021-03-12 16:50:30 -08:00
Doug Gregor
c18ef1af94 Properly collect all enclosing features. 2021-03-12 11:23:27 -08:00
Doug Gregor
7015543c9c [Module interfaces] More aggressively #if-out declarations.
Extend the checks for marker protocols and rethrows protocols to ensure
that we #if out more code that relies on them in module interface
generation. This makes the _Concurrency module parseable by much older
compilers.

Fixes rdar://75291705.
2021-03-11 22:03:29 -08:00
David Zarzycki
c0ec6c3235 [AST] NFC: Make ExtInfo param Optional<>
While it is very convenient to default the ExtInfo state when creating
new function types, it also make the intent unclear to those looking to
extend ExtInfo state. For example, did a given call site intend to have
the default ExtInfo state or does it just happen to work? This matters a
lot because function types are regularly unpacked and rebuilt and it's
really easy to accidentally drop ExtInfo state.

By changing the ExtInfo state to an optional, we can track when it is
actually needed.
2021-03-09 05:57:39 -05:00
Slava Pestov
6615e16bfa AST: Skip stub initializers when printing module interfaces
When a derived class does not inherit a designated initializer from
its base class, we override the designated initializer's vtable
entry with a stub which traps with a fatal error.

The stub cannot be called and clients do not need to be aware of
its existence, so don't print it at all in the module interface.

Fixes rdar://problem/71122015 / https://bugs.swift.org/browse/SR-13832.
2021-03-05 23:53:57 -05:00
Doug Gregor
2b9fa92914 [AST Printing] Consider the storage decl as the "enclosing" decl of an acccessor
Fixes spurious #if's when printing for backward compatibility, rdar://75074036
2021-03-04 21:47:17 -08:00
Argyrios Kyrtzidis
1620f2cb49 Merge pull request #36178 from akyrtzi/build-parser-lib-improvements
[parser lib] A few enhancements for the syntax-parser-only build
2021-02-26 12:16:03 -08:00
Argyrios Kyrtzidis
8cbfb545a2 [parser lib] A few enhancements for the syntax-parser-only build
* Make the `build-parser-lib` script more flexible on how it finds the llvm source path
* Make sure `swift-syntax-parser-test` can be built even though the script disables building for testing
* Fix a linker error for parser-only build
2021-02-26 08:39:24 -08:00
Slava Pestov
53e06d69b5 AST: Factor out a new Requirement::getProtocolDecl() utility method 2021-02-25 17:21:18 -05:00
Doug Gregor
5f9b8982bd Add a feature and module interface printing support for Builtin.Job 2021-02-22 21:07:03 -08:00
Doug Gregor
e7d7585503 Add a feature for global actors & module interface support 2021-02-22 20:46:58 -08:00
Doug Gregor
f21c60928c Add feature for rethrows protocols and use it in module interface generation 2021-02-22 16:18:47 -08:00
Holly Borla
11028350a7 Merge pull request #35589 from Jumhyn/placeholder-types
[AST, Sema] Replace HoleType with PlaceholderType
2021-02-22 08:35:37 -08:00
Doug Gregor
2fd1912f5a Simplify printing of marker protocols in Swift interfaces
Thanks to a great idea from Slava, simplify the printing of marker
protocols in Swift interfaces while maintaining backward compatibility.
For compilers that cannot handle marker protocols, print a typealias
to `Any` instead, which is a good stand-in for just about everything.
2021-02-18 22:58:19 -08:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
d78d95ef0d [AST] Introduce PlaceholderType and ThePlaceholderType singleton 2021-02-16 22:59:18 -05:00
Slava Pestov
cdbba60674 AST: ASTPrinter support for 'reasync'
Part of <rdar://problem/71098795>.
2021-02-15 22:18:54 -05:00