Commit Graph

84 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
Arnold Schwaighofer
850f65cb27 IRGen: Gracefully handle protocol forward declaration references without definitions
```
 @protocol DeclarationOnly;

 @protocol DeclarationOnlyUser<DeclarationOnly>
 - (void) printIt;
 @end
```

This should not be neccessary, but the compiler currently accepts cases
like the one in the test case added.

rdar://101828847
2022-11-07 14:41:39 -08:00
Arnold Schwaighofer
852c59fd56 IRGen: Fix usage of clang generated objective-c protocol metadata
When updating the inherited protocol list we need to compute the list of runtime protocols (excludes non-runtime protocols).

rdar://101876133
2022-11-02 15:12:12 -07:00
Allan Shortlidge
f71a3232cf IRGen: Use extern_weak linkage for Clang symbols from @_weakLinked imported modules.
rdar://96098097
2022-08-11 11:02:57 -07:00
Karoy Lorentey
2966dce3d9 [IRGen] Allow configuring a panic function to call instead of trapping
Add a new frontend option (called `-trap-function <name>`, similar to Clang’s existing `-ftrap-function`) that specifies a function to call instead of trapping.

When the option is used, the compiler will emit a call to the specified function every time it would have otherwise emitted a trap instruction. The function must have no parameters and it must never return.

rdar://89125883
2022-02-17 23:19:08 -08:00
Becca Royal-Gordon
14f48dceac [IRGen] Fix crashes involving ObjC generic params
Sema allows you to pass type-pinning parameters into an extension of an Objective-C generic class, but IRGen did not properly handle erasing these types to existential types in runtime metadata. This commit corrects that mistake.
2021-07-19 19:59:27 -07:00
Arnold Schwaighofer
532f0cb865 Type substitution: When substituting SILFunctionTypes we substitute unbound Objective-C generic for bound ones
IRGen does so. So don't assert on this case.

rdar://63509292
2020-05-26 13:26:08 -07:00
Arnold Schwaighofer
9c4bbc1028 IRGen: Use clang's objc encoding for types when there is a ClangNode
We do this because the swift code does not support all attributes and
does not support generics.

rdar://60474785
2020-04-16 06:27:47 -07:00
Arnold Schwaighofer
c9d490c5a9 Revert "Merge pull request #30612 from aschwaighofer/irgen_also_unique_ext_method_types_list"
This reverts commit f0cdd76f18, reversing
changes made to 703fe0f1a1.

Revert "IRGen: Refactor getObjCEncodingForMethod and getObjectEncodingFromClangNode into one"

This reverts commit 0082682b0d.

Revert "Merge pull request #30438 from aschwaighofer/irgen_prefer_clang_type_encoding"

This reverts commit eeb7fa52b2, reversing
changes made to 77af77fa8a.

Revert "Merge pull request #30433 from aschwaighofer/irgen_no_duplicate_objc_method_descriptor_entries"

This reverts commit 77af77fa8a, reversing
changes made to 841eeb05b0.

This reverts the changes for

rdar://60461850, rdar://60474785, rdar://60778637

There is still at least an issue that we address with PR#30654.

Revert until we have confidence that this is the right fix set.
2020-03-26 15:00:15 -07:00
Arnold Schwaighofer
259c9884ac IRGen: Use clang's objc encoding for types when there is a ClangNode
We do this because the swift code does not support all attributes and
does not support generics.

rdar://60474785
2020-03-16 16:47:13 -07: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
Slava Pestov
6d5ff209d0 IRGen: Implement support for __attribute__((ns_consumed)) block parameters
Fixes <rdar://problem/48792177>.
2019-12-02 18:41:27 -05:00
Karoy Lorentey
666a22feff [test] Modernize hashing throughout the test suite 2018-11-29 17:38:29 +00:00
John McCall
05c9671902 Change the ABI for the type descriptors of imported declarations.
- Instead of keeping multiple flags in the type descriptor flags,
  just keep a single flag indicating the presence of additional
  import information after the name.

