Commit Graph

81 Commits

Author SHA1 Message Date
Anthony Latsis
2cd90bdd69 AST: Quote attributes more consistently in DiagnosticsSema.def 2025-04-22 18:23:36 +01:00
Anthony Latsis
99f63ed933 DiagnosticEngine: Support TypeAttribute diagnostic arguments 2025-04-03 01:52:38 +01:00
Becca Royal-Gordon
c44284d874 Diagnose invalid @_hasStorage attributes
A bug in `@objc @implementation` is causing incorrect `@_hasStorage` attributes to be printed into module interfaces. As an initial step towards fixing this, diagnose bad `@_hasStorage` attributes and treat them as computed properties so that these malformed interfaces don’t cause compiler crashes.

Partially fixes rdar://144811653.
2025-03-27 16:24:44 -07:00
Meghana Gupta
dd037f896f Make Atomic.deinit @_transparent 2024-10-31 13:42:34 -07:00
Hamish Knight
cd1b6eddc2 [CS] Fix logic determining parens for non-optional weak diagnostic
We were previously checking the optional type,
which would never say that parens were needed.
Unwrap the type before checking, ensuring we
correctly handle e.g protocol compositions.
2024-07-15 12:47:50 +01:00
Holly Borla
9ba481ad53 [Diagnostics] Clarify the wording of error_in_future_swift_version. 2024-03-01 12:05:51 -08:00
Alex Hoppen
c6e425a559 [Parse] Disallow space between attribute name and '(' in Swift 6 mode
This allows us to resolve disambiguities of whether a parenthesis belong to an argument to the attribute or if it is eg. the start of a tuple.
2024-01-31 18:24:42 -08:00
Luciano Almeida
109b785e5d [Parser] Check let/var context when fix-it moving attributes from type to decl 2023-05-08 22:46:57 -03:00
Serena
570878ca33 Change message of invalid_ibinspectable, remove hardcoded invalid_iboutlet error and instead use non-hardcoded invalid_ibinspectable 2022-06-04 12:43:19 +03:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Rintaro Ishizaki
b6119018d7 [SourceKit] Print custom attributes in interface-gen requests
Custom attributes were not printed because they are marked
'UserInaccesible'.

* Make CustomAttr 'RejectByParser' instead of 'UserInaccessible'
* Remove special treatment for Result Builder attributes
* Load implicit modules in module/header interface gen requests

rdar://79927502
2022-03-02 11:05:26 -08:00
Erik Eckstein
5fd941eb67 Add the @exclusivity attribute.
The `@exclusivity(unchecked)` attribute can be used on variables to selectively disable exclusivity checking.
For completeness, also the `@exclusivity(checked)` variant is supported: it turns on exclusivity checking for specific variables if exclusivity enforcement is disabled by the command line option.

