Commit Graph

132 Commits

Author SHA1 Message Date
Michael Spencer
b2640e15e4 [test] Rename all module.map files to module.modulemap
`module.map` as a module map name has been discouraged since 2014, and
Clang will soon warn on its usage. This patch renames all instances of
`module.map` in the Swift tests to `module.modulemap` in preparation
for this change to Clang.

rdar://106123303
2023-08-21 15:58:59 -07:00
Saleem Abdulrasool
714eaefc78 Importer: remove ImportAsMember support
This functionality is not actively in use and the last usage of this has
been removed.  Remove the infrastructure that is no longer in need.
2021-03-22 08:53:56 -07:00
Alexis Laferrière
0fde935cc7 [ClangImporter] Move conflicting swift_name attributes tests
Fix rdar://72473419
2021-01-11 15:59:40 -08:00
Slava Pestov
305620b354 ClangImporter: Reconcile Clang declaration hidden-ness between loadAllMembers() and lazy loading
Lazy loading checked if the ClangDecl was hidden, but loading all
members did not. Let's make loadAllMembers() behave like the lazy
path, and fix some of the mock SDKs in the test suite.
2020-01-24 17:07:08 -05:00
Hamish Knight
8cccbe0118 [Sema] Infer @_nonEphemeral for various parameters
These include memberwise initializers for pointer properties and enum
case constructors for pointer payloads. In both cases, the pointer is
being immediately escaped, so don't allow the user to pass a temporary
pointer value.
2019-11-03 08:42:26 -08:00
Jordan Rose
e24c9e755d omitNeedlessWords: Fix self-type-stripping regression (#27742)
Turns out self-type-stripping /always/ operates on a type without
prefixes rather than /never/. Neither of these behaviors are really
what we'd want, but we'll live with it!

rdar://problem/56334797
2019-10-17 09:46:56 -07:00
Jordan Rose
0ba51b0eff [test] Remove overlays with extra NS stripping from the mock SDK (#20954)
There were only two tests still using them, and they weren't hard to
migrate over to the normal mock SDK overlays.
2018-12-03 10:48:08 -08:00
Xi Ge
87ed4b4488 [test] Remove Swift 3 flags from various tests. 2018-10-09 16:09:41 -07:00
Saleem Abdulrasool
ebaf0b6594 SILGen: remove duplicated module declaration
This module was specified in the IDE and SILGen testing module maps,
which causes a failure.  Remove the duplicated declaration in the
SILGen inputs and use IDE's definition.
2018-06-11 09:23:22 -07:00
Saleem Abdulrasool
bc27395838 Inputs: sprinkle _Null_unspecified to silence nullability-completness
When trying to figure out errors from an import failure, the nullability
completeness warnings would clutter the output making it difficult to
identify the errors.  Sprinkle the declaarations with
`_Null_unspecified` to maintain the current nullability semantics and
silence the warnings.  NFC.
2018-06-11 09:23:22 -07:00
Doug Gregor
24b96a7480 Delay import-as-member resolution even without an explicit swift_name.
When forming the Swift name lookup tables, import-as-member'd
declarations can precede the declaration of the context into which
they'll be imported as a member. In such cases, we already had logic
to delay the resolution until the end of the model (when the context
must be complete).

However, we would only delay when there is a swift_name attribute on
the declaration, which is... conceptually correct. If the swift_name
exists but is versioned (e.g., it is present only for Swift 4+), and
we're building before the swift_name took effect (e.g., in Swift 3
mode), the swift_name is buried under a "versioned" attribute in the
Clang AST. Therefore, we would end up dropping the declaration from
the name lookup table, which almost doesn't matter, except...

Serialization records the newest names for such declarations (e.g.,
Swift 4+ name in this case), so deserialization would fail to find the
declaration that had been dropped, causing a crash.

Eliminate the "optimization" that looks for the swift_name attribute
before delaying the resolution of such a declaration, so we'll visit
these later. Fixes rdar://problem/39115605.
2018-04-03 11:26:05 -07:00
Slava Pestov
1ed2cf09df AST: Don't find non-objc members with dynamic lookup
This can come up when we use import-as-member to turn top-level functions
into methods in an @objc class. Previously dynamic lookup would find
these, causing a SILGen crash.

Fixes <rdar://problem/36492980>.
2018-01-18 22:52:54 -08:00
Saleem Abdulrasool
bdb7901a1c test: modernise nullability attributes (NFC)
Use the modern spelling for the nullability attributes in the test mock
headers.  Currently, this was relying on the predefined macros from
clang to work.  However, those are only available on Darwin targets.
This is needed to make the mock environments more portable.
2017-11-01 23:27:33 -07:00
Slava Pestov
dfdd3a795d SILGen: Fix bug with NSString import-as-member globals
This is not really the right fix if we want to have physically
addressed lvalues support bridging in general, but doing so
requires adding a new LValue component type and doing a bunch
more refactoring, so just hack in a narrow fix for now since
it only seems to occur in one case.

Fixes <rdar://problem/34913892>.
2017-10-16 19:22:30 -07:00
Michael Ilseman
c7d9404e4a [Clang Importer] Account for indirection when importing swift_newtypes
Previously, we did not properly handle levels of indirection for
swift_newtype-ed typedefs of pointer types. We imported them in a way
that tried to present the value semantics of the pointee rather than
of the pointer. We then tried (sometimes incorrectly) to detect and
fix this up during SILGen.

Instead, model with the value semantics of the pointer itself. SILGen
can then be simplified to just pass swift_newtypes the same as any
other struct: directly for non-mutating and indirectly for mutating
(i.e. inout self). Tests added.
2017-06-22 13:14:55 -07:00
Jordan Rose
bd1920ba67 [ClangImporter] Fix versioned stubs for functions-as-members. (#8539)
That is, the stubs we generate when you rename a C global function
imported as a type member using the SwiftName API note. (See the
test case changes.) Previously we hit an assertion.

For good measure, also fix versioned stubs for types-as-members,
which were always added to their original context rather than the
new context.

rdar://problem/31435658
2017-04-04 15:20:30 -07:00
Jordan Rose
f7562e42b6 [ClangImporter] Add versioned stubs for import-as-member renames. (#8272)
A more general solution to ae458a84ad: import all versions of a name
that are going to show up as members, ignore those that aren't.

Further work on <rdar://problem/29170671> Import APIs under their
Swift 3 names.
2017-03-23 13:46:51 -07:00
Ben Langmuir
04107ed8b2 Revert "[omit-needless-words] Fix a bug found by -Wunused-result" 2016-09-14 14:27:32 -07:00
Ben Langmuir
7562c10333 [omit-needless-words] Fix a bug found by -Wunused-result
StringRef::drop_back() returns the new string; it doesn't mutate `this`.
2016-09-14 13:52:59 -07:00
Jordan Rose
258a0ade12 [APINotes] Protocols cannot use import-as-member. (#4482)
We could support this in the future but right now it's causing problems.
There's also a potential ambiguity issue here where a protocol and class
could have the same name.

In addition to updating the importer, remove the two entries from the
CryptoTokenKit API notes that were trying to use this feature.

rdar://problem/27990168
2016-08-24 16:02:28 -07:00
Ayaka Nonaka
a8f3eb8f66 Import @compatibility_alias as typealias
Objective-C’s @compatibility_alias compiler directive is imported as
a Swift typealias.
2016-07-25 12:28:44 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Michael Ilseman
9d76ce983e [Import as Member] Fix oversight where we skip getter validation.
In the code that makes sure to pair up getters/setters only from the
same top level module, we were accidentally skipping the final
validity checks (e.g. do the number of parameters line up). This fixes
that.
2016-06-30 18:34:29 -07:00
Doug Gregor
5bea187b0f [Omit needless words] Fix lowercasing of initialisms with two-letter initial words.
Fixes rdar://problem/26643039.
2016-06-13 18:15:43 -07:00
Doug Gregor
7b226ad177 [Omit Needless Words] Don't remove a first argument label when the parameter has as default argument.
Parameters that have default arguments should have argument labels;
don't remove them on import. Fixes rdar://problem/26611977.
2016-06-13 11:58:41 -07:00
Doug Gregor
1d39707311 [Omit needless words] Don't split "PlugIn".
Fixes rdar://problem/26334014.
2016-06-12 23:13:01 -07:00
Michael Ilseman
22ec60007a [Import as Member] Print full context in fixit
Due to swift_name and swift_newtype, we are frequently importing onto
different contexts. This was confusing the fixit logic for unavailable
swift2 names, as we were trying to use Clang names when the Swift name
might be totally different (and even a nested type). This change has a
two-fold effect:

1) Globals who are imported onto swift_newtype-ed typedefs should be
   considered ImportAsMember.
2) When printing out the name of an ImportAsMember Swift 3 decl, we
   need to print out a fully qualified context, which also uses the
   Swift names, not the Clang names.
2016-05-27 11:39:19 -07:00
Michael Ilseman
5aac3451ea Merge pull request #2654 from milseman/newtype
[swift_newtype] Structs have label-less init
2016-05-23 21:11:05 -07:00
Michael Ilseman
e0414a457f [swift_newtype] Structs have label-less init
Adds an unlabeled rawValue init for swift_newtype(struct), which
expresses the extensibility theme better.  This makes the use and
creation of new instances of that type more succinct.
swift_newtype(enum) still requires the explicit label, as it is
non-extensible.
2016-05-23 14:40:41 -07:00
Jordan Rose
28757ab2de [ClangImporter] Don't put forward-declared structs in the lookup table. (#2610)
Merge pull request #2610 from jrose-apple/cg-import-as-member
2016-05-23 14:23:21 -07:00
Doug Gregor
409132cb3f [Clang importer] swift_newtype'd types are bridged when their underlying types are.
A swift_wrapper/swift_newtype'd type can wrap a bridged type. In such
cases, we need to report both the unbridged type (which is the
unbridged underlying type) and the bridged type (which is the
importer-created wrapper type). This fixes a problem where Objective-C
generic specializations would use the wrapper types on type parameters
with "AnyObject" constraints, which... doesn't work.

Fixes rdar://problem/26340353.
2016-05-22 23:18:28 -07:00
Doug Gregor
1255a5cdb9 [Clang importer] Make sure an unavailable superclass init doesn't override an available import-as-member-init.
More generally, an unavailable initializer shouldn't stomp on an
available initializer, because it's possible that (for example) a
designated initializer will be unavailable but a factory initializer
will be available, so one still construct objects of that type.
Fixes rdar://problem/26238032.
2016-05-20 09:39:57 -07:00
Jordan Rose
a4162c5d79 [ClangImporter] Don't put forward-declared structs in the lookup table.
Otherwise, the lookup table for "CGColor" has two entries, because of
this:

    typedef struct CGColor *CGColorRef;

and that interferes with our ability to import things as members of
"CGColor" (as opposed to "CGColorRef"), which affects the fix-its we
generate when you try to use the non-member form.

This isn't necessarily the best long-term solution (as noted in the
FIXME) but it is expedient and won't break any current users.

More rdar://problem/26347297
2016-05-19 18:00:19 -07:00
Joe Groff
e248f83df9 Fix up some more non-prototyped declarations with swift_names.
This is now diagnosed on the Clang side.
2016-05-18 16:05:51 -07:00
Joe Groff
0103fb4eaf Update ImportAsMember test not to use unprototyped function.
We now reject this in Clang.
2016-05-18 15:16:24 -07:00
Michael Ilseman
9dd6217a14 [SILGen] Recognize swift_newtype-ed CF foreign class types
Teach isClangTypeMoreIndirectThanSubstType about swift_newtype-ed
typedefs, which may be of CF foreign class type. In these cases, we
should reason about the underlying, wrapped type. Includes
refactoring of common logic and tests.
2016-05-10 10:21:15 -07:00
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
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
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