Commit Graph

650 Commits

Author SHA1 Message Date
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
Xi Ge
a25d5ec47d ModuleInterface: skip printing the override keyword if the overriden decl is skipped
rdar://80918826
2021-07-21 19:30:10 -07:00
Doug Gregor
03f55d7bb4 Revert "Revert "Remove @actorIndependent attribute.""
This reverts commit 7c0b50e8ea.
2021-06-03 14:03:57 -07:00
Karoy Lorentey
7c0b50e8ea Revert "Remove @actorIndependent attribute." 2021-05-24 14:43:32 -07:00
Doug Gregor
d6e8fd81f5 Remove @actorIndependent attribute.
`@actorIndependent` has been superseded by `nonisolated`. Remove
the old spelling entirely.
2021-05-17 12:21:10 -07:00
John McCall
cc2863c136 Merge pull request #36878 from rjmccall/custom-executors
Introduce basic support for custom executors
2021-04-30 13:54:02 -04:00
Hamish Knight
fe3dbc2fd4 Fix typo in @completionHandlerAsync printing 2021-04-30 11:14:51 +01:00
John McCall
769c2e76f1 Add a utility to clone an @available attribute. 2021-04-30 03:11:43 -04:00
Richard Wei
adb916849d [AutoDiff] [AST] Handle null decl in 'printDifferentiableAttrArguments'.
`DeclAttribute::print()` accepts null decls and has a null default argument.  A segfault was triggered in SourceKitService because `printDifferentiableAttrArguments()` took a null decl and deferenced it.  This patch makes `printDifferentiableAttrArguments()` handle null decls — if the decl is null, we do not print the differentiability parameters or the `where` clause.

I have not added a unit test however because I haven't been able to reproduce it independently.  This will be done later as this change is low-risk.

Resolves rdar://76095289.
2021-04-18 01:26:17 -07:00
Ben Barham
3de83aca66 [ClangImporter] Add @completionHandlerAsync for imported decls
Implicitly add the @completionHandlerAsync attribute for ObjCMethodDecl
that have a completion handler. Adds a link from the non-async to the
async function for use in diagnostics and refactorings.

Resolves rdar://74665226
2021-03-31 08:39:12 +10:00
Becca (née Brent) Royal-Gordon
3df5ca6636 Merge pull request #36409 from beccadax/behave-yourself
Soften errors for invalid @objc attributes added by access notes
2021-03-25 15:44:22 -07:00
Becca Royal-Gordon
69fb104244 Diagnose access note @objc failures using remarks
This commit adds an ObjCReason::ExplicitlyObjCByAccessNote value which diagnoses invalid uses, but using remarks instead of errors so that the failures don’t block builds even with -warnings-as-errors enabled.

This commit also adds annotations to attr/attr_objc.swift to generate a ton of access note test cases from it. In this commit, many of these test cases don’t pass yet. Subsequent commits will fix these bugs.
2021-03-24 14:51:44 -07:00
Doug Gregor
a109736937 Make sure that imported @MainActor shows up in the interface.
... but don't show the (unsafe) part outside of Swift interfaces, because
it's messy and we don't want people to use it.
2021-03-23 17:29:58 -07:00
Evan Wilde
9f412616d8 Remove AsyncFunctionName from serialization
We can get the DeclName of the async function from the resolved function
decl itself, so we don't actually need to serialize it. This patch pulls
the declNameRef from the serialization.
2021-03-13 13:38:15 -08:00
Evan Wilde
2b0def501f Replace @hasAsyncAlt with @completionHandlerAsync
This patch replaces the @hasAsyncAlternative attribute with
@completionHandlerAsync. The @completionHandlerAsync attribute takes the
function decl name of the async function and optionally the index of the
completion hander parameter in the function that it's attached to.
If the completion handler index is not provided, it's assumed to be the
last parameter in the parameter list.

