Commit Graph

348 Commits

Author SHA1 Message Date
Cal Stephens
e73beb435e Support trailing commas in types within expressions 2025-05-20 15:49:07 -07:00
Cal Stephens
bad48874f0 Add trailing comma support in cases missing from Swift 6.1 2025-05-20 15:48:58 -07:00
Anthony Latsis
5e41794680 AST: Quote attributes more consistently in DiagnosticsSema.def 2025-04-23 19:18:08 +01:00
Allan Shortlidge
3c8a57f86d AST: Use consolidated availability constraint query for diagnostics.
Switch to calling `swift::getAvailabilityConstraintsForDecl()` to get the
unsatisfied availability constraints that should be diagnosed.

This was intended to be NFC, but it turns out it fixed a bug in the recently
introduced objc_implementation_direct_to_storage.swift test. In the test,
the stored properties are as unavailable as the context that is accessing them
so the accesses should not be diagnosed. However, this test demonstrates a
bigger issue with `@objc @implementation`, which is that it allows the
implementations of Obj-C interfaces to be less available than the interface,
which effectively provides an availability checking loophole that can be used
to invoke unavailable code.
2025-02-16 07:44:45 -08:00
Becca Royal-Gordon
956bd10be4 Prevent shadowing of unavailable member impls
Typically, access control denies access to member implementations, so the imported interface decl will be used instead. However, in contexts that permit direct access to stored properties—such as accessors, inits, and deinits—their member implementations are accessible; the compiler then relies on a shadowing rule favoring Swift decls over ObjC decls to eliminate the imported interface decl.

However, there are many rules that are higher-priority than the Swift vs. ObjC decls one. In particular, a recent change to availability checking in #77886 caused a higher-priority rule to begin eliminating member implementations which belonged to unavailable extensions. This caused regressions in projects using `@objc @implementation` with classes that are unavailable in Mac Catalyst.

Introduce a fairly high-priority shadowing rule that favors a member implementation over its interface when both are present (i.e. when direct access to storage is permitted).

Fixes rdar://143582383.
2025-01-31 21:01:06 -08:00
Meghana Gupta
e8abd59da5 Update tests 2024-11-18 18:09:19 -08:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Hamish Knight
2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00
Becca Royal-Gordon
0d0a02276d Restore explicit @objc objcImpl behavior for early adopters
The combination `@objc @_objcImplementation extension` used to be treated like a normal `@objc extension`. Restore that behavior for early adopters.
2024-09-20 13:47:28 -07:00
Becca Royal-Gordon
d0a2564581 Make behavior change detection generic
Automatically detect when shouldMarkAsObjC() will behave differently based on the objcImpl early adopter flag and diagnose it. This works in either direction, although there isn’t anything yet that will emit diag:: objc_implementation_will_become_nonobjc.

NFC except for some minor changes to the wording of notes.
2024-09-20 13:39:44 -07:00
Becca Royal-Gordon
fdc5aa8e30 Undo behavior change for final overrides
A previous change made it so that an objcImpl extension could declare a `final` or `static` member which overrode an `@objc` superclass method, or witnessed an `@objc` protocol requirement, without itself being `@objc`. Prevent that from happening by allowing processing of `final` members to continue to later codepaths, rather than returning early.

Fixes rdar://136113393.
2024-09-20 12:19:19 -07:00
Becca Royal-Gordon
cd8d3adab0 Mimic old objcImpl behavior for early adopters
Before the update to support the new syntax, the decl checker treated private and fileprivate members of objcImpl extensions as non-@objc by default. But SE-0436 specified that private and fileprivate members should be implicitly @objc unless opted out, so when support for the final syntax was added, this behavior was changed retroactively.

Unfortunately, we’ve found that some early adopters depended on the old behavior. Restore some logic deleted by #73309 for early adopter syntax *only*, with a warning telling the developer to put `final` or `@nonobjc` on the declaration if they want to preserve the behavior after updating it.

Also tweaks the ObjCImplementationChecker to ensure this logic will actually be run in time for it to suppress the “upgrade to @objc @implementation” warning, and corrects a couple of regressions arising from that change.

Fixes rdar://135747897.
2024-09-13 14:55:16 -07:00
Becca Royal-Gordon
4dae9eea5a Merge pull request #76270 from beccadax/objcimpl-serialization-2 2024-09-11 10:53:17 -07:00
Becca Royal-Gordon
94ec99c7f0 Avoid invalidating @_objcImplementation
In #69257, we modified `ObjCReason` to carry a pointer to the @implementation attribute for the `MemberOfObjCImplementationExtension` kind. This made it mark the @implementation attribute as invalid, suppressing diagnostics from the ObjCImplementationChecker.

However, invalidating the attribute *also* causes it to be skipped by serialization. That isn’t a problem if the diagnostics are errors, since we’ll never emit the serialized module, but #74135 softened these diagnostics to warnings for early adopters.