- That import information consists of a sequence of null-terminated
  C strings, terminated by an empty string (i.e. by a double null
  terminator), each prefixed with a character describing its purpose.

- In addition to the symbol namespace and related entity name,
  include the ABI name if it differs from the user-facing name of the
  type, and make the name the user-facing Swift name.

There's a remaining issue here that isn't great: we don't correctly
represent the parent relationship between error types and their codes,
and instead we just use the Clang module as the parent.  But I'll
leave that for a later commit.
2018-08-01 18:37:08 -04:00
Saleem Abdulrasool
5ace2d92f0 tests: adjust inputs for Windows
Windows does not have unsigned enumerations by default.  Use a typed
enum to ensure that we get unsigned enumerations on Windows.  Fixes the
handling for tests on Windows.
2018-04-23 20:33:07 -07:00
Doug Gregor
59077bdfc6 [GSB] Allow redundant inheritance for all Objective-C-defined protocols.
Swift complains about redundant inheritance of a protocol, and
canonicalizes away such redundancies in its metadata. Clang does not
warn about such redundancies, nor does the Objective-C "conforms to
protocol" check take inheritance into account. Extend the existing
"redundant inheritance" hack (designed for JSExport) to cover all
protocols defined in Objective-C, so we match Clang's output of
Objective-C metadata.

Fixes SR-7130 / rdar://problem/38394637.
2018-03-19 10:07:07 -07:00
Doug Gregor
12a774abec [Runtime] Fill in the superclass of foreign class metadata.
When emitting foreign class metadata (e.g., for an imported CF type), fill
in the superclass when we have one. The superclass will itself be a foreign
metadata candidate, so also register an initialization function that uniques
the superclass metadata once we've picked the canonical foreign class
metadata.
2018-01-04 10:15:32 -08:00
Saleem Abdulrasool
d8552ceb9e IRGen: ensure that ObjC sections match on all targets
Adjust the IRGen for ObjC interop to ensure that the section that
metadata is emitted into the correct section for non-MachO targets.

This also adds a more comprehensive test for ensuring that the IRGen can
now be tested on all targets.  Since the ObjC interop is now
controllable via the driver, this test does not require that the
objc_interop feature is present as it is a IRGen test.

This is the first step to remove the `REQUIRES: objc_interop` from the
IRGen tests.
2017-12-03 15:55:44 -08:00
swift-ci
f1536bcc36 Merge pull request #12712 from compnerd/test-nullability 2017-11-02 10:36:50 -07: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
Huon Wilson
44045e24da [test] Update SIL printing/parsing tests for 'witness_method: <protocol>'. 2017-11-01 11:33:27 -07:00
Saleem Abdulrasool
b53a422c59 IRGen: follow target specific ABI for FFI
When lowering the arguments for the FFI call on certain targets, LLVM
expects that the parameter be passed as a structure rather than the
extracted values.  Enhance the argument lowering for the call and the
function construction to ensure that the type can be flattened according
to the ABI for the target before attempting to explode it for the SIL
IRGen lowering.  This allows building for targets such as Linux ARM HF
and Linux ARM SF target with the HF floating point ABI.

Addresses SR-6142!
2017-10-26 09:42:21 -07:00
Arnold Schwaighofer
1832bcdfd5 Add test case that uses metadata of 'import as nested types' Objective-C types
This used to crash before we removed parent metadata references.

rdar://34846458
2017-10-10 09:32:14 -07:00
Arnold Schwaighofer
3d34fb3b07 IRGen: Fix linkage for shared declarations
They need external linkage not linkonce_odr which can only be used by defintions
not declarations.
This got exposed by clang imported protocol witness table declarations.
They get assigned shared linkage since they are potentially not unique.

rdar://26563441
2017-09-26 13:26:07 -07:00
Arnold Schwaighofer
ce85f8e79c IRGen: Fix ObjectiveC partial apply forwarding stub
We need to map from swift parameter passing ABI to local explosions in partial
apply forwarding stubs to ObjectiveC methods.

