Commit Graph

423 Commits

Author SHA1 Message Date
Doug Gregor
dfc8d5a5f8 [Sema/SILGen] Track per-source-file "used" conformances to reference in SILGen
Sema was dutifully tracking conformances that were "used" as part of
type checking, so it could make sure that those conformances got
completed for SILGen to use. However, this information never actually
made it to SILGen, which included its own (more conservative, not
broad enough) heuristics for finding "used" conformances. Teach Sema
to record conformances within the appropriate source file, and have
SILGen reference the conformances when it emits SIL for the source
file.
2016-05-09 20:43:12 -07:00
Michael Ilseman
c62eb2e5aa [swift_newtype] Handle un-audited CF types
Special case logic for CF types, which may be coming in as
unmanaged. In this case, we will use audit information if present to
import with the new type, otherwise we have to fall back to
Unmanaged<CF...>.

We still import global variables that must be unmanaged onto the new
type, though they keep their unmanaged types. This helps to
consolidate the definitions, as well as make future migration easier
if they get audited.

Test cases included.
2016-05-09 14:26:26 -07:00
Jordan Rose
fee9c2a130 Allow importing pointer-returning methods as throwing. (#2420)
Leftover bits of SE-0055. Now that pointer nullability is reflected
in the type system, we can properly import throwing methods with
non-object pointer return types.

Note that Swift still won't let you declare them. That's coming next.
2016-05-09 09:58:09 -07:00
Doug Gregor
de7ef4b676 [Clang importer] Don't prefix-strip notification names. 2016-05-08 23:55:50 -07:00
Michael Ilseman
a8cebdc5d3 [swift_newtype] Special handling for Notifications
We now specially import global decls who we identify as fitting the
notification pattern: extern NSStrings whose name ends in
"Notification". When we see them, we import them as a member of
NSNotificationName and, if NSNotificationName is swift_newtype-ed, we
use that new type.

Test cases included.
2016-05-08 19:17:32 -07:00
Doug Gregor
c390c97255 [Clang importer] Minor fixes for swift_newtype name adjustments. 2016-05-07 14:44:48 -07:00
Michael Ilseman
0c011c328c Merge pull request #2170 from milseman/coregraphics
[Import as member] Don't pair up get/set pairs from other modules
2016-04-27 07:00:00 -07:00
Michael Ilseman
aa1a68552d Merge pull request #2319 from milseman/newtype
[Clang importer] swift_newtype with bridged computed rawValue
2016-04-26 21:57:42 -07:00
Michael Ilseman
15e7d1f6d7 [Clang importer] Code re-use and testing.
Incorporates review feedback to re-use code more. Improves
swift_newtype testing by also testing non-bridging path.
2016-04-26 16:44:31 -07:00
Doug Gregor
a82cc07ee0 [Omit needless words] Strip context from "set" methods.
Fixes rdar://problem/25750367.
2016-04-26 16:42:35 -07:00
Doug Gregor
6e680798ae [Omit needless words] Treat "separated by" as a single preposition.
Fixes rdar://problem/25883450.
2016-04-26 16:05:08 -07:00
Doug Gregor
97e89471fe [Omit needless words] Treat "bound by" as a preposition.
Fixes rdar://problem/25729953.
2016-04-26 15:23:55 -07:00
Michael Ilseman
0c67ddd8b6 [Clang importer] swift_newtype with bridged computed rawValue
For swift_newtype structs that we create, we sometimes need to provide
a bridged type interface. In these cases, we use the original
non-bridged type as an underlying stored value, and create a computed
rawValue of bridged type. We similarly create an init() taking the
bridged type, and cast it appropriately to/from storage.

Tests updated.
2016-04-26 15:12:50 -07:00
Doug Gregor
2477206ed4 [Clang importer] Mark discardableResult attribute "implicit".
The Clang importer implicitly synthesizes @discardableResult for
nearly all imported functions. Printing this attribute in the
generated interface leads to a lot of noise. Mark it as implicit so we
don't print it.
2016-04-26 14:48:39 -07:00
Michael Ilseman
9c31aa45c5 [Clang Importer] implement swift_newtype(enum) as struct
This is a temporary solution that implements swift_newtype(enum) as
though it were written swift_newtype(struct). This is to work around
to the fact that a String-backed enum does not actually have a String
stored, and a struct is closer to reflecting that storage
properly. Struct provides most of the functionality and appearance for
now, though it does not allow for switching over the values.

Full support for swift_newtype(enum) as a Swift enum is forthcoming.
2016-04-21 16:43:52 -07:00
Michael Ilseman
faceb558d7 [Clang Importer] Initial support for swift_newtype(struct)
This introduces support for swift_newtype(struct) attribute (also
known as swift_wrapper). The Clang importer will create a brand new
struct corresponding to the annotated typedefs, which has a backing
raw value. Globals of that type are imported as static members on the
struct.

Additionally, this interacts seamlessly with prior import-as-member
work, meaning that the newly created type can be imported onto. Tests
included.
2016-04-21 16:40:10 -07:00
Michael Ilseman
08ac432d3c [Import as member] Don't pair up get/set pairs from other modules
While inferring get/set, we paired them up even when one of them was
available through a custom objc header (e.g. a private
header). Instead, fail to pair them up. Test case added.
2016-04-13 13:08:16 -07:00
Joe Groff
7feb60da04 SILGen: Handle C functions imported as labeled unit constructors. 2016-04-13 08:17:04 -07:00
Chris Lattner
066f285fbc tweak a few testcases that still fail with the @discardableResult attribute being auto-applied by the clang importer. 2016-04-12 19:40:09 -07:00
Trent Nadeau
8a55e428f4 Imported C decls w/o warn_unused_result get @discardableResult 2016-04-13 00:39:07 +00:00
Michael Ilseman
16baa6286c Merge pull request #2156 from jckarter/import-as-static-member-edge-cases
Clang importer: Global vars imported as static member properties are final.
2016-04-12 10:39:57 -07:00
Joe Groff
fe7c1ca670 Clang importer: Global vars imported as static member properties are final. 2016-04-12 10:03:48 -07:00
Ted Kremenek
6eb16f6550 Revert "Clang importer: Global vars imported as static member properties are final." (#2155) 2016-04-12 08:24:29 -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
Joe Groff
08a4267f66 Clang importer: Global vars imported as static member properties are final. 2016-04-11 18:02:41 -07:00
Michael Ilseman
1fdd1535d1 [Import as member] Simplified SILGen test for global assert 2016-04-11 15:29:23 -07:00
Michael Ilseman
151a19d3b8 [Import as member] Fixes to apinotes and tests
Fixes and clarifies a few API notes, and adds some test cases showing
current SILGen issues.
2016-04-11 11:31:12 -07:00
practicalswift
ea0ac3ac67 [gardening] Remove all tabs in C++ code 2016-04-08 21:22:57 +02:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Doug Gregor
138bbe2167 [Clang importer] Delay resolution of import-as-member declarations when needed.
It's possible for swift_name to make a global declaration into a
member of another entity that has not been seen yet. In such cases,
delay resolution until the end of the translation unit (module). Fixes
the rest of rdar://problem/25502497.
2016-04-05 00:03:36 -07:00
Doug Gregor
398d216eca [Clang importer] Always pass an effective context to importDeclContextOf.
Some of the callers to importDeclContextOf could and should have
passed an effective context, but didn't, so (e.g.) an enum defined in
C couldn't be mapped to a nested type in Swift. Eliminate the
single-argument importDeclContextOf honeypot so we remember to pass
down the effective Clang context. Fixes rdar://problem/25502497.
2016-04-04 15:18:37 -07:00
Jordan Rose
50e3b33739 [ClangImporter] Implement importing of ObjC class properties.
For the most part this was just "check isInstanceProperty"; the one feature not yet implemented
is the emission of ObjC metadata for class properties.

rdar://problem/16830785
2016-03-31 14:27:56 -07:00
Joe Groff
56ed71096f IRGen: Ignore generic parameters of SIL @convention(c) types.
That's the lowering we get for C functions imported as members of protocols.
2016-03-30 13:59:48 -07:00
Michael Ilseman
884155c09c [Import as member] Refactor testing.
Separate out error tests, so that we can more extensively test
protocol and non-prototype errors. NFC
2016-03-28 15:41:48 -07:00
Michael Ilseman
4e4c511cf0 [Import as error] Error on non-prototyped function declarations 2016-03-28 15:41:48 -07:00
Xi Ge
c94172869b Re-apply "[CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863" 2016-03-25 14:14:19 -07:00
Dmitri Gribenko
904b7f53c0 Revert "[CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863"
This reverts commit 218010afb9.  It causes
timeouts in IDE/complete_repl_from_cocoa.swift.
2016-03-25 14:14:19 -07:00
Xi Ge
baff806cf6 [CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863
Reported: http://stackoverflow.com/questions/36180575/struck-out-module-xcode-7-3
2016-03-25 14:14:19 -07:00
Michael Ilseman
bb43d88792 [Import as member] Bring up to date with fixes from master 2016-03-23 17:02:03 -07:00
Michael Ilseman
47e73ad4f1 Merge branch 'master' of github.com:apple/swift into import-as-member 2016-03-23 17:01:47 -07:00
Michael Ilseman
d7581d1b36 Merge commit 'a31edf53d0580efe47f4e9ef89dccc4429c056e8' into import-as-member 2016-03-23 13:05:57 -07:00
Michael Ilseman
b7bcc294ea [Clang importer] Fix obscure issue with submodule protocols.
In the Clang importer, and only in submodules, the first protocol
typedef with NSObject that we try to import results in a hidden lookup
result. So, allow hidden lookups, which is benign and failure is
actually an issue of a malformed header. Gracefully handles failure.

Test case included that will reproduce the issue if AllowHidden is
disabled.
2016-03-23 10:07:00 -07:00
Michael Ilseman
a94e07d820 [Import as member] Adjust test case to work around unknown bug
There's an odd, and unknown bug in the Clang Importer where we seem to
fail a Clang lookup of NSObject the very first time we try. While I'm
still diagnosing this, un-block SILGen work.
2016-03-22 15:09:42 -07:00
Joe Groff
5db097d098 SILGen: Fixes for C functions imported as CF class members. 2016-03-21 19:33:22 -07:00
Michael Ilseman
7953a5494c [Import as member] Test protocol setter, which exposes a different failure path 2016-03-21 17:26:20 -07:00
Michael Ilseman
9a5613a36d [Import as member] tests for import-as-protocol-member 2016-03-21 17:03:25 -07:00
Joe Groff
aec7be3930 SILGen: Handle C functions imported as property accessors. 2016-03-18 13:23:40 -07:00
Joe Groff
c4a69e9d5d SILGen: Basic code generation for C functions imported as methods.
Introduce abstraction patterns for curried C-functions-as-methods for type lowering, and plumb the "foreign self parameter index" through call emission so that we emit the "self" parameter in the right position. This gets us handling C functions imported as methods with explicit swift_name attributes in simple, fully-applied cases. There's still more work to be done for properties, partial applications, and initializers introduced by extensions.
2016-03-17 10:43:25 -07:00
Ben Langmuir
1b08d83b6f [SourceKit] Annotate class method dynamic Self return types
Pass through the original Type in addition to the TypeDecl so that we
can distinguish DynamicSelfType with underlying ClassType from just any
old ClassType.

rdar://problem/25158493
2016-03-14 19:43:54 -07:00
Daniel Duan
7cabf3555b [Parser] update test for SE-0040 changes 2016-03-11 16:01:37 -08:00