Commit Graph

931 Commits

Author SHA1 Message Date
Joe Groff
84ab2a47dc SILGen: Peephole physical lvalue-to-lvalue assignments.
When assigning between physical lvalues, emit a 'copy_addr' instead of a load + assign sequence. This provides a higher-level semantic instruction to SIL passes, and also produces better code in many cases.

It unfortunately exposes another bug in DI which affects the test/IRGen/objc.swift test, which I've XFAILed until it can be fixed.

Swift SVN r10564
2013-11-19 23:17:55 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
f6b1745650 SIL: Remove 'ModuleInst'.
Module values could never be used for anything, and we have SILUndef now, so when SILGen sees a ModuleExpr, we can just emit 'undef'.

Swift SVN r10548
2013-11-18 21:36:08 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Joe Groff
7b9f61de5c SILGen: Emit global var decl refs as calls to the accessor.
Route global var refs (except for those referencing top-level code vars) through the lazy-initializing global accessor functions for those globals.

Swift SVN r10519
2013-11-16 23:52:39 +00:00
Joe Groff
a049ee9d38 SILGen: (Optionally) emit lazy initializers and accessor fns for globals.
For every global pattern binding, emit a lazy initializer token and function that initializes the global variables in that binding. For each of those vars, create an accessor that Builtin.once's the lazy initializer before producing the address. Hide this all behind a switch till the surrounding serialization and IRGen infrastructure catches up.

Swift SVN r10511
2013-11-16 00:50:19 +00:00
John McCall
08171453da Make it a bit easier to propogate expressions around instead
of having to lower to an RValue.

This is valuable because we can often emit an expression to a
desired abstraction level more efficiently than just emitting
it to minimal abstraction and then generalizing.

Swift SVN r10455
2013-11-14 05:25:06 +00:00
Chris Lattner
4968cc208b A couple of related changes:
- Enhance SILBuilder::emitStrongRelease to be smarter.
- Start using emitStrongRelease in type lowering, SILGen,
  CapturePromotion (replacing its implementation of the
  same logic), and MandatoryInlining (one more place)
- Rename the primitive createStrongRetain/ReleaseInst
  instructions to lose their suffix.
- Now that createStrongRetain/ReleaseInst are not special
  cases from the naming perspective, remove some special cases
  from DeserializeSIL and ParseSIL.
  


Swift SVN r10449
2013-11-14 02:21:27 +00:00
Chris Lattner
9570e1fb0c Remove the "createStrongRetain" and "createStrongRelease" SILBuilder methods.
They are the same as createStrongRetainInst and createStrongReleaseInst, but
peephole away FunctionRefInst.  It turns out that there is only a couple
places in SILGen where this behavior is necessary, and this tramples on the
general pattern used in SILBuilder.


Swift SVN r10448
2013-11-14 02:00:41 +00:00
Doug Gregor
66b9f36ff5 When emitting sibling method calls, callect substitutions from all levels.
Previously, we were only looking at the innermost level, ignoring
outer generic types. Fixes the SILGen part of
<rdar://problem/15345742>, but IRGen issues remain.


Swift SVN r10418
2013-11-13 06:48:00 +00:00
Chris Lattner
425819ac07 Change the SIL string_literal instruction to produce three results
(the same way alloc_box returns two) instead of returning a tuple.

This eliminates a ton of tuple_extract instructions, which just
bloat the generated SIL.  This resolves rdar://15378135.



Swift SVN r10416
2013-11-13 06:43:09 +00:00
Doug Gregor
eb7ce396db Use VarDecl::get[GS]etterType() and SubscriptDecl::get[GS]etterType() in SILGen
Eliminate SILGen's own computation of getter/setter types in favor of
the AST methods to compute the same.


Swift SVN r9992
2013-11-06 06:53:13 +00:00
Joe Groff
1616276923 SILGen: Remove 'SILGenLValuePeepholes' flag.
r9931 fixes the crashes this exposes, so we can enable it by default now.

Swift SVN r9935
2013-11-04 22:54:54 +00:00
Joe Groff
18dd9335f3 SILGen: Factor abstraction change from branch in checked cast emission.
<rdar://problem/14835992> happens because, when we emitted a chain of checked casts for 'is' patterns in a 'switch', we would emit abstraction changes for each individual cast that required them. This is both redundant and makes cleaning up messier, because the number of branches with different stack heights increases. Instead, let's emit one abstraction change up front for all of the casts. No functionality change yet, but this is a step on the way to fixing <rdar://problem/14835992>.

Swift SVN r9921
2013-11-04 17:44:03 +00:00
Dmitri Hrybenko
91ce21666d Change 'func' keyword to 'def'
I tried hard find all references to 'func' in documentation, comments and
diagnostics, but I am sure that I missed a few.  If you find something, please
let me know.

rdar://15346654


Swift SVN r9886
2013-11-02 01:00:42 +00:00
Joe Groff
c57ea38b95 SILGen: Don't produce context arguments for captured typealiases.
If a local function tried to reference a local typealias, we were trying to emit a SIL variable reference and freaking out, causing <rdar://problem/15360605>. For now, don't emit any capture arguments for local typealiases. Any context a local typealias requires should be handled by capturing the external context's generic parameters.

