Commit Graph

620 Commits

Author SHA1 Message Date
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
Doug Gregor
c8ac000fbb Record specialized signature in (SIL)SpecializeAttr.
Rather than storing the set of input requirements in a
(SIL)SpecializeAttr, store the specialized generic signature. This
prevents clients from having to rebuild the same specialized generic
signature on every use.
2019-08-26 09:54:56 -07:00
Alexis Laferrière
6fe734541d Don't inherit the unavailability of extensions for imported decls
rdar://problem/53956555
2019-08-20 14:16:55 -07:00
Xi Ge
0e438f6ebd IDE: always print custom attributes associated with function builder
rdar://51592635
2019-07-09 10:33:30 -07:00
Alexis Laferrière
b54c619bef Support unavailable and obsoleted attributes on extensions
Members of an extension inherit the availability of the extension.
This was previously supported for introduced and deprecated, but not
unavailable and obsoleted.

rdar://problem/50949936
2019-07-03 11:39:57 -07:00
Doug Gregor
db5440bdef [SE-0258] Rename wrapperValue to projectedValue. 2019-06-26 07:39:01 -07:00
Doug Gregor
7bb01c743b [SE-0258] Promote projection variables ($foo) to the original property access
When the outermost property wrapper associated with a property has a
`wrapperValue`, create the projection property (with the `$` prefix)
at the same access level as the original property. This puts the
wrapped-value interface and the projection interface at the same level.

