Commit Graph

269 Commits

Author SHA1 Message Date
Doug Gregor
587cd4e463 Suppress inference of @_staticInitializeObjCMetadata for "newer" classes.
If a class was introduced in an OS newer than the deployment target,
suppress the inference of @_staticInitializeObjCMetadata, because
the resulting eager initialization will crash when run on older OS's.
This is a stop-gap solution; we want the eager initialization code to
check availability before registering the class, but that requires more
effort.

Fixes the main part of SR-6203 / rdar://problem/35161939.
2017-10-25 17:05:11 -07:00
Slava Pestov
7cbd0c0b37 Sema: Lift restriction on classes conforming to protocols with default implementations returning 'Self'
Now that we pass in the correct type metadata for 'Self', it is
sound for a class to conform to a protocol with a default implementation
for a method returning 'Self'.

Fixes <rdar://problem/23671426>.
2017-10-09 19:53:51 -07:00
Jordan Rose
192b523a8e Revert "Fix issue with 'Self' metadata when class conforms to protocol with default implementations" (#12344)
It broke the 32-bit iOS simulator, and possibly the 64-bit simulator as well. Reverts 5618553.
2017-10-09 10:02:48 -07:00
Slava Pestov
80ada27707 Sema: Lift restriction on classes conforming to protocols with default implementations returning 'Self'
Now that we pass in the correct type metadata for 'Self', it is
sound for a class to conform to a protocol with a default implementation
for a method returning 'Self'.

Fixes <rdar://problem/23671426>.
2017-10-09 00:53:03 -07:00
Alex Hoppen
2dd670ba8b Add test cases for special subscript name 2017-07-11 19:04:13 +02:00
Doug Gregor
a570a5a15e [Type checker] Check type equality even for argument tuples in Swift 4.
Replace a where Type-pointer-equality check with what it intended,
i.e., match up ParenTypes at the top level and perform a deeper
equality comparison of the underlying types.

Fixes SR-5166 / rdar://problem/32666189.
2017-06-20 23:49:47 -07:00
Xi Ge
568c861adc [FixCode] Protocol stubs shouldn't print any @ attributes.
This also addresses @jrose-apple's code review comments.
2017-06-16 16:04:57 -07:00
Xi Ge
088e4cd56b test: use platform-independent @available attribute and re-enable fixit_stub_editor.swift (#10322) 2017-06-16 14:02:54 -07:00
Jordan Rose
65ccd84943 [test] Disable fixit_stub_editor.swift entirely until fixed. (#10312)
Tracked by rdar://problem/32804941.
2017-06-16 09:33:46 -07:00
Mishal Shah
946cc75fbb Revert "Build fix: Update fix-it stub editor test"
This reverts commit 9a17226d26.
2017-06-15 22:17:53 -07:00
David Farler
9a17226d26 Build fix: Update fix-it stub editor test 2017-06-15 16:20:12 -07:00
Xi Ge
a2e5910efa FixCode: when inserting protocol stubs, avoid inserting @available. rdar://32645956 (#10272) 2017-06-14 20:49:42 -07:00
Jordan Rose
485ebefba7 Merge pull request #10083 from jrose-apple/nscoding-diags-take-2
Update and re-enable the diagnostics for unstable runtime names
2017-06-05 19:51:01 -07:00
Jordan Rose
5c1967397b Update and re-enable the diagnostics for unstable runtime names.
This time, the warnings only fire when the class in question directly
conforms to NSCoding. This avoids warning on cases where the user has
subclassed something like, oh, UIViewController, and has no intention
of writing it to a persistent file.

This also removes the warning for generic classes that conform to
NSCoding, for simplicity's sake. That means
'@NSKeyedArchiverEncodeNonGenericSubclassesOnly' is also being
removed.

Actually archiving a class with an unstable mangled name is still
considered problematic, but the compiler shouldn't emit diagnostics
unless it can be sure they are relevant.

rdar://problem/32314195
2017-06-05 17:32:26 -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
Dmitri Gribenko
984210aa53 tests: replace '// RUN: rm -rf' '// RUN: mkdir' pairs with '%empty-directory(...)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Mark Lacey
88077c33bf Merge pull request #9842 from rudkx/fix-rdar32215763
Make getWitnessType() return Type() for ErrorType.
2017-05-22 15:51:09 -07:00
Mark Lacey
ceacfb4c53 Make getWitnessType() return Type() for ErrorType.
None of the clients of this care about distinguishing between immediate
failures in getWitnessType() vs. earlier errors that result in
getWitnessType() returning ErrorType, so simplify the interface by
having it always return Type() if there is a problem.

Update the clients that were not already checking for null result to do
so.

Fixes rdar://problem/32215763.
2017-05-22 14:33:00 -07:00
Doug Gregor
f0abcac42c Diagnose unsound uses of same-type-to-Self requirements with non-final classes.
Protocol requirements involving same-type-to-Self constraints cannot
be witnessed by declarations in non-final classes that have the same
form of same-type requirement to the corresponding class type, because
it creates a soundness hole with subclasses:

    protocol Q {
      func foo<T: P>(_: T, _: T.T) where T.T == Self
    }

    class C: Q {
      func foo<T: P>(_: T, _: C) where T.T == C {}
    }

    class D: C {
      // in D, T.T == D does not hold
    }

Warn about this in Swift 3 compatibility mode, error on it in Swift 4
mode. When possible, provide a note + Fix-It suggesting that the
same-type constraint might be weakened to a superclass constraint
(which works with subclassing).

Fixes rdar://problem/30398503.
2017-05-22 09:31:27 -07:00
Jordan Rose
4a46d47a05 Disable diagnostics about problem NSCoding-conforming classes for now. (#9808)
Adoption so far shows that the criteria we set up here are too broad.
This is particularly problematic for subclasses of NS/UIView and the
like that might never be encoded at all.

rdar://problem/32306355
2017-05-20 14:26:30 -07:00
Slava Pestov
e58ae766a3 Fix and un-XFAIL regressed crashers from recent stdlib change 2017-05-17 05:51:51 -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
23bc3223ce Ban the use of @_staticInitializeObjCMetadata; it's an implementation detail. 2017-05-10 14:58:42 -07:00
Doug Gregor
6ceb47bd6c [Type checker] Provide actual ObjC runtime name in @NSKeyedArchiveLegacy Fix-Its. 2017-05-10 14:47:11 -07:00
Doug Gregor
ef7b8039ec [Type checker] Warn about classes conforming to AnyObject in Swift 3 mode.
Swift 3 allowed a class to explicitly conform to AnyObject, although
it was meaningless. Recent AnyObject-related changes started rejecting
such conformances as ill-formed; allow them with a warning + Fix-It in
Swift 3 compatibility mode.
2017-05-04 10:28:27 -07:00
Doug Gregor
3dbfa9789f [Associated type inference] Check solutions against full requirement signature
When we have a potential assignment of associated types to type
witnesses during associated type inference, check that set of type
witnesses against the requirements in the requirement signature, so
that we can reject any solutions that fail some of the protocol's
requirements.

This is most of rdar://problem/31830524 --- but gets thwarted by the
inability of associated type inference to work across multiple
protocols.
2017-05-04 00:21:52 -07:00
Doug Gregor
66f38da9a3 Merge pull request #9206 from DougGregor/NSKeyedArchiveLegacy
Warn about NSCoding classes with unstable mangled names
2017-05-03 08:20:23 -07:00
Doug Gregor
c805da7291 Improve/clarify the inference of @_staticInitializeObjCMetadata.
Infer @_staticInitializeObjCMetadata in those cases where we need a
static initializer to make an NSCoding-conforming class visible to the
Objective-C runtime. This does *not* include classes with one of the
@NSKeyedArchive attributes:

* @NSKeyedArchiveLegacy implies that we'll register the class
  directly, with the necessary side effect of initialize Objective-C
  metadata.
* @NSKeyedArchiveSubclassesOnly promises not to archive the class
  directly anyway.
2017-05-02 23:30:28 -07:00
Doug Gregor
bf7a8612e6 Add @NSKeyedArchiveSubclassesOnly to suppress NSCoding unstable name diags.
Introduce the @NSKeyedArchiveSubclassesOnly attribute, which can be
placed on a class that conforms to NSCoding to suppress the
unstable-name diagnostics by promising to only archive
subclasses---not this class directly.
2017-05-02 23:30:28 -07:00
Doug Gregor
9b65c85b44 Make diagnostics for NSCoding classes with unstable names more discouraging.
The diagnostic regarding NSCoding classes with unstable names can be
suppressed by adding @objc (the preferred solution for new code) or
@NSKeyedArchiveLegacy (for existing archives). Provide those as
Fix-Its, in that order.

(Thanks, Jordan!)
2017-05-02 23:30:28 -07:00
Doug Gregor
e6c6470f1e Properly warn about local classes that conform to NSCoding. 2017-05-02 23:30:28 -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
b912c7f7e1 Diagnose attempts to apply @NSKeyedArchiveLegacy to a generic class.
Generic classes don't have a single name to register, so disallow
@NSKeyedArchiveLegacy.
2017-05-02 22:38:32 -07:00
Doug Gregor
60f5a6529e Add Fix-Its suggesting @NSKeyedArchiveLegacy when it can be used. 2017-05-02 22:38:32 -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
Doug Gregor
28560ec005 [Type checker] Warn about NSCoding-conforming classes with unstable mangled names.
The name mangling changed from Swift 3 to Swift 4, and may get slight
tweaks as we lock down ABI stability. Identify and warn about (in
Swift 3) or error about (in Swift 4) the cases where we don't have
obviously-stable name mangling, e.g.,

* private/fileprivate classes (whose mangled names involve the file name)
* nested classes (whose mangled names depend on their enclosing type)
* generic classes (whose mangled names involve the type arguments)
2017-05-02 21:45:18 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Xi Ge
89d50e366f [Sema] -serialize-diagnostics-path should imply -diagnostics-editor-mode so that live issues and editor builds can have the consistent behavior. (#9166) 2017-05-02 10:53:38 -07:00
Doug Gregor
f7bccb0e68 [Type checker] Downgrade some "redundant conformance" errors to warnings.
When an extension introduces a conformance that already exists, the
type checker will reject the conformance and then ignore it. In cases
where the original conformance is in the same module as the type or
protocol (but the new, redundant conformance is in some other module),
downgrade this error to a warning. This helps with library-evolution
cases where a library omitted a particular conformance for one of its
own types/protocols in a previous version, then introduces it in a new
version.

The specific driver for this is the conformance of String to
Collection, which affects source compatibility. Fixes
rdar://problem/31104415.
2017-05-01 13:22:15 -07:00
Xi Ge
509a99b71d FixCode: for missing type witnesses with default definitions, avoid inserting stubs. (#8068) 2017-03-14 11:03:14 -07:00
Xi Ge
555e52206a Sema: fill-protocol-stub fixits should include those missing witnesses that are handled by delayed diagnostics. (#8011) 2017-03-10 11:54:25 -08:00
Xi Ge
b5256f53b2 Sema: introduce a language option flag, DiagnosticsEditorMode. (#7982)
SourceKit always sets it positively. This may lead to more aggressive fixits however
less informative messages. We currently use the flag only for filling protocol stubs.
2017-03-08 12:46:02 -08:00
Xi Ge
5d2cd20051 Sema/FixCode: Introducing a wrapper for ConformanceChecker to fix missing stubs for multiple protocols in a single fixit invocation. (#7937) 2017-03-06 16:37:43 -08:00
Xi Ge
d6cc431a8d [FixCode] Enhance existing fill-protocol-stub fixit so that all missing witnesses can fixed at once. 2017-03-02 14:48:20 -08:00
Joe Groff
6d9a40f455 Sema: Treat the implicit RawRepresentable conformance for enums as Synthesized again.
This reverts part of #4038 which made the compiler consider it to be an `Explicit` conformance, breaking source code that was accepted in Swift 3.0 which declared a raw type as well as explicit conformance to `RawRepresentable` (reported as rdar://problem/30386658). While I'm here, a couple of spot fixes:

- Ensure an enum's raw value exprs are type-checked before checking conformances of any of its extensions, since the RawRepresentable conformance derivation will blow up if the raw value exprs haven't been checked. Fixes an order dependency issue if `extension Foo: RawRepresentable {}` gets checked before `enum Foo: Int { ... }`.
- Don't display the custom `enum_declares_rawrep_with_raw_type` diagnostic if the source location for the enum's inheritance clause is invalid, so that we don't emit a dislocated diagnostic.
2017-02-08 15:31:17 -08:00
Slava Pestov
45ef0f5dfb Sema: Generic types cannot witness associated type requirements
Until recently we didn't allow nested generic types at all.
In Swift 3, generic typealiases were added, and we forgot to
guard against them in witness matching, leading to a crash if
a generic typealias witnesses an associated type requirement.

Now that nested generic nominals are allowed too, add a check.

The diagnostic is not very good, but I'll revisit this later.
2016-12-18 22:34:16 -08: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
1df6e51c14 AST: Only print DynamicSelfType as 'Self' for class types
This fixes a regression from the previous patch which got
rid of PrintOptions::StripDynamicSelf.

When printing protocol declarations with a BaseType set in
PrintOptions, we can end up with a DynamicSelfType wrapping
a non-class type, if the protocol requirement returned
Self.

Note that this changes the diagnostic for missing protocol
requirements slightly; we used to sometimes refer to 'Self'
even if the conforming type is not a class, which is not
accepted by the type checker anyway. I believe the new
diagnostics are more correct.
2016-11-19 22:53:54 -08:00
Doug Gregor
77942d37d5 Tighten up @objc optional near-miss detection heuristics.
The @objc optional requirement near-miss heuristics were too
permissive, and could occasionally produce ridiculous results that
were nowhere close to a "near" miss. Make the diagnostics more
conservative, and fix an issue with an errant sentinel value.

Fixes rdar://problem/26380688.
2016-10-19 10:55:47 -07:00
Doug Gregor
da2a7cef46 Don't complain about near misses for declarations that are overrides.
An overriding declaration doesn't have a choice about its signature,
because the signature is dictated by the overridden
declaration. Therefore, don't produce a warning for it.

Fixes rdar://problem/28524237.
2016-10-18 11:25:22 -07:00