Commit Graph

1069 Commits

Author SHA1 Message Date
Joe Groff
15c29e5d1f SIL: Add a project_box insn to project the address of the value from a box.
Still no implementation yet; we'll need to renovate how boxes work a bit to make them projectable (and renovate SILGen to generate typed boxes for the insn to be useful).

Swift SVN r29475
2015-06-18 04:07:23 +00:00
John McCall
1f80de3d71 Restore the original intent of our IRBuilder to not provide
functions to create load/store instructions without alignment.

Fix a couple of places that were unnecessarily using this.
This includes patching up some very suspicious code for generating
"shadow copies" of explosions for debug info that's not using
the existing TypeInfo-based load/store facilities for some
reason; I left the existing pattern in place for now, but it's
probably bogus.

Swift SVN r29459
2015-06-17 21:34:03 +00:00
Joe Groff
c354a7cf63 IRGen: Relax assertion that C parameter ABI types match size of Swift struct representation types.
Share the code that does elementwise coercions, which already behaved correctly, with the code that does struct-to-struct coercions, which still had the overly-conservative constraint. Fixes rdar://problem/21294916.

Swift SVN r29399
2015-06-16 17:23:52 +00:00
Joe Groff
e22908f569 IRGen: Peephole (copy_addr to [initialization] (init_existential_addr)) as well.
We can simultaneously allocate and initialize an opaque existential container's fixed-size buffer the same way, which benefits conversions from generic types to protocol types.

Swift SVN r29371
2015-06-13 00:35:04 +00:00
Nadav Rotem
f345ca33fd Fix unused variable warnings in Release builds.
Swift SVN r29367
2015-06-12 18:27:26 +00:00
Joe Groff
a321938d34 IRGen: Peephole (copy_addr to [initialization] (alloc_stack)) operations to use initializeBuffer value witnesses.
This saves a value witness call in the common case where a generic local variable or temporary is initialized from another value.

Swift SVN r29366
2015-06-12 16:59:14 +00:00
Adrian Prantl
35dac3b7c8 Debug info: Ensure that function arguments are only declared once.
Caught by an assertion in LLVM.

rdar://problem/21232690

Swift SVN r29304
2015-06-04 19:33:47 +00:00
Slava Pestov
3330b5ed85 IRGen: Support polymorphic @objc_method functions
The type of the self parameter of an @objc_method might be a
BoundGenericClassType or a GenericTypeParamType. In these cases
we have to bind metadata.

For an @objc protocol P, the calling convention for an existential P
would try to pass type metadata in an extra argument, just like it
would for a <T : P> T. However, it is only necessary in the latter
case, because only there we can reflect on T to observe the statically
bound generic type. Fix this with a small hack so that ObjC protocol
methods don't get an extra argument for Self.

This patch alone doesn't enable any new functionality by itself,
because we hit the 'unimplemented dynamic layout' error instead of
crashing.

Swift SVN r29258
2015-06-03 00:01:22 +00:00
Adrian Prantl
1f7eac97ab Debug Info: Do not attempt to reconstruct function arguments for
functions without a DeclContext. Currently this cannot happen,
but future SILPasses may rewrite functions in a way that it is meaningless
to preserve the function's DeclContext.

Swift SVN r29201
2015-06-01 18:16:37 +00:00
Adrian Prantl
b6e002cc70 Revert "Revert "Don't emit debug info for SILUndef values.""
This reapplies r29189.

Swift SVN r29193
2015-05-31 17:38:34 +00:00
Adrian Prantl
1daaf310fb Revert "Reverting commits 29181-29187 to investigate buildbot breakage."
This reverts commit 29189.

Swift SVN r29191
2015-05-31 17:38:32 +00:00
Adrian Prantl
b994bde5b5 Reverting commits 29181-29187 to investigate buildbot breakage.
Swift SVN r29190
2015-05-31 06:13:03 +00:00
Adrian Prantl
f2530aca51 Revert "Don't emit debug info for SILUndef values."
This reverts commit 18bb6cbf0a98b9ca082b26a470e3fba6e2d7d672.

Swift SVN r29189
2015-05-31 06:13:00 +00:00
Adrian Prantl
abeaf2b1a6 Don't emit debug info for SILUndef values.
rdar://problem/21103107