Swift SVN r9865
2013-11-01 00:12:29 +00:00
Argyrios Kyrtzidis
e31c93add3 [AST] The ASTContext parameter in FuncDecl::getResultType() is not really needed.
Swift SVN r9798
2013-10-30 17:09:56 +00:00
Joe Groff
1ff79ff951 SILGen: Fix use-after-free in 'x?' codegen.
Forward the result before closing the scope so it's still good when we pass it on out of the optional evaluation.

Swift SVN r9773
2013-10-30 00:17:34 +00:00
Anna Zaks
e5eb77ea6e [SIL] Mark these locations as cleanup.
The empty tuple used for return value when none is supplied does not really correspond to user code. (We don’t have epilog, so mark it as pert of cleanup.)
The destroy_addr instructions are doing the cleanup.

Swift SVN r9765
2013-10-29 22:27:25 +00:00
Doug Gregor
112c6123eb Terminate SpecializeExpr with extreme prejudice.
There are numerous other cleanups that could be performed now that
this is gone; I'll follow up with some of them.


Swift SVN r9717
2013-10-28 18:50:29 +00:00
Dmitri Hrybenko
b62e8903de Portability: libstdc++ does not implement is_trivially_copyable yet, implement
our own wrapper


Swift SVN r9695
2013-10-27 05:52:22 +00:00
Jordan Rose
64e0b2200a Make sure to resolve library intrinsics before using them.
Otherwise, compiling the standard library will try to use, say,
_getOptionalValue() before that function has any type.

Swift SVN r9671
2013-10-25 17:30:41 +00:00
Dmitri Hrybenko
80d753d0ab Portability: use std::make_tuple instead of relying on a libc++ extension (an
implicit constructor in std::tuple)


Swift SVN r9615
2013-10-23 06:17:28 +00:00
Joe Groff
3a5267c020 SILGen: Build a thunk in SILGen instead of using convert_cc instruction.
We already know how to call external functions in SILGen, why reimplement all that in IRGen? Instead of representing the thunk operation as a SIL instruction, let's just emit the thunk using existing SILGen machinery. Fixes <rdar://problem/14097136>.

Swift SVN r9576
2013-10-22 03:16:15 +00:00
Joe Groff
86481263ac SILGen: Remove some debug noise.
Swift SVN r9570
2013-10-21 23:33:20 +00:00
Joe Groff
0da9261182 SILGen: Thunk Clang-imported top-level functions when used unapplied as values.
And tweak the verifier to allow 'convert_cc' over a static FunctionRefInst to remain thin. The SILGen part of <rdar://problem/14097136>.

Swift SVN r9556
2013-10-21 20:39:57 +00:00
Doug Gregor
5521b53382 Use DeclRefExpr's substitutions rather than SpecializeExpr for free functions.
Rather than wrapping a DeclRefExpr in a SpecializeExpr for a reference
to a generic free function, just use the substitutions stored within
the DeclRefEXpr. Such DeclRefExprs will always have a concrete
type. One tiny nail in the SpecializeExpr coffin.


Swift SVN r9539
2013-10-21 15:39:56 +00:00
Adrian Prantl
3fafb6c7e7 Debug info: Make the ret instruction in the function epilogue a cleanup
location rather than a regular location to avoid the linetable jumping
back to the beginning of the function.
Add a large number of testcases that check the sanity of the return
locations in various scenarios involving implicit/explicit returns,
cleanups, and multiple return locations per function.

rdar://problem/14845534

Swift SVN r9511
2013-10-19 00:20:44 +00:00
Joe Groff
cd74f49434 Revert "SILGen: Enable lvalue-to-lvalue copy_addr initialization peephole by default."
This reverts commit r9347. The copy_addr peephole still crashes the
Demo-2012-07/uniq.swift test on the buildbot.

Swift SVN r9358
2013-10-15 18:18:29 +00:00
Joe Groff
47dd733c3f SILGen: Enable lvalue-to-lvalue copy_addr initialization peephole by default.
The Interpreter crashes this introduced in the end-to-end pipeline seem to have subsided, now that DI is prepared for it.

Swift SVN r9349
2013-10-15 16:56:15 +00:00
John McCall
8fbc790d39 Subsume OwnershipConventions into SILFunctionType.
Swift SVN r9186
2013-10-11 00:50:57 +00:00
Joe Groff
1bdbc97056 Drop the 'x as! T' cast syntax.
Now that we have a solid Optional-based story for dynamic casts, it's no longer needed, and can be expressed as '(x as T)!'. Future refinement of the 'as' syntax will deal with the unfortunate extra parens.

Swift SVN r9181
2013-10-10 23:47:59 +00:00
Doug Gregor
b314941328 SILGen: Generate an unconditional checked cast for (x as T)!.
This is a simple peephole optimization for cases where we're
performing a conditional checked cast and then immediately forcing it
to succeed with postfix '!'. It also happens with the new forced
downcast of 'id', e.g.,

  var w : NSView = foo.views()[0]!



