Commit Graph

650 Commits

Author SHA1 Message Date
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
David Zarzycki
0c4c02d7f3 [AST] NFC: Metaprogram DeclAttrOptions
Adding new Decl nodes shouldn't be harder than necessary.
2018-04-18 17:36:34 -04:00
David Zarzycki
a8fbe3a18e [AST] NFC: Repack misc DeclAttribute bits into inline bitfield 2018-04-18 11:25:11 -04:00
Arnold Schwaighofer
8ba434b7ca Fix indentation 2018-03-05 07:12:50 -08:00
Arnold Schwaighofer
390ba419fc Add an effects(releasenone) function effects attribute
A ``@effects(releasenone)`` function might read/write global state but does not
perform a release.
2018-03-05 07:03:54 -08:00
Huon Wilson
b94c5364f5 [NFC] Rename 'Ownership' to 'ReferenceOwnership'.
There's really two forms of ownership: references and values. Renaming
to make way for better distinguishing of the two.
2018-03-02 11:38:28 -08:00
Jordan Rose
a036033f9a [AST] Remove some redundant code for printing attributes
And make it less likely to happen again in the future.
2018-02-20 17:50:50 -08:00
Jordan Rose
3f4cba25d4 Use a semantic ClangImporterSynthesizedTypeAttr for error structs
...rather than the ad hoc CustomTypeNameManglingAttr I was using
before. As John pointed out, the AST should be semantic wherever
possible.

We may someday want to get out of this being an attribute altogether,
or duplicating information that's available in the original Clang
node, by actually storing a reference to that node somewhere. This is
tricky and mixed up with deciding what hasClangNode() or
getClangDecl() would mean, though, so for now the attribute just
carries the information we need.
2018-01-24 10:57:52 -08:00
Jordan Rose
e63879dc48 [Mangling] Define "related entity" operators 'LA'...'LJ'
(and 'La'...'Lj')

Use this for the synthesized structs for error enums, as described in
the previous commit, instead of reusing the "private discriminator"
feature. I left some space in the APIs for "related entity kinds" that
are longer than a single character, but I don't actually expect to use
it any time soon. It's mostly just easier to deal with StringRef than
with a bare char.

Note that this doesn't perfectly round-trip to the old mangling; I had
it treat these nodes as private discriminators with a prefixed "$"
instead. We don't depend on that for anything, though.
2018-01-24 10:52:46 -08:00
Jordan Rose
9c1a22ad0f Mangle synthesized error structs as a variant of the imported enum
When importing a C enum with the ns_error_domain attribute, we
synthesize a struct containing an NSError object to represent errors
in that domain. That synthesized struct should have a mangled name
that ties it to the original C enum, if we want it to be stable, and
now it does.

Before: $SSC7MyErrorV (a normal struct, which is a lie)
After: $SSC11MyErrorCode13ns_error_enumLLV
  kind=Global
    kind=Structure
      kind=Module, text="__C_Synthesized"
      kind=PrivateDeclName
        kind=Identifier, text="ns_error_enum"
        kind=Identifier, text="MyErrorCode"

Using the "private discriminator" feature allows us to pack in extra
information about the declaration without changing the mangling
grammar, and without stepping on anything the importer is using.

More rdar://problem/24688918
2018-01-23 17:05:43 -08:00
Erik Eckstein
8033476b64 Function-level optimization attributes.
For now these are underscored attributes, i.e. compiler internal attributes:
@_optimize(speed)
@_optimize(size)
@_optimize(none)

