Commit Graph

110 Commits

Author SHA1 Message Date
Doug Gregor
b182c96bd7 Print diagnostic group names by default
Print diagnostic groups as part of the LLVM printer in the same manner as the
Swift one does, always. Make `-print-diagnostic-groups` an inert option, since we
always print diagnostic group names with the `[#GroupName]` syntax.

As part of this, we no longer render the diagnostic group name as part
of the diagnostic *text*, instead leaving it up to the diagnostic
renderer to handle the category appropriately. Update all of the tests
that were depending on `-print-diagnostic-groups` putting it into the
text to instead use the `{{documentation-file=<file name>}}`
diagnostic verification syntax.
2025-03-29 15:40:56 -07:00
Allan Shortlidge
cad1ee75d5 AST: Optimize the layout of AvailabilityRange.
`AvailabilityRange` is now being used as a currency type in more of the
compiler, and some of those uses are in permanent `ASTContext` allocations. The
class wraps the `VersionRange` utility, which is itself a wrapper around
`llvm::VersionTuple` with some additional storage for representing sentinel
values. Even though the two sentinel values can be be represented with just a
single bit of additional storage on top of the 16 bytes required to represent
`VersionTuple`, because of alignment requirements the sentinel values end up
bloating the layout of `VersionRange` by many bytes.

To make `AvailabilityRange` and `VersionRange` more efficient to store, we can
instead reserve two unlikely `llvm::VersionTuple` bit patterns as the sentinel
values instead. The values chosen are the same ones LLVM uses to represent
version tuple tombstones and empty keys in a `DenseMap`.
2025-03-05 07:15:15 -08:00
Allan Shortlidge
272b2b43de AST: Accept AvailabilityDomains as diagnostic arguments.
This simplifies the code to emit availabilty diagnostics and ensures that they
display domain names consistently. While updating existing diagnostics, improve
consistency along other dimensions as well.
2025-02-28 09:18:38 -08:00
Allan Shortlidge
b0afd07e14 AST/Parse: Always delay AvailabilityDomain lookup to type-checking.
This will unblock parsing and type-checking availability queries that specify
custom availability domains, e.g.:

```
if #available(CustomDomain) {
  // Use declarations protected by @available(CustomDomain)
}
```
2025-02-26 21:46:14 -08:00
Allan Shortlidge
62c8e72f23 AST: Centralize AvailabilityDomain lookup.
Implement lookup of availability domains for identifiers on
`AvailabilityDomainOrIdentifier`. Add a bit to that type which represents
whether or not lookup has already been attempted. This allows both
`AvailableAttr` and `AvailabilitySpec` to share a common implementation of
domain lookup.
2025-02-25 22:00:31 -08:00
Allan Shortlidge
db29a1c6f4 Parse/Sema: Move #available query wildcard diagnostics to Sema.
In order to unblock resolution of availability domains during type-checking
instead of parsing, diagnostics about missing or superfluous wildcards in
availability specification lists need to move to Sema.
2025-02-23 22:09:33 -08:00
Dmitrii Galimzianov
aa5e10f8d2 [Diagnostics] DeprecatedDeclaration group 2024-09-25 23:18:25 +02:00
Dmitrii Galimzianov
a8b71ea97f Add -print-diagnostic-groups flag
This change adds the `-print-diagnostic-groups` flag as described by SE-0443.
2024-09-11 13:34:42 +02:00
Allan Shortlidge
0096904caa Parse: Diagnose empty version numbers.
The compiler treats version tuples that are all zeros as empty, or the same as
not having a version. Diagnose attempts to specify all-zeroes versions in
attributes and availability queries to prevent surprising behavior.

Resolves rdar://124661151
2024-03-19 18:17:56 -07:00
Allan Shortlidge
a92c9c0f6e Sema: Fix a null dereference when diagnosing a call to a renamed function.
Resolves rdar://117139757
2023-11-21 17:25:02 -08:00
Allan Shortlidge
6e5562a6c8 Sema: Improve diagnostics for overrides of unavailable decls.
Unavailable decls cannot be overridden by available decls. This change improves
the compiler diagnostics for this restriction in a few ways:

- Duplicate diagnostics are suppressed for getters and setters inside property
  declarations that have already been diagnosed.
- Diagnostics are suppressed for implicit accessors since they would typically
  duplicate diagnostics for the explicit accessors the implicit ones are
  derived from.