Swift SVN r9180
2013-10-10 22:37:17 +00:00
John McCall
b880e60100 Remove SILFunctionTypeInfo in favor of SILFunctionType.
We still don't actually use this as a type, however.

Swift SVN r9091
2013-10-09 20:55:55 +00:00
Joe Groff
1acbc5a74c SILGen: Fix a crash when 'x!' was able to emit into a buffer.
Swift SVN r9040
2013-10-09 00:36:36 +00:00
Joe Groff
2ffd735255 SILGen: Peephole lvalue-to-lvalue initializations as copy_addrs.
If we're using emitExprInto to emit a LoadExpr, we can handle that by emitting a copy_addr from the underlying lvalue to the initialization instead of building and storing the rvalue, which plays better with the direction we're taking for value semantics optimizations.

This is currently guarded behind a flag -enable-silgen-lvalue-peepholes because it introduces a miscompile in the stdlib that crashes some tests; requires further investigation before making live.

Swift SVN r9027
2013-10-08 20:44:09 +00:00
Joe Groff
554fcc9250 SILGen: Use SILBuilder::emitDestroyAddr in place of TypeLowering::emitDestroyAddress.
The other end of r8989. Canonicalize toward destroy_addr when destroying lvalues already in memory, instead of trying to emit a more specific sequence of operations.

Swift SVN r9022
2013-10-08 03:50:51 +00:00
Joe Groff
fd9fd40068 Properly nest class initializer 'self' box with other argument boxes.
Emit the 'self' argument of constructors first so that its box's lifetime follows proper stack discipline relative to the other arguments.

Swift SVN r8984
2013-10-07 20:32:59 +00:00
Joe Groff
0bff1ebe7b SILGen: Emit cleanups before returning from enum case constructors.
We were leaking dealloc_stacks when the enum constructor had to create temporary allocations in order to implode address-only tuple payloads.

Swift SVN r8971
2013-10-07 18:04:43 +00:00
Chris Lattner
607114f6c6 Introduce a new "emitDestroyAddr" function, which attempts to fold destroy_addr into
preceding copy_addr instruction when totally trivial.  Adopt this in SILGen, eliminating
a couple dozen destroy_addr instructions from the stdlib and producing more canonical SIL.


Swift SVN r8968
2013-10-07 17:47:17 +00:00
Doug Gregor
611a5cce4b Replace the library-defined postfix '!' with an expr-postfix production.
As with the monadic '?', we treat any left-bound '!' as a postfix
operator. Currently, it extracts the value of its optional
subexpression, failing at run-time if the optional is empty.


Swift SVN r8948
2013-10-06 23:09:58 +00:00
John McCall
affefbe1e0 Remove the AllocSelfExpr from constructors and teach
alloc_ref how to call +allocWithZone: for classes that might
(i.e. probably do) use ObjC allocation.

Swift SVN r8874
2013-10-03 06:36:34 +00:00
Joe Groff
3b0180b1b0 Allow '_' in assignments again.
Parse '_' as a DiscardAssignmentExpr. Type-check it as an lvalue, and check that it only appears in the LHS of AssignExprs. During matching pattern resolution, convert it into an AnyPattern. In SILGen, when we see '_' in the LHS of an assignment, ignore the corresponding RHS rvalue.

Swift SVN r8848
2013-10-02 18:43:20 +00:00
John McCall
6df6897756 Add an InjectIntoOptional implicit conversion expression
instead of generating ugly artificial calls to
_injectValueIntoOptional in the AST.

Swift SVN r8837
2013-10-02 05:48:30 +00:00
John McCall
97033996ba Rework optional intrinsic methods to work with RValues.
Swift SVN r8836
2013-10-02 05:48:29 +00:00
John McCall
298577676e Introduce the monadic ? operator.
A ? operator is interpreted as this if it's left-bound,
so ternary operators now have to be spaced on the left.

Swift SVN r8832
2013-10-02 01:27:45 +00:00
John McCall
a1867380d0 Distinguish the "cleanup handle" and "scope" use-cases
of CleanupsDepth.

Only with different typedefs for now, but the communicative
effect is significant.

Swift SVN r8831
2013-10-02 01:27:41 +00:00
John McCall
916b566fa6 Push and invalidate uninitialized-local cleanups.
No effect currently; just resolves a FIXME.

Swift SVN r8830
2013-10-02 01:27:39 +00:00
Joe Groff
ce2e87fa3e SILGen: Emit 'x as? T' conditional casts.
Wrap the result of a checked_cast_br into an Optional using John's injection functions.

Swift SVN r8811
2013-10-01 21:11:34 +00:00
Joe Groff
f1993cf231 Parse and type-check 'x as? T' conditional cast syntax.
Though we plan to revamp the casting syntax, our general plan is for this form of cast, which does a conditional cast and returns an Optional<T> result, to be the one that survives. Parse the status-quo syntax 'x as? T' and type-check it. While we're here, refresh some fixits for redundant casts that referred to the now defunct 'as T' coercion syntax to completely remove whatever cast was in the source code.

Swift SVN r8805
2013-10-01 17:00:54 +00:00