Commit Graph

893 Commits

Author SHA1 Message Date
Michael Gottesman
4c61867097 [silgen] Quick drive by thinko fix.
Just noticed this while reading over this code. Disheartening that our tests did
not catch it. = /.
2017-03-14 01:45:42 -07:00
Michael Gottesman
213ddd753f [silgen] Compute the ResultPlan outside of SILGenApply so that we can untangle indirect result/normal argument lifetime scopes.
rdar://30955427
2017-03-14 00:39:53 -07:00
Michael Gottesman
b0522635d4 [silgen] Instead of computing the indirect result addrs as we build/store it. Just generate it dynamically.
This is being done in preparation for moving ResultPlan /out of/
SILGenFunction::apply.

rdar://30955427
2017-03-14 00:39:48 -07:00
Michael Gottesman
4552355ff2 [silgen] Refactor SILGenFunction::apply to take a new struct called CalleeTypeInfo.
This structure contains all of the type information that we use to build a
ResultPlanPtr. In a subsequent commit, I am going to move ResultPlanPtr creation
out of emitApply and place it before the creation of arguments. This is to
enable indirect result initializations to belong to the scope outside of any
argument based scopes.

Without this the lifetimes of the indirect result initializations and arguments
can not be separated without using hacks. There is no reason why we can't emit
the indirect result temporaries before we emit any arguments since they will
remain dormant until after the final apply/any future committed argument scopes
being popped.

rdar://30955427
2017-03-14 00:39:41 -07:00
Michael Gottesman
8521601215 [silgen] Move ResultPlan from SILGenApply.cpp -> ResultPlan.{h,cpp}
ResultPlan and related constructs have already been written in a type erased
fashion. This commit takes advantage of this by moving the details of the code
to ResultPlan.{cpp,h}.

This slims down SILGenApply.cpp in a NFC way and ensures that other code in
SILGenApply can not depend on the details of ResultPlan. Also it is my hope that
this can become the beginning of the merging of the ResultPlan from SILGenApply
and from SILGenPoly. We should only have 1 way in SILGen to build applies and
create apply results.

rdar://29791263
2017-03-13 10:32:33 -07:00
Michael Gottesman
68c581f729 [gardening] As per discussion, begin standardizing in SILGen that the SILGenFunction variable is passed around as SGF.
The reason that this is being done is that:

1. SILGenFunction is passed around all throughout SILGen, including in between
APIs some of which call the SILGenFunction variable SGF and others that call it
gen.
2. Thus when one is debugging code in SILGen, one wastes time figuring out what
the variable name of SILGenFunction is in the current frame.

I did not do this by hand. I did this by:

1. Grepping for "SILGenFunction &gen".
2. By hand inspecting that the match was truly a SILGenFunction &gen site.
3. If so, use libclang tooling to rename the variable to SGF.

So I did not update any use sites.
2017-03-11 23:38:17 -08:00
Michael Gottesman
f064e26f31 [gardening] Normalize field capitalization. 2017-03-11 23:30:19 -08:00
Michael Gottesman
22e0fdafac [silgenapply][callemission] Change access of new helper methods to be private. 2017-03-11 21:38:08 -08:00
Michael Gottesman
2d9eb7f89f [silgenapply][callemission] Refactor out application of the first level callee into its own method.
Now that this is complete, the huge function CallEmission::apply is now only 20
lines and doesn't contain spaghetti code.
2017-03-11 21:36:59 -08:00
Michael Gottesman
d7b214252a [silgenapply][callemission] Refactor out the normal call part of CallEmission::apply. 2017-03-11 21:30:04 -08:00
Michael Gottesman
4391dbafad [silgenapply][callemission] Refactor out enum element constructor emission. 2017-03-11 21:05:36 -08:00
Michael Gottesman
cd8e131826 [silgenapply][callemission] Eliminate an unneeded parameter. 2017-03-11 20:49:29 -08:00
Michael Gottesman
10099a04ea [silgenapply][callemission] Eliminate shadowed variable. 2017-03-11 20:49:29 -08:00
Michael Gottesman
1a3ab56dfd [silgenapply][callemission] Refactor first level call partial applied super method into a helper method called applyPartiallyAppliedSuperMethod. 2017-03-11 19:50:26 -08:00
Michael Gottesman
46260379cc [silgenapply][callemission] Refactor out code for applying a first level specialized emitter. 2017-03-11 19:38:39 -08:00
Michael Gottesman
dad7a55506 [silgenapply][callemission] Refactor out argument emission for non-early specialized emitter and non-enum constructor calls. 2017-03-11 15:56:53 -08:00
Michael Gottesman
230259cffd [silgen][callemission] Refactor out the handling of the remaining call sites after the first call site into its own method.
This is in preperation for eliminating the spaghetti code in
CallEmission::apply.
2017-03-11 15:18:05 -08:00
Joe Groff
99ea154151 Merge pull request #7965 from jckarter/invariant-load
Add a `loadInvariant` builtin.
2017-03-09 06:39:42 -08:00
Joe Groff
39ecc53a25 Add a loadInvariant builtin.
Lowers to an invariant load in LLVM; probably useful for SIL too at some point too, but NFC at that level yet.
2017-03-08 21:02:03 -08:00
Slava Pestov
c4f32ed4d7 SILGen: Remove unused parameter from prepareArchetypeCallee() 2017-03-08 13:54:31 -08:00
Slava Pestov
76eb5dd66d SILGen: Clean up ad-hoc SubstitutionList construction when calling intrinsics
Change emitApplyOfLibraryIntrinsic() to take a SubstitutionMap,
and use the correct abstractions to build the map.

