Commit Graph

2523 Commits

Author SHA1 Message Date
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
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
Doug Gregor
a2e03d556b Stage implementation of SE-0033 behind a flag, -enable-swift-newtype.
We're going to quarantine this feature behind a frontend flag for a
bit.
2016-04-25 18:03:04 -07:00
Joe Groff
825e02e2f1 Remove -enable-import-objc-generics staging flag. 2016-04-25 14:25:11 -07:00
practicalswift
9a078b54ef [gardening] Fix recently introduced typo: "a executable" → "an executable"
[gardening] Fix recently introduced typo: "a offset" → "an offset"
[gardening] Fix recently introduced typo: "accessiblity" → "accessibility"
[gardening] Fix recently introduced typo: "cant" → "can't"
[gardening] Fix recently introduced typo: "inteference" → "interference"
[gardening] Fix recently introduced typo: "unsatified" → "unsatisfied"
[gardening] Remove accidental space.
2016-04-24 22:11:59 +02: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
65288eec66 [Clang Importer] Cleanup and sharing of code
Adds makeStructRawValued utility function, which shares common code
for raw-value-backed structs from both OptionSets and many imported
enums. NFC.
2016-04-21 15:59:28 -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
Trent Nadeau
8a55e428f4 Imported C decls w/o warn_unused_result get @discardableResult 2016-04-13 00:39:07 +00: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
Joe Groff
08a4267f66 Clang importer: Global vars imported as static member properties are final. 2016-04-11 18:02:41 -07:00
Doug Gregor
9e2c68866c [Clang importer] Be robust against invalid Objective-C categories.
The Clang importer was crashing when encountering an Objective-C
category for an unknown class. Fixes rdar://problem/24244116.
2016-04-05 13:55:24 -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
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02: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
Michael Ilseman
4e4c511cf0 [Import as error] Error on non-prototyped function declarations 2016-03-28 15:41:48 -07:00
Jordan Rose
639e437ab5 Merge pull request #1820 from jrose-apple/specialization-crash
[ClangImporter] Correctly set up inherited protocol conformances
2016-03-28 13:49:33 -07:00
Joe Groff
f443fb105c Use isGenericContext instead of getGenericParamsOfContext where possible. 2016-03-28 09:50:30 -07:00
Chris Willmore
3bcb169f0b Import lightweight Objective-C generics as Swift generic type
parameters.
2016-03-28 09:50:30 -07:00
Michael Ilseman
b01caa01c6 Merge remote-tracking branch 'origin/master' into import-as-member 2016-03-25 15:47:47 -07:00
Chris Lattner
668d224b62 Fix <rdar://problem/25168818> Don't import None members in NS_OPTIONS types
When importing members of an NS_OPTIONS (aka an option set), mark imported
members that have a value of 0 with an unavailable error.  This produces an
experience like this:

  x = NSRuncingOptions.none // expected-error {{'none' is unavailable: use [] to construct an empty option set}}

This is important to do, because option set members with a value of zero
do not act like members of the option set.  For example, they always fail a
"contains" check.
2016-03-25 13:57:18 -07:00
Michael Ilseman
8759905351 Merge remote-tracking branch 'origin' into import-as-member 2016-03-24 11:37:36 -07:00
Jordan Rose
1c5dd6001e [ClangImporter] Correctly set up inherited protocol conformances.
Previously we just left them out, and then bits of the SIL optimizer
would just crash when they asked about them.

rdar://problem/24547884
2016-03-24 10:33:40 -07:00
Slava Pestov
98c9a9c4f4 ClangImporter: Mark generated union accessors as transparent
This ensures their bodies are fragile in SIL. While they can
be synthesized again, this change will avoid tripping up the
SIL verifier after some upcoming changes.

