Commit Graph

9332 Commits

Author SHA1 Message Date
Adrian Prantl
68e1df49f5 Fix a couple more glitches that were uncovered by assertions.
Swift SVN r5774
2013-06-23 03:35:28 +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
8fde18e787 Don't allow [objc] protocols to refine non-[objc] protocols.
This case isn't implemented, and we don't need it right away. We may revisit this restriction later.

Swift SVN r5738
2013-06-21 16:31:14 +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
Chris Lattner
8d53e68a68 switch function_ref/builtin_function_ref/global_addr to print their
referenced symbol with the name, followed by a colon, followed by the type
instead of the type first (following local value references).  For example,
instead of:

  %1 = function_ref $[thin] ((val : Builtin.Int128), Int64.metatype) -> Int64, @_TSi33_convertFromBuiltinIntegerLiteralfMSiFT3valBi128__Si // user: %4

we now get:
  %1 = function_ref @_TSi33_convertFromBuiltinIntegerLiteralfMSiFT3valBi128__Si : $[thin] ((val : Builtin.Int128), Int64.metatype) -> Int64 // user: %4




Swift SVN r5735
2013-06-21 04:54:01 +00:00
Joe Groff
df230cdd7f SIL: Add verifier checks that function conversions preserve cc.
Verify that ConvertFunction and ThinToThick instructions don't change the calling convention of function types.

Swift SVN r5729
2013-06-20 22:29:45 +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
37c36cf255 SILGen: Annotate naked intentional fallthrough.
Swift SVN r5691
2013-06-19 20:20:36 +00:00
Joe Groff
062fbf7edb Don't crash mangling single-protocol<T> types.
Swift SVN r5685
2013-06-19 19:13:54 +00:00
Joe Groff
e129ad26d0 Recursively consider ObjC protocol conformances.
Propagate ObjC-ness and emit ObjC thunks and metadata for ObjC protocols indirectly conformed to through protocol refinement.

Swift SVN r5680
2013-06-19 05:35:27 +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
f5101ddb97 Stop trusting the inliner to handle trivial 'size()' method calls.
Swift SVN r5671
2013-06-19 01:14:27 +00:00
Joe Groff
a0932125c6 SILGen: Emit thunks if an ObjC extension conforms w/ non-ObjC methods.
An [objc] protocol extension of a non-[objc] class from another module might introduce [objc]-ness onto methods from that other module, so we do have to do an extra pass while emitting extensions to make sure the conformance methods get thunked.

Swift SVN r5667
2013-06-19 00:22:32 +00:00
Joe Groff
254bc26d30 SIL: Allow cast/bridge builtins to be used with class archetypes.
Swift SVN r5661
2013-06-18 23:12:38 +00:00
Joe Groff
1deb3a9c44 Sema: Propagate ObjC-ness of protocol mappings at type-checking time.
Tag methods as 'isObjC' during decl type-checking if they're mapped into an ObjC protocol conformance. This is better than r5646 because it means we don't need another pass of thunking in SILGen and IRGen, and the thunks will get mapped in a deterministic order and not freak out the buildbot.

Swift SVN r5654
2013-06-18 20:58:29 +00:00
Joe Groff
bec09c334c SILGen: Emit ObjC thunks for methods conforming to ObjC protocols.
When emitting SIL for classes and class extensions, emit ObjC thunks not only for natively [objc] classes but for methods of native Swift classes used to conform to [objc] protocols as well.

Swift SVN r5648
2013-06-18 17:20:26 +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
f399ccbdb0 SILGen: Deinit existential after concrete value is cast out of it.
When we cast an opaque existential to a concrete type, we steal ownership of the contained value, which leaves the existential container deinitialized. We need a deinit_existential cleanup to deallocate its buffer so it doesn't leak.

Swift SVN r5625
2013-06-17 19:57:54 +00:00
Joe Groff
ad7c3ee361 SILGen: Calls to opaque existentials don't consume 'this'.
At the highest abstraction level, we pass 'this' to protocol witnesses byref and ownership isn't taken. (The witness thunk for class methods retains 'this' behind the scenes.) Don't disable the cleanup for existential containers on which methods are called so we don't leak it.

Swift SVN r5624
2013-06-17 19:57:51 +00:00
Joe Groff
c7f86f1ffe SILGen: Emit generic dynamic casts.
Use the new SIL instructions from the previous commit to implement archetype and existential dynamic casts.

Swift SVN r5613
2013-06-17 01:23:58 +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
f2500d79b7 Sema: Allow dynamic casts from generics to concrete types.
Open us 'a as! T' to allow dynamic casts from archetypes to archetypes, archetypes to concrete types, existentials to archetypes, and existentials to concrete types. When the type-checker finds these cases, generate new Unchecked*To*Expr node types for each case.

We don't yet check whether the target type actually makes sense with the constraints of the archetype or existential, nor do we implement the SILGen/IRGen backends for these operations. We also don't extend 'x is T' to query the new operation kinds. There's a better factoring that would allow 'as!' and 'is' to share more code. For now, I want to make sure 'x as! T' continues to work for ObjC APIs when we flip the switch to import protocol types.

