Commit Graph

1693 Commits

Author SHA1 Message Date
Mark Lacey
03d5cb233f Refactor argument emission for apply. NFC.
Split out argument emission into a function that handles calling into
Swift calling convention functions and a function that handles
foreign ("external") calling conventions.

The emission for foreign calling conventions simply falls back on the
one for Swift calling conventions at the moment, i.e. there is no change
in behavior yet.

Swift SVN r13282
2014-02-01 02:36:38 +00:00
Mark Lacey
52ae907e5d Remove unused SILValue.
Swift SVN r13209
2014-01-31 09:41:07 +00:00
Joe Groff
53ed008acb IRGen: Add an "unimplemented" error when trying to call ObjC blocks.
Beats crashing.

Swift SVN r13083
2014-01-29 01:32:29 +00:00
Adrian Prantl
0b40f0bda3 Debug info: Use a small dense map to keep track of argument numbers.
Swift SVN r12872
2014-01-23 19:46:33 +00:00
Adrian Prantl
7468054191 Debug info: Emit O0 shadow copies more consistently for (most) debuggable
values.

Swift SVN r12803
2014-01-22 22:42:07 +00:00
Adrian Prantl
69c58421ec Debug info: emit alloca shadow copies for DebugValues at -O0.
<rdar://problem/15849532> iteration variables in "for X in Y" statements don't have debug information

Swift SVN r12675
2014-01-21 23:58:37 +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
0ad29a86dd IRGen: Emit unconditional casts as bitcasts when runtime checks are disabled.
Swift SVN r12602
2014-01-20 18:47:12 +00:00
John McCall
11bd9bbbd9 Prune unnecessary #includes.
Swift SVN r12429
2014-01-16 22:32:36 +00:00
Doug Gregor
3a6db8292e Revert "Introduce the self_downcast SIL instruction to downcast the result of super.init."
We need to model the difference between Objective-C- and Swift-rooted
class hierarchies in SIL. IRGen is too late to handle nil returns.

This reverts commit 549db981ea0136a67aee3029aefe18a05d3c8833.

Swift SVN r12400
2014-01-16 06:01:21 +00:00
Doug Gregor
d59cf64dbf Revert "self_downcast never deals in address-only types."
This reverts commit a877f20420b14a7f053d6496d43b20689631ac4b.

Swift SVN r12399
2014-01-16 06:01:19 +00:00
Doug Gregor
8647c3c295 Revert "For Swift-rooted class hierarchies, emit self_downcast as a bitcast."
This reverts commit fb1ed53c039a46aa501734948e417a4dfbc86f69.

Swift SVN r12398
2014-01-16 06:01:18 +00:00
Doug Gregor
a6148459ef Revert "Simplify the emission of self_downcast. NFC"
This reverts commit d674023b0d5e4e7e058cc8b6275d2bad569fbf80.

Swift SVN r12397
2014-01-16 06:01:17 +00:00
Doug Gregor
9dfa5171a9 Simplify the emission of self_downcast. NFC
Swift SVN r12396
2014-01-16 06:01:13 +00:00
Doug Gregor
0c554b77da For Swift-rooted class hierarchies, emit self_downcast as a bitcast.
Swift-rooted class hierarchies don't permit the replacement of "self",
so it's guaranteed that the 'self' returned from a 'super.init'
invocation is identical to the previous self. Elide the unconditional
checked downcast (that manifests as a call to
swift_dynamicCastClassUnconditional in the runtime) by simply putting
a bitcast in its place.

For Objective-C-rooted hierarchies, 'self' can be replaced so memory
safety dictates that we keep the
swift_dynamicCastClassUnconditional(). Note that this path is still
unsafe against nil returns.

Swift SVN r12384
2014-01-16 04:24:59 +00:00
Doug Gregor
4abc10f2f4 self_downcast never deals in address-only types.
Swift SVN r12383
2014-01-16 04:24:59 +00:00
Doug Gregor
d19065048b Introduce the self_downcast SIL instruction to downcast the result of super.init.
No functional difference from the unconditional checked downcast we
had before, but this gives IRGen the chance to specialize the
implementation.

