Commit Graph

815 Commits

Author SHA1 Message Date
Doug Gregor
12c064d501 IR generation for DynamicSelf method invocations on existentials.
When projecting an existential into an opened archetype, bind the
archetype with metadata and witness tables extracted from the
existential. Tweak SILGen so that it doesn't destroy the opened
archetype value an extra two times.

Use an executable testcase to ensure end-to-end operation, because we
still don't have a parsable form existential projection to opened
archetype instructions.



Swift SVN r13755
2014-02-10 18:47:24 +00:00
Mark Lacey
e54a454cca Handle the remaining types in Clang type generation.
With this we generate Clang types for everything we allow to be in the
signature of a C/@objc function.

Swift SVN r13734
2014-02-10 05:07:22 +00:00
Mark Lacey
660bb20909 Select correct IR types for direct arguments to C/@objc functions.
Reapply r13532 fixes for dealing with arguments that should be exploded
for C/Obj-C functions.

This gets us a bit closer to properly generating the correct types for
arguments. The remaining piece is generating all the argument types at
once rather than one at a time, which also requires being able to always
generate Clang types for the Swift types we see in the signatures of
these functions.

Swift SVN r13638
2014-02-07 18:04:45 +00:00
Mark Lacey
d335817783 Revert "Generate arguments with the correct ABI types for C/Obj-C functions."
This reverts commit r13532 which broke the build.

Swift SVN r13547
2014-02-06 02:07:17 +00:00
Mark Lacey
fd8e10fa68 Generate arguments with the correct ABI types for C/Obj-C functions.
This gets us a bit closer to properly generating the correct types for
arguments. The remaining piece is generating all the argument types at
once rather than one at a time.

That part cannot happen until we can always generate Clang types for
the Swift types we see in the signatures of these functions.

Swift SVN r13532
2014-02-06 01:06:32 +00:00
Mark Lacey
db70ec74be Minor refactoring of return type handling for C/Obj-C functions.
Swift SVN r13520
2014-02-05 23:18:50 +00:00
Mark Lacey
e9e4db4168 Use the correct type when determining whether we need to coerce.
Swift SVN r13379
2014-02-03 22:48:39 +00:00
Doug Gregor
9740ccc33e Adopt Clang's new ABITypes.arrangeFreeFunctionCall API
Swift SVN r13308
2014-02-01 22:41:17 +00:00
Mark Lacey
088d7b5f20 IRGenModule users shouldn't need to know about clang::CodeGenerator.
Swift SVN r13179
2014-01-30 22:59:00 +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
c06facbdd1 Small simplification of IRGenFunction::coerceValue().
We know the type of the value we are reinterpreting so it does not need
to be a parameter.

Swift SVN r12911
2014-01-24 07:51:26 +00:00
Mark Lacey
6fa70874fa Correctly select when C/ObjC arguments are passed as byvals.
Swift SVN r12890
2014-01-24 00:21:06 +00:00
Joe Groff
2af8cf2343 IRGen: Use interface types to lower ApplyInst args and returns, and SILFunction parameters and returns.
Swift SVN r12626
2014-01-21 00:23:07 +00:00
Joe Groff
dd5dec3dd5 IRGen: Use SILFunctionType interface types in easy places.
ObjC partial_apply thunks are never generic, and neither are cast builtins, so the interface types are always equivalent.

Swift SVN r12625
2014-01-21 00:23:06 +00:00
Joe Groff
5fc62094c7 IRGen: Fix handling of u_to_s_checked_trunc with runtime checks disabled.
I forgot to update this case from an implementation that doesn't work. Factor out the common implementation with the other cases and use it in both places. This enables the libraries and tests to build and run with -DSWIFT_RUNTIME_CHECKS=OFF.

Swift SVN r12609
2014-01-20 20:16:17 +00:00
Joe Groff
c7a8b4f1a5 IRGen: Emit unchecked operations for checked builtins with -disable-all-runtime-checks.
Emit checked arithmetic and conversion instructions as unchecked LLVM IR when runtime checks are disabled.

Swift SVN r12592
2014-01-20 18:01:02 +00:00
Joe Groff
4c6ef04d02 IRGen: Expand function signatures from SILFunctionType's interface types.
Now that we unique equivalent archetypes and lower interface types from the AST, we can convert IRGen over to using the interface types of the SILFunctionType when expanding out an LLVM function signature.