The newly-introduced @_projectionValueProperty attribute is implicitly
created to establish the link between the original property and the
projection value within module interfaces, where both properties will
be explicitly written out.
2019-06-26 07:39:01 -07:00
Jordan Rose
15bcd23e37 [ModuleInterface] Propagate availability for nested types too (#25662)
Previously the module interface printing would scrape the
AvailableAttrs from the containing decl in order to print synthesized
extensions for conformances that wouldn't otherwise be printed...but
that missed the case where a containing lexical scope had the
availability attributes instead. Now it walks up the chain of parent
DeclContexts and collects the most specific AvailableAttr for each
platform.

This /still/ isn't formally correct because it doesn't merge
availability for one platform (if something inside is deprecated
unconditionally but outside has an "introduced" version), but it's
going to match the vast majority of code out there.

Pre-requisite for rdar://problem/50100142
2019-06-21 18:00:44 -07:00
Karoy Lorentey
1069fc2c44 Revert "Support unavailable and obsoleted attributes on extensions" (#25127) 2019-05-29 15:16:49 -07:00
Alexis Laferrière
1cc25b98c7 Support unavailable and obsoleted attributes on extensions
Members of an extension inherit the availability of the extension.
This was previously supported for introduced and deprecated, but not
unavailable and obsoleted.

rdar://problem/50949936
2019-05-22 16:41:34 -07:00
Doug Gregor
a848d12665 Parse unknown attributes as "custom" attributes.
Parse custom attributes with the grammar:

```
'@' type-identifier expr-paren?
```
2019-03-29 23:10:36 -07:00
Brent Royal-Gordon
3fb93cd05d Merge pull request #22198 from brentdax/im-on-the-case
Guard returns of limited-availability cases in init(rawValue:)
2019-02-12 16:28:06 -08:00
Brent Royal-Gordon
6d8dbfa0f1 [NFC] Style/assertion/test design improvements 2019-02-08 14:17:38 -08:00
Xi Ge
c0598b9888 ASTPrinter: add an option to skip keywords with a prefix of underscore.
DocSupport will use set this flag to avoid printing __consuming, __owned, and
__shared.

rdar://47777848
2019-02-06 14:51:39 -08:00
Brent Royal-Gordon
5da6668b8a Refactor availability-checking code to handle more cases
Moves a lot of it into helper functions and types so it doesn’t disrupt the main flow of the code so much. Also makes it handle always-unavailable and obsolete cases (by skipping them).
2019-02-04 15:54:23 -08:00
Brent Royal-Gordon
2bd9eb38d8 Add accessor with potentially unavailable attrs
DeclAttributes::getUnavailable() only cares about attributes which make a declaration definitely unavailable, but you sometimes need a version which will also return a potentially unavailable (i.e. “introduced:”) attribute. This adds that.
2019-02-04 13:53:35 -08:00
Harlan Haskins
a61d1f6476 [ParseableInterfaces] Re-escape multi-line strings in attribute messages
Previously, we would print multi-line string literals with single quotes, which were not re-parseable. Instead, re-escape their contents and print them out escaped.
2019-01-30 17:24:48 -08:00
Harlan Haskins
9c8ed0ba93 [ParseableInterfaces] Print @_show_in_interface
This attribute needs to be preserved in the .swiftmodule, otherwise these declarations will stop showing up in the interface. Print it in the parseable interface.
2019-01-29 11:50:58 -08:00
Mike Ash
d3c2a295a6 [AST] Fix the printing of @_objcRuntimeName.
rdar://problem/46646438
2019-01-15 12:21:20 -05:00
Ankit Aggarwal
92d09f4e19 Extend @available to support PackageDescription
<rdar://problem/46548531> Extend @available to support PackageDescription

This introduces a new private availability kind "_PackageDescription" to
allow availability testing by an arbitary version that can be passed
using a new command-line flag "-swiftpm-manifest-version". The semantics
are exactly same as Swift version specific availability. In longer term,
it maybe possible to remove this enhancement once there is
a language-level availability support for 3rd party libraries.

Motivation:

Swift packages are configured using a Package.swift manifest file. The
manifest file uses a library called PackageDescription, which contains
various settings that can be configured for a package. The new additions
in the PackageDescription APIs are gated behind a "tools version" that
every manifest must declare. This means, packages don't automatically
get access to the new APIs. They need to update their declared tools
version in order to use the new API. This is basically similar to the
minimum deployment target version we have for our OSes.

This gating is important for allowing packages to maintain backwards
compatibility. SwiftPM currently checks for API usages at runtime in
order to implement this gating. This works reasonably well but can lead
to a poor experience with features like code-completion and module
interface generation in IDEs and editors (that use sourcekit-lsp) as
SwiftPM has no control over these features.
2018-12-08 09:38:40 +05:30
Arnold Schwaighofer
e4099d0e88 Address remaining feedback from Jordan 2018-11-08 15:13:48 -08:00
Arnold Schwaighofer
963c64e3e7 Add @_private(from: "SourceFile.swift") imports
A module compiled with `-enable-private-imports` allows other modules to
import private declarations if the importing source file uses an
``@_private(from: "SourceFile.swift") import statement.

rdar://29318654
2018-11-08 08:00:47 -08:00
Arnold Schwaighofer
b102c7f6b4 Parser/Sema/SILGen changes for @_dynamicReplacement(for:)
Dynamic replacements are currently written in extensions as

extension ExtendedType {
  @_dynamicReplacement(for: replacedFun())
  func replacement() { }
}

The runtime implementation allows an implementation in the future where
dynamic replacements are gather in a scope and can be dynamically
enabled and disabled.

For example:

dynamic_extension_scope CollectionOfReplacements {
  extension ExtentedType {
    func replacedFun() {}
  }

  extension ExtentedType2 {
    func replacedFun() {}
  }
}

CollectionOfReplacements.enable()
CollectionOfReplacements.disable()
2018-11-06 09:58:36 -08:00
Jordan Rose
08d4a93896 [AST] More static_asserts for non-destroyed bump-allocated AST types (#19670)
Attributes, ParameterLists, GenericParamLists, Patterns, Types, and
TypeReprs. Thanks, Rintaro!
2018-10-02 14:58:18 -07:00
Jordan Rose
237c6bbdf3 [AST] Don't coalesce @available(swift 5) with @available(iOS 5) (#19236)
Doing so was leading to nonsense attribute forms like

  @available(* 5, iOS 5, *)
2018-09-11 09:34:18 -07:00
Jordan Rose
7046980f99 [ModuleInterface] Print normally unprinted attributes
We need @_transparent to control mandatory inlining; @_fixed_layout to
control, well, layout; and @_effects to help optimization. We still
don't need the ImplicitlyUnwrappedOptional attribute, and we don't
need access control attributes (because we handle that uniformly).

This also fixes up the printing of the '_effects' attribute to include
its underscore, so that it matches the source spelling.
2018-08-20 18:30:01 -07:00
Jordan Rose
1958d7aea3 [AST] Add an AccessScope::dump helper (#18756)
And factor an existing getAccessLevelString out into a
generally-available swift::getAccessLevelSpelling.
2018-08-16 10:30:30 -07:00
swift-ci
decf2b1130 Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 11:49:26 -07:00
David Zarzycki
5b9f5062f9 [AST] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:33 -04:00
Bob Wilson
c3e02955bb [master-next] Adjust for VersionTuple moving from clang to llvm.
LLVM r334399 (and related Clang changes) moved clang::VersionTuple to
llvm::VersionTuple. Update Swift to match.

Patch by Jason Molenda.
rdar://problem/41025046
2018-06-12 16:44:11 -07:00
David Zarzycki
e57467a563 [AST] NFC: Attr.def clean up (#16031)
1) Formalize "OnAccessor". A hack used to alias this to "OnFunc".
2) New aggregates: OnNominalType, OnGenericType, OnAbstractFunction.
3) Consistent and self-documented (albeit custom) style to ease code review/audits.
4) Removes a few cases of `OnAccessor` based on pull request #16031 feedback.
2018-04-24 21:24:48 -04:00