Commit Graph

794 Commits

Author SHA1 Message Date
Chris Lattner
0c288e0829 introduce a new UnresolvedTypeConversionExpr implicit conversion node for
conversions to and from UnresolvedType.  This will allow UnresolvedType to be
used more aggressively and predictably by CSDiags.  This is NFC, but used in
the next patch.


Swift SVN r31318
2015-08-18 23:41:11 +00:00
Slava Pestov
e5cb73fe41 SILGen: Clean up ErasureExpr lowering, NFC
This is a step towards partially-applying methods that return Self
on existentials.

- We model opening of both existential values and metatypes with
  OpenExistentialExpr, but erasure had two forms, ErasureExpr and
  MetatypeErasureExpr. Combine them into one, since both Sema and
  SILGen have similar code paths for each.

- If the source type of an ErasureExpr is a closed existential,
  have Sema emit an OpenExistentialExpr, and remove SILGen's
  openExistentialForErasure() path, which mostly duplicates
  openExistentialImpl().

- There was one difference between openExistentialForErasure() and
  openExistentialImpl(). The former would emit the opaque value in
  +0 context, and the latter in a +1 with initialization. The
  previous patch ensures that visitOpaqueValueExpr() generates
  equivalent code in both cases.

Swift SVN r31261
2015-08-16 16:45:48 +00:00
Slava Pestov
27fec84a74 SILGen: Peephole for lowering OpenExistentialExpr with an Initialization
I think this is NFC for now, because it never comes up, but is required
for the next patch.

Swift SVN r31260
2015-08-16 16:45:45 +00:00
Slava Pestov
9b74a4b0d6 SILGen: Fix memory leak when sub-expression of ErasureExpr throws
If we didn't initialize the existential, we have to emit a cleanup
because we may have allocated a buffer on the heap to store the value.

Factor out the TakeExistentialCleanup that appears in a few places,
rename it to DeinitExistentialCleanup and add support for deallocating
boxed existentials.

Then, use a special Initialization subclass to keep track of the
state of the memory in emit{AddressOnly,Boxed}Erasure().

Swift SVN r31259
2015-08-16 16:45:44 +00:00
Slava Pestov
57971159ca SIL: Fix self cleanup with self.init() delegation
When we take the self value out of the box inside a
RebindSelfInConstructorExpr, zero out the box right away
instead of doing it right before the apply or try_apply
instruction.

This way, if we have to emit a try_apply while while
evaluating arguments, we don't double-free the self
value.

Also, teach DI about releases of loads from the self box,
since now we might release the uninitialized self this
way.

This change also lets us get rid of some weird code.

Progress on <rdar://problem/21991742>.

Swift SVN r31141
2015-08-11 18:37:57 +00:00
Chris Lattner
654cb861ed fix <rdar://problem/21886435> Swift compiler crashes on "()=()"
... which was just a pair of over-conservative SILGen assertions.

This was our shortest practical swift crasher.



Swift SVN r31135
2015-08-11 17:41:44 +00:00
Jordan Rose
74c634524e Pull 'try' et al inside RebindSelfInConstructorExprs.
And give a proper warning when you use 'try?' in a non-failable init.

And do the right thing when trying to SILGen 'try?' delegating to a
failable throwing init.

And make sure DI understands that this is, in fact, an initialization.

More rdar://problem/21692467

Swift SVN r31060
2015-08-06 21:02:43 +00:00
Jordan Rose
e2197b6feb Add SILGen support for 'try?'.
rdar://problem/21692467

Swift SVN r31032
2015-08-05 22:17:38 +00:00
Jordan Rose
5b98703f36 [SILGen] Simplify ForceTryExpr generation a bit.
No functionality change.

Swift SVN r31031
2015-08-05 22:17:37 +00:00
Jordan Rose
2801d47e59 Add Parse and Sema support for 'try?'.
rdar://problem/21692467

Swift SVN r31030
2015-08-05 22:17:25 +00:00
Jordan Rose
953424072e Guard "object literals" feature with SWIFT_ENABLE_OBJECT_LITERALS.
This is not a feature we're releasing at the moment, so provide a way
to turn it off.

rdar://problem/21935551

Swift SVN r30966
2015-08-04 00:16:52 +00:00
Slava Pestov
48fe3e1c9b SILGen: Fix static computed properties in protocol extensions
We need to keep the AST formal type of the base around when building up
lvalues.