This new attribute is a missing implementation part of SE-0176 (https://github.com/apple/swift-evolution/blob/main/proposals/0176-enforce-exclusive-access-to-memory.md).

rdar://31121356
2022-01-25 08:06:45 +01:00
Doug Gregor
7f6b681ced [Parser] Parse custom attributes on types.
Extend the parsing of custom attributes to apply to types. Improve the
lookahead for the arguments so we don't arbitrarily consume the parameter
list of a function type as an attribute argument, or consume a tuple type
as the attribute argument.

Doesn't actually change behavior, because after parsing the custom
attribute on a type, we reject it as an unknown attribute.
2021-03-16 19:52:05 -07:00
Hamish Knight
65dda6d945 Address other review feedback 2019-11-03 08:42:26 -08:00
Hamish Knight
92c42ec791 [AST] Add @_nonEphemeral parameter attribute
This non-user-facing attribute is used to denote pointer parameters
which do not accept pointers produced from temporary pointer conversions
such as array-to-pointer, string-to-pointer, and in some cases
inout-to-pointer.
2019-11-03 08:40:59 -08:00
Rintaro Ishizaki
4eadbaa9f6 Revert "Merge pull request #27466 from rintaro/syntaxparse-type"
This reverts commit a4fcd26b38, reversing
changes made to 88ecae4b9a.
2019-10-14 12:19:04 -07:00
Rintaro Ishizaki
7b31d2b4fb [SyntaxParse] Finish type parsing
- Type attributes
- SIL types
2019-10-01 15:40:10 -07:00
Slava Pestov
003a9a47b2 Parse: Remove obsolete @autoclosure(escaping) and @noescape type attributes
Some diagnostics got worse, but I think the reduction in compiler complexity
is worth it, and copy-and-pasting Swift 2 code is not likely to produce great
results anyway.

Also, this corrects an oversight where we did not reject @pseudogeneric on
function types in AST parsing.
2019-04-09 15:02:14 -04:00
Doug Gregor
7ea7d3252e [Type checker] Allow unowned/unowned(unsafe) optional lets.
Unlike weak values of optional type, an unowned or unowned(unsafe)
value of optional type will not silently become 'nil' when the
referenced instance goes away: rather, the program will trap. Don't
reject unowned or unowned(unsafe) optional lets.

Fixes rdar://problem/45732251.
2019-01-04 09:56:13 -08:00
Slava Pestov
eb147d9ec6 Merge pull request #20531 from slavapestov/inline-always-is-not-inlinable
@inline(__always) should not imply @inlinable
2018-11-13 20:39:35 -05:00
Slava Pestov
6e4400567b AST: Allow @inline(__always)/@inline(never) to be applied to properties and subscripts
Previously we only permitted it on the accessor itself, but there is
no reason not to allow it on the storage declaration.

Fixes <https://bugs.swift.org/browse/SR-3624> / <rdar://problem/31865137>.
2018-11-13 16:40:31 -05:00
Harlan Haskins
66a61c5eca Rename @sil_stored to @_hasStorage 2018-11-12 11:32:32 -08:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
David Zarzycki
e326954bd0 [Diag] QoI: Add ReferenceOwnership to DiagnosticArgumentKind
By formalizing ReferenceOwnership as a diagnostic argument kind, we get
less boilerplate, better type safety, better output consistency, and
last but not least: future proofing.
2018-04-20 08:32:43 -04:00
Hamish
92931b7434 Merge remote-tracking branch 'upstream/master' into warn-weak-insta-dealloc 2018-04-02 18:06:45 +01:00
Slava Pestov
d3e32388c5 Parse: Better error recovery from invalid attributes 2018-03-30 21:55:30 -07:00
Hamish
48f08bdbc7 [Sema] Diagnose immediate deallocation of instances assigned to non-owning variables
When performing a binding/assignment to a weak or unowned variable/property from an initialiser call, emit a warning that the instance will be immediately deallocated.
2018-03-08 16:32:35 +00:00
Slava Pestov
e659befcf3 Sema: Clean up wording in some attribute-related diagnostics 2017-11-15 16:26:13 -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
Graydon Hoare
81aecb6a54 [Diagnostics] s/may/must/ in 'may not be applied to' 2017-09-29 16:09:23 -04: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
David Zarzycki
f0b1924a19 [Diags QoI] Avoid premature return in checkOwnershipAttr()
This also removes some dead code, where an early assert() ensures that
'strong' is never passed into the function, but then the function later
tries to handle 'strong'.

Finally, use a switch statement for future proofing.
2017-08-09 13:13:36 -04:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Slava Pestov
f63dff16c7 AST: Don't allow @_transparent on extensions
Quiz: What does @_transparent on an extension actually *do*?

1) Make all members @_transparent?
2) Allow your members to be @_transparent?
3) Some other magical effect that has nothing to do with members?

The correct answer is 1), however a few places in the stdlib defined
a @_transparent extension and then proceeded to make some or all members
also @_transparent, and in a couple of places we defined a @_transparent
extension with no members at all.

To avoid cargo culting and confusion, remove the ability to make
@_transparent extensions altogether, and force usages to be explicit.
2016-11-01 21:14:09 -07:00
Rintaro Ishizaki
183d4763f1 [QoI][Parse] Improve recovering from unknown attribute
By consuming parens.
As for type attributes, handle `@unknownAttribute(Arg) -> Ret` case.

Improves diagnostic QoI. For example, on:
func foo(x: @unknown(x) Int) {}

