Commit Graph

1696 Commits

Author SHA1 Message Date
Dmitri Hrybenko
43137f155c Fix warning: use an unused variable
Swift SVN r5879
2013-06-28 21:12:48 +00:00
Adrian Prantl
ae9bd9397b Debug Info: Generate scope information for many more builtin/artificial functions.
Swift SVN r5876
2013-06-28 20:05:41 +00:00
Adrian Prantl
ceb32c281c Debug Info: Attach (some of the) functions without sources to their scopes.
Various cleanups.

Swift SVN r5863
2013-06-28 00:52:07 +00:00
Adrian Prantl
c375617244 Address a couple of Joe's comments.
Swift SVN r5858
2013-06-27 23:25:22 +00:00
Adrian Prantl
de32b201d0 Debug Info: Add support for subprograms.
This means that single-stepping in lldb actually works now!

Swift SVN r5828
2013-06-27 00:46:30 +00:00
Adrian Prantl
0f7533dc7e Debug Info! Add basic support for line tables, compilation units, files,
and lexical scopes, which can be enabled through the new -g option.
When -g is enabled, line tables and scopes compile all the way
down to DWARF.

Changes to SIL:
- In addition to a SILLocation, every instruction now also has a pointer
  to a SILDebugScope (its containing lexical scope).
- Added LexicalScope, which is to be used for all Scopes we want to show
  up in the debug info.

Swift SVN r5772
2013-06-23 00:09:17 +00:00
Joe Groff
f072c48e45 Refactor cast representation in AST and SIL, and implement 'is'.
Improve our representations of casts in the AST and SIL so that 'as!' and 'is' (and eventually 'as?') can share almost all of the same type-checking, SILGen, and IRGen code.

In the AST, we now represent 'as!' and 'is' as UnconditionalCheckedCastExpr and IsaExpr, respectively, with the semantic variations of cast (downcast, super-to-archetype, archetype-to-concrete, etc.) discriminated by an enum field. This keeps the user-visible syntactic and type behavior differences of the two forms cleanly separated for AST consumers.

At the SIL level, we transpose the representation so that the different cast semantics get their own instructions and the conditional/unconditional cast behavior is indicated by an enum, making it easy for IRGen to discriminate the different code paths for the different semantics. We also add an 'IsNonnull' instruction to cover the conditional-cast-result-to-boolean conversion common to all the forms of 'is'.

The upshot of all this is that 'x is T' now works for all the new archetype and existential cast forms supported by 'as!'.

Swift SVN r5737
2013-06-21 05:54:03 +00:00
Joe Groff
470cb9eae0 IRGen: Implement opaque archetype/existential casts.
Use the new swift_dynamicCastIndirect runtime functions to implement casts from opaque archetype and existential types to concrete types.

Swift SVN r5684
2013-06-19 18:56:14 +00:00
Joe Groff
4db5b84dde Oops, 'requiresClassExistential' -> 'isClassExistential'.
Clbuttic search-and-replace mistake.

Swift SVN r5675
2013-06-19 04:01:48 +00:00
Joe Groff
a55f246946 Remove the controversial "bounded" from "class-bounded".
Just refer to "class archetypes" and "class protocols". Change 'isClassBounded' methods to 'requiresClass', which is a character shorter.

Swift SVN r5674
2013-06-19 03:58:11 +00:00
Joe Groff
665cbf56c1 IRGen: Implement conversions between class protocol types.
Implement existential upcasts from a class-bounded protocol type to a more general one.

Swift SVN r5673
2013-06-19 02:46:29 +00:00
Joe Groff
ff5f41b5f0 Archetypes with superclass bounds are class-bounded.
Treat archetypes with a superclass bound as class-bounded. Change SILGen and IRGen to use the new SuperToArchetypeRef and ArchetypeRefToSuper cast instructions, and drop the old SuperToArchetype and ArchetypeToSuper instructions, which are unneeded because any archetype with a superclass will be class-bounded.

Note that this patch doesn't implement representation optimization for archetypes with superclass bounds--they're still always represented with a worst-case UnknownRefCountedPtrTy.

