Commit Graph

745 Commits

Author SHA1 Message Date
Joe Groff
a68cca872b Start->End Typo 2015-12-26 15:23:13 -08:00
Joe Groff
25e43e3d48 IRGen: Mark more allocas with lifetime markers.
This should cover most temporary buffers, except for those used by indirected value arguments, which need some cooperation with CallEmission to properly mark lifetime end after the call's completed.
2015-12-26 15:19:07 -08:00
Joe Groff
0991b2c5d8 IRGen: Factor out IRBuilder helpers for CreateLifetimeStart/End. 2015-12-25 12:24:56 -08:00
Dmitri Gribenko
11ab3d537f Revert "Include access functions for the metadata and witness tables"
This reverts commit 7576a91009.
It broke the testsuite for swift-corelibs-foundation.
2015-12-25 19:17:50 +02:00
John McCall
7576a91009 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.

This reverts commit 6528ec2887, i.e.
it reapplies b1e3120a28, with a fix
to unbreak release builds.
2015-12-24 20:21:17 -08:00
Joe Groff
1524b5146e IRGen: Put lifetime markers on stack allocations. 2015-12-24 12:11:19 -08:00
Joe Groff
2201c99a32 IRGen/Runtime: Open-code respondsToSelector: checks for AnyObject lookup.
Emit the respondsToSelector: msgSend inline instead of relying on a runtime call.
2015-12-24 09:00:43 -08:00
Sean Callanan
6528ec2887 Revert "Include access functions for the metadata and witness tables"
This reverts commit b1e3120a28.

Reverting because this patch uses WitnessTableBuilder::PI in NDEBUG code.
That field only exists when NDEBUG is not defined, but now NextCacheIndex, a
field that exists regardless, is being updated based on information from PI.

This problem means that Release builds do not work.
2015-12-23 15:42:10 -08:00
Adrian Prantl
52ed238cee Enable a previously commented assertion.
rdar://problem/22035399
2015-12-23 10:24:58 -08:00
John McCall
b1e3120a28 Include access functions for the metadata and witness tables
of associated types in protocol witness tables.

We use the global access functions when the result isn't
dependent, and a simple accessor when the result can be cheaply
recovered from the conforming metadata.  Otherwise, we add a
cache slot to a private section of the witness table, forcing
an instantiation per conformance.  Like generic type metadata,
concrete instantiations of generic conformances are memoized.

There's a fair amount of code in this patch that can't be
dynamically tested at the moment because of the widespread
reliance on recursive expansion of archetypes / dependent
types.  That's something we're now theoretically in a position
to change, and as we do so, we'll test more of this code.
2015-12-23 00:37:24 -08:00
Adrian Prantl
c44931ec1b Debug Info: Support generic function specialization by substituting
the archetype with the specialized type.

rdar://problem/21949734
2015-12-22 13:16:22 -08:00
Daniel Duan
ae601d2744 replace NULL with nullptr 2015-12-20 13:28:21 -08:00
Adrian Prantl
f1709c0cf6 Debug Info: Assign unique names to anonymous variables and arguments.
rdar://problem/18139663
This reapplies ef84c81429 and also takes
$match variables into account.
2015-12-16 15:43:36 -08:00
Adrian Prantl
7a84f0dce0 Debug Info: Support updates to debug values.
This allows SIL transformations to describe one source variable with more
than one debug_value instruction.

rdar://problem/22705966
(cherry picked from commit fd6e8a9bef)
2015-12-16 15:43:36 -08:00
Adrian Prantl
be3cec7b6d Revert "Debug Info: Support updates to debug values."
This reverts commit fd6e8a9bef
while investigating buildbot breakage.
This uncovered a bug in the debug scoping of pattern match variables.
2015-12-16 12:17:42 -08:00
Adrian Prantl
97332afa62 Temporarily revert "Debug Info: Assign unique names to anonymous variables and arguments."
This reverts commit ef84c81429 because fd6e8a9bef needed to be reverted.
2015-12-16 12:17:41 -08:00
Adrian Prantl
ef84c81429 Debug Info: Assign unique names to anonymous variables and arguments.
rdar://problem/18139663
2015-12-16 11:29:25 -08:00
Adrian Prantl
fd6e8a9bef Debug Info: Support updates to debug values.
This allows SIL transformations to describe one source variable with more
than one debug_value instruction.

rdar://problem/22705966
2015-12-16 11:29:25 -08:00
Adrian Prantl
5835e5b734 Debug info: Get variable names from the VarInfo instead of the Decl. 2015-12-16 08:37:56 -08:00
Michael Gottesman
f3c8c5a774 Create SILBasicBlock::getSuccessorBlocks().
This just runs a transform range on getSuccessor()'s ArrayRef<SILSuccessor> so
one does not need to always call Successor.getBB() when iterating over successor
blocks. Instead the transform range does that call for you.