When the getter or setter involves an accessor call, we would use the
lowered type of the self argument to form the call. However, it might be
at the wrong level of abstraction, causing a @thin -vs- @thick metatype
mismatch. Using the formal type instead allows SILGenApply logic to emit
a thin to thick metatype conversion if necessary.

Fixes <rdar://problem/21358641>.

Swift SVN r30913
2015-08-01 07:21:25 +00:00
Slava Pestov
20781df9ab SILGen: Fix crash when opening boxed existential lvalue
Fixes <rdar://problem/21395086>.

Swift SVN r30707
2015-07-28 00:02:37 +00:00
Dave Abrahams
06d59f3102 Suppress a warning
Swift SVN r30594
2015-07-24 22:14:40 +00:00
Doug Gregor
07135ac4e9 Handle initializer delegation in a protocol extension with a class-bound Self.
When extending a protocol where the 'Self' type is a subclass of some
known class type, initializers within the protocol extension can
delegate to required initializers of that superclass bound. Correctly
adjust the 'self' we produce in SILGen to the superclass type.

Fixes rdar://problem/21370992.

Swift SVN r30584
2015-07-24 18:22:43 +00:00
Doug Gregor
f00e5bc6ab Allow a variadic parameter anywhere in the parameter list.
Requiring a variadic parameter to come at the end of the parameter
list is an old restriction that makes no sense nowadays, and which we
had all thought we had already lifted. It made variadic parameters
unusable with trailing closures or defaulted arguments, and made our
new print() design unimplementable.

Remove this restriction, replacing it with a less onerous and slightly
less silly restriction that we not have more than one variadic
parameter in a given parameter clause. Fixes rdar://problem/20127197.

Swift SVN r30542
2015-07-23 18:45:29 +00:00
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Devin Coughlin
c1caddae62 Remove experimental support for treating unavailable symbols as optional.
This has always been off by default and is a language direction we have decided not to
pursue.

Swift SVN r30355
2015-07-18 01:56:25 +00:00
Doug Gregor
fdf5c64bd7 Force implicit unwrapping in self.init/super.init within the AST
... rather than having SILGen do it. This is NFC, but feels more correct.

Swift SVN r30276
2015-07-16 22:21:55 +00:00
Roman Levenstein
e6969a03c7 [silgen] Emit tuple initializers for global variables of trivial tuple types using tuple instructions.
SILGen was not imploding tuple initializers for global variables and always generated an element-by-element initialization.
This made it difficult for GlobalOpt to propagate the value of the global into its uses. Therefore, SILGen now generates tuple instructions to initialize global variables of trivial tuple types.

Swift SVN r30237
2015-07-15 23:40:09 +00:00
Andrew Trick
778012c479 Handle SIL unchecked_addr_cast conservatively when promoting to a value cast.
Unless we can prove that the input and output are layout identical we must use either trivial_bit_cast or bitwise_cast.

This changes the lowering to be more conservative for:

- Builtin.reinterpretCast
- address_to_pointer -> pointer_to_address

This also makes LoadStoreOpts more conservative in:

- forwardAddrToUncheckedCastToLd

In order to commit this without massive performance regressions, I added SILType::canBitCastAsSingleRef. When this is true for both sides
of a bitwise case, we can convert it to a RefBitCast, which has RC identity.

Swift SVN r30172
2015-07-13 22:46:17 +00:00
John McCall
ed0681004c Remove the almost-pointless Materialize type from SILGen,
and stop forcing optionals to memory in a bunch of places
where the callee is perfectly capable of handling a
non-address value.

Swift SVN r30107
2015-07-11 02:58:49 +00:00
Justin Bogner
086c2d49ea InstrProf: Handle IfExpr correctly for coverage maps
We were creating counters for IfExpr coverage, but weren't actually
mapping these when emitting coverage. Handle this.

rdar://problem/21720161

Swift SVN r29971
2015-07-08 07:17:08 +00:00
Slava Pestov
942b44d2e2 SILGen: Fix comment wording I found while reading code, NFC
Swift SVN r29911
2015-07-04 01:53:31 +00:00
Joe Groff
6e30d61f58 SILGen: Reabstract values when passing by pointer to C functions.
This allows the value to be cast to an UnsafePointer type and correctly loaded out in all cases. In particular, this lets you pass a Swift closure by pointer as the context parameter to a C function pointer, allowing callback-based C APIs to be more conveniently wrapped. Fixes rdar://problem/21505805.