Before:
test.swift:1:14: error: unknown attribute 'unknown'
test.swift:1:25: error: expected ',' separator
test.swift:1:25: error: unnamed parameters must be written with the empty name '_'
test.swift:1:22: error: use of undeclared type 'x'

Now, we just emit the first one:
test.swift:1:14: error: unknown attribute 'unknown'
func foo(x: @unknown(x) Int) {}
             ^
2016-10-11 02:26:13 +09:00
Mishal Shah
87b7bcfd3e Update master to build with Xcode 8 beta 1, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-06-14 14:53:55 -07:00
David Farler
cafbff53af [QoI] Improve diagnostics when putting a class bound in a generic signature
When declaring a nominal type:

struct Weak<T> {
  weak var value: T
}

The diagnostic might mislead the developer to adding ': class' literally
to the 'T' in the generic parameters for `Weak`:

"'weak' may not be applied to non-class-bound protocol 'T'; consider
adding a class bound"

This is misleading in two ways: 1, 'T' isn't necessarily a protocol
(this patch generalizes that part of the message) and 2, you can't put
`: class` in the generic parameter list for `Weak`. In addition, the
stray class constraint causes diagnostic spew that also hides the issue.

Also provide a fix-it to constrain with 'AnyObject', which is probably
what the devloper means in this case.

rdar://problem/25481209
2016-05-17 15:52:22 -07:00
Chris Lattner
725f1ba737 Remove the long-obsolete and deprecated Swift 1 @objc_block and @thin attributes,
these were subsumed by @convention in Swift 2.

We still support @thin for metatypes in SIL of course.
2016-04-15 15:06:58 -07:00
Chris Lattner
b5828e6a61 Port over all the semantic checking for @noescape/@autoclosure from the
declattr path to the typeattr path.  The decl attr path will eventually
go away, but we need to keep it for now to support the legacy syntax
migration.
2016-04-15 14:16:43 -07:00
Argyrios Kyrtzidis
345d05e2e9 Introduce an internal attribute '@_show_in_interface' to be used in stdlib for underscored protocols that
should be shown in the interface.

Also switch the option and hide all underscored protocols by default, unless they are marked with the new attribute.
2016-03-08 23:30:58 -08:00
Daniel Duan
780b58a9a5 [Parser] update tests for 'inout' syntax adjustment 2016-02-26 01:33:22 -08:00
Chris Willmore
983a674e0c Make use of curried function declaration syntax an error.
<rdar://problem/23111018>
2016-01-20 21:57:38 -08:00
Doug Gregor
83412bc219 Revert "[AST] Introduce internal attribute '_migration_id'."
This reverts commit 042efbfb26. We're
going to take a different approach to the migration attribute.
2016-01-13 16:34:50 -08:00
Argyrios Kyrtzidis
042efbfb26 [AST] Introduce internal attribute '_migration_id'.
It's intended use is to keep track of stdlib changes for migration purposes.
2015-12-16 21:28:38 -08:00
Jordan Rose
cf8baedee2 Re-apply "Rename @transparent to @_transparent for now."
This re-applies 90fcbfe9a6. I'll be committing
the corresponding change to Foundation momentarily.
2015-11-16 10:53:56 -08:00
Chris Lattner
ea06af5afb fix <rdar://problem/22918558> Improve error message for weak protocol properties 2015-11-15 13:28:35 -08:00
Xin Tong
16843684b2 Revert "Rename @transparent to @_transparent for now."
This reverts commit 90fcbfe9a6.

Seems there are still some tests that are left not modified.
2015-11-14 07:04:31 -08:00
Jordan Rose
90fcbfe9a6 Rename @transparent to @_transparent for now.
This feature has not been fully designed, let alone properly implemented.
For more information, see docs/TransparentAttr.rst.
2015-11-13 16:25:34 -08:00
Jordan Rose
6e1bf0d10d Rename @exported to @_exported for now.
At some point I want to propose a revised model for exports, but for now
just mark that support for '@exported' is still experimental and subject
to change. (Thanks, Max.)
2015-11-05 11:59:00 -08:00
Chris Willmore
30af42fda9 Add warning that curried function decl syntax is going away.
<rdar://problem/23111018>
2015-11-02 15:45:11 -08:00