Swift SVN r5611
2013-06-16 21:54:13 +00:00
Joe Groff
a491a3fc93 ClangImporter: Emit metadata for imported protocol types.
Swift SVN r5605
2013-06-16 02:55:47 +00:00
Joe Groff
23ae370987 SILGen: Emit objc protocol method calls with ObjC conventions.
Use the ObjC method calling convention and ownership conventions when emitting method calls to ObjC protocol methods.

Swift SVN r5599
2013-06-15 21:28:56 +00:00
Joe Groff
c20eda7b15 SILGen: Remove dead emit{Archetype,Protocol}Method helper methods.
SILGenApply handles archetype and protocol methods internally now.

Swift SVN r5598
2013-06-15 19:37:28 +00:00
Joe Groff
1adf43c472 SIL: Fix failures introduced by r5593.
Swift SVN r5596
2013-06-15 16:21:32 +00:00
Joe Groff
d4f9579eac IRGen: Class-bounded generics don't need extra metatype data.
Since the type metadata for the underlying method will be taken from the class instance, the witness entry point for a class-bounded protocol conformance doesn't need to pass on an extra metatype parameter for the 'This' archetype.

Swift SVN r5595
2013-06-15 16:10:04 +00:00
Joe Groff
7d322fcd35 "class-bound" -> "class-bounded"
English.

Swift SVN r5568
2013-06-11 00:19:29 +00:00
Ted Kremenek
05508d147c Add FIXME.
Swift SVN r5567
2013-06-11 00:17:05 +00:00
Ted Kremenek
ee9925495a Add llvm_unreachable() to silence uninitialized variable warning from the analyzer.
In this case "naturalUncurryLevel" *might* be uninitialized.  I'd prefer
that this code be structured with a switch to prove that all cases
are covered, but that might not be the cleanest solution.  I'll
leave that for Joe to decide.

Swift SVN r5565
2013-06-11 00:11:20 +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
Joe Groff
2d2ee387e7 Class-bound archetypes and existentials are reference types.
Archetypes and existentials with a class bound can be assumed to have reference semantics, and don't need to be treated as address-only in SIL.

Swift SVN r5553
2013-06-09 04:36:46 +00:00
Joe Groff
87f6b96d5a Mangle: Fix archetype depth calculation.
We were re-counting archetype depth levels and ended up mangling the triangular number of the archetype depth instead of the linear archetype depth. Measure archetype depth starting from zero to fix this.

Swift SVN r5546
2013-06-08 21:10:20 +00:00
Joe Groff
fdb1033e80 Fix protocol type mangling harder.
Didn't take substitutions into account last time. Always mangle a single-protocol type as a single protocol list, so that substituted protocols mangle as 'PS<n>__' as expected. Also, actually update the tests this time.

Swift SVN r5541
2013-06-08 04:51:25 +00:00
Joe Groff
075e0031d7 Fix mangling of single-protocol types.
The protocol type mangling is 'P' protocol+ '_', and so needs a trailing '_' to terminate the list, but we were missing the '_' for single-protocol types, which we tried to mangle as a nominal type context.

Swift SVN r5539
2013-06-08 03:11:07 +00:00
Doug Gregor
85f32c5c07 Prepend the magic "\01" to asm names of Clang declarations.
Should actually fix <rdar://problem/14094368> properly.


Swift SVN r5522
2013-06-07 21:26:10 +00:00
Doug Gregor
b4e68f1eaa Head Clang's AsmLabelAttr when mangling the name for the Clang declaration.
Fixes <rdar://problem/14094368>.


Swift SVN r5516
2013-06-07 20:08:27 +00:00
Joe Groff
cb1f81db84 Make assignment an expression.
Change AssignStmt into AssignExpr; this will make assignment behave more consistently with assignment-like operators, and is a first step toward integrating '=' parsing with SequenceExpr resolution so that '=' can obey precedence rules. This also nicely simplifies the AST representation of c-style ForStmts; the initializer and increment need only be Expr* instead of awkward Expr*/AssignStmt* unions.

This doesn't actually change any user-visible behavior yet; AssignExpr is still only parsed at statement scope, and typeCheckAssignment is still segregrated from the constraint checker at large. (In particular, a PipeClosureExpr containing a single assign expr in its body still doesn't use the assign expr to resolve its own type.) The parsing issue will be addressed by handling '=' during SequenceExpr resolution. typeCheckAssignment can hopefully be reworked to work within the constraint checker too.

Swift SVN r5500
2013-06-06 22:18:54 +00:00
Joe Groff
a9a2bff829 SIL: Print index_addr operands with types.
As required by the SIL parser.

Swift SVN r5481
2013-06-05 19:59:10 +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
Doug Gregor
109290c6f0 Introduce the StringLiteralConvertible formal protocol for string literals.
Swift SVN r5473
2013-06-04 21:35:12 +00:00
Doug Gregor
17e788e04f Open literal types as binding types, to provide [] sugar for arrays.
Swift SVN r5436
2013-06-03 19:43:02 +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