Commit Graph

1108 Commits

Author SHA1 Message Date
Michael Gottesman
54a97bbf53 [silgen] Scope ArgEmitter::emit{SubstToOrigValue,NativeToBridgedArgument} using popPreservingValue to move its result into the outer scope.
rdar://31145255
2017-03-22 14:55:03 -07:00
Michael Gottesman
41f425a503 Revert "[silgen] If we have a direct guaranteed convention and have an owned value, perform a borrow."
This reverts commit 4c8595b002.
2017-03-20 05:00:31 -07:00
Devin Coughlin
fdd9ea6c7d SILGen: Reapply 'Add experimental TSan instrumentation for inout accesses.'
(This re-applies #7736 with an update to the
tsan-inout.swift execution test to handle configurations where
TSan's ignore_interceptors_accesses is enabled by default.)

Add SILGen instrumentation to treat inout accesses as Thread Sanitizer writes.
The goal is to catch races on inout accesses even when there is a not an
llvm-level read/write to a particular address. Ultimately
this will enable TSan to, for example, report racy writes to distinct
stored properties of a common struct as a data race.

This instrumentation is off by default. It can be enabled with the
'enable-experimental-tsan-inout-instrumentation' frontend flag.

The high-level approach is to add a SIL-level builtin that represents a call
to a TSan routine in compiler-rt. Then, when emitting an address for an LValue
as part of an inout expression, we call this builtin for each path component
that represents an LValue. I've added an 'isRValue()' method to PathComponent
that tracks whether a component represents an RValue or an LValue. Right the
only PathComponent that sometimes returns 'true' is ValueComponent().

For now, we're instrumenting only InoutExprs, but in the future it probably
makes sense to instrument all LValue accesses. In this patch I've
added a 'TSanKind' parameter to SILGenFunction::emitAddressOfLValue() and
its helpers to limit instrumentation to inout accesses. I envision that this
parameter will eventually go away.
2017-03-18 20:10:19 -07:00
Michael Gottesman
4c8595b002 [silgen] If we have a direct guaranteed convention and have an owned value, perform a borrow.
Now that all arguments are properly scoped, we do not need to worry about this
extending the lifetimes of COW times inappropriately.

rdar://30955427
2017-03-18 18:59:31 -07:00
Michael Gottesman
b99c47c006 [silgen] Scope argument cleanups with a new scope called "ArgumentScope".
Once this is in, I will be able to finish the SILGenApply part of Semantic SIL.

rdar://30955427
2017-03-18 17:03:41 -07:00
Michael Gottesman
8723301205 [silgen] Move implementation of emitForeignErrorArgument into ResultPlan. 2017-03-18 16:06:58 -07:00
Michael Gottesman
f4f41337e3 [gardening] Change some CalleeTypeInfo '&' parameters to be 'const &' parameters. NFC. 2017-03-18 14:40:50 -07:00
Greg Parker
c17cfb69d8 Revert "SILGen: Add experimental TSan instrumentation for inout accesses. (#7736)"
This reverts commit 52d5178a3e.
2017-03-16 21:11:58 -07:00
Devin Coughlin
52d5178a3e SILGen: Add experimental TSan instrumentation for inout accesses. (#7736)
Add SILGen instrumentation to treat inout accesses as Thread Sanitizer writes.
The goal is to catch races on inout accesses even when there is a not an
llvm-level read/write to a particular address. Ultimately
this will enable TSan to, for example, report racy writes to distinct
stored properties of a common struct as a data race.

This instrumentation is off by default. It can be enabled with the
'enable-experimental-tsan-inout-instrumentation' frontend flag.

The high-level approach is to add a SIL-level builtin that represents a call
to a TSan routine in compiler-rt. Then, when emitting an address for an LValue
as part of an inout expression, we call this builtin for each path component
that represents an LValue. I've added an 'isRValue()' method to PathComponent
that tracks whether a component represents an RValue or an LValue. Right the
only PathComponent that sometimes returns 'true' is ValueComponent().

For now, we're instrumenting only InoutExprs, but in the future it probably
makes sense to instrument all LValue accesses. In this patch I've
added a 'TSanKind' parameter to SILGenFunction::emitAddressOfLValue() and
its helpers to limit instrumentation to inout accesses. I envision that this
parameter will eventually go away.
2017-03-16 17:08:48 -07:00
Joe Shajrawi
067c867e5d Add inital support of Address-only enums under opaque values mode 2017-03-15 12:59:23 -07:00
Slava Pestov
61e9a980a7 SILGen: Calculate substituted formal type upfront
Also for class method callees, use the formal type of the base
method and not the override, fixing an issue with concrete
subclasses of generic base classes which bind a generic
parameter to a tuple type.

Fixes <https://bugs.swift.org/browse/SR-3541>.
2017-03-14 18:11:55 -07:00
Slava Pestov
708523d82e SILGen: Kill Callee::setSubstitutions() 2017-03-14 18:11:55 -07:00
Slava Pestov
f29661d40c SILGen: Callee::getOrigFormalType() is now an abstraction pattern 2017-03-14 18:11:55 -07:00
Slava Pestov
510d233543 SILGen: Refactor Callee a bit 2017-03-14 17:46:54 -07:00
Slava Pestov
64adf7495e SILGen: Change ArchetypeOpenings map to be keyed by ArchetypeType * and not CanType 2017-03-14 17:46:54 -07:00
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