Commit Graph

327 Commits

Author SHA1 Message Date
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
Slava Pestov
ea15d9f9b2 Stop passing -warn-redundant-requirements in tests 2024-02-02 14:57:19 -05:00
Becca Royal-Gordon
e5dbe40367 Stub out basic tests for future extensions
We eventually want to be able to implement functions imported as globals or members in Swift, but we’re not there yet. Add some basic tests to make sure we get reasonable diagnostics for them.
2023-12-13 11:09:50 -08:00
Becca Royal-Gordon
9bd70f3aec Test cImpl type and name mismatches 2023-12-13 11:09:50 -08:00
Becca Royal-Gordon
426e5beb8d Begin checking cdecl implementations
This commit diagnoses cdecl implementations with no matching imported declaration, and also runs them through the ObjCImplementationChecker. Actually testing that the ObjCImplementationChecker diagnoses various failure conditions correctly will be added in a subsequent commit.
2023-12-13 11:09:50 -08:00
Becca Royal-Gordon
8651af4325 Make @objcImpl work with @_cdecl
No real diagnostics yet, but we’re emitting mostly correct code.
2023-12-13 11:09:49 -08:00
Becca Royal-Gordon
6b795a493e Diagnose lightweight generic classes with objcImpl
Extensions to lightweight generic classes are such a huge mess that we’re just removing these from the feature’s scope for now.

Fixes rdar://116066409.
2023-10-25 16:20:16 -07:00
Becca Royal-Gordon
81b5d59363 Diagnose root classes with @objcImpl
@objcImpl, like @objc, cannot be used to implement root classes. Diagnose an attempt to do so.

Fixes rdar://109130979.
2023-10-25 16:20:16 -07:00
Becca Royal-Gordon
1b7adbe6fd Diagnose invalid Swift-only @objcImpl inits
Required and designated inits have to be overridable—the former so that uses of the initializer on `any T.Type` will call the subclass initializer, the latter so that inherited convenience inits will call the subclass initializer. However, Swift-only members use vtables to dispatch to subclasses, and @objcImpl classes don’t have vtables, so their Swift-only inits cannot be made overridable. Upshot: Swift-only inits on @objcImpl classes must be `convenience`, not `required` or designated.

Enforce this rule in the ObjCImplementationChecker.

Fixes rdar://109121293.
2023-10-24 12:33:56 -07:00
Becca Royal-Gordon
9bb71ff91f Add @objcImpl vtable fallback diagnostic
Nothing in an `@_objcImplementation` block—including Swift-only declarations—should ever require a vtable entry. Diagnose any such members.

The diagnostic emitted here is intended to be a fallback that will be used when a vtable entry is needed but we don’t know the specific reason. A future commit will add a more specific diagnostic for Swift-only non-convenience inits.
2023-10-24 12:32:42 -07:00
Becca Royal-Gordon
231de1a666 Add ObjCReason for @objcImpl
Besides improving diagnostics, this also allows us to track whether there were any @objc failures using the invalid bit on the @_objcImplementation attribute.
2023-10-24 10:21:37 -07:00
Becca Royal-Gordon
76f25e53d9 Allow @nonobjc inits in objcImpl extensions
Initializers can’t be made final, but they *can* be made @nonobjc. (This isn’t always enough to ensure they’re actually valid, but I’ll get to that in a follow-up commit.)
2023-10-24 10:21:37 -07:00
Becca Royal-Gordon
2ff70e00ce Replace existing access control in objcImpl fixit
The fix-it suggesting that an unmatched `@objc`-able member can be turned `private` always suggested adding a new modifier, even if one already existed. Make it suggest replacing the existing one instead.
2023-10-24 10:21:37 -07:00
Becca Royal-Gordon
b69e416f7c Support overrides of unavailable inits in objcImpl
Suppose a superclass declares an initializer unavailable and then a subclass wants to redeclare and use it. Formally, the subclass declaration overrides the superclass one; however, Swift will not actually require the subclass to use the `override` keyword. As currently implemented, this means that the requirement will be skipped as an override, but the candidate will be included as a member implementation. Result: a “candidate does not match any requirement” diagnostic.

Fix this by skipping requirements that are overrides *only* if the declaration they override is not unavailable.

Fixes rdar://109541045.
2023-10-19 15:42:20 -07:00
Slava Pestov
fd06bd87aa AST: Allow the extended type of an extension to refer to be a tuple type
Either directly, or via a type alias.
2023-09-05 23:21:26 -04:00
Becca Royal-Gordon
fa0e6285fc Merge pull request #67925 from beccadax/objcimpl-warning-main
Temporarily soften @objcImpl errors into warnings
2023-08-16 01:34:39 -07:00
Becca Royal-Gordon
ad960a1e2d Temporarily soften @objcImpl errors into warnings
Temporarily cherry-pick Swift 5.9’s behavior of turning @objcImplementation errors into warnings to 5.10 until we fix the last few bugs in these diagnostics.
2023-08-14 16:49:51 -07:00
Becca Royal-Gordon
37e42d178f Handle inherited required inits in @objcImpl
Because `required init`s do not have the `override` keyword, they are always treated as member implementations (if they pass other checks). However, these methods sometimes actually are overrides, and when they are, they should not be treated as member implementations. This results in required inits being treated as candidates when there won’t be a requirement for them to match.

Hack around this by separately checking for this situation and skipping the affected members.

Fixes rdar://112910098.
2023-08-14 11:06:35 -07:00
Becca Royal-Gordon
1d6b041e58 Reword @objcImpl diagnostics to avoid “an”
…and also adopt new DiagnosticEngine features.
2023-07-19 13:08:12 -07:00
Becca Royal-Gordon
a8fbad3551 Match @objcImpl members’ foreign error conventions
ClangImporter can import some methods as throwing that `@objc` cannot generate. For instance, an imported Objective-C method with an error out parameter in an unconventional position can still be imported as throwing no matter its selector, but `@objc` can only generate an error out parameter in an unconventional position if the matching selector part consists of the word `error` or (for the first part) ends with `Error`. Detect and diagnose these situations.

Note that the tests do not cover all of the new diagnostics because some of these conditions (like the `Void` parameter) cause selector mismatches and others (like the owned error parameter) are representable in the compiler but cannot currently be imported. I have chosen to add these diagnostics anyway in case there is a corner case that I haven’t discovered.

Fixes rdar://110100071.
2023-06-27 16:08:49 -07:00
Pavel Yaskevich
ce4ec06547 Merge pull request #66796 from xedin/rdar-111059036
[CSSimplify] Add special handling if specialized type comes from `TypeExpr`
2023-06-23 09:08:39 -07:00
Becca Royal-Gordon
49831a9e93 Fix @objcImpl crash with async/sync overloads
The @objcImpl checker would accidentally dereference a null pointer when it tried to check if an async requirement could be satisfied by a non-async method. Fix that mistake.

Fixes rdar://111064481.
2023-06-22 13:15:56 -07:00