We resolve the async function while typechecking the attribute. Before
resolving, we verify that the function the attribute is attached to
isn't async, that it has enough parameters to at least have the
indicated completion handler referenced by the index, that the
completion handler is an escaping non-auto-closure function that returns
Void.

The async function declaration resolution isn't perfect yet, but I want
to get this patch up and we can refine it later. It pulls all of the
delcs with the specified declname in the same context as the
function that the attribute is attached to. Going through that list, it
keeps any that are async functions. If there are none, we emit an error
saying that there are no viable functions, if there are multiple we emit
an error saying that the decl name is ambiguous, and if there is one
function, we keep that as the resolve async function declaration.

This does not take into account the data types of the completion handler
or the async function. There are some complexities to making this
mapping. Here are the pieces:
 - If the completion handler takes a single data type, the async
   function should return that type. (easy case)
 - If the completion handler takes a `Result<T, Error>`, the async
   function is a throwing function that returns a T. (Medium difficulty)
 - If the completion handler looks like `(T?, Error?) -> Void`, we have
   an ambiguous situation between the following async functions:
   - func foo() async throws -> T
   - func foo() async throws -> T?
   That is, we cannot tell whether the `T?` in the completion handler is
   optional because it will be nil on an error, or if it is intended to
   be optional.

This can be done later if it becomes a problem.
2021-03-13 13:38:15 -08:00
Doug Gregor
451e6cc1f5 [Concurrency] Add support for @GlobalActor(unsafe).
Allow us to tag declarations that are meant to be in a global actor, but
for which we don't yet want to enforce everything. This will be used for
better staging-in of global actor annotations, but for now it's a fancy
way to document @actorIndependent(unsafe).

Stages in the syntax for rdar://74241687 without really implementing it.
2021-02-25 22:41:32 -08:00
Ben Barham
3a7bf2301b [AST] Add a new attribute @hasAsyncAlternative
This attribute marks a function has having an async alternative,
optionally providing the name of that function as a string. Intended to
be used to allow warnings when using a function with an async
alternative in an asynchronous context, to make the async refactorings
more accurate, and for documentation.
2021-02-18 16:18:38 +10:00
Slava Pestov
cdbba60674 AST: ASTPrinter support for 'reasync'
Part of <rdar://problem/71098795>.
2021-02-15 22:18:54 -05:00
Richard Wei
af8942d940 [AutoDiff] Rename '@differentiable' to '@differentiable(reverse)'.
Compiler:
- Add `Forward` and `Reverse` to `DifferentiabilityKind`.
- Expand `DifferentiabilityMask` in `ExtInfo` to 3 bits so that it now holds all 4 cases of `DifferentiabilityKind`.
- Parse `@differentiable(reverse)` and `@differentiable(_forward)` declaration attributes and type attributes.
- Emit a warning for `@differentiable` without `reverse`.
- Emit an error for `@differentiable(_forward)`.
- Rename `@differentiable(linear)` to `@differentiable(_linear)`.
- Make `@differentiable(reverse)` type lowering go through today's `@differentiable` code path. We will specialize it to reverse-mode in a follow-up patch.

ABI:
- Add `Forward` and `Reverse` to `FunctionMetadataDifferentiabilityKind`.
- Extend `TargetFunctionTypeFlags` by 1 bit to store the highest bit of differentiability kind (linear). Note that there is a 2-bit gap in `DifferentiabilityMask` which is reserved for `AsyncMask` and `ConcurrentMask`; `AsyncMask` is ABI-stable so we cannot change that.

_Differentiation module:
- Replace all occurrences of `@differentiable` with `@differentiable(reverse)`.
- Delete `_transpose(of:)`.