I also updated some loops to use this new SILBasicBlock method to make sure that
the code is tested out by tests that are already in tree. All these places
should be functionally the same albeit a bit cleaner.
2015-12-15 00:36:56 -06:00
Adrian Prantl
64cbec3805 Add SIL syntax for declaring debug variables.
Debug variable info may be attached to debug_value, debug_value_addr,
alloc_box, and alloc_stack instructions.

In order to write textual SIL -> SIL testcases that exercise the handling
of debug information by SIL passes, we need to make a couple of additions
to the textual SIL language. In memory, the debug information attached to
SIL instructions references information from the AST. If we want to create
debug info from parsing a textual .sil file, these bits need to be made
explicit.

Performance Notes: This is memory neutral for compilations from Swift
source code, because the variable name is still stored in the AST. For
compilations from textual source the variable name is stored in tail-
allocated memory following the SIL instruction that introduces the
variable.

<rdar://problem/22707128>
2015-12-14 10:29:50 -08:00
practicalswift
0a39f6e10e Fix typo: guranteed → guaranteed 2015-12-14 00:11:50 +01:00
John McCall
5fddd4a704 Remove the autorelease_return and strong_retain_autoreleased instructions.
There's a buggy SIL verifier check that was previously tautological,
and it turns out that it's violated, apparently harmlessly.  Since it
was already doing nothing, I've commented it out temporarily while
I figure out the right way to fix SILGen to get the invariant right.
2015-12-09 14:50:20 -08:00
John McCall
23ea72b21e Teach IRGen to apply the ARC autorelease optimization implicitly
when working with autoreleased result conventions, and stop
emitting autorelease_return and strong_retain_autoreleased in
SILGen.

The previous representation, in which strong_retain_autoreleased
was divorced from the call site, allowed it to "wander off" and
be cloned.  This would at best would break the optimization, but
it could also lead to broken IR due to some heroic but perhaps
misguided efforts in IRGen to produce the exact required code
pattern despite the representational flaws.

The SIL pattern for an autoreleased result now looks exactly
like the pattern for an owned result in both the caller and
the callee.  This should be fine as long as interprocedural
optimizations are conservative about convention mismatches.
Optimizations that don't wish to be conservative here should
treat a convention mismatch as an autorelease (if the callee
has an autoreleased result) or a retain (if the formal type
of the call has an autoreleased result).

Fixes rdar://23810212, which is an IRGen miscompile after the
optimizer cloned a strong_retain_autoreleased.  There's no
point in adding this test case because the new SIL pattern
inherently prevents this transformation by construction.

The 'autorelease_return' and 'strong_retain_autoreleased'
instructions are now dead, and I will remove them in a
follow-up commit.
2015-12-09 00:49:42 -08:00
John McCall
bdb4b896a2 Move ObjC-compatible unowned references to the new runtime
functions.

Take the code for the old, broken reference-counting
implementation and delete it with prejudice.
2015-12-08 16:20:32 -08:00
Adrian Prantl
dd0db18ad4 Debug Info: Unify the handling of indirect values and fix a bug where
ParenTypes were not recognized as generic.

Fixes rdar://problem/23681035
2015-12-04 16:40:52 -08:00
Adrian Prantl
7eeece6cbd Debug Info: Unify the unwrapping of inout/lvalue types. (NFC) 2015-12-04 16:40:52 -08:00
Joe Groff
5e4bb4b96c Merge pull request #207 from mrecachinas/irgensil-assertion
[IRGen] Add assertion to `emitPHINodesForBBArgs`
2015-12-04 14:08:27 -08:00
John McCall
4d1b6e2eb6 Reform the runtime interface for unowned reference-counting.
This is a bit of a hodge-podge of related changes that I decided
weren't quite worth teasing apart:

First, rename the weak{Retain,Release} entrypoints to
unowned{Retain,Release} to better reflect their actual use
from generated code.

Second, standardize the names of the rest of the entrypoints around
unowned{operation}.

Third, standardize IRGen's internal naming scheme and API for
reference-counting so that (1) there are generic functions for
emitting operations using a given reference-counting style and
(2) all operations explicitly call out the kind and style of
reference counting.