- Decls inside unavailable a derived class are no longer incorrectly diagnosed.
2023-04-26 18:29:22 -07:00
Casper Jeukendrup
7f9885b791 Let generated availability attributes of initializers of subclasses inherit the message and renaming from the initializer of the superclass 2023-01-12 22:35:33 +01:00
Casper Jeukendrup
a59cdc548b Fix #57354: Fix-it for deprecated initializers removes the .init part from self.init 2023-01-12 22:35:32 +01:00
Luciano Almeida
52e2b3dc24 [Parse] Suggest platform correction based on known platforms edit distance 2022-09-26 19:44:04 -03:00
Allan Shortlidge
f1ecb4c215 Parse: Offer a fix-it when platform is specified with the wrong case in availability attributes and queries.
Resolves rdar://100195680
2022-09-21 16:21:36 -07:00
Anthony Latsis
85fae6b9ff Gardening: Migrate test suite to GH issues: attr 2022-08-11 18:00:04 +03:00
Evan Wilde
aa51bdf17a Add noasync availability kind to available attr
This patch adds the `noasync` availability kind to `@available`. The
spelling is `@available(*, noasync)`.
2022-03-22 15:12:51 -07:00
Minhyuk Kim
3e8b076fef PR Review 2021-08-31 23:48:13 +09:00
Minhyuk Kim
51176d4c5d Fix diagnostics to produce valid rename fixit for SubscriptExpr 2021-08-30 00:27:17 +09:00
Hamish Knight
5aeb49f5dd [Sema] Correct fix-its for availability rename
Update to handle multiple trailing closures.

rdar://81289222
2021-08-02 12:59:43 +01:00
Robert Widmann
b11b67c79b [DiagnosticsQoI] Inform the User When Unavailable Inits Are Called
When a no-args init is the only designated init in the superclass, Swift will automatically
call it from the subclass. Unfortunately, if this initializer is
unavailable, an error is issued that points at the subclass' init but
makes no mention of the implicit call. Fix that by providing a note that
explains what's going on here.
2021-04-08 16:14:50 -07:00
Slava Pestov
027563733a AST: Disallow @available attributes on generic parameters
This was a no-op and it doesn't make sense in the current model.
2020-10-16 00:34:56 -04:00
Slava Pestov
94e999a1b5 Sema: Pull availability checking out of resolveType()
We used to diagnose references to unavailable declarations in
two places:

- inside Exprs, right after type checking the expression
- inside TypeReprs, from resolveType()

In broad terms, resolveType() is called with TypeReprs
stored inside both Stmts and Decls.

To handle the first case, I added a new overload of
diagAvailability() that takes a Stmt, to be called from
typeCheckStmt(). This doesn't actually walk into any Exprs
stored inside the statement; this means it only walks
Patterns and such.

For the second case, a new DeclAvailabilityChecker is
now defined in TypeCheckAccess.cpp. It's structure is
analogous to the other three walkers there:

- AccessControlChecker
- UsableFromInlineChecker
- ExportabilityChecker

The new implementation of availability checking for types
introduces a lot more code than the old online logic
it replaces. However, I hope to consolidate some of the
code duplication among the four checkers that are defined
in TypeCheckAccess.cpp, and do some other cleanups that
will make the benefit of the new approach apparent.
2020-10-14 23:42:02 -04:00
Brent Royal-Gordon
57469a6472 Allow shadowing of unavailable members
This change permits a subclass to redeclare an unavailable member from a superclass. For instance, suppose you write this code (or, more likely, a version where `Base` is an ObjC class):

```swift
class Base {
  @available(*, unavailable) init() {}
}

class Derived: Base {
  /* override */ init() {}
}
```

Previously, Swift would reject `Derived.init()` without the `override` keyword, telling you that you should add it, but it would also reject it *with* the `override` keyword, telling you that you can't override something that's unavailable. This PR makes Swift accept it without the `override` keyword; declaring it with the keyword is still forbidden.

Fixes rdar://65702529.
2020-07-22 15:49:01 -07:00
Doug Gregor
b3790978d1 [Type checker] Fix assertion diagnosting a rename with a different # of arguments. 2019-09-10 10:33:03 -07:00
Alexis Laferrière
abbbc01d20 Allow the use of unavailable types from unavailable code
This change permits the use of unavailable types in unavailable signatures.
It affects only usage of `available(*, unavailable)`.

This fixes a compilation error in swift-corelibs-foundation/Foundation/
URLSession/URLSessionConfiguration.swift where an unavailable property
was typed by an unavailable type.
2019-07-03 11:40:22 -07:00
mishal_shah
1e38fc3030 Update master to build with Xcode 11 beta, macOS 10.15, iOS 13, tvOS 13, and watchOS 6 SDKs 2019-06-03 22:50:02 -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
9b59ec54b2 Allow the use of unavailable types from unavailable code
This change permits the use of unavailable types in unavailable signatures.
It affects only usage of `available(*, unavailable)`.