Those attributes override the command-line specified optimization mode for a specific function.
The @_optimize(none) attribute is equivalent to the already existing @_semantics("optimize.sil.never") attribute
2017-11-14 11:25:02 -08:00
Marcelo Fabri
2bf49b0151 [SourceKit] Add range for attributes in a structure (SR-5587) (#11750) 2017-09-20 15:54:42 -07:00
Jordan Rose
449cd98997 Excise "Accessibility" from the compiler (3/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

Rename AccessibilityAttr to AccessControlAttr and
SetterAccessibilityAttr to SetterAccessAttr, then track down the last
few uses of "accessibility" that don't have to do with
NSAccessibility. (I left the SourceKit XPC API alone because that's
supposed to be more stable.)
2017-08-28 13:27:59 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
Doug Gregor
1b2a2c9b90 [GSB/IRGen] Allow redundant inheritance of the JSExport protocol.
Inheritance of a protocol from JavaScriptCore's JSExport protocol is
used to indicate that the methods and properties of that protocol
should be exported to JavaScript. The actual check to determine
whether a protocol (directly) inherits JSExport is performed via the
Objective-C runtime. Note that the presence of JSExport in the
protocol hierarchy is not sufficient; the protocol must directly
inherit JSExport.

Swift warns about redundant conformance requirements and eliminates
them from the requirement signature (and, therefore, the Objective-C
metadata). This behavior is incorrect for JSExport, because the
conformance is actually needed for this API to work properly.

Recognize a protocol's inheritance JSExport specifically (by
name) when computing the requirement signature of the protocol. When
we find such a redundancy, suppress the "redundant conformance
constraint" diagnostic and add a new (hidden) attribute
@_restatedObjCConformance(proto). The attribute is used only by Objective-C
protocol metadata emission to ensure that we get the expected metadata
in the Objective-C runtime.

Fixes rdar://problem/32674145.
2017-07-24 17:02:34 -07:00
Robert Widmann
ab580a3a0a Remove @autoclosure and @noescape as decl attributes
Using these in declaration position has been deprecated and
removed in Swift 3.  These attributes were not being parsed and
contained deadweight diagnostics that should have been moved
when these attributes became type attributes.
2017-07-05 21:27:04 -07:00
Jordan Rose
f0aca936c7 Allow '@objc(RuntimeName)' on classes with generic ancestry.
This is accomplished by recognizing this specific situation and
replacing the 'objc' attribute with a hidden '_objcRuntimeName'
attribute. This /only/ applies to classes that are themselves
non-generic (including any enclosing generic context) but that have
generic ancestry, and thus cannot be exposed directly to Objective-C.

This commit also eliminates '@NSKeyedArchiverClassName'. It was
decided that the distinction between '@NSKeyedArchiverClassName' and
'@objc' was too subtle to be worth explaining to developers, and that
any case where you'd use '@NSKeyedArchiverClassName' was already a
place where the ObjC name wasn't visible at compile time.

This commit does not update diagnostics to reflect this change; we're
going to change them anyway.

rdar://problem/32414557
2017-06-05 17:32:25 -07:00
Robert Widmann
4f35068772 Implement @_downgrade_exhaustivity_check
Dispatch requests the ability to add a new case, but to treat missing
instances of that case in patterns as warnings instead of errors.  It is
still an error to make reference to the annotated case in at least one
pattern then not cover the rest of the space, but it is not an error
to omit the space of patterns referencing the case entirely.

This attribute is private and uglified to intentionally discourage
its use outside just this one use case.
2017-05-25 12:51:17 -07:00
Doug Gregor
7955aa13e6 Rename @NSKeyedArchive* attributes.
@NSKeyedArchiveLegacy -> @NSKeyedArchiverClassName
@NSKeyedArchiveSubclassesOnly -> @NSKeyedArchiverEncodeNonGenericSubclassesOnly

Fixes rdar://problem/32178796.
2017-05-15 11:02:31 -07:00
Doug Gregor
bafa99cd6e Add the @_staticInitializeObjCMetadata attribute.
Currently inactive, this attribute indicates that a static initializer should be emitted to register the Objective-C metadata when the image is loaded, rather than on first use of the Objective-C metadata. Infer this attribute for NSCoding classes that won’t have static Objective-C metadata or have an @NSKeyedArchiveLegacy attributed.
2017-05-02 23:30:27 -07:00
Doug Gregor
aaf7933a6d Add the @NSKeyedArchiveLegacy attribute.
This attribute allows one to provide the "legacy" name of a class for
the purposes of archival (via NSCoding). At the moment, it is only
useful for suppressing the warnings/errors about classes with unstable
archiving names.
2017-05-02 22:38:32 -07:00