This gets rid of the last remaining uses of gatherAllSubstitutions()
in SIL.
2017-03-08 13:54:29 -08:00
Slava Pestov
66ff05820e SILGen: Remove SubstFormalType computation
There was a lot of rather elaborate code that didn't do
anything at all.
2017-03-05 02:26:25 -08:00
Slava Pestov
0611d663b8 SIL: Remove SILType::getSwiftType() 2017-02-27 20:01:35 -08:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
Michael Gottesman
5a15f880ee [silgen] Change a bunch of self accesses to use true formal evaluation scopes and formal accesses.
This is in preparation for removing the +0 self hack.

This commit in more detail does the following:

1. It adds Formal Evaluation Scopes to certain places where the scopes were
missing. Specifically:

   a. The SILGenLValue cases are places where we are invoking accessors. In each
      one of these cases, we had a formal evaluation scope in the accessor
      itself, but we did not have a scope that closed over the base access and
      the accessor access. The base access is a formal evaluation in the sense
      that just like with inout bases, we must create a new reference to the
      base and re-destroy the base in a chain of accesses. This is to ensure
      that we do not extend the lifetime of the base inappropriately.

   b. The SILGenPoly case is a place where we have never properly placed a
      Formal Evaluation Scope and have completely been relying on the +0 self
      hack to make sure that archetype callees are properly destroyed
      immediately after a +0 call.

2. It changes all of the places in SILGen that emit self to using formal access
cleanups instead of normal cleanups.

rdar://29791263
2017-02-23 10:36:48 -08:00
Michael Gottesman
784d5d16fc [silgen] Change emitClassConstructorInitializer to use ownership and make calling designated/chaining initializes use proper ownership.
rdar://29791263
2017-02-23 08:48:58 -08:00
Michael Gottesman
dd5120e9f0 [silgen] Create a closure API called bufferForExprResult based on getBufferForExpr/manageBufferForExpr but managing the ownership for the user.
There are many cases where getBufferForExpr and manageBufferForExpr occur right
next to each other. The closure based API expresses this pattern in a more
convenient manner where the user can express his/her intent with one action
instead of two. In these cases, the split is messy and not necessary.
2017-02-19 11:15:01 -08:00
Michael Gottesman
9a96403496 [silgen] Refactor prepareArchetypeCallee to use a builder class instead of iterated closures.
The way iterated closures were used to propagate around state that caused the
flow of data in the program to be confusing to read. This makes the dataflow
explicit by communicating clearly what variables are "global" to the
computation.

Beyond the refactoring this is a NFC.

rdar://29791263
2017-02-19 08:28:37 -08:00
Michael Gottesman
d051583378 [semantic-sil] When emitting a base for an accessor use a load_borrow when appropriate.
This builds on 92bf345. I am very pleased that a couple of the cases I needed to
update, a retain/release was eliminated on the base.