Swift SVN r29188
2015-05-31 05:39:33 +00:00
Adrian Prantl
6830021b4e Debug Info: Use the AST instead of SIL to determine the argument ordering.
The old SIL-based approach failed to recognize function arguments of
SIL-inlined functions as arguments.

Post-Xcode 7 it would be better to lower this information during SILGen
and emit a debug_value for every function argument so we don't need
to reconstruct them after all the SIL optimizations.

rdar://problem/21109015

Swift SVN r29180
2015-05-31 05:39:26 +00:00
Ted Kremenek
a154ae25f8 Revert "Revert "Revert "IRGen: Support polymorphic @objc_method functions"""
I didn't revert in the right order.

Swift SVN r29152
2015-05-29 19:16:32 +00:00
Ted Kremenek
7c24079ead Revert "Revert "IRGen: Support polymorphic @objc_method functions""
Start reverting 'reverts' incrementally to see if they trigger issues
on the iOS builder.

Swift SVN r29151
2015-05-29 18:38:12 +00:00
Ted Kremenek
ac40accfc1 Revert "IRGen: Support polymorphic @objc_method functions"
Speculatively reverting because the iOS bots are broken.

Swift SVN r29147
2015-05-29 14:11:29 +00:00
Slava Pestov
70db2c18d1 IRGen: Support polymorphic @objc_method functions
The type of the self parameter of an @objc_method might be a
BoundGenericClassType or a GenericTypeParamType. In these cases
we have to bind metadata.

For an @objc protocol P, the calling convention for an existential P
would try to pass type metadata in an extra argument, just like it
would for a <T : P> T. However, it is only necessary in the latter
case, because only there we can reflect on T to observe the statically
bound generic type. Fix this with a small hack so that ObjC protocol
methods don't get an extra argument for Self.

This patch alone doesn't enable any new functionality by itself,
because we hit the 'unimplemented dynamic layout' error instead of
crashing.

Swift SVN r29136
2015-05-29 06:19:00 +00:00
Joe Groff
aad6bc87fd IRGen: Pass large explosions as indirect arguments.
It's not worth burning more than three registers on a parameter, and doing so causes code size issues for large structs and enums. Make it so that values with more than three explosion members get passed indirectly, just like they get returned indirectly.

This time, modify emitPartialApplyForwarder not to attempt to 'tail' call the original function when indirect arguments get alloca'ed on the stack, which is UB, and don't use "byval", as suggested by John.

Swift SVN r29032
2015-05-26 17:38:22 +00:00
Joe Groff
7a5b199a34 Revert "IRGen: Pass large explosions as indirect byval arguments."
This reverts commit r29016, because of a test failure on the bots.

Swift SVN r29018
2015-05-26 02:13:16 +00:00
Joe Groff
abba73c77f IRGen: Pass large explosions as indirect byval arguments.
It's not worth burning more than three registers on a parameter, and doing so causes code size issues for large structs and enums. Make it so that values with more than three explosion members get passed indirectly, just like they get returned indirectly.

Swift SVN r29016
2015-05-26 01:49:45 +00:00
Slava Pestov
888132ec3f IRGen: get unchecked_ref_cast working with class existential operand
There was some duplicated code and we weren't doing a claimAll() on the
input explosion in one of the duplicates.

This partially reverts r28686, but keeping the test and updating it.

Second version of this patch makes the SIL verifier and combiner passes
use the same predicate, fixing assertion failures when casting
metatypes.

Fixes <rdar://problem/21005110>.

Swift SVN r28873
2015-05-21 16:01:45 +00:00
Dmitri Hrybenko
a795e87c65 Revert "IRGen: get unchecked_ref_cast working with class existential operand"
This reverts commit r28840.  It broke check-swift-optimize-unchecked.

Swift SVN r28847
2015-05-20 20:41:18 +00:00
Adrian Prantl
b8f15cf0f5 Debug info: Fix a bug in the argument numbering for exploded arguments
that manifested itself as tuple arguments having multiple entries.

rdar://problem/20005023

Swift SVN r28841
2015-05-20 20:09:37 +00:00
Slava Pestov
8e179d646e IRGen: get unchecked_ref_cast working with class existential operand
There was some duplicated code and we weren't doing a claimAll() on the
input explosion in one of the duplicates.

