Commit Graph

94 Commits

Author SHA1 Message Date
Nate Chandler
2d03664e45 [TypeLowering] Return pseudogeneric @autoreleasing
Previously, when a pseudogeneric function returned a type parameter, it
was unowned.  That resulted in invalid OSSA out of SILGen.  Here, this
is fixed to use the @autoreleasing convention.

rdar://64375208
2024-05-31 18:42:25 -07:00
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
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Slava Pestov
0b0d7dcff9 Sema: Remove most of the remaining Swift 3 support 2018-10-08 18:43:52 -07:00
Slava Pestov
c69d43e87d SILGen: Fix crash when emitting foreign-to-native thunk for allocating init in -swift-version 5
This comes up when we import a static factory method as a convenience init.
The thunk was using DynamicSelfType as the type of a basic block argument,
because that was the type of the 'self' parameter in -swift-version 5.

Fixes <rdar://problem/44242156>.
2018-09-11 15:22:30 -07:00
Joe Groff
cba32f79a5 SILGen: Cope with overloads when emitting artificial main for @UIApplicationMain.
The overlay may add overloads for UIApplicationMain for various reasons. When we generate the special `main` implementation for a `@UIApplicationMain` class, we want to call the original function from Objective-C, so pick that one where there are multiple overloads to choose from. Fixes rdar://problem/42352695.
2018-07-18 15:58:11 -07:00
Saleem Abdulrasool
a330db60bd SILGen: stub out CoreData
One of the SILGen tests uses CoreData.  Provide a stubbed out definition
sufficient for the tests.
2018-06-11 09:23:22 -07:00
Saleem Abdulrasool
61c53467c6 SILGen: flesh out Foundation stubs further
The local bridging headers needed two new definitions:
  - NSErrorDomain
  - NS_OPTIONS

These can be used by the SILGen tests to build against a stubbed
Foundation rather than requiring the host to provide it.
2018-06-11 09:23:22 -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
Arnold Schwaighofer
a9786978b2 Ensure lifetimes of optional convert_escape_to_noescape closures
rdar://38124009
2018-03-30 06:20:13 -07:00
Jordan Rose
38e2cfe1e2 Mangle imported declarations using their C names.
This makes them consistent no matter what shenanigans are pulled by
the importer, particularly NS_ENUM vs. NS_OPTIONS and NS_SWIFT_NAME.

The 'NSErrorDomain' API note /nearly/ works with this, but the
synthesized error struct is still mangled as a Swift declaration,
which means it's not rename-stable. See follow-up commits.

The main place where this still falls down is NS_STRING_ENUM: when
this is applied, a typedef is imported as a unique struct, but without
it it's just a typealias for the underlying type. There's also still a
problem with synthesized conformances, which have a module mangled
into the witness table symbol even though that symbol is linkonce_odr.

rdar://problem/31616162
2018-01-09 17:55:24 -08:00
John McCall
f9e28aff2a When building a block-to-func reabstraction thunk, be sure to bridge
the block's formal parameter and result types, because otherwise
the bridging code gets real confused.

Fixes rdar://35402696
2017-11-15 03:10:29 -05: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
John McCall
484d6761f9 Handle labeled singleton tuples in the setter value argument.
This can get introduced by somewhat pathological behavior in the
importer combined with SILGenApply's reliance on parallel tuple
destructuring.  Both of these should be fixed, but this patch is
much simpler.

rdar://34913800
2017-10-26 20:33:19 -04:00
Jordan Rose
a5d3178471 [test] Factor out a module just for objc_nonnull_lie_hack.swift.
Previously we ran into problems where this test used API notes for the
'gizmo' module and other tests did not, leading to potentially-invalid
information being cached in Clang's module cache. That might actually
no longer be an issue because textual API notes are now included
directly, but even so it's cleaner to just have a dedicated module for
this.