SR-5569
rdar://33591146
2017-08-02 07:00:51 -07: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
practicalswift
cc852042c9 [gardening] Fix accidental trailing whitespace. 2016-10-29 10:22:58 +02:00
Jordan Rose
e7fe0abeed Don't treat Swift methods named "init" as ObjC ARC init methods. (#2989)
Under ARC, methods in the "init" family are considered to have
NS_REPLACES_RECEIVER semantics ("consumes" self and returning a
value at +1). This is correct for Objective-C "init methods",
which are equivalent for Swift's initializers, but almost never
correct for any other methods that happen to start with the word
"init".

Note that Swift still follows all the other ARC conventions, so
if you name a method or property, say, "newItemController", the
value will be returned at +1. For methods this is probably
desirable, but for properties maybe not. We could do something
similar for property accessors to make sure they always have
the default "no method family" semantics in Objective-C.

rdar://problem/25759260
2016-06-20 14:09:53 -07:00
Mishal Shah
87b7bcfd3e Update master to build with Xcode 8 beta 1, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-06-14 14:53:55 -07:00
David Farler
8ca30ff2d7 Ask SILFunction link entities' clang nodes for weakness when applicable
When importing C functions with availability attributes, we don't
properly use that information to decide whether a symbol should be
weak_extern, causing load failures in dylibs that reference these
symbols when deployed to an older OS.

This is a very targeted fix and we need a better architecture for
deciding this.

rdar://problem/26359452
2016-06-01 12:52:04 -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
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
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Slava Pestov
79b24fa7d1 Update availability tests to be independent of the actual deployment target
Use fictional version numbers in the 10.50..10.99 range.
2016-01-13 19:27:26 -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
ca394f3e05 Make sure to IRGen all static functions.
...not just inline ones. Otherwise we'll end up with linker errors.

Swift SVN r31248
2015-08-14 19:50:25 +00:00
Joe Groff
be18da2286 IRGen: Implement init_existential_ref from NSError to ErrorType.
Swift SVN r26712
2015-03-30 04:52:53 +00:00
Joe Groff
a0ecab5b16 ClangImporter: Don't attempt to bridge __unsafe_unretained NSString * fields in structs.
We certainly can't import them as stored properties, and it's too late to try to bridge them as computed property, so restore the old behavior of importing them as unbridged object types. The types still come in as strong managed reference types, which is still wrong, but seems to be right enough for Khan Academy and potentially other existing apps for now, and I don't want to introduce additional source-breaking changes and instability this late in the game. Fixes rdar://problem/19789023, leaving rdar://problem/19790608 to be done when we can afford more churn.

Swift SVN r25158
2015-02-11 01:30:20 +00:00
John McCall
2ff77a9cd1 Only import *Ref typedefs as CF types if they have a bridging
attribute or appear in a whitelist.

The initial whitelist is based on an audit I performed of our current
public SDKs.  If there are CF types which appear only in our internal
SDKs, and somebody urgently needs to use them from Swift, they can
adopt the bridging attributes.  The goal is to eventually eliminate
the whitelist and rely solely on bridging attributes anyway.