Swift SVN r5629
2013-06-17 21:54:01 +00:00
Joe Groff
dcc414026e IRGen: Lower SIL DeinitExistentialInst.
Provide a lowering for the DeinitExistential instruction to deallocate the buffer in an existential container with an uninitialized value, using its deallocateBuffer witness.

Swift SVN r5623
2013-06-17 19:57:48 +00:00
Joe Groff
c3e2afd4ef IRGen: Implement class-bounded generic dynamic casts.
Casts from class-bounded archetypes and existentials can use the existing dynamicCast runtime entry points.

Swift SVN r5614
2013-06-17 16:10:47 +00:00
Joe Groff
54c6cb383f IRGen: Emit ObjC archetype/protocol method calls.
Emit ObjC method dispatch for ObjC method calls. This should get calls to generics bound by ObjC protocols working; ObjC existentials still need their representation tweaked not to include witness table pointers.

Swift SVN r5600
2013-06-15 22:12:46 +00:00
Joe Groff
f678700dce IRGen: Implement class-bounded existential containers.
Provide TypeInfo for class-bounded existentials, which represents them as an explosion comprising one witness table per subscribed protocol and then the class instance pointer as an ObjC-refcounted pointer. Provide lowerings for the SIL instructions that manipulate class-bounded existentials (except for existential-to-existential erasures, which aren't critical to getting basic operations working and will need some abstraction remapping to deal with class-bounded-to-opaque upcasts aside from the representation change).

Swift SVN r5579
2013-06-14 14:52:47 +00:00
Joe Groff
00f9494d8f IRGen: Remove dead variable from getCallEmissionForLoweredValue.
As reported by Ted in <rdar://problem/14109803>.

Swift SVN r5571
2013-06-11 00:33:19 +00:00
Joe Groff
b22fd22d57 SILGen: Handle Builtin.gep as a SIL builtin.
Add an index_raw_pointer instruction that acts like index_addr but for RawPointers, and use it to lower Builtin.gep into SIL instead of into IR.

Swift SVN r5479
2013-06-05 16:49:50 +00:00
Joe Groff
ed6b5ad497 SIL: Made index_addr index operand dynamic.
Instead of taking an integer constant index, index_addr now takes a value operand of builtin integer type, which makes more sense.

Swift SVN r5478
2013-06-05 16:49:41 +00:00
Joe Groff
3e3e5710ec Set proper DeclContext for ImplicitClosureExprs.
Now that SILGen and IRGen can both handle capturing archetypes from generic scopes, we can set the DeclContext of ImplicitClosureExprs correctly, so that SILGen captures their context archetypes. &&, and ||, and assert now work in generic contexts, at least in simple test cases.

Swift SVN r5476
2013-06-05 05:09:59 +00:00
Joe Groff
ae56951d08 IRGen: Emit specialized partial_apply thunks.
If a specialization is partially applied, emit a single thunk bundling the bound polymorphic arguments and the partially-applied argument values into a single context object. This should almost get closures in generic contexts (at least, ones that never cross abstraction boundaries) working.

Swift SVN r5475
2013-06-05 04:51:51 +00:00
Doug Gregor
109290c6f0 Introduce the StringLiteralConvertible formal protocol for string literals.
Swift SVN r5473
2013-06-04 21:35:12 +00:00
Joe Groff
0cb8adb46f SIL: Force all SILInstruction allocations through SILModule.
Delete the non-placement operator new/delete in the SILAllocated CRTP base so that the compiler saves us from accidentally allocating and leaking SILInstructions on the main heap instead of the owning SILModule's BPA.

Swift SVN r5468
2013-06-04 15:32:11 +00:00
Joe Groff
0dc5c66cd2 SIL: Move SILFunctionTypeInfo into a side table.
Generate and cache SILFunctionTypeInfo from Swift types on the fly, and simplify the SILType representation down to a CanType and isAddress bit.

Swift SVN r5298
2013-05-24 16:33:52 +00:00
Joe Groff
e3269a3b95 Pick one name for 'getAbstractCC'.
getCC, getFunctionCC, getConvention...consolidate them all under one name.

Swift SVN r5297
2013-05-24 03:08:40 +00:00
Joe Groff
5e2779b51e SIL: Uncurry function types within the Swift type system.
Remove uncurry level as a property of SILType/SILFunctionTypeInfo. During SIL type lowering, map a (Type, UncurryLevel) pair to a Swift CanType with the uncurried arguments as a Swift tuple. For example, T -> (U, V) -> W at uncurry level 1 becomes ((U, V), T) -> W--in reverse order to match the low-level calling convention. Update SILGen and IRGen all over the place for this representation change.

SILFunctionTypeInfo is still used in the SILType representation, but it's no longer load-bearing. Everything remaining in it can be derived from a Swift type.

This is an ABI break. Be sure to rebuild clean!

Swift SVN r5296
2013-05-24 01:51:07 +00:00
Joe Groff
8993ed707e Split 'C' and 'ObjCMethod' calling conventions.
This cleans up some wishy-washy control flow that relied on the uncurryLevel of a type to distinguish ObjC methods from freestanding C functions. While we're here, clean up all the places we use ad-hoc comparison logic on the AbstractCC enum to use switches that properly cover the enum.

Swift SVN r5251
2013-05-21 15:19:37 +00:00
Joe Groff
409655e037 SIL: Split tuple/struct field accessor insns.
Split ExtractInst and ElementAddrInst into separate Tuple and Struct versions, and have the Struct versions reference struct member VarDecls directly instead of integer indices.

Swift SVN r5215
2013-05-17 23:34:11 +00:00
Joe Groff
6abe889cae IRGen: Push SILType through a couple layers of partial application.
Swift SVN r5193
2013-05-16 23:33:48 +00:00
Joe Groff
c4317411b6 IRGen: Use SILType in functions used for existential container insts.
Swift SVN r5191
2013-05-16 22:47:49 +00:00
Joe Groff
285031cc8c IRGen: Use SILTypes for utility functions used by conversion insns.
Push SILTypes down into the helper functions used to emit SuperToArchetype, Downcast, and BridgeToBlock instructions.

Swift SVN r5189
2013-05-16 22:31:46 +00:00
Joe Groff
3d2cd72330 IRGen: Push SILTypes into emitClassAllocation.
Swift SVN r5188
2013-05-16 21:52:28 +00:00
Joe Groff
a8a7e16cf9 IRGen: requiresExternal{ByvalArgument,IndirectResult} can use SILType now.
These functions are now used in places where we're emitting ObjC calls and have a SILType.

Swift SVN r5187
2013-05-16 21:44:43 +00:00
Joe Groff
8303addde0 IRGen: Get ObjC thunks from SIL.
Use the SIL-generated ObjC thunk symbols instead of generating them in IRGen. Kill all the now-dead IRGen OwnershipConventions stuff. Teach IRGenSILFunction how to emit a C-calling-convention function, and getFunctionType how to map a C-calling-convention function type. Fix a bug in SILGen where ObjC thunks for methods and properties from extensions weren't getting emitted.

Swift SVN r5180
2013-05-16 19:03:37 +00:00
Joe Groff
b439e49625 IRGen: Use SILTypes in field projection functions.
Swift SVN r5154
2013-05-10 23:17:08 +00:00
Joe Groff
cdf95e6c5a IRGen: Use SILTypes when dispatching archetype/existential methods.
Swift SVN r5153
2013-05-10 22:26:24 +00:00
Joe Groff
667ef5d651 IRGen: Look up metatypes and class methods using SIL types.
Swift SVN r5150
2013-05-10 21:20:11 +00:00
Joe Groff
197c3e6d02 IRGen: Strip unneeded parameters from IRGenFunction constructor.
Swift SVN r5146
2013-05-10 18:18:14 +00:00
Joe Groff
c012c2e1ce IRGen: Add 'Callee::forKnownFunction' for SIL types.
Swift SVN r5145
2013-05-10 18:18:12 +00:00
Joe Groff
223d0251bd IRGen: Add getFragileTypeInfo and getFunctionType for SIL types.
Add overloads of getFragileTypeInfo and getFunctionType that take a SILType instead of a Swift CanType, and use them where it's easy to do so. Right now they just forward to the CanType versions, but we'll want to do SILType-specific type conversion soon. Clean up some IRGenSILFunction interfaces now that SILFunction carries most of the information IRGen needs intrinsically. No functionality change.

Swift SVN r5141
2013-05-10 16:28:25 +00:00
Joe Groff
c0a44f71c9 IRGen: Reify SpecializeInst thunks.
Teach IRGen how to emit thunks for SpecializeInsts that aren't immediately called and actually get used as values. This allows generic function instance to get passed around as values (again), and is a step along the way to making closures in generic contexts work (so we can specialize the local function, then partially apply its specialized context).

This doesn't work yet if we specialize to local archetypes--SIL needs to learn that we need a [thick]-typed thunk for local archetype specializations, in order to pack the metadata and wtables for the local type variables.

Swift SVN r5083
2013-05-07 23:39:06 +00:00
Chris Lattner
6c9c6c47a9 revert r5028, re-eliminating Scope since its caching behavior is better handled
by the LLVM IR optimizer.  Tuple metadata refs are now largely
readnone, function metadata refs are already readnone.  There may be some
left that are not, but they can be handled later. 


Swift SVN r5071
2013-05-06 23:27:05 +00:00
Joe Groff
f79e939460 SIL: Sever load-bearing links to the AST.
Make IntegerLiteral, FloatLiteral, and StringLiteral own their own copies of their values so they don't depend on the AST. Remove the now-redundant IntegerValueInst, which only existed to be a non-AST-dependent variant of IntegerLiteral.

Swift SVN r5045
2013-05-06 03:08:58 +00:00
Joe Groff
d91f78556a IRGen: Implement protocol typeof.
Represent protocol 'P.metatype' types using the type metadata of the contained metatype. Emit 'typeof' value witnesses for protocol types that project the existential container buffer and then call the 'typeof' witness for the contained value. Implement the SIL protocol_metatype instruction the same way.

You can't quite call static methods on protocols yet because protocol_method doesn't know how to look up static methods from an existential metatype yet.

This breaks references to protocol names—they will try to create an existential metatype that refers to the metadata of the protocol type itself, rather than to the metadata of a conforming type. <rdar://problem/13438779> would fix them.

Swift SVN r5033
2013-05-03 01:00:06 +00:00
Joe Groff
df059d02cc IRGen: Revive scoped metadata caching, at BB level.
John talked me out of this. We still want to cache metadata at the BB level, because even with SIL GVN, there are potentially redundant metadata bits at a level SIL doesn't know about.

Swift SVN r5030
2013-05-02 23:28:31 +00:00
Joe Groff
14cef05844 IRGen: Kill scoped metadata caching.
It doesn't really work with SIL-IRGen, and SIL GVN and LICM will hopefully have the same intended effect eventually.

Swift SVN r5028
2013-05-02 22:17:21 +00:00
Joe Groff
08b6f87524 Add 'typeof' to value witness tables.
To be able to get the dynamic type of a generic value, the 'typeof' operation needs to be part of the value witness for the type. Add 'typeof' to the value witness table layout, and in the runtime, provide standard typeof witnesses for static, Swift class, and ObjC class values.

Swift SVN r5013
2013-05-01 18:49:25 +00:00
Joe Groff
0566088bf2 Move name mangling into SIL.
Sever the last load-bearing link between SILFunction and SILConstant by naming SILFunctions with their mangled symbol names. Move the core of the mangler up to SIL, and teach SILGen how to use it to mangle a SILConstant.

Swift SVN r4964
2013-04-28 03:32:41 +00:00
Joe Groff
54e101c517 SIL: Give BuiltinFunctionRef its own instruction.
We don't want to have to recover from a mangled name whether a function call is to an IRGen-lowered builtin, so add an instruction for referencing builtins.

Swift SVN r4919
2013-04-26 18:36:47 +00:00
Joe Groff
ac1a7b3d0a IRGen: Walk local decls independent of SILFunctions
Find function bodies and emit their local type decls using the AST instead of relying on SILConstants to point the way back to the function bodies.

Swift SVN r4916
2013-04-26 00:32:22 +00:00