Finally, implement a number of new entrypoints for unknown unowned
reference-counting.  These entrypoints use a completely different
and incompatible scheme for working with ObjC references.  The
primary difference is that the new scheme abandons the flawed idea
(which I take responsibility for) that we can simulate an unowned
reference count for ObjC references, and instead moves towards an
address-only scheme when the reference might store an ObjC reference.
(The current implementation is still trivially takable, but that is
not something we should be relying on.)  These will be tested in a
follow-up commit.  For now, we still rely on the bad assumption of
reference-countability.
2015-12-04 13:18:14 -08:00
Mike Recachinas
75ecee2d3c [IRGen] Add assertion to emitPHINodesForBBArgs
Converted the check that the DebugScope `DS` exists and that the
DebugScope's `SILFn` is the same as the `IGF`'s to an assertion
based on the FIXME's suggestion on line 831.
2015-12-04 15:43:30 -05:00
Adrian Prantl
beb0d00758 Remove dead code. 2015-12-04 11:05:27 -08:00
Adrian Prantl
0d300206cd Remove wrapper functions that added little value. (NFC) 2015-12-04 11:05:26 -08:00
Adrian Prantl
7821341542 Add an argument-number field to DebugValueInst and friends.
This commit adds a DebugVariable field that is shared by
- AllocBoxInst
- AllocStackInst
- DebugValueInst
- DebugValueAddrInst
Currently DebugVariable only holds the Swift argument number.

This allows us to retire several expensive heuristics in IRGen that
attempted to identify which local variables actually where arguments
and recover their relative order.

Memory footprint notes:
This commit adds a 4-byte field to 4 SILInstructin subclasses.
This was offset by 8ab1e2dd50
which removed 20 bytes from *every* SILInstruction.

Caveats:
This commit surfaces a known bug in FunctionSigantureOpts, tracked in
rdar://problem/23727705 — debug info for exploded function arguments
cannot be expressed until this is fixed.

This reapplies ed2b16dc5a with a bugfix for
generic function arrguments and an additional testcase.

<rdar://problem/21185379&22705926>
2015-12-03 13:40:35 -08:00
Johan K. Jensen
fa76656c82 Remove instances of duplicated words 2015-12-03 20:00:29 +01:00
Adrian Prantl
2740ad6976 Temporarily Revert "Add an argument-number field to DebugValueInst and friends."
while investigating buildbot breakage.

This reverts commit ed2b16dc5a.
2015-12-02 19:10:05 -08:00
Adrian Prantl
ed2b16dc5a Add an argument-number field to DebugValueInst and friends.
This commit adds a DebugVariable field that is shared by
- AllocBoxInst
- AllocStackInst
- DebugValueInst
- DebugValueAddrInst
Currently DebugVariable only holds the Swift argument number.

This allows us to retire several expensive heuristics in IRGen that
attempted to identify which local variables actually where arguments
and recover their relative order.

Memory footprint notes:
This commit adds a 4-byte field to 4 SILInstructin subclasses.
This was offset by 8ab1e2dd50
which removed 20 bytes from *every* SILInstruction.

Caveats:
This commit surfaces a known bug in FunctionSigantureOpts, tracked in
rdar://problem/23727705 — debug info for exploded function arguments
cannot be expressed until this is fixed.

<rdar://problem/21185379&22705926>
2015-12-02 18:33:07 -08:00
Roman Levenstein
378442185f Merge a switch case into the identical case block below. NFC. 2015-12-01 21:27:50 -08:00
Roman Levenstein
5cc14abb82 [sil-devirtualizer] Improve devirtualization of witness_method instructions.
Handle such cases like partial applications of witness methods and applications of witness methods with substitutions.

Some of these uses-cases occur when there is a protocol defining an operator, a generic struct conforming to this protocol, and the operator conformance of this struct is expressed as a global function.
2015-12-01 14:49:47 -08:00
David Farler
fbbb593b1c IRGen: Lower super_method SIL instruction for native classes
This is the first part of making class method dispatch resilient.

If we have the following class hierarchy:

    // Module A
    class Parent {
      func foo() {}
    }

    class Child : Parent {}

    // Module B
    class Grandchild : Child {
      override func foo() {
        super.foo()
      }
    }

dispatch to `Parent.foo` will be static via a `function_ref`, so if
someone adds a `foo()` to `Child` later on, `Grandchild` won't know
about it without recompiling.

Stage in the IRGen portion of dynamic dispatch when calling methods on
`super`:

- Don't assert in IRGen if we see a native super_method instruction.
- Perform virtual lookup on superclass's metadata. If we see a
  `super_method` instruction for a native class:
  - Get the address of the superclass's metadata at offset 1
  - Load the superclass's metadata
  - Perform virtual lookup on this metadata instead

TODO: SILGen super_method instructions for native classes.
TODO: Devirtualize back down to static dispatch with a reslience lookup
mechanism.

