Commit Graph

6634 Commits

Author SHA1 Message Date
Adrian Prantl
5cf577282d Debug Info: Wire up more compile unit metadata and clean up the code a bit.
Swift SVN r5794
2013-06-25 00:19:32 +00:00
Adrian Prantl
05976c9612 Fix a typo that I would have caught with an asserts build..
Swift SVN r5773
2013-06-23 02:35:27 +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
a56be726da SILGen: Set [volatile] attribute on ObjC method dispatches.
Tag ObjC dynamic method dispatch instructions so that future optimizers know they can't be devirtualized.

Swift SVN r5728
2013-06-20 22:17:34 +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
7420089303 SIL: Add instructions to represent generic dynamic casts.
Add Downcast{Archetype,Existential}{Addr,Ref} instructions to represent casting of archetypes and existentials to concrete types.

Swift SVN r5612
2013-06-17 01:23:55 +00:00
Joe Groff
7d322fcd35 "class-bound" -> "class-bounded"
English.

Swift SVN r5568
2013-06-11 00:19:29 +00:00
Joe Groff
e1b70c8def SILGen: Method calls on class-bound existentials.
Tweak things so that looking up methods and projecting 'this' from a class-bound existential works.

Swift SVN r5556
2013-06-10 01:50:32 +00:00
Joe Groff
e1746bd24f SILGen: Use class-bound instructions to emit class-bound ErasureExprs.
Swift SVN r5555
2013-06-10 00:22:05 +00:00
Joe Groff
2ce2d33a64 SIL: Add instructions for class-bound archetype/existential operations.
Add class-bound versions of archetype conversion and existential creation/projection/conversion instructions. Since class-bound generics aren't address-only these instruction variants don't need to indirect through addresses.

Swift SVN r5554
2013-06-09 18:12:43 +00:00
Chris Lattner
e4e1d635a2 fix couple fixme's by having the SILParser make SILTypes directly
instead of going through TypeConverter.


Swift SVN r5527
2013-06-07 23:19:18 +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
dbc314cdab Add a -use-malloc switch for memory debugging.
This flag makes ASTContext and SILModule's allocators go through malloc instead of using bump pointer allocators, so that GuardMalloc or similar tools can be used to look for memory bugs.

Swift SVN r5472
2013-06-04 20:35:01 +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
6ea8add764 SILGen: Forward archetypes into local function contexts (take 2).
If a closure appears in a generic function, the standalone function type for the SIL function needs to include not only the captured values from the outer context, but the generic parameters from the outer context as well. In order to maintain SIL invariants we then need to hand generic parameters from the outer function to the inner closure using a SpecializeInst before partially applying the inner function to create the closure object.

It turns out that ImplicitClosureExprs seem to always be given null parent DeclContexts, so getFunctionTypeWithCaptures was missing adding the generic parameters into implicit closures, causing a crash building the stdlib. This version of the patch has a workaround for the case where a function is generic but a closure in the function is not generic with context (which shouldn't happen if the decl contexts are set correctly).

Swift SVN r5429
2013-06-01 00:40:32 +00:00
Joe Groff
7de743d28b Revert "SILGen: Forward archetypes into local function contexts."
This reverts commit c83c4a1859a99fbe45dcc48a8da12bbad64cea33.

Swift SVN r5425
2013-05-31 20:15:15 +00:00
Joe Groff
f20d16adc8 SILGen: Forward archetypes into local function contexts.
If a closure appears in a generic function, the standalone function type for the SIL function needs to include not only the captured values from the outer context, but the generic parameters from the outer context as well. In order to maintain SIL invariants we then need to hand generic parameters from the outer function to the inner closure using a SpecializeInst before partially apply the inner function to create the closure object.

Swift SVN r5424
2013-05-31 19:09:17 +00:00
Joe Groff
12c5999b44 Strip out -no-nsstring-is-string flag and associated LangOptions bit.
Swift SVN r5383
2013-05-29 19:42:12 +00:00
Chris Lattner
5350849cbe Parser support for retain/release/retain_autoreleased.
Swift SVN r5357
2013-05-26 23:22:40 +00:00
Joe Groff
8693c5efaa SIL: Emit String-to-NSString conversions.
If -nsstring-is-string is enabled, lower Strings in cc(c) and cc(objc) function types to NSString, and when calling them, insert calls to StringToNSString/NSStringToString to perform the bridging conversion.

This isn't quite ready for prime-time yet, because we still need to emit the inverse bridging for ObjC method thunks, and I haven't tested the IRGen end of things yet.

Swift SVN r5355
2013-05-26 20:29:09 +00:00
Chris Lattner
a34f4efa13 parse integer_literal. Parse and print tuple instructions with named
elements in a way that we can not lose information.


Swift SVN r5348
2013-05-26 01:09:46 +00:00
Chris Lattner
2e69c61f71 Implement more reasonable local value name lookup:
- Allow forward references.
  - Diagnose redefinitions.
  - Diagnose cases where the use/def of a value mismatch type.

While I'm at it, this fixes a bug where tuple parsing wasn't parsing
the separating commas.


Swift SVN r5343
2013-05-25 18:42:38 +00:00
Chris Lattner
7383d09a36 add a new SILType::getAsString() method, to be used in diagnostics when
printing SILTypes.  Bias the values in ValueToIDMap in SILPrinter so that
uses of invalid operands will print as %-1.



Swift SVN r5342
2013-05-25 18:40:47 +00:00
Chris Lattner
3db9fff98f implement SILValue::replaceAllUsesWith, fix a linked list manipulation
bug in removeFromCurrent.  Clearly I would fail an interview manipulating
linked lists :-)