Swift SVN r12382
2014-01-16 04:24:56 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Joe Groff
677576cffb IRGen: Use a shared bb for condfail instructions and kill the runtime call.
Swift SVN r12339
2014-01-15 19:33:01 +00:00
Adrian Prantl
7f28907cae Reapply r12201 and r12289 with a workaround that does not crash when
the location of a DebugValueInst is not a Decl.
FIXME: This should probably not happen <rdar://problem/15825786>.


This reverts commit 12323 + bugfix.

Swift SVN r12332
2014-01-15 18:05:51 +00:00
Joe Groff
56128aca65 IRGen: Don't emit a trap for SIL 'unreachable'.
Missing return diagnostics are mature now, so a SIL 'unreachable' that makes it to IRGen should be legitimately unreachable now.

Swift SVN r12329
2014-01-15 17:42:03 +00:00
Greg Parker
a9697b308e Revert r12201 and r12289 because they crash in the stdlib -O0 build.
Swift SVN r12323
2014-01-15 07:41:04 +00:00
Adrian Prantl
bc084d7962 Debug info: Implement IRGen support for debug_value_addr.
rdar://problem/15785053.s

Swift SVN r12289
2014-01-14 18:21:39 +00:00
Doug Gregor
68e416bb21 SIL: Zap the unused "coerce" instruction.
The coercion doesn't represent anything interesting for SIL.


Swift SVN r12261
2014-01-13 23:50:12 +00:00
Adrian Prantl
739754bed8 Debug info: Initial IRGen support for SIL-level debug.value.
Swift SVN r12201
2014-01-11 06:21:32 +00:00
Chris Lattner
1c7803a1f9 Introduce new debug_value and debug_value_addr instructions to
give 'let' declarations debug info.  This is part of rdar://15785053.

IRGen is just stubbed out and nothing generates these yet (other than
the sil parser).


Swift SVN r12179
2014-01-11 01:07:36 +00:00
Adrian Prantl
946dc5678b Debug info: Provide an in interface for LLDB to mangle types and refactor
some code in IRGenDebugInfo along the way.
This is WIP for rdar://problem/15498877.

Swift SVN r12146
2014-01-10 22:35:53 +00:00
Doug Gregor
993754c1fe IR generation for the dealloc_ref SIL instruction.
Note that this lowering currently assumes that the static type of the class is its dynamic type. This should be a flag on the dealloc_ref instruction, not an assumption.

Swift SVN r12144
2014-01-10 22:32:52 +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
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
Doug Gregor
3f09a9891d Add an [objc] bit to the alloc_ref instruction to indicate when to use Objective-C's +allocWithZone:.
Swift SVN r12099
2014-01-09 21:35:55 +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
Doug Gregor
6ae381a12c Address Jordan's much-appreciated feedback
Swift SVN r12017
2014-01-07 23:02:15 +00:00
Joe Groff
8f6a58b998 SIL: Split address-only enum dispatch from destructive projection.
Split 'destructive_switch_enum_addr' into separate 'switch_enum_addr' and 'take_enum_data_addr' instructions. This should unblock some optimization work we would like to do with enums.

Swift SVN r12015
2014-01-07 22:58:21 +00:00
Doug Gregor
23fff50b69 Use UTF-16 string literals when the (builtin) string literal type supports it.
Make the compiler fully support both UTF-8 and UTF-16 string
literals. A (standard-library-defined) string type (such as String)
that wants UTF-16 string literals should conform to the
BuiltinUTF16StringLiteralConvertible protocol; one that wants UTF-8
string literals should conform to the BuiltinStringLiteralConvertible
protocol.