Swift SVN r12566
2014-01-19 17:14:09 +00:00
Mark Lacey
0564fae0bd Assert if we attempt to coerce types of different sizes.
We shouldn't store to one size and load as another, and shouldn't need
to handle things like truncation and extension of numeric types, either.

Swift SVN r12530
2014-01-18 04:49:32 +00:00
Mark Lacey
85edc079b7 Coerce scalar types in function returns.
Previously we coerced only struct return types, but we actually need to
be able to coerce scalar types as well, e.g. differing pointer types
when the ABI type differs from the type used in the body of the
function.

Swift SVN r12527
2014-01-18 02:08:04 +00:00
Mark Lacey
d9c88e94db Small clean-up in Clang type generation.
Factor our code to get to Clang ASTContext.

Swift SVN r12462
2014-01-17 04:25:10 +00:00
John McCall
32d4ef7001 Remove IR-gen's specialized ASTVisitor.
Swift SVN r12427
2014-01-16 22:32:35 +00:00
Joe Groff
0c20833d5f IRGen: Optimize copy/destroy of ObjC tagged or nullable enums too.
Rename TypeInfo::isSingleRetainablePointer to TypeInfo::isSingleSwiftRetainablePointer, and add an isSingleUnknownRetainablePointer entry point to ask whether a type has any single-refcounted representation, native or not. Use that to provide the same nullable-pointer and pointer-with-tag optimizations for copying and destroying enums with ObjC payloads as we do for Swift class payloads.

Swift SVN r12410
2014-01-16 19:08:01 +00:00
Joe Groff
197a1653fd SIL: Start on a StripRuntimeChecks pass.
In the long term we want more detailed configurability of runtime checks, but for our short-term performance work we just want a blanket on/off switch. Add a StripRuntimeChecks SIL pass that, as a start, converts invocations of checked overflow builtins to the equivalent unchecked builtins and kills cond_fails. Expose it through the compiler with a -disable-all-runtime-checks switch.

NB: I haven't tested building the stdlib or running the tests with the switch thrown yet.

Swift SVN r12379
2014-01-16 02:35:16 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Joe Groff
1001745ac0 IRGen: Forward indirectly-returned SIL return value in partial application forwarder.
A type may be treated as a by-value return in SIL but still be lowered to an indirect return in IR if it's big enough, so handle this case in the partial application forwarder. Fixes <rdar://problem/15826328>.

Swift SVN r12351
2014-01-15 22:05:50 +00:00
Joe Groff
0bc54babdb IRGen: Don't assume the ABI return type of a function is a struct.
For some structs on arm64 this doesn't hold, and the assumption isn't important to the code.

Swift SVN r12333
2014-01-15 18:17:28 +00:00
Mark Lacey
673a65c2a5 Move Clang type generation into its own file.
We want to be able to share this both for signature type generation and
Objective-C type encoding.

A separate implementation file will follow when I expand the
functionality for more than just imported struct types.

Swift SVN r12137
2014-01-10 22:05:12 +00:00
Joe Groff
5e5f31d5e3 IRGen: Share TypeInfo among equivalent generic instantiations, take 2.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

In this revision, we profile the nested archetypes of each recursively, which I neglected to take into account originally in r12112, causing failures when archetypes that differed by associated type constraints were incorrectly collapsed.

Swift SVN r12116
2014-01-10 05:25:45 +00:00
Doug Gregor
03edef185a Emit a -dealloc method for Swift classes whose root class is defined in Objective-C.
Teach SILGen to emit a -dealloc method that runs user code, destroys
instance variables, and then calls up to the superclass dealloc. Teach
IRGen to deal with Objective-C destructor methods and add -dealloc to
the instance method table.

There are a few things still wrong here: we're emitting both a Swift
destructor and -dealloc, even though only one of them should ever
actually be used. Additionally, instance variables shouldn't be
destroyed in -dealloc, but in .cxx_destruct, so they persist until the
last of the -dealloc methods is invoked.

Swift SVN r12115
2014-01-10 05:07:33 +00:00
Joe Groff
97ff9e47a8 Revert "IRGen: Share TypeInfo among equivalent generic instantiations."
This reverts commit r12112. It gives the buildbot indigestion.

