Commit Graph

609 Commits

Author SHA1 Message Date
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
Robert Widmann
27b211c1f9 Lazy-load the eraser of @_typeEraser where possible
Type erasure requires a circular construction by its very nature:

@_typeEraser(AnyProto)
protocol Proto { /**/ }
public struct AnyProto : Proto {}

If we eagerly resolve AnyProto, the chain of resolution steps that
deserialization must make goes a little something like this:

Lookup(Proto)
    -> Deserialize(@_typeEraser(AnyProto))
    -> Lookup(AnyProto)
    -> DeserializeInheritedStuff(AnyProto)
    -> Lookup(Proto)

This cycle could be broken if the order of incremental inputs was
such that we had already cached the lookup of Proto.

Resolve this cycle in any case by suspending the deserialization of the
type eraser until the point it's demanded by adding
ResolveTypeEraserTypeRequest.

rdar://61270195
2020-04-03 14:52:21 -07:00
marcrasi
1be86adbfc [AutoDiff] forbid derivative registration using @differentiable (#30001)
Delete `@differentiable` attribute `jvp:` and `vjp:` arguments for derivative
registration. `@derivative` attribute is now the canonical way to register
derivatives.

Resolves TF-1001.
2020-03-24 00:41:27 -07:00
Xi Ge
b00698d977 ModuleInterface: print function-builder custom attribute only on parameters
Printing this attribute on other definitions isn't necessary.

rdar://58544718
2020-03-19 15:41:08 -07:00
Xi Ge
75abee8f45 ModuleInterface: skip override keywords when overriding an invisible decl from super class
When we are printing Swift interface, we have to skip the override keyword
if the overriden decl is invisible from the interface. Otherwise, an error
will occur while building the Swift module because the overriding decl
doesn't override anything.

We couldn't skip every `override` keywords because they change the
ABI if the overriden decl is also publicly visible.

For public-override-internal case, having `override` doesn't have ABI
implication. Thus we can skip them.

rdar://58562780
2020-03-19 11:47:54 -07:00
Holly Borla
3a361c7f02 [Attr] Implement printing the typeEraser attribute. 2020-02-25 19:53:25 -08:00
Holly Borla
9f09add09b Merge pull request #29966 from hborla/type-check-type-eraser-attribute
[Sema] Implement type checking for the `_typeEraser` attribute
2020-02-21 14:12:59 -08:00
Holly Borla
ebb727c0a3 [TypeCheckAttr] Allow a type eraser initializer to have more than one
generic requirement.
2020-02-19 17:07:30 -08:00
Argyrios Kyrtzidis
3d5cb90904 Merge pull request #29938 from akyrtzi/annotated-property-wrapper-attribute
[ASTPrinter] When printing a property wrapper attribute name for the fully annotated declaration, make sure that it is wrapped within the `syntaxtype.attribute.name` tag
2020-02-19 16:41:25 -08:00
Argyrios Kyrtzidis
8cfc5eda94 [ASTPrinter] When printing a property wrapper attribute name for the fully annotated declaration, make sure that it is wrapped within the syntaxtype.attribute.name tag 2020-02-19 14:20:51 -08:00
Alexis Laferrière
0e7029dfb5 Use "SPI group" for the name used in an @_spi attribute 2020-02-19 14:18:11 -08:00
Alexis Laferrière
901392896d [Frontend] Output the private module interface with the SPI info 2020-02-19 14:17:14 -08:00
Alexis Laferrière
d5969a9f3a [AST] Intro SPI attribute for access control and imports 2020-02-19 14:17:08 -08:00
Holly Borla
c0d936ec8d [Sema] Implement type checking for the typeEraser attribute. 2020-02-14 17:47:23 -08:00
Holly Borla
24826e01bd Merge pull request #29775 from hborla/parse-type-eraser-attribute
[Parse] Add an attribute for typeEraser.
2020-02-12 09:58:14 -08:00
Holly Borla
ffba71b889 [Parse] Add an attribute for typeEraser.
This will be used for compiler-driven type erasure for dynamic
replacement of functions with an opaque return type. For now, just
parse the attribute and ignore it.
2020-02-11 17:30:21 -08:00
Mattt
d40d47f209 Fix spelling of '@available' in error message "'@availability' attribute cannot be applied to this declaration" (#29760)
* Update DAK_Available name to match @available keyword

Update expected errors for @available attribute tests

* Update available attribute keyword name in DeclAttrKeyword documentation comment
2020-02-11 22:45:38 +00:00
Xi Ge
26c16174f8 TBDGen: also using target variant to decide whether @_originallyDefinedIn is active
This ensures we could emit linker directives for multiple platforms when building
zippered libraries.
2020-01-27 15:29:01 -08:00
Devin Coughlin
082421048a [AST/Sema] Add availability attributes for macCatalyst
Add a platform kind and availability attributes for macCatalyst. macCatalyst
uses iOS version numbers and inherits availability from iOS attributes unless
a macCatalyst attribute is explicitly provided.
2020-01-21 20:27:14 -08:00
Dan Zheng
44d937d7c2 [AutoDiff upstream] Add @differentiable declaration attribute type-checking. (#29231)
The `@differentiable` attribute marks a function as differentiable.

Example:
```
@differentiable(wrt: x, jvp: derivativeFoo where T: Differentiable)
func id<T>(_ x: T) -> T { x }
```

The `@differentiable` attribute has an optional `wrt:` clause specifying the
parameters that are differentiated "with respect to", i.e. the differentiability
parameters. The differentiability parameters must conform to the
`Differentiable` protocol.

If the `wrt:` clause is unspecified, the differentiability parameters are
currently inferred to be all parameters that conform to `Differentiable`.

The `@differentiable` attribute also has optional `jvp:` and `vjp:` labels
for registering derivative functions. These labels are deprecated in favor of
the `@derivative` attribute and will be removed soon.

The `@differentiable` attribute also has an optional `where` clause, specifying
extra differentiability requirements for generic functions.

The `@differentiable` attribute is gated by the
`-enable-experimental-differentiable-programming` flag.

Code changes:
- Add `DifferentiableAttributeTypeCheckRequest`.
  - Currently, the request returns differentiability parameter indices, while
    also resolving `JVPFunction`, `VJPFunction`, and
    `DerivativeGenericSignature` and mutating them in-place in
    `DifferentiableAttr`. This was the simplest approach that worked without
    introducing request cycles.
- Add "is type-checked" bit to `DifferentiableAttr`.
  - Alternatively, I tried changing `DifferentiableAttributeTypeCheckRequest` to
    use `CacheKind::Cache` instead of `CacheKind::SeparatelyCached`, but it did
    not seem to work: `@differentiable` attributes in non-primary-files were
    left unchecked.

Type-checking rules (summary):
- `@differentiable` attribute must be declared on a function-like "original"
  declaration: `func`, `init`, `subscript`, `var` (computed properties only).
- Parsed differentiability parameters must be valid (if they exist).
- Parsed `where` clause must be valid (if it exists).
- Differentiability parameters must all conform to `Differentiable`.
- Original result must all conform to `Differentiable`.
- If JVP/VJP functions are specified, they must match the expected type.
  - `@differentiable(jvp:vjp:)` for derivative registration is deprecated in
    favor of `@derivative` attribute, and will be removed soon.
- Duplicate `@differentiable` attributes with the same differentiability
  parameters are invalid.
- For protocol requirements and class members with `@differentiable` attribute,
  conforming types and subclasses must have the same `@differentiable` attribute
  (or one with a superset of differentiability parameter indices) on
  implementing/overriding declarations.
2020-01-19 12:23:04 -08:00
Xi Ge
3ee9b1175c TBDGen: when previous install name map is specified, emit $ld$previous linker directives.
Progress towards: rdar://58281536
2020-01-17 15:57:25 -08:00
Xi Ge
80d6230105 Merge pull request #29241 from nkcsgexi/refactor-originally-defined
TBDGen: some refactoring to allow multiple platform kinds for linker directives. NFC
2020-01-16 13:16:00 -08:00
Xi Ge
caf88fb1eb TBDGen: some refactoring to allow multiple platform kinds for linker directives.
Tentatively fixing: rdar://58569201
2020-01-16 11:42:03 -08:00
Brent Royal-Gordon
0c478b6be6 Revert "Merge pull request #28665 from CodaFi/the-phantom-menace"
This reverts commit 43a3ab7e35, reversing
changes made to 4f39d9c749.

# Conflicts:
#	include/swift/AST/Attr.def
#	lib/AST/Attr.cpp
#	lib/Serialization/Deserialization.cpp
#	lib/Serialization/ModuleFormat.h
#	lib/Serialization/Serialization.cpp
2020-01-15 15:28:42 -08:00
Dan Zheng
6a7f84048d [AutoDiff upstream] Store @differentiable original declaration. (#29082)
Store in `DifferentiableAttr` the original declaration on which the attribute
is declared.

The original declaration is resolved during parsing and deserialization
(not yet upstreamed).

Progress towards TF-828: upstream `@differentiable` attribute type-checking.
2020-01-09 10:33:22 -08:00
Dan Zheng
c9c51beda3 [AutoDiff] Attribute gardening. (#29050)
Upstream changes from `tensorflow` branch:
- https://github.com/apple/swift/pull/28932: deprecate `@differentiable(jvp:vjp)` arguments.
- https://github.com/apple/swift/pull/29038: gardening.

Additional gardening included.
2020-01-07 19:24:52 -08:00
Kita, Maksim
b4b3f98d86 SR-11889: Fixed code review issues
1. Use Located in Convention structure
2019-12-20 17:19:00 +03:00
Dan Zheng
14ee6c5d1c [AutoDiff] Enable @derivative attribute qualified declaration names. (#28892)
Enable qualified declaration names in `@derivative` attribute, just like
`@transpose` attribute.

`DerivativeAttr` now stores a base type `TypeRepr *`, which is non-null for
parsed attributes that reference a qualified original declaration.

Add `TypeResolutionFlags::AllowModule` flag to enable module lookup via
`TypeChecker::lookupMember` given a `ModuleType`.

Add tests for type-qualified and module-qualified declaration names.

Resolves TF-1058.
2019-12-19 21:06:20 -08:00
Argyrios Kyrtzidis
a9c9f260d0 Merge pull request #27545 from apple/transposing-attr
[AutoDiff upstream] Add `@transpose` attribute.
2019-12-18 11:52:14 -08:00
Dan Zheng
cd1400d675 Merge branch 'master' of github.com:apple/swift into upstream-transpose-attr 2019-12-17 12:44:29 -08:00
Dan Zheng
c842fee0a4 [AutoDiff upstream] Add @transpose(of:) attribute.
The `@transpose(of:)` attribute registers a function as a transpose of another
function. This patch adds the `@transpose(of:)` attribute definition, syntax,
parsing, and printing.

Resolves TF-827.

Todos:
- Type-checking (TF-830, TF-1060).
- Enable serialization (TF-838).
- Use module-qualified names instead of custom qualified name syntax/parsing
  (TF-1066).
2019-12-16 12:23:08 -08:00
Xi Ge
03fab30ee0 Merge branch 'master' into tbdgen-ld-hide 2019-12-14 20:57:05 -08:00
Dan Zheng
27dad91d64 [AutoDiff upstream] Upstream @derivative attribute serialization. (#28781)
Upstream `@derivative` attribute serialization/deserialization.
Test all original declaration kinds and various `wrt:` parameter clauses.

Resolves TF-837.
2019-12-13 19:02:06 -08:00
Xi Ge
66b4737ddc TBDGen: use active platform versions to genearate linker directives 2019-12-12 22:22:28 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
1df792ae9f [NFC] Convert TypeRepr to use DeclName(Loc)?
Replaces `ComponentIdentTypeRepr::getIdentifier()` and `getIdLoc()` with `getNameRef()` and `getNameLoc()`, which use `DeclName` and `DeclNameRef` respectively.
2019-12-11 00:45:08 -08:00
Robert Widmann
06d27f08fd Define @_implicitly_synthesizes_nested_requirement
State the previously unstated nested type requirement that CodingKeys adds to the witness requirements of a given type. The goal is to make this member cheap to synthesize, and independent of the expensive protocol conformance checks required to append it to the member list.

Further, this makes a clean conceptual separation between what I'm calling "nested type requirements" and actual type and value requirements.

With luck, we'll never have to use this attribute anywhere else.
2019-12-10 16:28:50 -08:00
Dan Zheng
0585eb0e90 [AutoDiff upstream] Add @derivative(of:) attribute. (#28321)
The `@derivative(of:)` attribute registers a function as a derivative of another
function. This patch adds the `@derivative(of:)` attribute definition, syntax,
parsing, and printing.

Resolves TF-826.

Todos:
- Type-checking (TF-829).
- Serialization (TF-837).
2019-12-10 09:29:43 -08:00
Dan Zheng
67423687b0 [AutoDiff] NFC: @differentiable attribute gardening. (#28666)
- Move `DifferentiableAttr` definition above `DeclAttributes` in
  include/swift/AST/Attr.h, like other attributes.
- Remove unnecessary arguments from `DifferentiableAttr::DifferentiableAttr`
  and `DifferentiableAttr::setDerivativeGenericSignature`.
- Add libSyntax test for `@differentiable` attributes.
2019-12-09 20:53:38 -08:00
Varun Gandhi
3cc452eee8 Merge pull request #28479 from varungandhi-apple/vg-allow-clang-types-in-convention-attr
Allow spelling out a C type in the convention attribute.
2019-12-09 18:36:56 -08:00
Robert Widmann
eea5cfbe82 Refactor DynamicReplacementAttr::create
Remove a dead overload and add an overload for lazy member loading
2019-12-03 15:28:19 -08:00
Varun Gandhi
7d297bc678 Print the full calling convention; include the Clang type if applicable. 2019-12-02 21:06:01 -08:00