Resolves rdar://69980056.
2021-02-07 14:09:46 -08:00
Matt Zanchelli
be13b470aa Fix typos
becuase -> because
preceeds -> precedes
initalizer -> initializer
intialize -> initialize
libary -> library
notfication -> notification
reciever -> receiver
collecton -> collection
exlcusive -> exclusive
techincal -> technical
compatability -> compatibility
setps -> steps
accomodate -> accommodate
brakcet -> bracket
fraciton -> fraction
programm -> program
concequently -> consequently
ecoding -> encoding
timeIntervalforSelfEnd -> timeIntervalForSelfEnd
2020-12-21 18:44:03 -05:00
Alexis Laferrière
2ce140dfa0 [ModuleInterface] Print custom attributes on function protocol requirements
Protocol requirements declared as a function with a result-builder
custom attribute should keep that attribute in the generated textual
swiftinterface file.

rdar://72063255
2020-12-08 11:26:07 -08:00
Doug Gregor
3b6fd4ece8 Merge pull request #34374 from DougGregor/se-0289-result-builders-rename
[SE-0289] Rename "function builders" to "result builders"
2020-10-21 09:08:46 -07:00
Doug Gregor
b6c0145932 [SE-0289] Continue printing @_functionBuilder in .swiftinterfaces.
Maintain the ability for older Swift compilers to read .swiftinterfaces
that make use of result builders by always emitting @_functionBuilder
rather than the newer @resultBuilder.
2020-10-20 22:24:41 -07:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Kavon Farvardin
34d22105b8 implemented parsing and typechecking for @actorIndependent(unsafe)
[broken] first impl of @actorIndependent in the type checker.

[broken] fixed mistake in my parsing code wrt invalid source range

[broken] found another spot where ActorIndependent needs custom handling

[broken] incomplete set of @actorIndependent(unsafe) tests

updates to ActorIndependentUnsafe

[fixed] add FIXME plus simple handling of IndependentUnsafe context

finished @actorIndependent(unsafe) regression tests

added wip serialization / deserialization test

focus test to just one actor class

round-trip serialize/deserialize test for @actorIndependent

serialize -> deserialize -> serialize -> compare to original

most of doug's comments

addressed robert's comments

fix printing bug; add module printing to regression test

[nfc] update comment for ActorIsolation::IndependentUnsafe
2020-10-19 15:20:24 -07:00
Doug Gregor
2a3f4f6665 [AST] Allow resolution of the @_typeEraser type when printing. 2020-10-15 16:15:47 -07:00
Arnold Schwaighofer
2a2cf91dcd Add support for marking a _specialize attribute as SPI
```
  @_specialize(exported: true, spi: SPIGroupName, where T == Int)
  public func myFunc() { }
```

The specialized entry point is only visible for modules that import
using `_spi(SPIGroupName) import ModuleDefiningMyFunc `.