Note that BuiltinUTF16StringLiteralConvertible inherits from
BuiltinStringLiteralConvertible, so a string type that wants UTF-16
string literals also has to implement support for UTF-8. The UTF-16
entry point is preferred when the compiler knows that UTF-16 is
supported. This only tends to happen when we have a generic parameter
that is required to conform to StringLiteralConvertible, e.g.,

  func f<T: StringLiteralConvertible>() {
    var t: T = "Hello, World!" // uses UTF-8 entry point
  }

because the UTF-8 entry point is the only one guaranteed to be available.



Swift SVN r12014
2014-01-07 22:55:07 +00:00
Joe Groff
530e948cb2 SIL: Rename 'enum_data_addr' to 'init_enum_data_addr'.
Emphasize the fact that this address is only intended for initialization. When we split destructive_switch_enum_addr, there will be another similar instruction for destructively taking the payload out of an already-initialized enum.

Swift SVN r12000
2014-01-07 18:40:00 +00:00
Doug Gregor
1cf3bdbe8c Use objc_msgSendSuper[Stret] for foreign initializer delegation.
Introduce the SIL instruction peer_method, which references a method
in the given class or one of its superclasses (but not a subclass). It
IRGen's to objc_msgSendSuper[Stret] (vs. super_method IRGen'ing to
objc_msgSendSuper[Stret]2 for superclass lookup).

Use peer_method for initializer delegation to a foreign initializer
(i.e., an init-family method written in Objective-C) to close the
safety loophole introduced by initializer delegation in r11965. The
loophole still exists, but can only be triggered from Objective-C.

Teach definite initialization that peer_method really isn't a use of
self.



Swift SVN r11992
2014-01-07 17:33:41 +00:00
John McCall
12b1c9daf7 Add support for multiple encodings to the string_literal
SIL instruction.  Implement IR-gen support for same.  Fix
the parsing of SIL string literals to properly unescape them.

SIL-gen still emits UTF8 literals unconditionally.

Swift SVN r11904
2014-01-04 11:42:57 +00:00
Doug Gregor
1ee513e7e8 Use Builtin.Word for array lengths, string literal lengths, etc.
This eliminates a number of 64-bit integer/64-bit pointer assumptions
in the type checker and SILGen.


Swift SVN r11863
2014-01-03 18:53:01 +00:00
Joe Groff
1c9e924b8b IRGen: Disable debug info for witnesses.
To mangle archetypes from a witness context, we'd need to bind archetypes from both the witness and requirement's context, and IRGenDebugInfo isn't set up to do that yet. I'm not sure we want debug info for these thunks.

Swift SVN r11592
2013-12-23 03:57:33 +00:00
Joe Groff
dd55e97c76 IRGen: Lower a 'void' result value for ApplyInsts with out parameters.
Even if a function has an out parameter, in SIL the ApplyInst formally has a void return value, which ends up getting used occasionally by the reabstraction machinery. Make that work in IRGen.

Swift SVN r11590
2013-12-23 02:45:27 +00:00
Joe Groff
2f66cfed70 IRGen: Lower protocol_method in -emit-sil-protocol-witness-tables mode.
We still abuse the 'ExtraData' concept to carry the existential self type metadata from the protocol_method to the application, so we let that argument come from ExtraData when expanding the signature and consume it when binding arguments.

Swift SVN r11565
2013-12-22 04:44:41 +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
Connor Wakamo
3e81830385 Move "include/swift/IRGen/Options.h" to "include/swift/AST/IRGenOptions.h".
This commit only moves the header file; updating the class so that it is no longer in the irgen namespace will be handled separately.

Swift SVN r11404
2013-12-18 01:17:09 +00:00
Adrian Prantl
5dc5f4963c Debug info: set the appropriate scope for box-allocated variables.
Fixes rdar://problem/15638864.

Swift SVN r11321
2013-12-14 23:53:45 +00:00
Adrian Prantl
8e86f3d8b4 When emitting debug intrinsics for generic arguments, make sure they point
to the cop[ied]_addr and not to the incoming value.

Fixes <rdar://problem/15606136> Incorrect DWARF for arguments of generic types

Swift SVN r11203
2013-12-12 19:29:03 +00:00