Swift SVN r5341
2013-05-25 18:39:37 +00:00
Chris Lattner
22a14d7214 simplify the ctor for SILBuilder
Swift SVN r5333
2013-05-25 15:21:52 +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
Chris Lattner
0ad6fac283 Remove the basic block name field from SILBasicBlock. The name is currently
ignored and is going to be a private detail of the SILParser.


Swift SVN r5276
2013-05-22 22:24:39 +00:00
Chris Lattner
02f02fca0f [overpedantic] Get plurality right in the # users comment, printing:
%0 = tuple ()                                   // user: %1
  %1 = return %0 : $()

instead of "users".



Swift SVN r5268
2013-05-22 17:58:44 +00:00
Chris Lattner
38f19fed50 de-indent classes in this file and fit 80 columns. No functionality change.
Swift SVN r5264
2013-05-22 17:23:40 +00:00
Chris Lattner
d2de474371 Add a public raw_stream inserter for SILType. Change SILType printing
to always prefix a printed SILType with a $.  Update SILPrinter to use
this instead of manually adding $ everywhere.

The only behavioral change of this is that BB arguments now have a $ on
their type.


Swift SVN r5263
2013-05-22 17:14:05 +00:00
Joe Groff
12c7d01708 SIL: Write a function for uncurrying function types within the Swift type system.
Add a TypeConverter::uncurryFunctionType method for making an uncurried AnyFunctionType given a nested AnyFunctionType and an uncurry level. Without actually wiring it into anything yet, spot-check that it does the right thing by hacking SILPrinter to print the uncurried types of SILFunctions in a comment before the sil decl.

Swift SVN r5260
2013-05-22 03:14:13 +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
a4ce448280 Move cc attribute from SILType to AnyFunctionType.
We decided we're going to want to surface fine-grained representational control of functions to the user, so move AbstractCC and the calling convention attributes into the Swift type system. Like the [thin] attribute, we don't set this in the type-checker or importer at all yet, and let SILGen set the attribute where it wants it for now.

Swift SVN r5222
2013-05-20 17:55:51 +00:00
Chris Lattner
af3f2d2a66 cache the (recursive) computation of SILType::isAddressOnly in SILModule
to avoid expensive cases in extreme situations.


Swift SVN r5220
2013-05-19 04:23:29 +00:00
Chris Lattner
c1a7c7e3b9 flip the sense of the isLoadable predicate to check for isAddressOnly at
Joe's request.


Swift SVN r5219
2013-05-18 03:22:37 +00:00
Chris Lattner
1f971f88dd Remove the IsLoadable flag from SILType, and the isInvalid() state for SILType.
This frees up an extra bit in SILType, which we can expose to LLVM through
PointerLikeTypeTraits.  Use this bit in a PointerUnion, which allows simplifying
ValueBase, which happened to be the last use of the isInvalid() state.



Swift SVN r5218
2013-05-18 00:21:46 +00:00
Chris Lattner
650fafb11a Switch "loadable" from being a bit in SILType to being a predicate
function.  For now I'm not caching the result at all, and the
old bit still stays around until other dependencies can get
untangled.


Swift SVN r5217
2013-05-18 00:00:25 +00:00
Joe Groff
0b17473b03 Remove SILCompoundTypeInfo now that we don't need it.
We lose some verification for StructInst, but it was broken for generic types anyway.

Swift SVN r5216
2013-05-17 23:57:53 +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
Chris Lattner
2171b2f8b2 remove an inconvenient assertion (loadability will require a module to determine)
which happened to be written incorrectly anyway.


Swift SVN r5214
2013-05-17 23:21:53 +00:00
Chris Lattner
9a9acb11ba SILType::isLoadable is going to soon require a SILModule argument.
Add it, and propagate this through other APIs that call it (like
isAddressOnly and isTrivial).  No functionality change.



Swift SVN r5213
2013-05-17 23:13:38 +00:00
Chris Lattner
fd398e32e3 add a public way to get a primitive SILType. SILFunctionTypeInfo and
SILCompoundTypeInfo already have public construction functions that
unique in the SILModule.


Swift SVN r5201
2013-05-17 05:31:27 +00:00
Chris Lattner
e40f09aa25 remove a dead method, and move const to the "right" place per prevalent coding standard.
Swift SVN r5199
2013-05-17 05:08:56 +00:00