rdar://problem/22749732
2015-11-30 21:19:06 -08:00
Slava Pestov
e6d35f29f2 Fix typos I noticed in IRGen and SILGen, NFC 2015-11-30 13:32:55 -08:00
Adrian Prantl
f40d28f402 Debug Info: Don't reset the debug scope after leaving the outermost scope,
because the debugger is not expecting the function epilogue to
be in a different scope.

rdar://problem/23621232
2015-11-19 17:41:51 -08:00
Adrian Prantl
8ab1e2dd50 Unify debug scope and location handling in SILInstruction and SILBuilder.
The drivers for this change are providing a simpler API to SIL pass
authors, having a more efficient of the in-memory representation,
and ruling out an entire class of common bugs that usually result
in hard-to-debug backend crashes.

Summary
-------

SILInstruction

Old                   New
+---------------+     +------------------+    +-----------------+
|SILInstruction |     |SILInstruction    |    |SILDebugLocation |
+---------------+     +------------------+    +-----------------+
| ...           |     | ...              |    | ...             |
|SILLocation    |     |SILDebugLocation *| -> |SILLocation      |
|SILDebugScope *|     +------------------+    |SILDebugScope *  |
+---------------+                             +-----------------+

We’re introducing a new class SILDebugLocation which represents the
combination of a SILLocation and a SILDebugScope.
Instead of storing an inline SILLocation and a SILDebugScope pointer,
SILInstruction now only has one SILDebugLocation pointer. The APIs of
SILBuilder and SILDebugLocation guarantees that every SILInstruction
has a nonempty SILDebugScope.

Developer-visible changes include:

SILBuilder
----------

In the old design SILBuilder populated the InsertedInstrs list to
allow setting the debug scopes of all built instructions in bulk
at the very end (as the responsibility of the user). In the new design,
SILBuilder now carries a "current debug scope" state and immediately
sets the debug scope when an instruction is inserted.
This fixes a use-after-free issue with with SIL passes that delete
instructions before destroying the SILBuilder that created them.

Because of this, SILBuilderWithScopes no longer needs to be a template,
which simplifies its call sites.

SILInstruction
--------------

It is neither possible or necessary to manually call setDebugScope()
on a SILInstruction any more. The function still exists as a private
method, but is only used when splicing instructions from one function
to another.

Efficiency
----------

In addition to dropping 20 bytes from each SILInstruction,
SILDebugLocations are now allocated in the SILModule's bump pointer
allocator and are uniqued by SILBuilder. Unfortunately repeat compiles
of the standard library already vary by about 5% so I couldn’t yet
produce reliable numbers for how much this saves overall.

rdar://problem/22017421
2015-11-19 09:31:26 -08:00
Michael Gottesman
9fb54bf4bf Fix for upstream ilist changes. 2015-11-11 16:07:41 -08:00
Adrian Prantl
098c07957e Debug Info: Don't skip updating IRGenDebugInfo's current location for SILLocations that are marked as prologue. IRGenDebugInfo will handle them correctly anyway and if the instruction with the prologue location originates from an inlined function, this would result in dropping debug location information.
rdar://problem/23288366
2015-11-10 10:24:57 -08:00
Argyrios Kyrtzidis
f0f83d32c2 Fix -Wunused-function warnings. 2015-11-05 19:04:10 -08:00
Erik Eckstein
5067dad4dc IRGen: create end-of-lifetime intrinsics for dealloc_ref [stack] 2015-11-04 12:50:50 -08:00
Erik Eckstein
68fa1c2c34 Support for stack promotion in IRGen.
This means: handling of alloc_ref [stack].
It can be configured with two new options. See Option/FrontendOptions.td.

As the [stack] attribute is not generated yet, there should be NFC.




Swift SVN r32929
2015-10-28 00:44:25 +00:00
Adrian Prantl
2f9f964219 Change the contract between Swift compiler and LLDB about how the function
prologue is handled in the line table.
We now mark the first instruction after the stack setup as end_prologue and
any further initilizations (which may include function calls to metadata
accessors) with line 0 which lldb will skip. This allows swiftc to emit
debug info for compiler-generated functions such as metadata accessors.
Mixing debug and non-debug functions is not very well supported by LLVM
and the resulting line table makes it impossible for LLDB to determine
where a function with debug info ends and a nondebug function starts.

rdar://problem/23042642

Swift SVN r32816
2015-10-22 00:20:03 +00:00
Slava Pestov
76f1168adf Remove dealloc_ref's [constructor] form since its no longer needed
Swift SVN r32688
2015-10-14 22:50:09 +00:00
Slava Pestov
7cc59e01d7 SIL: Add DeallocPartialRefInst
This instruction destroys instance variables in a partially-initialized
object, then frees it.

Swift SVN r32661
2015-10-13 19:56:20 +00:00