rdar://64993425
2020-10-12 09:19:29 -07:00
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Slava Pestov
995eb66aa7 AST: Rename SpecializeAttr::getSpecializedSgnature() 2020-08-24 19:16:36 -04:00
Slava Pestov
b93ee4c7d2 AST: Remove some calls to getSugaredType() which are no longer necessary
It appears that these were working around <rdar://problem/67579220>.
2020-08-24 19:16:36 -04:00
Slava Pestov
b0208a134f AST: Move getSugaredType() from GenericEnvironment to GenericSignature
None of this actually involves archetypes, so it can just be an
operation on the GenericSignature itself.
2020-08-24 19:16:36 -04:00
Matei Oprea
f971b349b4 [NFC] Refactor manual size calculations in memory allocation (#33256) 2020-08-03 22:02:31 -07:00
Dan Zheng
bf47403162 [AutoDiff] Serialize and print @derivative and @transpose accessor kind. (#32839)
Serialize and print the optional accessor kind in `@derivative` and `@transpose`
attributes.

Resolves TF-1293.
2020-07-12 15:04:49 -07:00
Robert Widmann
89ae325d22 Use Formal Access To Compute Override Elision Check
The effective access of an overridden declaration is subject to
escalation by -enable-testing. When this is flag is enabled, an
interface containing an internal-overriding-public declaration will
still print `override`. This is because the effective access of the base
of the override is formally internal but effectively public.

Instead, use the formal access scope of the overridden declaration to
compute its access relative to the override. While I'm here, catch the
case where the base declaration is `@usableFromInline` and therefore
*will* be printed in the interface. We treat these declarations as
effectively public for the purpose of printing `override`.

Resolves rdar://64969741
2020-06-30 21:28:42 -07:00
Robert Widmann
90cb347cd9 Merge pull request #32466 from martinboehme/pass-print-options-by-const-ref
Pass PrintOptions by const reference instead of by value.
2020-06-19 22:44:13 -07:00
Martin Boehme
0f7eb02559 Pass PrintOptions by const reference instead of by value.
`PrintOptions` likely started as a small type that made sense to pass by
value, but it's become big enough that passing by const reference is
more efficient now.
2020-06-19 14:27:39 +02:00
Dan Zheng
cc523bed6b [AutoDiff] NFC: remove unused variable. (#32411) 2020-06-17 10:07:24 -07:00
Robert Widmann
29cdbe87f1 Strip TypeEraserAttr of its TypeLoc 2020-06-10 19:33:31 -07:00
Robert Widmann
80d3a32ff5 Strip ImplementsAttr of its TypeLoc 2020-06-10 19:33:07 -07:00
Robert Widmann
fb8fdd9644 Replace resolveCustomAttrType with a Request 2020-06-10 19:31:41 -07:00
Doug Gregor
bf7eea08da [Function builders] Infer function builder from a protocol requirement.
Allow a protocol requirement for a function or property to declare
a function builder. A witness to such a protocol requirement will
infer that function builder when all of the following are two:
* The witness does not explicitly adopt a function builder
* The witness is declared within the same context that conforms to the
protocol requirement (e.g., same extension or primary type declaration)
* The witness's body does not contain a "return" statement (since those
disable the function builder transform).
2020-05-24 23:18:18 -07:00
John McCall
a518e759d9 WIP for a different syntax for multiple trailing closures
that allows arbitrary `label: {}` suffixes after an initial
unlabeled closure.

Type-checking is not yet correct, as well as code-completion
and other kinds of tooling.
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
d06126da3b [Parser] Add support for multiple trailing closures syntax
Accept trailing closures in following form:

```swift
foo {
  <label-1>: { ... }
  <label-2>: { ... }
  ...
  <label-N>: { ... }
}
```

Consider each labeled block to be a regular argument to a call or subscript,
so the result of parser looks like this:

```swift
foo(<label-1>: { ... }, ..., <label-N>: { ... })
```

Note that in this example parens surrounding parameter list are implicit
and for the cases when they are given by the user e.g.

```swift
foo(bar) {
  <label-1>: { ... }
  ...
}
```

location of `)` is changed to a location of `}` to make sure that call
"covers" all of the transformed arguments and parser result would look
like this:

```swift
foo(bar,
   <label-1>: { ... }
)
```

Resolves: rdar://problem/59203764
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
45ac1bcf17 [Parser] Adjust parseExprList to return multiple trailing closures
Also extend returned object from simplify being an expression to
`TrailingClosure` which has a label, label's source location and
associated closure expression.
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
4650091efb [AST] Remove unused "trailing closure" argument from totalSizeToAlloc and initializeCallArguments 2020-05-06 01:56:40 -04:00
Marc Rasi
7abf8ae305 actually set the lazy resolver 2020-04-07 15:05:27 -07:00
Marc Rasi
78ac5eb0a3 add PointerUnion for parsed vs deserialized derivative attr 2020-04-07 10:25:30 -07:00
Dan Zheng
83f6714334 [AutoDiff] Start fixing SR-12526.
Start fixing SR-12526: `@derivative` attribute cross-module deserialization
crash. Remove original `AbstractFunctionDecl *` from `DerivativeAttr` and store
`DeclID` instead, mimicking `DynamicReplacementAttr`.
2020-04-06 06:37:23 -07:00