Sadly, CoreCooling was not included in my SDK audit and must be
explicitly annotated. :(

I've left the main database organized by framework, but I wanted
a quasi-lexicographically sorted version to permit efficient lookup.
We generate that copy automatically with gyb.  I ended up having
to tweak handle_gyb_sources to allow it to drop the result in
CMAKE_CURRENT_BINARY_DIR instead of CMAKE_CURRENT_BINARY_DIR/{4,8}
if an architecture is not provided.  I think this is abstractly
reasonable for generated includes, which have independent ability
to detect the target word size.  But just between you and me,
I did it because I couldn't figure out how to add
"-I${CMAKE_CURRENT_BINARY_DIR/{4,8}" as a compile flag;
the obvious thing didn't work.  Anyway, I'd appreciate it if
someone double-checked my cmake hackery here.

Swift SVN r24850
2015-01-30 18:39:07 +00:00
Doug Gregor
f19a320ffe Ban the definition of Objective-C '+load' methods.
They don't work properly, and if we want eager static initialization,
we'll add a Swift feature for it. Fixes rdar://problem/18423731.

Swift SVN r24814
2015-01-29 05:47:36 +00:00
Doug Gregor
5dd13979bc Fix Clang type mapping for Set<T> (rdar://problem/18944875).
Swift SVN r24394
2015-01-13 18:54:23 +00:00
Jordan Rose
06f283f310 [IRGen] Always use the definition of a static inline C function.
...rather than whatever declaration happened to be referenced by a
DeclRefExpr in another function's body.

rdar://problem/18448699

Swift SVN r23877
2014-12-12 03:14:09 +00:00
Joe Groff
056f55fd47 IRGen: Install the AlwaysInliner pass at -O0.
We want to make sure C definitions that get emitted as alwaysinline actually get inlined.

Swift SVN r23786
2014-12-08 22:07:30 +00:00
Jordan Rose
1d85cc7e0b Check user-written functions before looking at any imported types.
User-written functions can trigger the use of delayed protocols on imported
types. In the case of enums and structs, it's possible that we need to
synthesize a conformance for one of these protocols. We were failing to do
so because we were checking imported types before looking at any user code,
and deciding not to bother with the delayed protocols because no one had
referenced them yet.

This isn't necessarily a good long-term solution because it doesn't handle
implicitly-defined functions triggering the use of implicit conformances
on imported types. The general problem of "this enum was never compared
so I never made an Equatable performance" is still there, just much less
likely (since our synthesized declarations are usually quite simple). We
may want to revisit this later to make it more robust.

I also couldn't find a reduced test case that triggered this issue. The
reported code looks very similar to the test case I added, but the one I
added doesn't actually fail before this commit. I'm including it anyway to
guard against regressions.

rdar://problem/18198880

Swift SVN r21840
2014-09-10 16:56:55 +00:00
Jordan Rose
ee22004b84 [IRGen] Walk inlineable Clang functions and emit their dependencies.
This handles things like NSSwapHostLongLongToBig and MKMapRectMake that
are static inline functions that themselves call other static inline
functions.

<rdar://problem/17227237>

Swift SVN r21080
2014-08-06 23:21:17 +00:00
Doug Gregor
29108b932a Weak-link to Objective-C classes that Clang considers to be weak-imported.
This is a simple, trivialy, not-even-half-way-there solution to weak
leaking of Objective-C classes introduced after the deployment
target. It only works for Objective-C classes and C global variables
that Clang consideres to be "weak imported". However, this bare
minimum should be enough to develop an app (by jumping through various
hoops) that uses new functionality when its
available. <rdar://problem/17296490>, which I've restricted in scope
to capture this.

Swift SVN r20956
2014-08-02 19:33:36 +00:00
Joe Groff
db71d20bd0 IRGen: Fix misorderings and omissions in extended method types for protocols.
We were neglecting to include initializers and accessors for vars and subscripts, and we were mingling instance and class methods, causing the ObjC runtime to associate the wrong extended type information with methods. Fixes <rdar://problem/17791953>.

Swift SVN r20513
2014-07-24 21:11:27 +00:00
Jordan Rose
ca6d58a4b4 [test] Mark NSObject's 'description' property as readonly for SILGen/IRGen.
A change I missed in r20291. Doesn't affect anything now, but better to be
correct.

Swift SVN r20321
2014-07-22 17:16:38 +00:00
Jordan Rose
ce1e02c6c0 [ClangImporter] Remove hack for non-property 'description' and 'hash'.
...and 'debugDescription'. All SDKs now have the updated NSObject.h.

<rdar://problem/17719783>

Swift SVN r20291
2014-07-22 02:38:58 +00:00
Joe Groff
6cf0cf64b4 IRGen: Assert that categories are never emitted for foreign classes.
And add a test that an extension to a CF type doesn't emit a bogus class object reference. <rdar://problem/17569520>

Swift SVN r19590
2014-07-07 00:03:50 +00:00