Part of https://bugs.swift.org/browse/SR-267.
2016-03-24 00:50:39 -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
7867533f2c Merge commit 'b894798e461077b30a3aa4afe89639f312f44858' into import-as-member 2016-03-23 15:40:04 -07:00
Michael Ilseman
d7581d1b36 Merge commit 'a31edf53d0580efe47f4e9ef89dccc4429c056e8' into import-as-member 2016-03-23 13:05:57 -07:00
Doug Gregor
593932741c Remove historical flags -enable-omit-needless-words/-enable-infer-default-arguments/-enable-swift-name-lookup-tables.
NFC; all of these options are always-on now and we no longer have a
way to turn them off.
2016-03-22 17:04:19 -07:00
Michael Ilseman
a1dabba674 [Clang importer] Note for where import errors are failing 2016-03-21 13:17:02 -07:00
Joe Groff
f42e579040 Change SILGen to use ImportAsMemberStatus populated by ClangImporter. 2016-03-17 17:09:41 -07:00
Michael Ilseman
bbde50e2a2 [Import as member] Protocols: generic signature and interface type
Computes the generic signature correctly for protocol extensions. Sets
the correct function and interface type when forming the imported
protocol member. This makes import-as-protocol-member work and fixes
the disappearing return value issue in protocols.
2016-03-17 13:32:06 -07:00
Michael Ilseman
875920b540 [Import as member] Also encode when imported as a static member in the AST 2016-03-17 11:16:20 -07:00
Slava Pestov
552a6ad1b7 Sema: Remove some dead code for "delayed members", NFC
This was added at some point to make 'import Foundation' faster in the REPL.
What we really care about though is not delaying synthesis of the rawValue
accessors (those are synthesized on demand anyway), but delaying the
conformance check to RawRepresentable.
2016-03-16 18:35:31 -07:00
Michael Ilseman
09c98f7be8 [Import as member] Permit instance members on protocols
When the identified decl context gets imported as a protocol, reject
init and statics with an error. Support instance members.
2016-03-16 14:33:45 -07:00
Michael Ilseman
332959df8e [Import as member] Store selfIndex in the AST 2016-03-15 13:18:59 -07:00
Michael Ilseman
c8e2422838 [Clang importer] Extract CFPointeeInfo into separate file
Moves CFPointeeInfo into CFTypeInfo.h/cpp, so that other parts of the
importer can re-use the logic for reasoning about CF types. This will
be needed by the import as member inference system to reason about
effective Clang contexts.
2016-03-10 17:30:29 -08:00
Michael Ilseman
919b973edc [Import as member] Import as implicit final.
Mark the inferred final attribute as implicit, as we care about
bringing in the right semantics, but don't need to print back that
fact.
2016-03-10 12:55:50 -08:00
Michael Ilseman
3c690d422d [Import as method] Create an empty tuple first parameter
For function that we are importing as init, if there's dangling words
after the "Create" or "Make", we move them onto the first argument
label. This introduces the creation of an empty tuple parameter when
that init has no arguments.
2016-03-09 15:20:04 -08:00
Max Moiseev
1fae0d1325 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-08 12:48:48 -08:00
Chris Lattner
fe9fe47b7e Implement support for generic typealiases. 2016-03-07 22:20:16 -08:00
Doug Gregor
09a0e6cc05 [Clang importer] Test minimal SILGen for global variables imported as static properties. 2016-03-07 20:57:18 -08:00
Michael Ilseman
73f7fd2eb6 [Clang importer] Infer get-only properties and static properties.
Expands support for inference of computed properties, whether instance
or static, to include get-only. Adds test cases for both inference and
manual annotation for static computed properties.
2016-03-07 16:51:34 -08:00
Michael Ilseman
23c818ed57 [Clang importer] Support static methods in swift_name 2016-03-07 15:58:01 -08:00
Doug Gregor
c40b45eb8c [Clang importer] Factor out and tidy up global-as-initializer import. 2016-03-06 21:57:37 -08:00
Doug Gregor
47b2be3138 [Clang importer] Import a getter or getter/setter pair as a property.
When a global function is determined to be a lone getter or a
getter/setter pair, import it as a property. Handle global, instance,
and static properties.

As part of this, generalize importAsMethod to also handle static
methods and map pointer-to-non-const arguments to 'mutating' methods.
2016-03-06 21:25:43 -08:00