Commit Graph

31 Commits

Author SHA1 Message Date
Jordan Rose
33ed767933 [ClangImporter] Preserve the names of imported ObjC properties. (#6182)
This is necessary for proper working of #keyPath, as well as improving
the experience of PrintAsObjC.

rdar://problem/28543037
2017-01-10 13:37:12 -08:00
Jordan Rose
7ae0825781 [ClangImporter] Default optional "options" params to nil, not [:]. (#3789)
When a parameter has distinct "nil" and "empty" values, "nil"
generally represents the default settings, while "empty" is
explicitly cleared.

rdar://problem/27196867
2016-07-28 23:09:05 -07:00
Jordan Rose
bc83940301 Make pointer nullability explicit using Optional.
Implements SE-0055: https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md

- Add NULL as an extra inhabitant of Builtin.RawPointer (currently
  hardcoded to 0 rather than being target-dependent).
- Import non-object pointers as Optional/IUO when nullable/null_unspecified
  (like everything else).
- Change the type checker's *-to-pointer conversions to handle a layer of
  optional.
- Use 'AutoreleasingUnsafeMutablePointer<NSError?>?' as the type of error
  parameters exported to Objective-C.
- Drop NilLiteralConvertible conformance for all pointer types.
- Update the standard library and then all the tests.

I've decided to leave this commit only updating existing tests; any new
tests will come in the following commits. (That may mean some additional
implementation work to follow.)

The other major piece that's missing here is migration. I'm hoping we get
a lot of that with Swift 1.1's work for optional object references, but
I still need to investigate.
2016-04-11 20:06:38 -07:00
Dmitri Gribenko
dd75aed67a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-17 14:40:05 -08:00
practicalswift
9eb2ee0638 [gardening] Fix accidental double spaces 2016-02-14 17:30:44 +01:00
Doug Gregor
1a38e0ad3b Merge branch 'master' into swift-3-api-guidelines 2016-01-06 15:32:55 -08:00
Doug Gregor
5aa40dd0aa Extend DefaultArgumentKind with cases for nil, [], and [:].
Under -enable-infer-default-arguments, the Clang importer infers some
default arguments for imported declarations. Rather than jumping
through awful hoops to make sure that we create default argument
generators (which will likely imply eager type checking), simply
handle these cases as callee-side expansions.

This makes -enable-infer-default-arguments usable, fixing
rdar://problem/24049927.
2016-01-06 10:19:12 -08:00
Doug Gregor
06c5e9cd5b Enable "omit needless words" by default.
Most of this is in updating the standard library, SDK overlays, and
piles of test cases to use the new names. No surprises here, although
this shows us some potential heuristic tweaks.

There is one substantive compiler change that needs to be factored out
involving synthesizing calls to copyWithZone()/copy(zone:). Aside from
that, there are four failing tests:

    Swift :: ClangModules/objc_parse.swift
    Swift :: Interpreter/SDK/Foundation_test.swift
    Swift :: Interpreter/SDK/archiving_generic_swift_class.swift
    Swift :: Interpreter/SDK/objc_currying.swift

due to two independent remaining compiler bugs:
  * We're not getting partial ordering between NSCoder's
  encode(AnyObject, forKey: String) and NSKeyedArchiver's version of
  that method, and
  * Dynamic lookup (into AnyObject) doesn't know how to find the new
  names. We need the Swift name lookup tables enabled to address this.
2015-12-11 14:46:50 -08:00
Jordan Rose
8edbbef5fe [ClangImporter] Use real negative literals for imported constants.
The old code predates NumberLiteralExpr having a "negative" field.
Fixing this avoids creating a temporary signed integer with a value of
INT_MAX+1 when trying to compute INT_MIN.

rdar://problem/21680700

Swift SVN r30814
2015-07-30 21:55:04 +00:00
Jordan Rose
de1b83659d [test] We expect to find NSString in the Foundation module.
Import our fake Foundation rather than redeclaring NSString in SILGen's
fake "gizmo" module...then fix up other tests to more carefully use SILGen's
mock SDK in avoiding the real set of overlays...using -enable-source-import.

In the mid-term SILGen should probably switch to using the shared
clang-importer-sdk in test/Inputs/. In the long term we need that to be
using proper modules too rather than -enable-source-import.

No intended functionality change, but without this the next commit breaks
things (because members are deserialized less eagerly).

Swift SVN r27195
2015-04-10 01:31:24 +00:00
Doug Gregor
f05cd00036 Handle reference storage types in the optional-injection workaround from r21176.
Swift SVN r21179
2014-08-13 18:57:30 +00:00
Doug Gregor
21dcd07846 Extend the optional-injection-of-erroneous-nil hack for more entities.
r21096 introduces an optimization barrier for failing initializers
that allows the pattern

  let x: NSFoo? = NSFoo()

be used to detect whether NSFoo() returned nil, even though the type
system says it cannot. Extend this check to Objective-C methods and
properties, where the non-optional annotation may be incorrect
<rdar://problem/17984530>.




Swift SVN r21176
2014-08-13 16:44:53 +00:00
Joe Groff
5e7b22ac5e Test more cases of delegation to foreign initializers.
Swift SVN r19993
2014-07-15 23:50:05 +00:00
Joe Groff
0cb3091f30 SILGen: Foreign initializers always require @objc dispatch.
Covers the case where a convenience initializer delegates to a factory initializer of an imported class.

Swift SVN r19990
2014-07-15 23:36:46 +00:00
Joe Groff
47d04ddba8 AST: Always require objc dispatch on foreign accessors.
Swift SVN r19842
2014-07-11 00:53:21 +00:00
Doug Gregor
6bbbda2798 Make the structure of SILGen's "fake" bridging SDK look more like the real thing.
Specifically, introduce an ObjectiveC model written in Objective-C, and put the relevant, de-duplicated bits (such as NSObject) there. Use -I %S/Inputs -enable-source-import wherever we need to use this bridging SDK.

Swift SVN r17836
2014-05-10 19:50:58 +00:00
Joe Groff
bf858cc8a1 SILGen: Handle inner pointer returns through currying and dynamic lookup.
When we partially apply an inner-pointer method or property, the thunk or partial_apply that applies "self" needs to be the one that handles lifetime-extending "self". Verify that a partial_apply-ed inner pointer method is not inner pointer and implement lifetime extension in the partial apply thunk. Fixes <rdar://problem/16803701>.

Swift SVN r17321
2014-05-03 18:37:42 +00:00
Joe Groff
a3a54545e5 SIL: Fix up ownership and bridging when emitting dynamic method calls.
There were a bunch of things broken here--it's amazing this ever appeared to work.

- Retain 'self' before partial_applying it to the method, so we don't overrelease it.
- Correctly lower the ownership conventions of the dynamic method against the SILDeclRef, so we don't overrelease arguments or over-over-release self, and we handle ObjC methods with weird conventions correctly.
- Thunk when there are bridging type differences between the partially-applied ObjC method and a Swift method, so we don't crash if the method takes NSStrings or other bridged types.

Add verifier checks that the result of 'dynamic_method' and BB arg of 'dynamic_method_br' actually match the method they're dispatching.

Swift SVN r17198
2014-05-01 22:46:11 +00:00
Joe Groff
164870c0c3 SILGen: Reenable partial application of ObjC methods.
Make ObjC method partial applications go through a native-to-foreign thunk so that we properly handle bridging conversions in the resulting function value. Partial applications through dynamic lookup are still broken because they apparently go through a different path.

Swift SVN r17108
2014-04-30 19:57:44 +00:00
Joe Groff
5b7659fed9 ClangImporter: Stop building thunks for @objc properties and just use the imported getter/setter decls for the computed property.
This saves us some work producing dead thunks we no longer use, and also makes us correctly handle NS_RETURNS_INNER_POINTER getters.

Swift SVN r16639
2014-04-22 03:13:49 +00:00
Joe Groff
d90f9d46ae SILGen: Lifetime-extend the "self" parameters of inner-pointer methods.
Do this the lazy way, just autoreleasing "self" after the call. A future optimization pass may be able to eliminate this autorelease when it recognizes the lifetime of the derived value, but that's not immediately necessary.

Swift SVN r16635
2014-04-22 00:25:17 +00:00
Chris Lattner
adff5375fe Initial support for the @NSCopying attribute on properties. This is enough to
wire it up, do basic semantic analysis and code gen a simple case of it.  There is
more type checking work to come, so it isn't complete yet.

This is the first step to:
<rdar://problem/15864836> Need a @NSCopying attribute for Cocoa types that aren't manually bridged



Swift SVN r16345
2014-04-15 00:31:59 +00:00
Joe Groff
03a7b98806 SILGen/IRGen: Don't emit redundant witness thunks for @objc protocol witnesses that are already @objc.
If an extension introduces an @objc protocol conformance using existing methods that are already @objc, then we shouldn't emit @objc thunks for them again, and indeed, we can't for native ObjC classes. Fixes <rdar://problem/16330856>.

Swift SVN r15087
2014-03-14 22:48:59 +00:00
Joe Groff
c5feea4697 SILGen: Emit conformances for external definitions.
Teach IRGen to honor the linkage of SILWitnessTables, and teach SILGen to emit witness tables and protocol witness thunks for external definitions with shared linkage. Fixes <rdar://problem/16264703>.

Swift SVN r14908
2014-03-11 05:08:58 +00:00
Doug Gregor
00162dc243 Start emitting stubs for unimplemented designated initializers of the superclass.
When a subclass does not implement a designated initializer of its
superclass, introduce a stub initializer that simply traps. Such stubs
cannot be invoked directly using Swift syntax, but can be invoked
through the Objective-C runtime and from Objective-C code. Catch such
errors rather than allowing them to violate the memory safety of the
language.

Note that we're currently using cond_fail to trap; this will be
improved in the future,


Swift SVN r14839
2014-03-09 07:16:30 +00:00
Joe Groff
3a680d6dc1 SILGen: Add some tests for Clang-imported properties.
We aren't handling block properties correctly as @objc, so add a FIXME'd test for that. Also enable a test that now works.

Swift SVN r14739
2014-03-06 17:44:56 +00:00
Argyrios Kyrtzidis
3882ab6bd4 [ClangImporter] When checking for NS_ENUM/NS_OPTIONS enums, use clang::Preprocessor::getImmediateMacroName()
and check for CF_ENUM/CF_OPTIONS, which NS_ENUM/NS_OPTIONS expand to.

This:
- Simplifies code
- Handles CF_ENUM/CF_OPTIONS enums
- Handles correctly an NS_ENUM/NS_OPTIONS enum that was itself expanded from another macro.

Swift SVN r11542
2013-12-21 17:40:28 +00:00
Joe Groff
6f519d7b6f SILGen: Emit enum constructors for Clang-imported enums.
Swift SVN r9990
2013-11-06 06:31:26 +00:00
Greg Parker
9fe5f880c4 Objective-C Class<Proto> is unretained just like unqualified Class.
Swift SVN r8613
2013-09-24 23:18:55 +00:00
Doug Gregor
9b0525bc70 Objective-C "Class" (which maps to DynamicLookup.metatype) is unretained.
Swift SVN r8554
2013-09-23 15:13:56 +00:00
Stephen Lin
bb92973204 Reorganize test/SIL to match lib/SIL reorganization
Swift SVN r7247
2013-08-15 00:08:20 +00:00