Commit Graph

1703 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
Joe Groff
7275b2f34c IRGen: Pass in the debug DeclContext when building debug info for boxes.
So we don't crash when emitting debug info for a box of archetype type.

Swift SVN r13721
2014-02-09 22:25:57 +00:00
Joe Groff
05daca8e79 IRGen: Use interface types to implement the PolymorphicConvention.
Refactor the base PolymorphicConvention implementation to work using generic signatures and dependent types instead of GenericParamLists and archetypes, using an ArchetypeBuilder to produce representative archetypes as a convenience when we need to consider all of the requirements attached to a dependent type. In EmitPolymorphicParameters, map the dependent types into context to resolve the archetypes that should be bound in the body of the function.

Swift SVN r13685
2014-02-08 21:04:15 +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
Adrian Prantl
bacd2d3c04 Debug info: Fix the locations for branches in case statements.
<rdar://problem/15899195> Step from a case the middle of a switch goes to the beginning of the containing function

Swift SVN r13623
2014-02-07 02:37:36 +00:00
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +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
0d62463ce3 Revert "Refactor argument emission for apply. NFC."
This was r13282, and it turned out to be unnecessary.

Swift SVN r13490
2014-02-05 18:44:35 +00:00
Chris Lattner
7532213f4a simplify the SIL string_literal instruction to only produce a single value,
which is the address of the string data.  Have SILGen compute and produce the
isASCII bit as an integer literal, and remove the logic from IRGen.

This overall approach is simpler and enables better SIL-level optimizations.


Swift SVN r13363
2014-02-03 19:10:37 +00:00
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