Commit Graph

47 Commits

Author SHA1 Message Date
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
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
6d5ff209d0 IRGen: Implement support for __attribute__((ns_consumed)) block parameters
Fixes <rdar://problem/48792177>.
2019-12-02 18:41:27 -05: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
Huon Wilson
44045e24da [test] Update SIL printing/parsing tests for 'witness_method: <protocol>'. 2017-11-01 11:33:27 -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
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
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
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
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
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
Fariborz Jahanian
7578316937 Test for type encoding of imported
ObjectiveC enum type which is not
modernized.


Swift SVN r13687
2014-02-08 21:28:21 +00:00
Mark Lacey
1a97f18887 Switch ABI tests to using the real SDK.
Swift SVN r13423
2014-02-04 09:30:21 +00:00
Mark Lacey
d69b305200 Generate IR for inline functions from Clang modules.
Currently only inline functions referenced from Swift source files, or
from the REPL, will get IR generated for them. Inline functions
referenced by other inline functions will require additional effort to
generate properly.

With this change we use the clang::CodeGenerator-created llvm::Module
for all IR generation in Swift. This is perhaps undesirable, but
unavoidable given the interface the public Clang APIs expose, which do
not allow for building a ModuleBuilder that borrows an existing
llvm::Module.

Also unfortunate is the hack to generate a UsedAttr for each imported
inline function, but the public Clang APIs do not provide a way to only
emit deferred decls without emitting other things (e.g. module flags
that conflict with what the Swift IRGen emits). Note that we do not do
IRGen for every inline function in the module - only the ones that the
importer pulls in, which appears to be only those transitively
referenced from Swift code.

Swift SVN r13134
2014-01-30 02:33:37 +00:00
Mark Lacey
b1cc2545b4 Test calling an imported func that uses BOOL.
Swift SVN r12717
2014-01-22 07:09:11 +00:00
Doug Gregor
3caa3b78c5 Make CBool a typealias of Bool.
Swift SVN r12657
2014-01-21 21:28:55 +00:00
Mark Lacey
9b81800432 Choose correct IR types for @objc return values.
This change updates signature generation as well as IR generation for
calls and returns so that the correct ABI types are generated for the
results of @objc functions.

Swift SVN r11527
2013-12-20 23:31:01 +00:00
Mark Lacey
a7f6f9e006 Handle indirect returns in @objc methods properly.
Reapply r11184 with fixes for makefile builds.

Use CodeGenABITypes to determine which return values should be indirect
in @objc methods.

Swift SVN r11226
2013-12-13 00:39:24 +00:00
Mark Lacey
dffef5d02b Revert "Handle indirect returns in @objc methods properly."
This reverts r11184, which broke some builds due to a missing library.

Swift SVN r11186
2013-12-12 09:11:39 +00:00
Mark Lacey
973ece4dc9 Handle indirect returns in @objc methods properly.
Use CodeGenABITypes to determine which return values should be indirect
in @objc methods.

Swift SVN r11184
2013-12-12 07:22:12 +00:00
Joe Groff
6370f91383 ClangImporter: Handle negative C enum constants.
We needed some patching up to convert negative enum constants into proper negative IntegerLiteralExprs in the imported Swift AST, to handle the obnoxious INT_MIN edge case, and to handle "negative" values of unsigned enums.

Swift SVN r10005
2013-11-06 21:28:24 +00:00
Joe Groff
1d31ce558b Add tests that we import octal and hex enum constants properly.
Swift SVN r9994
2013-11-06 18:24:40 +00:00
Joe Groff
c5305f3e60 IRGen: Lay out enums from Clang with C-compatible layout.
Borrow the scalar type of the raw type as the representation type of C enums, and use the raw values from C as the discriminator values of the cases.

Swift SVN r9988
2013-11-06 05:54:17 +00:00
Joe Groff
5ec3cad5f6 ClangImporter: Emit metadata for imported enums.
Whatever kind of Swift decl we cons up for a Clang enum, add it to the externals list so we can pick it up and emit Swift metadata for it in IRGen. Fixes <rdar://problem/15242452>.