The upshot was that if Swift emitted one of these warnings when it compiled a library, clients of that library would see the objcImpl extension as a normal extension instead. This would cause various kinds of mischief: ambiguous name lookups because implementations weren’t being excluded, overrides failing because an implementation was `public` instead of `open`, asserts and crashes in SILGen and IRGen because stored properties were found in seemingly normal extensions, etc.

Fix this by setting a separate bit on ObjCImplementationAttr, rather than the invalid bit, and modifying the implementation checker to manually suppress many diagnostics when that bit is set.

Fixes rdar://134730183.
2024-09-05 17:55:12 -07:00
Alexis Laferrière
750b141f31 Tests: enable library-evolution in tests using @_implementationOnly imports 2024-09-05 10:40:14 -07:00
Becca Royal-Gordon
fc81208293 Merge pull request #75919 from beccadax/objcimpl-selector-crasher 2024-08-20 14:04:28 -07:00
iMostfa
80a8a0746b Replace uses of the word "accessor" in diagnostics with user-facing terminology (#74462)
In this PR i worked on replacing the word accessor in diagnostics with more user-facing terminologies like setter, getter, didSet Observer, and members based on the context of the message.

in some messages i didn't need to pass DescriptiveDeclKind instead i just changed the text copy itself.

i also updated tests, so you might find it easier to check my changes this way.

Please let me know if there's something i should've done in a better way, and request changes if needed. !

i can squash my commits after reviewing getting the PR Reviewed, just to make it easier to be checked commit by commit

Resolves #55887
2024-08-16 16:29:30 -07:00
Becca Royal-Gordon
a0842b5f7a Fix crasher in objcImpl diagnostic
`fixDeclarationObjCName()` accepted optional selectors, but crashed if they were None. Make these parameters non-optional, treat an invalid `targetName` selector as “no name”, and adjust callers to pass non-optional values.

Re-enables decl/ext/objc_implementation.swift, which was disabled due to this bug.

Fixes rdar://128683206.
2024-08-15 16:26:03 -07:00
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Becca Royal-Gordon
6deec96034 Update objcImpl diagnostics to final syntax
Update diagnostics that mention `@_objcImplementation` to mention `@objc @implementation` instead.

Fixes rdar://130707698
2024-06-27 15:38:41 -07:00
Becca Royal-Gordon
c19aaddd8c Enable @objc @implementation feature 2024-06-27 14:51:27 -07:00
Becca Royal-Gordon
baf276077e Merge pull request #74161 from beccadax/objcimpl-not-so-minimum-deployment-target 2024-06-06 20:09:14 -07:00
Becca Royal-Gordon
eb1ea452f9 Soften min version for objcImpl early adopters
Weaken the minimum deployment target error to a warning for objcImpl adopters using the legacy `@_objcImplementation` syntax until we determine exactly how far back it can be safely used.

Fixes rdar://129225596.
2024-06-06 13:39:00 -07:00
Becca Royal-Gordon
c4e152c2d0 Soften objcImpl implicit final errors to warnings
Before the change from @_objcImplementation to @objc @implementation, if a member was unrepresentable in ObjC, it would become implicitly `final`. After that change, this is now an error. We do want a diagnostic here, but we don’t want to break backwards compatibility for early adopters.

Soften the error to a warning when the old @objcImplementation syntax is used.

Fixes rdar://129247349.
2024-06-04 18:07:24 -07:00
Hamish Knight
4b7ee104d1 [test] Disable decl/ext/objc_implementation.swift 2024-05-28 21:56:29 +01:00
Becca Royal-Gordon
d9912009b0 Merge pull request #73309 from beccadax/objcimpl-category-on-objc 2024-05-21 10:19:14 -07:00
Becca Royal-Gordon
9db14c36ad Require @objc to be used with @implementation
…for extensions. This change also removes @implementation(CategoryName); you should attach the category name to the @objc attribute instead. And there are small changes to how much checking the compiler will do on an @objc @implementation after the decl checker has discovered a problem with it.
2024-05-17 14:57:32 -07:00
Becca Royal-Gordon
0fbea28459 Test stable and unstable objcImpl separately
Their syntaxes are about to diverge, so let’s make sure that we maintain source compatibility for @_objcImplementation.
2024-05-16 13:40:13 -07:00
Becca Royal-Gordon
07b9fe9ce6 Support @objc(CustomName) on extensions
This now specifies a category name that’s used in TBDGen, IRGen, and PrintAsClang. There are also now category name conflict diagnostics; these subsume some @implementation diagnostics.

(It turns out there was already a check for @objc(CustomName) to make sure it wasn’t a selector!)
2024-05-16 13:40:13 -07:00
nate-chandler
bcd08c0c9a Merge pull request #73235 from nate-chandler/bitwise-copyable/enable
[BitwiseCopyable] Promote to feature.
2024-05-04 10:16:40 -07:00
Becca Royal-Gordon
6d3e1ad794 Fix -target in several objcImpl tests 2024-04-30 12:03:46 -07:00
Becca Royal-Gordon
4578be2810 Set a minimum deployment target for objcImpl
We’re not committing to @objc @implementation back-deploying to pre-stable Apple platforms.
2024-04-30 12:03:46 -07:00
Nate Chandler
b1fbe4ea91 [BitwiseCopyable] Remove underscore. 2024-04-25 11:44:15 -07:00
Kavon Farvardin
f0a69a3ef1 prevent uses of Escapable in general
This protocol appears in the stdlib as scaffolding for the
`NonescapableTypes` feature, which is still experimental and not gone
through evolution as an approved addition to the stdlib.

Rather than delete it from the stdlib, because it needs to still remain
to support that feature work, gate references to it behind a feature
flag.

Additionally, prevent documentation from seeing this declaration.

rdar://126705184
2024-04-22 20:40:11 -07:00
Becca Royal-Gordon
6b02202cb9 Merge pull request #71743 from beccadax/objcimpl-implonly 2024-03-29 17:43:01 -07:00
Becca Royal-Gordon
858b557762 Tweak @_objcImpl deprecation warning behavior
• Simpler wording
• Now emitted only if there are no other @objcImpl diagnostics (so @implementation would not emit any new errors)
2024-03-27 17:47:22 -07:00
Becca Royal-Gordon
d2e9fb20cb Guard uses of ObjC in objc_implementation.h
Helps allow test/decl/ext/cdecl_implementation.swift to run on non-ObjC platforms.
2024-03-27 14:29:57 -07:00
Becca Royal-Gordon
2a53433ad7 Soften @impl warnings only for early adopters
Adopting @implementation turns all of the warnings into errors.
2024-03-27 14:29:57 -07:00
Becca Royal-Gordon
29b5a92335 Warn that @objcImpl extension is deprecated
…only when the ObjCImplementation experimental language feature is enabled. (`@implementation extension` is the preferred form.)
2024-03-27 14:29:57 -07:00
Becca Royal-Gordon
492d4ad49d Add experimental feature flags for @implementation
• ObjCImplementation controls @implementation on extensions
• CImplementation controls @implementation and @_objcImplementation on cdecl functions

Why the difference between them? Because `@_objcImplementation extension` has already been adopted pretty widely, while `@_objcImplementation @_cdecl` is very new.
2024-03-27 14:29:57 -07:00
Becca Royal-Gordon
d8f440ee80 Add @implementation as alias for @_objcImpl
They will eventually have slightly different deprecation status and error behavior, but not yet.

Fixes rdar://110728033.
2024-03-27 14:29:23 -07:00
Becca Royal-Gordon
34dd632889 Merge pull request #71858 from beccadax/objcimpl-private-selector-conflict
Soften objcImpl selector conflict errors
2024-02-27 11:51:35 -08:00
Slava Pestov
7909d83229 AST: Refactor directReferencesForTypeRepr() to track inverses 2024-02-24 07:25:59 -05:00
Becca Royal-Gordon
d33002cb34 Soften objcImpl selector conflict errors
The recent change to make objcImpl examine class extensions has collided with a workaround some projects were employing where they declared class extension member implementations `private`. Now that we’re checking class extensions in objcImpl extensions, this workaround is creating selector conflict errors in some circumstances. Soften selector conflict errors in objcImpl extensions to warnings so the affected projects continue to build.

Fixes rdar://123347290.
2024-02-23 21:15:17 -08:00
Kavon Farvardin
f296d8e158 NCGenerics: mass XFAIL tests
It's easier to get a handle on regressions while working through
failures if the tests that are known to not pass are XFAIL'd for
NoncopyableGenerics.
2024-02-20 18:26:05 -05:00
Becca Royal-Gordon
b70ecfaf31 Support objcImpl + implementationOnly
Member implementations are never directly visible to clients of a module, even if they are formally public, but TypeCheckAvailability did not know this. As a result, it would incorrectly diagnose member implementations in an objcImpl extension as violating @_implementationOnly import rules or other, similar access checks. This commit excludes them from being considered as exported declarations.

Fixes rdar://121229058.
2024-02-19 17:13:51 -08:00
Becca Royal-Gordon
6438b96577 Fix crash checking objcImpl block property
ObjCImplementationChecker::matchTypes() implicitly assumed that if it was comparing function types, it must be working on an AbstractFunctionDecl. This isn’t true for a property of block type, which could cause crashes when checking their parameter types. Fix this oversight.

Fixes rdar://122280735.
2024-02-15 12:33:06 -08:00
Becca Royal-Gordon
7aa5b7fd88 Merge pull request #71445 from beccadax/category-error 2024-02-13 11:13:48 -08:00
Becca Royal-Gordon
68ec6b68de Support class extensions in objcImpl
Their requirements are now included when typechecking the main body extension, and their conformances are emitted in IRGen.

Fixes rdar://118535473.
2024-02-09 21:32:06 -08:00
Kavon Farvardin
3ab4c7548c Sema: ban extensions of known marker protocols
There's no good reason to permit them. Conformances like Copyable and
Sendable are pervasive, so it's as though we are permitting extensions
of `Any`. Until there's a good argument in favor of such extensions,
remove the capability now.
2024-02-07 14:54:36 -08:00