This partially reverts r28686, but keeping the test and updating it.

Fixes <rdar://problem/21005110>.

Swift SVN r28840
2015-05-20 19:57:05 +00:00
Andrew Trick
1ba9b58668 Add SILFunction::hasSelfMetadataParam() and getSelfMetadataArgument().
I want IRGen and the SIL optimizer to use consistent logic.

Swift SVN r28785
2015-05-19 20:54:07 +00:00
Roman Levenstein
42fb70a413 [sil-verifier] Allow upcasts between optional types.
Allow for
 upcast %0 : $Optional<D> to $Optional<C>
as long as D is a subclass of C.

Swift SVN r28433
2015-05-11 19:34:22 +00:00
Adrian Prantl
f18d802c19 Debug Info: Emit the error result argument.
If a function has an error result slot, emit debug info for an artificial
function argument "$error" with indirect storage that holds a pointer
to the error object address.

<rdar://problem/20736999> lldb needs to be able to locate the error return location when stepping out of a function

Swift SVN r28229
2015-05-07 00:29:40 +00:00
Adrian Prantl
2aff7e78d7 Debug Info: Mangle the AST type instead of the SIL type for local variables
and function arguments.

<rdar://problem/20565180> Debug info should not expose ImplFunctionType

Swift SVN r28148
2015-05-05 03:50:28 +00:00
Erik Eckstein
94b3f8c545 IRGen: improve debug logging for multi-threaded compilation
Swift SVN r28115
2015-05-04 15:10:49 +00:00
Chris Lattner
7733b060c5 Enhance IRGen to know a simple heuristic in emitValueBitCast to avoid
going to the stack when two explosions will end up with the same elements.
This helps with optional to optional conversions.  We now compile:

public func opt_to_opt_trivial(x: Int?) -> Int! { return x }
public func opt_to_opt_reference(x : C!) -> C? { return x }

into:

define { i64, i1 } @_TF1x18opt_to_opt_trivialFGSqSi_GSQSi_(i64, i1) {
entry:
  %2 = insertvalue { i64, i1 } undef, i64 %0, 0
  %3 = insertvalue { i64, i1 } %2, i1 %1, 1
  ret { i64, i1 } %3
}

define i64 @_TF1x20opt_to_opt_referenceFGSQCS_1C_GSqS0__(i64) {
entry:
  ret i64 %0
}

instead of:

define { i64, i1 } @_TF1x18opt_to_opt_trivialFGSqSi_GSQSi_(i64, i1) {
entry:
  %bitcast = alloca %Sq, align 8
  %2 = bitcast %Sq* %bitcast to i64*
  store i64 %0, i64* %2, align 8
  %3 = getelementptr inbounds %Sq, %Sq* %bitcast, i32 0, i32 1
  %4 = bitcast [1 x i8]* %3 to i1*
  store i1 %1, i1* %4, align 8
  %5 = bitcast %Sq* %bitcast to %SQ*
  %6 = bitcast %SQ* %5 to i64*
  %7 = load i64, i64* %6, align 8
  %8 = getelementptr inbounds %SQ, %SQ* %5, i32 0, i32 1
  %9 = bitcast [1 x i8]* %8 to i1*
  %10 = load i1, i1* %9, align 8
  %11 = insertvalue { i64, i1 } undef, i64 %7, 0
  %12 = insertvalue { i64, i1 } %11, i1 %10, 1
  ret { i64, i1 } %12
}

define i64 @_TF1x20opt_to_opt_referenceFGSQCS_1C_GSqS0__(i64) {
entry:
  %bitcast = alloca %SQ.17, align 8
  %1 = bitcast %SQ.17* %bitcast to i64*
  store i64 %0, i64* %1, align 8
  %2 = bitcast %SQ.17* %bitcast to %Sq.16*
  %3 = bitcast %Sq.16* %2 to i64*
  %4 = load i64, i64* %3, align 8
  ret i64 %4
}




Swift SVN r28107
2015-05-04 03:50:48 +00:00
Andrew Trick
5bc23acf75 Add wrappers around Builtin.isUnique.
Currently they do nothing but allow stdlib code to use regular (Bool)
types.  However, soon the wrappers for the _native variants will
provide point-of-use sanity checking.