rdar://29791263
2017-02-18 00:55:36 -08:00
Joe Shajrawi
935a54bace Opaque values: fix a bug in ResultPlanBuilder + support for-each loops 2017-02-17 14:50:15 -08:00
Joe Shajrawi
831769b446 Opaques: initialize optionals by-value under new opaque value mode 2017-02-17 11:06:48 -08:00
Joe Shajrawi
2b8dfaf064 Merge pull request #7470 from shajrawi/var_args_SpecialDest_opaque_mode
Support for address based array initialization under opaque values mode
2017-02-14 14:39:05 -08:00
Joe Shajrawi
03d55cd023 Support for address based array initialization under opaque values mode 2017-02-14 13:47:04 -08:00
Michael Gottesman
906763f545 [silgen] Add a SILGenFunction & argument to Cleanup::dump().
This enables LValueWritebackCleanup and a future version of EndBorrowCleanup to
dump their values which have to be looked up from SILGenFunction.
2017-02-14 13:34:46 -08:00
Michael Gottesman
9747214e92 [silgen] Refactor WritebackScope functionality into a new FormalEvaluationScope.
As per John, WritebackScope was always an unfortunate name. Generally these
scopes are meant for formal evaluations of inout parameters. The cases that I am
interested in generalizing them to be used for are borrows of the base of a
class that will then be used as an lvalue.

This also eliminates the out of line vector of lvalue writebacks.

rdar://29791263
2017-02-14 13:15:23 -08:00
Andrew Trick
341c481e8b Disable SILGen apply assert. 2017-02-13 17:10:02 -08:00
Andrew Trick
c5b7dc076c Disable SILGen apply assert. 2017-02-13 17:10:02 -08:00
practicalswift
8bdec1f570 [gardening] Remove unused method isDirectGuaranteed() 2017-02-13 15:21:53 +01:00
practicalswift
6daa23fa8e [gardening] Fix a vs an typos 2017-02-13 14:45:16 +01:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Michael Gottesman
d153f36e48 [silgen] Handle forwarding of direct tuple args using a borrow + extract + copy triple
Once we have a destructure operation this will not be necessary.

rdar://29791263
2017-02-08 16:00:23 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Slava Pestov
7e927b578d Merge pull request #7283 from slavapestov/kill-uncurry-level
SIL: Remove uncurryLevel parameter from type lowering
2017-02-06 15:45:07 -08:00
Slava Pestov
162b1c0de0 SIL: Remove uncurryLevel parameter from type lowering
There was only one place where we lowered AST types with a non-zero
uncurry level, in SILGenApply.cpp. Add a new overload of the
getSILFunctionType() method that takes an uncurry level. All the
other methods no longer have to thread it through.
2017-02-06 15:24:03 -08:00
Michael Gottesman
54a44068ce [silgen] Refactor the emission of argument bases of Accessors to use a visitor pattern instead of 1 huge function.
This makes the code much easier to read.

rdar://29791263
2017-02-06 15:01:36 -08:00
Michael Gottesman
e192b56a88 [silgen] Create CleanupManager::dump and the relevant dump methods to dump the current cleanups.
This is useful to discover when a specific cleanup is being eliminated while
debugging. The implementation is compiled out when assertions are disabled.

rdar://29791263
2017-02-05 18:38:41 -08:00
Jordan Rose
59ddb5b00f [SILGen] Don't crash when calling a generic init with default args. (#7169)
In cases where a default value is used for a parameter with generic
type, the argument list might be empty. In that case, we don't need
to emit any arguments!
2017-01-31 15:43:52 -08:00
Joe Groff
8bdc8ecf25 Merge pull request #7167 from jckarter/super-final-c-extension-expialidocious
Sema: "super" calls to non-ObjC extension methods must be statically dispatched.
2017-01-31 14:23:52 -08:00
Joe Groff
8159c84bc9 Sema: "super" calls to non-ObjC extension methods must be statically dispatched.
They currently can't ever show up in the vtable, so we must emit static calls to them. Fixes rdar://problem/30030229.
2017-01-31 13:30:21 -08:00
Slava Pestov
dca292c652 Serialization: Don't serialize contextual enum argument type
Storing this separately is unnecessary since we already
serialize the enum element's interface type. Also, this
eliminates one of the few remaining cases where we serialize
archetypes during AST serialization.
2017-01-30 00:08:53 -08:00