Swift SVN r29904
2015-07-03 00:38:06 +00:00
Doug Gregor
b646af0ec2 Eliminate some unnecessary uses of getAllArchetypes(). NFC
Swift SVN r29843
2015-07-01 18:14:52 +00:00
Slava Pestov
a64d505a98 SILGen: Fix some problems when generating delegating init calls
- If delegating to an initializing constructor for a value type,
  the ApplyInst takes an @out parameter for Self, instead of
  returning Self like with references. Fix the def-use traversal
  to handle that instead of crashing.

- When calling an allocating constructor, the formal type is
  the instance type because Sema constructs the constructor call
  as if it were an initializing constructor. This causes us to
  fail to re-abstract a @thin metatype to @thick. Fix this to
  use the correct metatype type for allocating constructors.

Fixes <rdar://problem/20945954>.

Swift SVN r29555
2015-06-22 22:26:17 +00:00
Joe Groff
d84993108b SILGen: Emit Clang-imported witness tables by need too.
The other part of rdar://problem/21444126. This is a little trickier since SIL doesn't track uses of witness tables in a principled way. Track uses in SILGen by putting a "SILGenBuilder" wrapper in front of SILBuilder, which marks conformances from apply, existential erasure, and metatype lookup instructions as used, so we can avoid emitting shared Clang importer witnesses when they aren't needed.

Swift SVN r29544
2015-06-22 03:08:41 +00:00
Mark Lacey
75b5b1248e Small clean-up. Add createUncheckedBitCast to SILBuilder.
This new method eliminates repeated code sequences that all create an
unchecked_trivial_bit_cast if the result type is trivial or
unchecked_ref_bit_cast otherwise.

NFC.

Swift SVN r29486
2015-06-18 07:30:42 +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
29bacaf3ad typo
Swift SVN r29342
2015-06-08 04:11:06 +00:00
Joe Groff
0303d4ee51 SILGen: Project 'let' properties from address-only structs at the proper abstraction level.
Fixes rdar://problem/19297122.

Swift SVN r29333
2015-06-06 03:25:50 +00:00
Slava Pestov
7319a97ab4 Sema: Rewrite witness method calls as ApplyExpr + DeclRefExpr
Special-casing these as MemberRefExprs created an asymmetry
where unbound archetype instance methods (<T : P> T.f) could
not be represented. Treating class and protocol methods
uniformly also eliminates a handful of special cases around
MemberRefExpr.

SILGen's RValue and call emission peepholes now have to know
about DeclRefExprs that point to protocol methods.

Finally, generalize the diagnostic for partially applied
mutating methods to any partially applied function with an
inout parameter, since this is not supported.

Fixes <rdar://problem/20564672>.

Swift SVN r29298
2015-06-04 15:57:58 +00:00
John McCall
ccc6e55021 Zero out the 'self' box immediately before the delegating
call in order to make delegations to throwing initializers work.

Fixes <rdar://20861374>.

Swift SVN r28864
2015-05-21 00:45:08 +00:00
John McCall
f0f8787b0f Generalize the 'transparent' flag passed around to
various emitApply routines.  NFC.

Swift SVN r28720
2015-05-18 20:30:12 +00:00
Chris Lattner
e517ad9182 Fix unreachable code handling to properly diagnose things like:
throw x 
whatever()  

as being unreachable after the throw.



Swift SVN r28680
2015-05-17 15:13:35 +00:00
Dmitri Hrybenko
0a1f7c09df Revert "Fix unreachable code handling to properly diagnose things like:"
This reverts commit 28678.  It broke the IDE/complete_exception.swift
test.

Swift SVN r28679
2015-05-17 12:27:57 +00:00
Chris Lattner
5ead9764bd Fix unreachable code handling to properly diagnose things like:
throw x
  whatever()

as being unreachable after the throw.



Swift SVN r28678
2015-05-17 05:56:02 +00:00
Chris Lattner
c9e0657529 fix <rdar://problem/20941576> SILGen crash: Failable struct init cannot delegate to another failable initializer
in a trivial struct, the 'self' argument in an initializer won't have
a cleanup, so don't disable or reenable it when rebinding self due to delegation.