These need to be fully generic to support class protocols and
single-payload enums (not just for optional). It also avoids a massive
amount of overloading for all the reference type variations
(AnyObject, Native, Unknown, Bridge) x 2 for optional versions of
each.

Because the wrapper is generic, type checking had to be deferred until
IRGen. Generating code for the wrapper itself will result in an
IRGen-time type error. They need to be transparent anyway for proper
diagnostics, but also must be internal.

Note that the similar external API type checks ok because it
forces conformance to AnyObject.

The sanity checks are disabled because our current facilities for
unsafe type casting are incomplete and unsound. SILCombine can
remove UnsafeMutablePointer and RawPointer casts by assuming layout
compatibility. IRGen will later discover layout incompatibility and
generate a trap.

I'll send out a proposal for improving the casting situation so we can
get the sanity checks back.

Swift SVN r28057
2015-05-01 23:45:44 +00:00
Andrew Trick
ec31f6dbc9 Revert "Add wrappers around Builtin.isUnique."
This reverts commit 64e9f11211a19fa603f5bc2d2bea171a9b07d3fa.

I think this is breaking ExistentialCollection test in the
Release + stdlib asserts build.

Swift SVN r27947
2015-04-29 23:23:13 +00:00
Andrew Trick
09db0dda92 Add wrappers around Builtin.isUnique.
The wrappers for the _native variants provide point-of-use sanity checking.
They also allows stdlib code to use regular (Bool) types.

These need to be fully generic to support class protocols. It also
avoids a massive amount of overloading for all the reference type
variations (AnyObject, Native, Unknown, Bridge) x 2 for optional
versions of each.

Because the wrapper is generic, type checking had to be deferred until
IRGen. Generating code for the wrapper itself will result in an
IRGen-time type error. They need to be transparent anyway for proper
diagnostics, but also must be internal.

The external API passes type checks because it forces conformance to AnyObject.

Swift SVN r27930
2015-04-29 21:59:19 +00:00
Andrew Trick
a174aa4dfe Add AST and SILGen support for Builtin.isUnique.
Preparation to fix <rdar://problem/18151694> Add Builtin.checkUnique
to avoid lost Array copies.

This adds the following new builtins:

    isUnique : <T> (inout T[?]) -> Int1
    isUniqueOrPinned : <T> (inout T[?]) -> Int1

These builtins take an inout object reference and return a
boolean. Passing the reference inout forces the optimizer to preserve
a retain distinct from what’s required to maintain lifetime for any of
the reference's source-level copies, because the called function is
allowed to replace the reference, thereby releasing the referent.

Before this change, the API entry points for uniqueness checking
already took an inout reference. However, after full inlining, it was
possible for two source-level variables that reference the same object
to appear to be the same variable from the optimizer's perspective
because an address to the variable was longer taken at the point of
checking uniqueness. Consequently the optimizer could remove
"redundant" copies which were actually needed to implement
copy-on-write semantics. With a builtin, the variable whose reference
is being checked for uniqueness appears mutable at the level of an
individual SIL instruction.

The kind of reference count checking that Builtin.isUnique performs
depends on the argument type:

    - Native object types are directly checked by reading the
      strong reference count:
      (Builtin.NativeObject, known native class reference)

    - Objective-C object types require an additional check that the
      dynamic object type uses native swift reference counting:
      (Builtin.UnknownObject, unknown class reference, class existential)

    - Bridged object types allow the dymanic object type check to be
      bypassed based on the pointer encoding:
      (Builtin.BridgeObject)

Any of the above types may also be wrapped in an optional.  If the
static argument type is optional, then a null check is also performed.

Thus, isUnique only returns true for non-null, native swift object
references with a strong reference count of one.

isUniqueOrPinned has the same semantics as isUnique except that it
also returns true if the object is marked pinned regardless of the
reference count. This allows for simultaneous non-structural
modification of multiple subobjects.

In some cases, the standard library can dynamically determine that it
has a native reference even though the static type is a bridge or
unknown object. Unsafe variants of the builtin are available to allow
the additional pointer bit mask and dynamic class lookup to be
bypassed in these cases:

    isUnique_native : <T> (inout T[?]) -> Int1
    isUniqueOrPinned_native : <T> (inout T[?]) -> Int1

