Commit Graph

754 Commits

Author SHA1 Message Date
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Adrian Prantl
60c71c9b33 Point the SILLocations of function-level SILDebugScopes to the beginning of the scope.
This mostly makes textual SIL easier to read and has no effect on the generated DWARF.

<rdar://problem/28859432>
2018-06-26 18:07:04 -07:00
Slava Pestov
ebb1198d57 AST: There's no longer any reason to pass SubstitutionMap by const reference
SubstitutionMaps are now just a trivial pointer-sized value, so
pass them by value instead.

I did have to move a couple of functors from Type.h to SubstitutionMap.h
to resolve some issues with forward declarations.
2018-05-19 00:45:36 -07:00
Joe Groff
aeb16baa6f Revert "SILGen: Open existential lvalues on entry into an OpenExistentialExpr again."
This reverts commit 742e7fc583. This
causes other source compatibility regressions due to the extended exclusive access to
the existential (such as rdar://problem/39524104). A false-positive
exclusivity failure might lead to runtime errors, whereas the cases we
can't support previous to this patch can at least reliably be handled
statically.
2018-05-17 13:17:44 -07:00
Doug Gregor
049c56dde6 Eliminate getForwardingSubstitutions().
Use the SubstitutionMap version everywhere.
2018-05-11 17:37:27 -07:00
Doug Gregor
cb3bf10d62 [SILGen] Eliminate SubstitutionList from SILGenFunction::emitApply(). 2018-05-11 17:37:27 -07:00
Doug Gregor
c9b50e0171 [SILGen] Eliminate SubstitutionList from the LValue infrastructure. 2018-05-11 17:37:27 -07:00
Doug Gregor
0bf0a1ee6a [SILGen] Eliminate more SubstitutionLists for accessor calls. 2018-05-11 17:37:26 -07:00
Doug Gregor
921d41ca10 [SILGen] Eliminate emitApplyOfLibraryIntrinsic() for SubstitutionList.
There was only one caller; update it to use the SubstitutionMap version.
2018-05-11 17:37:26 -07:00
Doug Gregor
4b5abbddbc [SIL] Teach *ApplyInst to traffic in SubstitutionMap.
Push SubstitutionMaps through most of SILGen and the SIL optimizers
that involve the various *ApplyInsts.
2018-05-11 13:18:06 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
Huon Wilson
0343a788f7 [SILGen] std::function -> llvm::function_ref for some non-escaping params. 2018-05-01 08:29:07 +10:00
Arnold Schwaighofer
e36655fddc SILGen: Remove PostponedCleanup in favor or the SIL pass that fixes
closure lifetimes.

SILGen will now unconditionally emit

  %cvt = convert_escape_to_noescape [guaranteed] %op

instructions. The mandatory ClosureLifetimeFixup pass ensures that %op's
lifetime spans %cvt's uses.

The code in DefiniteInitialization that handled a subset of cases is
removed.
2018-04-13 13:44:09 -07:00
Arnold Schwaighofer
b510227224 SILGen: Remove variable with negated name: 2018-03-30 08:51:06 -07:00
Arnold Schwaighofer
3ab1580cf9 SILGen: Don't postpone the cleanup of the convertEscapeToNoEscape inside an bind optional
This would violate dominance since the convertEscapeToNoEscape
instruction does not dominate the postpone point.

rdar://38124009
2018-03-30 06:20:13 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
Slava Pestov
b61255c2b8 SILGen: Simplify buildWithoutActuallyEscapingThunkType() 2018-03-18 00:13:55 -07:00
Slava Pestov
dac689a470 SILGen: Remove unused method 2018-03-14 17:21:39 -07:00
Harlan
a42c5ce733 Add no-op visitor in SILGenFunction for #warning/#error (#15008)
* Add no-op visitor in SILGenFunction for #warning/#error

* Switch to a compile-based test

* Actually add file substitution
2018-03-06 12:26:39 -05:00
Joe Groff
2f0a3f2e2d SILGen: Refactor key path component lowering.
Factor out the code to lower an individual key path component to be independent of overall KeyPathExpr lowering, so that we can soon reuse the same code paths to build property descriptors for resilient properties. NFC intended.
2018-02-28 15:06:44 -08:00
Adrian Prantl
9b6a9946ec Be explicit about whether a DebugInfo-carying SILInstruction has debug info.
This patch both makes debug variable information it optional on
alloc_stack and alloc_box instructions, and forced variable
information on debug_value and debug_value_addr instructions. The
change of the interface uncovered a plethora of bugs in SILGen,
SILTransform, and IRGen's LoadableByAddress pass.

Most importantly this fixes the previously commented part of the
DebugInfo/local-vars.swift.gyb testcase.

rdar://problem/37720555
2018-02-21 10:50:19 -08:00
Arnold Schwaighofer
a9fa8c9c2b Merge pull request #14514 from aschwaighofer/wip_closure_capture_abi_part2
WIP: Closure ABI - Make @noescape Swift closures trivial
2018-02-14 05:19:25 -08:00
Michael Gottesman
8a7e652e81 [+0-normal-args] Change SILGenFunction::emitDynamicMethodRef to return a ManagedValue.
There are a bunch of methods in this area that do not use ManagedValues, but
that should. This is another step towards unwinding the hairball.

rdar://34222540
2018-02-13 13:11:11 -08:00
Arnold Schwaighofer
025a8b909a Fix PostponedCleanup and use it in more places.
It can't be moved because there are pointers to it
2018-02-13 04:19:59 -08:00
Arnold Schwaighofer
64943836ba SILGen: Support for trivial @noescape function types
- Emit a withoutActuallyEscapingClosure partial apply
This is to convert an @noescape closure to an escaping closure.
This needs to be done in preparation of @noescape closure contexts
becoming trivial.

- Insert escaping to noescape conversions

- Fix SILGen for @noescape

- Postpone closure cleanups to outside the argument scope

- Apply postponement recursively for closures passed to subscripts

- Only skip applying escapeness conversions for Swift thick functions

- Fix parameter convention for noescape closures in thunks

Part of:
SR-5441
rdar://36116691
2018-02-13 04:19:59 -08:00
Joe Groff
742e7fc583 SILGen: Open existential lvalues on entry into an OpenExistentialExpr again.
4b25945 changed codegen for lvalue OpenExistentialExprs so that the existential was not opened until the OpaqueValue's lvalue was evaluated, but this is incorrect—we need to open the dynamic type of the existential immediately since it can be used arbitrarily within the subexpression. This caused a regression when evaluating default argument generators on protocol extension methods (rdar://problem/37031037), and would become a bigger problem when we generalize the ability to open existentials.
2018-02-06 19:44:53 -08:00
Slava Pestov
9b0f6fca53 IRGen: Emit class dispatch thunks in IRGen instead of SILGen
This allows us to re-use the same code for emitting protocol dispatch
thunks.
2018-01-15 22:38:16 -08:00
Slava Pestov
48897ded11 SIL: Remove never-emitted SILDeclRef::Kind::GlobalGetter 2018-01-14 21:39:53 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Vedant Kumar
dd560d2aa6 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-05 17:20:20 -08:00
Slava Pestov
38dfe296e9 SILGen: Remove selfType parameter from SILGenFunction::emitProtocolWitness() 2018-01-04 21:53:35 -08:00
Slava Pestov
2590142b7b SILGen: Remove shouldReferenceForeignAccessor()
Also, the 'isDirectAccess' parameter to various methods is now dead,
because it was never being set to true in the foreign case anyway.
2018-01-04 21:53:34 -08:00
Vedant Kumar
cccee1df03 Revert "[Coverage] Refactor SIL generation for profiling" 2018-01-03 21:57:49 -08:00
Vedant Kumar
aba9d53736 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-03 11:18:40 -08:00
Michael Gottesman
5f5ed55741 [silgen] When emitting a curry thunk, if the canonical type of the function differs from the actual function type in a non-ABI compatible way, use a canonical function thunk instead of a convert_function.
convert_function can only be used for to convert in between ABI compatible
functions.

rdar://34222540
2017-12-30 18:41:37 -05:00
Slava Pestov
e688da3b88 SILGen: Allow +0 parameter forwarding in protocol witness and re-abstraction thunks 2017-11-20 00:37:38 -05:00
adrian-prantl
4a92c603f1 Merge pull request #12889 from adrian-prantl/35430708
Debug Info / SILGen: fix the source location of variable assignments
2017-11-12 11:11:44 -08:00
Adrian Prantl
5e36991290 Debug Info / SILGen: fix the source location of variable assignments
by setting the location of the store emitted for a pattern binding
decl to the location of that PBD.

<rdar://problem/35430708>
2017-11-12 10:35:26 -08:00
Slava Pestov
2146383697 SILGen: Resilient method dispatch thunks 2017-11-11 16:31:53 -08:00
Slava Pestov
17da172b01 SILGen: Factor out SILGenFunction::emitClassMethodRef() 2017-11-08 21:27:31 -08:00
Michael Gottesman
798bff756a [silgen] Rename SavedInsertionPoint => SILGenSavedInsertionPoint.
This rename makes since since:

1. This is SILGen specific functionality.
2. In the next commit I am going to be adding a SIL SavedInsertionPoint class. I
want to make sure the two can not be confused.
2017-11-08 10:40:39 -08:00
Huon Wilson
0236db7be1 [SIL] Witness methods store the conformance from which they come. 2017-11-01 11:33:26 -07:00
Slava Pestov
a85f602636 SILGen: Clean up class_method instruction construction a bit 2017-10-03 18:48:19 -07:00
Joe Shajrawi
75939510cd PGO: Use ProfileCounter instead of Optional<uint64_t> to hold profile counts 2017-09-26 13:34:46 -07:00
Joe Shajrawi
64830c2d5e PGO: add support for checked_cast_addr_br 2017-09-26 11:14:31 -07:00
Joe Shajrawi
2c03144436 Add support for function_entry_count Profile counter 2017-09-26 11:10:52 -07:00
Joe Shajrawi
9999aa193a Refactor PGO code 2017-09-26 10:54:01 -07:00
Vedant Kumar
3685bd961e [SwiftPGO] Move counts attached to If{Expr,Stmt} into SIL
Specifically, load profiler counts corresponding to 'if' AST nodes and
attach them to the corresponding CondBranchInst's in SIL.

This is done using dirty tricks and isn't tested well enough :(.

  - Hack the SIL printer to make profile count loading testable.
  - Hack the profiler's counter map to store the indices of parent
    region counters in entries for 'else stmts' and 'else exprs'.

It's too early to hack up the SILOptimizer to propagate profile counts.
It doesn't seem too hard, but I definitely don't know the code well
enough to write tests for it :(. So that's still a TODO.

Next, we should be able to produce some acutual llvm branch_weight
metadata!
2017-09-26 10:54:01 -07:00
Vedant Kumar
5573313df2 [SwiftPGO] Make profile counts available to SILGenProfiler
This makes it possible to look up the execution count corresponding to
an ASTNode through SILGenFunction. The profile reader itself is stored
in a SILGenModule: this doesn't seem like the best place for it, so
suggestions for improvement are welcome!

Next, we'll actually attach this data to SIL objects and pass it all
down to IRGen.
2017-09-26 10:54:01 -07:00
Joe Groff
78d75428d6 SILGen: Lower key path subscript indexes.
And fill out SIL support for parsing, printing, and serializing key path
patterns with captured indexes.
2017-09-15 10:00:32 -07:00