Swift SVN r28674
2015-05-17 02:51:30 +00:00
John McCall
312a9c1f6e Clean up correctly if a variadic argument throws.
rdar://20942603

Swift SVN r28622
2015-05-15 08:20:36 +00:00
Slava Pestov
cbbde4739e SILGen: remove dead diagnostics for error handling
Looks like Sema is checking all of this stuff now. NFC

Swift SVN r28571
2015-05-14 17:22:44 +00:00
Chris Lattner
8a7b3f414e Revise the parser and AST representation of #available to be part of StmtCondition
instead of being an expression.

To the user, this has a couple of behavior changes, stemming from its non-expression-likeness.
 - #available cannot be parenthesized anymore
 - #available is in its own clause, not used in a 'where' clause of if/let.

Also, the implementation in the compiler is simpler and fits the model better.  This
fixes:
<rdar://problem/20904820> Following a "let" condition with #available is incorrectly rejected



Swift SVN r28521
2015-05-13 19:00:40 +00:00
Joe Groff
0e3bb2dc57 SILGen: Implement ErrorType-to-Any erasure.
And take advantage of the guaranteed peephole when available to emit the base expression at +0 in general existential-to-existential erasures. Fixes rdar://problem/20890504.

Swift SVN r28447
2015-05-11 23:18:53 +00:00
Doug Gregor
2653a6569b Eliminate ModuleExpr; DeclRefExpr is good enough for anyone.
Swift SVN r28285
2015-05-07 21:10:53 +00:00
Michael Gottesman
8361ba44a9 Revert "Revert "[+0 self] Teach SILGen how to avoid emitting extra rr pairs when emitting RValues with Nominal Types and Tuples.""
This reapplies commit r27632 with additional fixes, tests.

I turned off the guaranteed struct optimization since we really don't have the
infrastructure to do it right and more importantly I don't have the time to do
so (and was not asked to do so).

We still have the class optimization though!

This means that there is one retain in ClassIntTreeMethod.find.

class ClassIntTreeNode {
  let value : Int
  let left, right : ClassIntTreeNode

  init() {}

  func find(v : Int) -> ClassIntTreeNode {
    if v == value { return self }
    if v < value { return left.find(v) }
    return right.find(v)
  }
}

Swift SVN r28264
2015-05-07 15:47:34 +00:00
John McCall
36c605f7dc Remove ScalarToTupleExpr in favor of a flag on TupleShuffleExpr.
Also, implement in-place initialization through tuple shuffles.

Swift SVN r28227
2015-05-06 23:44:26 +00:00
Chris Lattner
6a5009e0ce implement <rdar://problem/17013042> T! <-> T? conversions should not produce a diamond
Two pieces to this: 
 - Peephole OptionalEvaluationExpr(InjectOptionalExpr(BindOptionalExpr(X))) to  bitcast x to the result type. 
 - Enhance OptionalEvaluationExpr to delete the failure block if not needed.  

This is the same as r28150, but it includes a fix for the case when a non-address-only type
is initializing a contextally-provided-and-addressible buffer, tested by the new 
testContextualInitOfNonAddrOnlyType testcase.



Swift SVN r28153
2015-05-05 05:39:17 +00:00
Chris Lattner
9eb115fadf revert r28150, the perftestsuite isn't happy.
Swift SVN r28151
2015-05-05 05:16:23 +00:00
Chris Lattner
1ffe86b327 implement <rdar://problem/17013042> T! <-> T? conversions should not produce a diamond
Two pieces to this:
 - Peephole OptionalEvaluationExpr(InjectOptionalExpr(BindOptionalExpr(X))) to 
   bitcast x to the result type.
 - Enhance OptionalEvaluationExpr to delete the failure block if not needed.

This is the same as r28111, except that we finalize the initialization in the
address-only case.  A reduced testcase for the specific issue is added to
optional-casts.swift.



Swift SVN r28150
2015-05-05 05:01:22 +00:00
Erik Eckstein
40c1160713 Revert r28111 "rework the peephole for optional-to-optional casts to be more specific"
and r28105: "implement <rdar://problem/17013042> T! <-> T? conversions should not produce a diamond"

r28111 broke the stdlib build. I also reverted r28105, because r28111 fixes regressions introduced in r2805.



Swift SVN r28114
2015-05-04 07:24:13 +00:00