These builtins perform an implicit cast to NativeObject before
checking uniqueness. There’s no way at SIL level to cast the address
of a reference, so we need to encapsulate this operation as part of
the builtin.

Swift SVN r27887
2015-04-28 22:54:24 +00:00
Nadav Rotem
3e8c871c6a Emit calls to swift_willThrow as part of SILGen using a builtin.
Calls to willThrow are marked as read-none so that the optimizer can remove
them. The willThrow builtin is still generated for all throw/rethrow sites,
but I plan to look at this next.

rdar://20356658

Swift SVN r27877
2015-04-28 18:36:22 +00:00
Erik Eckstein
2a366df113 Remove SILType::isExistentialMetatypeType().
Suggested by John.



Swift SVN r27864
2015-04-28 08:43:15 +00:00
Erik Eckstein
519dfca347 IRGen: fix crash on x.dynamicType.dynamicType.
rdar://problem/19545563



Swift SVN r27862
2015-04-28 07:36:13 +00:00
Nadav Rotem
217d6ba5a6 Don't emit calls to swift_willThrow in optimized builds.
rdar://20356658.

Swift SVN r27764
2015-04-26 16:41:23 +00:00
Nadav Rotem
9b2b75b859 IRGen: Insert a call to swift_willThrow to allow lldb to place a breakpoint.
rdar://20356658.

Swift SVN r27710
2015-04-24 22:09:15 +00:00
Chris Lattner
42b4a966b0 Introduce a new null_class SIL instruction for forming a null pointer
reference to something of class type.  This is required to model
RebindSelfInConstructorExpr correctly to DI, since in the class case, 
self.init and super.init *take* a value out of class box so that it 
can pass the +1 value without performing an extra retain.  Nothing
else in the compiler uninitializes a DI-controlled memory object
like this, so nothing else needs this.  DI really doesn't like something
going from initialized to uninitialized.

Yes, I feel super-gross about this and am really unhappy about it.  I
may end up reverting this if I can find an alternate solution to this
problem.



Swift SVN r27525
2015-04-21 05:56:55 +00:00
Erik Eckstein
7dcbdb0c3f IRGen for bridge_object_to_ref: don't emit a check for a tagged pointer if not required.
Swift SVN r27122
2015-04-08 09:25:12 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Joe Groff
4821f594bb SIL: Separate SILFunctionType::Representation and ExtInfo from AST FunctionTypes.
The set of attributes that make sense at the AST level is increasingly divergent from those at the SIL level, so it doesn't really make sense for these to be the same. It'll also help prevent us from accidental unwanted propagation of attributes from the AST to SIL, which has caused bugs in the past. For staging purposes, start off with SILFunctionType's versions exactly the same as the FunctionType versions, which necessitates some ugly glue code but minimizes the potential disruption.

Swift SVN r27022
2015-04-05 17:04:55 +00:00
John McCall
dab7302d7c Finish wiring up try_apply in IRGen.
Swift SVN r26821
2015-04-01 21:08:25 +00:00
John McCall
6d8fff9c06 Parsing and basic structure of try_apply. Not yet properly
threaded into IRGen; tests to follow when that's done.

I made a preliminary effort to make the inliner do the
right thing with try_apply, but otherwise tried to avoid
touching the optimizer any more than was required by the
removal of ApplyInstBase.

Swift SVN r26747
2015-03-31 02:41:03 +00:00
John McCall
1ffb87bb1f Implement a 'throw' instruction in SIL.
Swift SVN r26668
2015-03-28 02:00:20 +00:00
John McCall
dc5a03a7bc Add IRGen support for error results from functions.
As part of this, re-arrange the argument order so that
generic arguments come before the context, which comes
before the error result.  Be more consistent about always
adding a context parameter on thick functions, even
when it's unused.  Pull out the witness-method Self
argument so that it appears last after the error
argument.

Swift SVN r26667
2015-03-28 02:00:17 +00:00
Joe Groff
1c18a71ab7 IRGen: Implement boxed existential instructions.
Provide a special single-ObjC-refcounted type info for error existentials, and lower the existential box instructions to their corresponding runtime calls.

Swift SVN r26469
2015-03-24 01:10:31 +00:00