Swift SVN r9801
2013-10-30 18:15:09 +00:00
Joe Groff
514d659ead IRGen: Emit categories for extensions that conform to ObjC protocols.
Swift SVN r5659
2013-06-18 22:37:55 +00:00
Joe Groff
34dc94679d IRGen: Get objc protocol erasure working.
Don't try to emit witness tables for protocols that don't need them when emitting a protocol erasure. (We'll need to eventually ensure that ObjC method metadata gets generated for the conforming methods, but we don't yet, so this will only work for types that already have ObjC-dispatchable methods.)

Swift SVN r5610
2013-06-16 05:06:28 +00:00
Joe Groff
b50eb85fc9 Flip the -nsstring-is-string switch and update tests.
Make nsstring-is-string the default, and invert the commandline flag to -no-nsstring-is-string. Update tests to use String where they used to use NSString, particularly with block arguments. (While we're here, update them to use the new closure syntax.)

Swift SVN r5374
2013-05-29 16:27:16 +00:00
Joe Groff
0132f279a7 IRGen: ObjC super dispatch for super.constructor.
Implement super.constructor for ObjC superclasses by dispatching the superclass init message with objc_msgSendSuper2. Fixes <rdar://problem/13107128>.

Swift SVN r4288
2013-03-05 21:39:42 +00:00
Joe Groff
a9f747ec1f IRGen: Emit categories for ObjC class extensions.
Emit ObjC stubs and categories for methods defined in extensions of ObjC-compatible classes. This makes extensions of ObjC classes available to ObjC in statically compiled code. For immediate-mode code we'll still need to dynamically register extension methods using the ObjC runtime.

Swift SVN r4149
2013-02-22 05:40:09 +00:00
Joe Groff
4792c60d2d IRGen: Implement super method calls.
For Objective-C super calls, build an objc_super struct value containing the receiver and class/metaclass object and pass it to objc_msgSendSuper2. For Swift super calls, emit a direct call to the super implementation.

Swift SVN r4023
2013-02-13 02:41:20 +00:00
Joe Groff
aa75885266 IRGen: Fix C funcs with big struct return and arg.
Should have tested both together. Oops.

Swift SVN r3998
2013-02-09 01:39:22 +00:00
Joe Groff
9c022d5d65 IRGen: Fudge passing large ObjC structs as byvals.
Push LLVM attribute generation from expandAbstractCC into getFunctionSignature and CallEmission so that they can generate sret and/or byval attributes per-argument according to the calling convention. Copy our bogus rule for emitting sret returns (more than three elements in the explosion) and reuse it to pass large struct values as byvals rather than as explosions. This should be good enough to get both 'NSRect' and
'NSRange', 'NSSize' etc. to pass correctly to ObjC methods. Next step is to set the AbstractCC correctly for imported func decls so that standalone C functions follow the same bogus rule.

Swift SVN r3993
2013-02-08 21:50:08 +00:00
Joe Groff
6cca08826a IRGen: Hack in calls to block converter funcs.
Add a mangling for 'block converter' functions and for [objc_block] function types. [objc_block] types also need their own HeapTypeInfo representation that uses ObjC retain/release. When we see a BridgeToBlockExpr, feed the function pointer and context from the Swift closure to the external conversion function and hope we get a block back.

Swift SVN r3899
2013-01-30 01:01:34 +00:00
John McCall
521f0742b4 Account for types that explode to sizes != 1 when computing the
consumed arguments of a method.

Swift SVN r3464
2012-12-13 00:24:42 +00:00
John McCall
4b246bce50 Implement the ObjC ownership conventions, using ARC-in-clang's
method annotations when possible.

Swift SVN r3427
2012-12-10 08:18:11 +00:00
John McCall
c6374093f6 Add support for messaging Objective-C classes.
Notably, there is still no support for +1 return values,
so we'll leak when doing alloc/init and so on;  but this gets
the fundamentals in place.  A lot of the extra stuff in here
is dealing with mapping between metatypes and class objects.

Swift SVN r3425
2012-12-10 08:18:03 +00:00
John McCall
59d4677b35 Implement metatype references to ObjC classes.
The interesting thing here is that we need runtime support in
order to generate references to metatypes for classes, mostly
because normal ObjC classes don't have all the information we want
in a metatype (which for now just means the VWT pointer).
We'll need to be able to reverse this mapping when finding a
class pointer to hand off to, say, an Objective-C class method,
of course.

Swift SVN r3424
2012-12-10 08:17:57 +00:00