Commit Graph

650 Commits

Author SHA1 Message Date
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
Xi Ge
5a862e49bd Merge pull request #28369 from nkcsgexi/originally-defined-in-attribute
AST: introduce a new attribute @_originallyDefinedIn to the AST
2019-11-21 20:26:29 -08:00
Xi Ge
7f8c04e0b7 AST: introduce a new attribute @_originallDefinedIn to the AST
We need this attribute to teach compiler to use a different name from the current
module name when generating runtime symbol names for a declaration. This is to serve
the workflow of refactoring a symbol from one library to another without breaking the existing
ABI.

This patch focuses on parsing and serializing the attribute, so @_originallyDefinedIn
will show up in AST, swiftinterface files and swiftmodule files.

rdar://55268186
2019-11-21 14:25:57 -08:00
Dan Zheng
baed3591e4 [AutoDiff upstream] Clean up parsing and printing. (#28377)
- Use general `Parser::isIdentifier(Token, StringRef)` function.
  - Remove specialized `isWRTIdentifier`, `isJVPIdentifier`, `isVJPIdentifier`
    functions from `Parser`.
- Clarify doc comments and parameter nullability for attribute printing code:
  `getDifferentiationParametersClauseString`.
- Minor formatting and naming updates.
2019-11-20 12:37:04 -08:00
Dan Zheng
2d2a5ded9d [AutoDiff upstream] Minor cleanup for @differentiable attribute.
Add TODO comments referencing JIRA issues.

Add disabled `@differentiable` attribute serialization test.
TF-836 tracks enabling the test.
Blocked by TF-828: `@differentiable` attribute type-checking.
2019-11-16 15:12:47 -08:00
Gogul Balakrishnan
5accda22b2 [AutoDiff upstream] Introduce @differentiable attribute to mark functions as differentiable. (#27506)
This PR introduces `@differentiable` attribute to mark functions as differentiable. This PR only contains changes related to parsing the attribute. Type checking and other changes will be added in subsequent patches.

See https://github.com/apple/swift/pull/27506/files#diff-f3216f4188fd5ed34e1007e5a9c2490f for examples and tests for the new attribute.
2019-11-11 13:58:34 -08:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Jordan Rose
8ff1dac381 [AST] Break some header dependencies for faster rebuilds (#27374)
DiagnosticEngine.h no longer depends on Attr.h.
Expr.h no longer depends on TypeRepr.h.

No functionality change.
2019-09-26 09:17:10 -07:00
Xi Ge
e2708f79cc AST: introduce the opposite options for ABIBreakingToAdd and others
Adding ABIBreakingToAdd and other options for decl attribute kind isn't
sufficient because future attributes may forget to add the ABI/API impact bits.
This patch introduces the opposite options of these breaking bits (ABIStableToAdd, etc)
, and adds several static assertions to ensure one of the opposite ABI/API impact
flags is explicitly specified.
2019-09-13 16:36:24 -07:00
Doug Gregor
8c2707c3f3 Fix printing of (SIL)SpecializeAttr.
Print the requirements that are in the `@_specialize` signature but aren’t
part of the enclosing context, matching the previous form but after
semantic analysis.
2019-08-26 09:54:56 -07:00