This fixes a compilation error in swift-corelibs-foundation/Foundation/
URLSession/URLSessionConfiguration.swift where an unavailable property
was typed by an unavailable type.
2019-05-24 10:22:38 -07:00
Brent Royal-Gordon
facaad1873 A diagnosis from the argument clinic (#20997)
[Parse] Warn if the same argument is specified more than once in @available
2018-12-04 01:05:09 -08:00
Pavel Yaskevich
63b802ca88 [AST/Printing] Don't omit empty labels in special names
This makes diagnostics more verbose and accurate, because
it's possible to distinguish how many parameters there are
based on the message itself.

Also there are multiple diagnostic messages in a format of
`<descriptive-kind> <decl-name> ...` that get printed as
e.g. `subscript 'subscript'` if empty labels are omitted.
2018-09-24 18:36:53 -07:00
fischertony
9a05c9edf9 Add test for usage of deprecated inherited init 2018-09-13 14:59:18 +03:00
fischertony
f5e363df00 [Sema] Suppress deprecation warnings in synthesized code 2018-09-12 15:19:34 +03:00
Jordan Rose
23260b8e7b Revert "'@available' without an OS is ignored on extensions" warning (#16298)
This is still useful for the feature where deprecated declarations are
allowed to be used within a context that's marked deprecated. There's
probably a better balance to be found here, because marking the
extension deprecated still does not mark all the members deprecated,
but for now it still has an effect, and we shouldn't produce a warning
for legitimately making use of that effect.

The warning was added in f21d9f332, mostly as an opportunity "fix".

https://bugs.swift.org/browse/SR-7577
2018-05-02 16:53:24 -07:00
Jordan Rose
0b632aa9df Diagnose unavailable getters and setters
This handles the case where one accessor is /unavailable/ but not the
other. This is rarer than deprecation (handled in b0e12f4c), but could
still happen.

Finishes rdar://problem/18633725 / SR-7201.
2018-04-10 19:35:43 -07:00
Slava Pestov
f7697291df Parse: Backward compatibility for old spellings @_inlineable and @_versioned
Just parse these as @inlinable and @versioned, then emit a warning
(Swift 4.2 and below) or error (Swift 5).
2018-03-30 21:55:31 -07:00
Jordan Rose
b0e12f4c80 Check deprecation for getters and setters
This handles the case where just one accessor is deprecated but not
the other, which does come up sometimes in Apple's frameworks.

rdar://problem/18633725
2018-03-16 10:12:52 -07:00
Jordan Rose
f21d9f332d Allow @available(swift, ...) nested within @available(macOS, ...)
Previously, we treated this as an attempt to widen the availability
of a member beyond its context, but it's really a different axis of
availability.

Also, warn about using @available on extensions without an OS, which
we just completely ignore right now.

rdar://problem/32632327
2018-03-14 16:37:36 -07:00
Max Moiseev
4c0368a02a [test] Cleaning up tests 2017-08-29 10:04:39 -07:00
Pavel Yaskevich
e5a2c7c7dc [QoI] Improve fix-it when renamed method has contextual member lookup argument
Currently we generate incorrect fix-it in situations where we
have contextual member lookup as one of the arguments.

Resolves: rdar://problem/32526620
2017-07-14 12:15:29 -07: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
Michael Ilseman
045bc16b6d Merge pull request #4031 from milseman/noescape_by_default
noescape by default: deprecate @noescape and @autoclosure(escaping)
2016-08-05 13:25:00 -07:00
Michael Ilseman
caa9d67469 [noescape by default] Emit deprecation warning/fixit for @noescape
@noescape is now the default behavior, so deprecate it and offer a
fixit.
2016-08-04 16:28:43 -07:00
Rintaro Ishizaki
2f6b6d2c67 [Fix-it] Support defaulted and variadic arguments in renamed fix-it 2016-08-05 02:05:42 +09:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Michael Ilseman
c37751ae96 [noescape by defaul] make noescape the default
This flips the switch to have @noescape be the default semantics for
function types in argument positions, for everything except property
setters. Property setters are naturally escaping, so they keep their
escaping-by-default behavior.

Adds contentual printing, and updates the test cases.

There is some further (non-source-breaking) work to be done for
SE-0103:

- We need the withoutActuallyEscaping function
- Improve diagnostics and QoI to at least @noescape's standards
- Deprecate / drop @noescape, right now we allow it
- Update internal code completion printing to be contextual
- Add more tests to explore tricky corner cases
- Small regressions in fixits in attr/attr_availability.swift
2016-07-29 13:49:08 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Tony Parker
2a4e916296 Rename OutputStream to TextOutputStream [SE-0086] 2016-07-18 16:47:23 -07:00
Robert Widmann
2bcb86264b Do not subject protocol Self to accessibility diagnostics
It is currently impossible to declare a protocol as unavailable and
still ship valid Swift code because while typechecking protocol Self,
we attempt to do an accessibility check on its generic signature and
find that, surprise surprise, the protocol is unavailable.  Rather than
plumb another parameter through Sema, this patch piggybacks on existing
behavior of AllowPotentiallyUnavailableProtocol to disable the check
for protocol self.
2016-07-12 02:51:57 -07:00
Xi Ge
1e85e1bcd2 Revert "[Fixit] Add a fixit for converting non-trailing closures to trailing closures (#3317)"
This patch needs some polish to fix more false positives found by @rintaro and @lattner
2016-07-02 09:39:07 -07:00