Commit Graph

2682 Commits

Author SHA1 Message Date
Joe Shajrawi
cd38903450 Support reabstraction / partial apply of protocols under opaque value mode 2017-03-23 14:53:38 -07:00
Michael Gottesman
001345ee67 [silgen] Add helper methods to compute ArgumentSource::getSubst{RValue,}Type() as SILTypes.
rdar://31145255
2017-03-23 13:09:31 -07:00
Joe Shajrawi
b0cb327c17 Add support for opaque value call result types 2017-03-23 11:47:39 -07:00
Joe Shajrawi
54b0d9fda1 Merge pull request #8291 from shajrawi/optional_cast
Optional cast of opaque values
2017-03-22 21:33:31 -07:00
Joe Shajrawi
9790333d06 Support contextual init of opaque optional types 2017-03-22 17:30:49 -07:00
Joe Shajrawi
b9ee609369 Support casting of optional to optional for opaque values 2017-03-22 17:08:33 -07:00
Devin Coughlin
70fbfea397 TSan: Enable treating inout accesses as Thread Sanitizer writes by default
Flip the polarity of the frontend flag controlling whether TSan treats inout
accesses as conceptual writes. It is now on by default. This lets TSan detect
racing mutating methods even when those methods are not themselves instrumented
(such as methods on Standard Library collections).

This behavior can be disabled by passing:

  -Xfrontend -disable-tsan-inout-instrumentation

when compiling under TSan.

rdar://problem/31069963
2017-03-22 16:44:47 -07:00
Joe Shajrawi
204030a455 Merge pull request #8282 from shajrawi/enum_match
Resolve an issue with indirect enum's match for opaque values
2017-03-22 16:22:56 -07:00
swift-ci
86ac28c3f9 Merge pull request #8285 from gottesmm/scope_arg_transforms_1 2017-03-22 16:09:58 -07:00
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
225fd4acfc [silgen] Create Scope::popPreservingValue(ManagedValue).
What this routine does is:

1. "Imprints" a cleanup cloner with the managed value.
2. Forwards the managed value.
3. Pop the scope.
4. Use the imprinted cleanup cloner to recreate the managed value in the scope
outside of the current scope.
2017-03-22 14:55:03 -07:00
Joe Shajrawi
3d846b2f1a Resolve an issue with indirect enum's match for opaque values 2017-03-22 14:18:12 -07:00
Joe Shajrawi
a03f38c3c5 Add support for if statements for opaque value(s) under new mode 2017-03-22 12:48:01 -07:00
Michael Gottesman
572dbd44d0 [silgen] Add a small convenience constructor to Scope that takes a SILGenFunction/SILLocation.
This just automates the work of:

1. Grabbing the cleanup manager from the SGF.
2. Forming a CleanupLocation from a SILLocation.

Much of the time when one creates a scope, that is the information that one has
available. So lets make it... wait for it... convenient to construct a scope
with this data.
2017-03-22 12:39:34 -07:00
Michael Gottesman
2e75d56adf [silgen] Move CleanupCloner into SILGenBuilder.h so it is available as a utility to other parts of SILGen. 2017-03-22 12:28:50 -07:00
Joe Shajrawi
38e20af6dc Support for capture of a (im)mutable opaque value type 2017-03-21 17:18:52 -07:00
Joe Shajrawi
985af514ca Merge pull request #8212 from shajrawi/translateAndImplode_Any
Support translateAndImplodeIntoAny under opaque value mode
2017-03-20 16:22:04 -07:00
Joe Shajrawi
b0bf93eb43 Support translateAndImplodeIntoAny under opaque value mode 2017-03-20 15:39:57 -07:00
eeckstein
996b618875 Merge pull request #8204 from eeckstein/rename-namespace
rename namespace NewMangling -> Mangle
2017-03-20 11:51:56 -07:00
Michael Gottesman
89496492b2 [silgen] Fix a variable lifetime scoping issue.
rdar://31145255
2017-03-20 10:16:29 -07:00
Erik Eckstein
d70bfc5de2 rename namespace NewMangling -> Mangle 2017-03-20 10:09:30 -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
2e80412f5c [silgen] Move the creation of the allocation for foreignErrors when creating the result plan, so it is created early before we create any potential argument scopes.
rdar://30955427
2017-03-18 16:25:34 -07:00
Michael Gottesman
8723301205 [silgen] Move implementation of emitForeignErrorArgument into ResultPlan. 2017-03-18 16:06:58 -07:00
Michael Gottesman
a5747c4dbc [silgen] Create a ForiegnErrorInitiliazation plan as a first step towards eliminating special handling of foreign error parameters. 2017-03-18 15:57:46 -07:00
Michael Gottesman
f4f41337e3 [gardening] Change some CalleeTypeInfo '&' parameters to be 'const &' parameters. NFC. 2017-03-18 14:40:50 -07:00
Michael Gottesman
cf5540e53d Merge pull request #8180 from gottesmm/small_result_plan_refactor
[silgen] Move foreignErrorPreparation code in ResultPlanBuilder into a new buildTopLevelResult method.
2017-03-18 08:57:47 -07:00
swift-ci
eebcda9fd0 Merge pull request #8170 from gottesmm/scope_gardening 2017-03-17 19:27:48 -07:00
Michael Gottesman
53eab13be8 [silgen] Move foreignErrorPreparation code in ResultPlanBuilder into a new buildTopLevelResult method.
I am going to be cleaning up some of the code here so that I can move the
creation of a temporary needed for foreign error handling earlier and move the
handling of the error parameter in general into ResultPlanBuilder.