rdar://problem/28313536
2017-07-21 19:38:31 -06:00
Jordan Rose
5c21e12fdb [API notes] Remove all API notes present in the Xcode 9 SDKs. (#10615)
The framework versions already superseded the files here, so let's not
even bother building and packaging them. There /are/ still a few
frameworks that aren't shipping their own API notes at the moment,
however, though some of them are deprecated in their entirety.

rdar://problem/32908357
2017-07-07 19:52:49 -07:00
John McCall
b542c75cb1 Use abstract implicit-conversion expressions for bridging cases instead of
expanding the conversion calls in Sema.
2017-06-11 01:39:51 -04:00
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
practicalswift
cc852042c9 [gardening] Fix accidental trailing whitespace. 2016-10-29 10:22:58 +02:00
Jordan Rose
8141363e32 Optional swift_newtype types are @objc if the raw type would be @objc.
This was causing issues where the compiler rejected overrides of
imported members as being non-ObjC-compatible, even though the type
was exactly the same as what the Clang importer was using.

https://bugs.swift.org/browse/SR-2344
2016-08-16 18:02:30 -07:00
Arnold Schwaighofer
723e2f912f TypeChecker: Fix implicit dynamic inference for extensions methods
Even if the method is marked override we need to emit an objective C method
call.

There is no v-table guarantee because of the override keyword. The base class
method might be in an objective c class.

rdar://27389992
2016-08-01 15:32:57 -07: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
Doug Gregor
3739470553 [Clang importer] Fix rawValue initializer for swift_newtype'd types.
The code was creating a new "self" rather than using the existing
"self", which was caught by DI.
2016-05-08 00:00:50 -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
Doug Gregor
cb9e2ca829 [Clang importer] Refactor mapping of bridged Objective-C class types.
Localize and simplify the computation of the type to which an
Objective-C type is bridged. NFC.
2016-03-10 19:30:28 -08: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
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Slava Pestov
249242b08d SILGen: Always open-code materializeForSet
This improves MaterializeForSetEmitter to support emission
of static materializeForSet thunks, as well as witnesses.

This is now done by passing in a nullptr as the conformance
and requirement parameters, and adding some conditional code.

Along the way, I fixed a few limitations of the old code,
namely weak/unowned and static stored properties weren't
completely plumbed through. There was also a memory leak in
addressed materializeForSet, the valueBuffer was never freed.

Finally, remove the materializeForSet synthesis in Sema since
it is no longer needed, which fixes at least one known crash
case.
2016-01-11 19:53:16 -08: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
Joe Groff
0cdbe89576 Fix some regressions with handling of blocks.
- If a @convention(block) function parameter was also marked @noescape, then during type-checking, we would accidentally propagate the convention directly onto a literal closure expr, instead of going through a function_conversion, which SILGen didn't handle. Fixes rdar://problem/23261912.
- If an Objective-C API declared a block parameter with a _Nonnull return of a bridged type, such as NSString *_Nonnull, then native-to-bridged thunking would fail to recognize this case, since we still bridge to an Optional type in the lowered ObjC interface. Fixes rdar://problem/23285766.
2015-11-03 19:29:51 -08:00
Joe Groff
48e1bcb4ce SILGen: Optionalize NS containers when necessary for a func-to-block thunk.
Fixes rdar://problem/22205792.

Swift SVN r32116
2015-09-21 18:13:35 +00:00
Slava Pestov
d313fa7d42 SILGen: @convention(block) bridging thunks need to copy blocks in optionals
The @objc method argument bridging did the right thing but for
func to block thunks we didn't handle optionals and IUOs.

Symptoms included memory leaks because IRGen would later try to
retain the block by calling Block_copy() and discarding the result,
or memory corruption because the on-stack block could outlive
its stack frame.

Fixes <rdar://problem/22471309>.

Swift SVN r31882
2015-09-11 03:08:03 +00:00
Slava Pestov
7cf72989b7 Re-apply "Fix linkage of 'static inline' Clang-imported definitions"
This re-applies commit r31763 with a change to the predicate we
use for determining the linkage of a definition. It turns out we
could have definitions with a Clang body that were still public,
so instead of checking for a Clang body just check if the Clang
declaration is externally visible or not.

Swift SVN r31777
2015-09-08 22:12:06 +00:00
Dave Abrahams
8269d8130b Revert "Fix linkage of 'static inline' Clang-imported definitions"
This reverts commit r31763, as it was breaking the bots:

Swift SVN r31765
2015-09-08 16:31:35 +00:00
Slava Pestov
fc0a18be3f Fix linkage of 'static inline' Clang-imported definitions
If an external SIL function has a Clang-generated body, I think this
means we have a static function, and we want to use Shared linkage,
not Public.

Add a new flag to SILFunction for this and plumb it through to
appease assertions from SILVerifier.

Swift SVN r31763
2015-09-08 06:26:35 +00: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
Joe Groff
fabd029324 SILGen: Make the materializeForSet closure for Clang-imported properties shared.
There's a hack to make closures in transparent contexts always public in order to support transparent inlining in user code, but it's the wrong thing to do with the artificial callback for materializeForSet, which will be generated in modules that need it. Any problems with this linkage would already be problems with referencing the other shared accessors, and this fixes a duplicate symbol bug when materializeForSet is demanded by multiple TUs (rdar://problem/21314681).

Swift SVN r30098
2015-07-10 23:50:50 +00:00
Jordan Rose
498ab24341 [ClangImporter] Allow performSelector... methods, but make the result Unmanaged.
Per discussion, there are certain times where our APIs really want you to use
the performSelector family of methods (e.g. when the framework hands you a selector
and expects you to call it upon completion).

Although the methods still aren't type-safe, we are at least making the result
Unmanaged so that you're forced to think about whether it's +1 or +0 before you
use it, and so that the compiler doesn't accidentally try to retain a non-object
pointer.

This commit also removes the blocks on the makeObjectsPerformSelector... methods,
but Foundation plans to add NS_SWIFT_UNAVAILABLE there (see rdar://problem/21150180).

rdar://problem/21150277

Swift SVN r30044
2015-07-09 22:54:41 +00:00
Joe Groff
cbb6d71c96 Sema: Register synthesized accessors for protocol witnesses as external decls.
This ensures SILGen will emit the accessor bodies. Fixes rdar://problem/19509451.

Swift SVN r28685
2015-05-17 19:15:43 +00:00
Joe Groff
fa8e2aac08 ClangImporter: Associate imported subscript accessors with Clang nodes.
This allows SILGen to recognize them as foreign declarations, fixing a bug when classes with subscripts defined in Objective-C were extended to conform to Swift protocols with subscript requirements. rdar://problem/20371661

Swift SVN r27998
2015-04-30 21:59:40 +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
Joe Groff
751724c3fa SILGen: Special-case NSError to ErrorType erasure.
We want this to be a "toll-free" adoption of the class reference without requiring a second box allocation.

Swift SVN r26711
2015-03-30 04:52:41 +00:00
Dmitri Hrybenko
ab408d4dc3 Update the compiler and SDK overlay for nullability and generics in Foundation
We have an SPI between the Swift compiler and Foundation based on the
SWIFT_SDK_OVERLAY_FOUNDATION_EPOCH preprocessor macro that allows us to
request the new API.  rdar://20270080 tracks removing it.

Swift SVN r26475
2015-03-24 02:18:06 +00:00
Joe Groff
c1db47ed13 Sema: Synthesize materializeForSet with dynamically-dispatched accessors for dynamic properties.
Semantically, a dynamic property must always be dispatched in case it gets replaced at runtime, and an @NSManaged property may not have static accessors at all. Use ordinary access to the computed property accessors in materializeForSet when a property is dynamic or ObjC-originated. More rdar://problem/18706056.

There's still a problem--we try to vtable-dispatch materializeForSet, which is redundant for native classes, but impossible for imported ObjC classes. We should suppress this, but trying to make materializeForSet "final" breaks subclassing if the property is overridden.

This time, update test/SILGen/objc_properties.swift to avoid a false negative test failure.

Swift SVN r24888
2015-02-01 20:24:57 +00:00
Dmitri Hrybenko
2037fe0059 Revert "Sema: Synthesize materializeForSet with dynamically-dispatched accessors for dynamic properties."
This reverts commit r24882.  It broke SILGen/objc_properties.swift.

Swift SVN r24883
2015-02-01 03:17:49 +00:00
Joe Groff
456288fb6f Sema: Synthesize materializeForSet with dynamically-dispatched accessors for dynamic properties.
Semantically, a dynamic property must always be dispatched in case it gets replaced at runtime, and an @NSManaged property may not have static accessors at all. Use ordinary access to the computed property accessors in materializeForSet when a property is dynamic or ObjC-originated. More rdar://problem/18706056.

There's still a problem--we try to vtable-dispatch materializeForSet, which is redundant for native classes, but impossible for imported ObjC classes. We should suppress this, but trying to make materializeForSet "final" breaks subclassing if the property is overridden.

Swift SVN r24882
2015-02-01 02:09:27 +00:00