Swift SVN r12113
2014-01-10 03:22:53 +00:00
Joe Groff
57cacbfe38 IRGen: Share TypeInfo among equivalent generic instantiations.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

Swift SVN r12112
2014-01-10 02:02:58 +00:00
Mark Lacey
15a26af8ac Replace getClangABIType() with a CanTypeVisitor<>.
No functionality change. This is in preparation for generating Clang
types for more than just imported structs.

Swift SVN r12108
2014-01-10 00:27:25 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
Joe Groff
e672eef600 IRGen: Remove long comment about uncurrying.
All uncurrying happens in SILGen now.

Swift SVN r11994
2014-01-07 17:56:33 +00:00
Chris Lattner
8d854f3e0b straighten out IRGen's @lvalue vs @inout handling. Since SILGen lowers all
@lvalue types, IRGen only needs to handle @inout.


Swift SVN r11799
2014-01-01 20:35:02 +00:00
Joe Groff
fecffda067 IRGen: Handle abstraction changes in partial_apply thunks.
When partial_applying a generic we still need to handle trivial abstraction changes such as bitcasting pointers to archetypes at the IR level. Along with the previous commit this fixes <rdar://problem/15597271>.

Swift SVN r11621
2013-12-24 20:14:03 +00:00
Joe Groff
e06ee37dca Enable SIL protocol witnesses.
We should be able to cut out another layer of IRGen grime now.

This does XFAIL one test, test/Prototypes/TextFormatting.swift, which fails because of a weird archetype ordering in a nested substitution list. This should get sorted out by switching to interface types, so I'm going to let it go until then.

Swift SVN r11618
2013-12-24 04:36:03 +00:00
Joe Groff
14362cd8e2 IRGen: Lower metatypes respecting SIL's 'thin' bit.
Use the 'thin' bit set by SIL to decide whether a metatype lowers to an empty type or not. In GenPoly we still need to accommodate unlowered metatypes to keep protocol witnesses limping along; hopefully that code can be killed soon. With this change we now lower @cc(witness_method) consistently for static methods.

Swift SVN r11535
2013-12-21 02:05:37 +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
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Joe Groff
f9a5b2cf25 IRGen: Lower the witness polymorphic convention.
Add a new SourceKind for PolymorphicConvention, 'WitnessSelf', which always introduces a final 'Self' metadata argument to the signature and uses it to fulfill all of the generic parameters of the Self type, regardless of the SIL-level polymorphic signature of the function.

Swift SVN r11467
2013-12-19 06:48:08 +00:00
Joe Groff
9929f25f74 IRGen: Build correct TypeInfos for thin and thick function types.
Derive the appropriate ExtraData for a SILFunctionType from its thinness and calling convention. Consider @!thin @cc(witness_method) as having ExtraData::Metatype. This should eliminate all of the unspoken gentleperson's agreements that let thin and witness functions survive IRGen currently when we can turn on SIL witness tables.

Swift SVN r11446
2013-12-18 23:03:39 +00:00
Joe Groff
44dcc43fa9 ClangImporter: Make NS_OPTIONS imports conform to RawOptionSet.
This makes the bitwise operations &|^~ work with NS_OPTIONS.

Swift SVN r11349
2013-12-16 19:22:27 +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
0ff977d407 Add a 'WitnessMethod' enumerator to AbstractCC.
We'll use this to represent the slightly-different polymorphic calling convention used for passing Self into protocol witnesses.

Swift SVN r10898
2013-12-06 01:32:35 +00:00
Chris Lattner
a5cf0fa60a Hoist the FuncDecl out of builtin function IRGen, working in terms
of the simpler Identifier instead.


Swift SVN r10693
2013-11-30 01:04:38 +00:00
Chris Lattner
3b954ed44d strength reduce SILGenModule::getBuiltinInfo/getIntrinsicInfo to
take an identifier instead of a FuncDecl.


Swift SVN r10692
2013-11-30 00:57:46 +00:00
Chris Lattner
9410440bbd don't pass a FuncDecl into functions that ignore it. Don't recompute the
BuiltinInfo for an intrinsic when we already have it on hand.


Swift SVN r10690
2013-11-30 00:48:45 +00:00