Otherwise, the temporary is cleaned up when I pop a soon to be committed patch
that creates scopes around call sites.

rdar://30955427
2017-03-17 19:03:33 -07:00
Michael Gottesman
e52eea2199 [silgen] When a formal evaluation scope is in an inout conversion scope, exit early when popping.
This fixes a logic error. Specifically: When we create a formal evaluation scope
in an inout conversion scope, we set it as if it was already popped. In the case
when we pop the scope by hand, this causes a "don't pop this scope twice" assert
to fire.
2017-03-17 19:00:28 -07:00
Michael Gottesman
fb3817ef29 [gardening] Canonicalize the header guard of Scope.h. NFC. 2017-03-17 18:45:55 -07:00
swift-ci
05fd943ff7 Merge pull request #8177 from shajrawi/tuple_to_any_reloaded 2017-03-17 17:38:04 -07:00
Joe Shajrawi
951f6d9e8e Refactor supporting tuple to any reabstraction: avoid alloc_box and support non-empty tuples 2017-03-17 16:48:57 -07:00
Erik Eckstein
1625345b90 Remove the old mangler.
NFC
2017-03-17 16:10:36 -07:00
Joe Shajrawi
435c789996 Merge pull request #8168 from shajrawi/tuple_to_any
Add support for reabstraction of () to Any under opaque value mode
2017-03-17 14:26:24 -07:00
Joe Shajrawi
7effefcaef Add support for reabstraction of () to Any under opaque value mode 2017-03-17 12:43:55 -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
Joe Shajrawi
46af3eb102 Merge pull request #8159 from shajrawi/indirect_translate
Add support for Translating a single opaque value with an indirect ParameterConvention under opaque value mode
2017-03-16 17:19:29 -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
9a87c07bc2 Add support for creating optionals to optionals during translation / reabstraction 2017-03-16 16:59:40 -07:00
Joe Shajrawi
f2cf6d26fa Add support for Translating a single opaque value with an indirect ParameterConvention under opaque value mode 2017-03-16 16:21:15 -07:00
Joe Shajrawi
8a7f9ba057 Support Optional Injection of Opaque value types 2017-03-16 11:32:05 -07:00
Joe Shajrawi
91186d48d9 Merge pull request #8127 from shajrawi/address_enum
Opaque values mode: address-only enum support
2017-03-15 17:18:48 -07:00
Michael Gottesman
16c67f5f48 [gardening] Change Cleanup.{h,cpp} to match SILGen ivar naming conventions. 2017-03-15 15:47:15 -07:00
Michael Gottesman
6c9eb3fead [gardening] Change Scope, LexicalScope, DebugScope, FullExpr to match ivar naming conventions in SILGen. 2017-03-15 15:47:15 -07:00
Joe Shajrawi
444b59ccbe Further enum support under opaque value mode: Builtins and address only types. Including opaque tuples as a return value. Adds library / stdlib unit tests. 2017-03-15 15:39:49 -07:00
Michael Gottesman
99a0058c11 [silgen] Add a doxygen doc above FormalEvaluationScope.
I added a general description, but more importantly, I added a note about a
quirk in our current implementation that existed before my current changes.

Specifically:

All formal access contain a pointer to a cleanup in the normal cleanup
stack. This is to ensure that when SILGen calls Cleanups.emitBranchAndCleanups
(and other special cleanup code along error edges), writebacks are properly
created. What is key to notice is that all of these cleanup emission types are
non-destructive. Contrast this with normal scope popping. In such a case, the
scope pop is destructive. This means that any pointers from the formal access to
the cleanup stack is now invalid.

rdar://30955427
2017-03-15 13:56:20 -07:00