Commit Graph

2864 Commits

Author SHA1 Message Date
Michael Gottesman
5e278fdf67 [semantic-arc-opts] Create a new pass called semantic arc opts.
I am going to run it very early and use it to ensure that extra copies due to my
refactoring of SILGenPattern do not cause COW copies to be introduced.

For now, it does a very simple optimization, namely, it eliminates a copy_value,
with only a destroy_value user on a guaranteed parameter.

It is now disabled behind a flag.
2017-04-05 16:16:57 -07:00
Michael Gottesman
a0f903eaf1 [arc] Add a statistic to guaranteed-arc-opts that prints out the number of instructions removed. 2017-04-05 16:16:57 -07:00
Michael Gottesman
bd225f9fc4 [capture-promotion] Update capture-promotion for semantic-sil.
rdar://29870610
2017-04-02 11:44:14 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
Slava Pestov
1f260281b6 Merge pull request #8366 from brentdax/di-diagnosis-crash
[SIL][DI] Don’t crash when emitting closure errors
2017-03-28 23:58:50 -07:00
Andrew Trick
f5f5a9ac2b AddressLowering: Fix indirect concrete existential arguments. 2017-03-28 13:46:28 -07:00
Brent Royal-Gordon
c6f62b1fae [SIL][DI] Fix diagnostic bug more cleanly
No reason to call getCalledValue() twice.
2017-03-27 18:37:17 -07:00
Brent Royal-Gordon
bf1791b492 [SIL][DI] Don’t crash when emitting closure errors
When the DI lifetime checker diagnoses an `inout`-related error, it tries to examine the function you’re calling to emit its name in the error message. Unfortunately, it implicitly assumes that `ApplyExpr::getCalledValue()` will find a `ValueDecl` to return; if the `ApplyExpr` directly calls a closure, it won’t, and so `handleInOutUse` will try to `dyn_cast` a `nullptr`. This change adds a check to avoid that.
2017-03-27 01:01:08 -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
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
Erik Eckstein
a0079ba5be SIL optimizations: Implement the new API for analysis invalidation.
There are now separate functions for function addition and deletion instead of InvalidationKind::Function.
Also, there is a new function for witness/vtable invalidations.

rdar://problem/29311657
2017-03-14 13:00:54 -07:00
John McCall
3c5de5fa0a Preserve type canonicality better in several places and
idiomatize some uses of SILType::getSwiftRValueType().
2017-03-14 14:59:43 -04:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Xi Ge
b4cf37bf7d Sema: several improvements on missing switch cases diagnostics. (#8026)
1. Make sure the actions taken by fixits are reflected in diagnostics messages.
2. Issue missing cases diagnostics at the start of the switch statement instead of its end.
3. Use <#code#> instead of <#Code#> in the stub.
2017-03-10 19:32:37 -08:00
Bob Wilson
9546da3939 Add a missing #include to fix the master-next build.
The AddressLowering.cpp file uses LLVM's CommandLine.h but was not
explicitly including that header. It was implicitly pulled in via other
headers, but LLVM r296846 changed "llvm/ProfileData/InstrProf.h" to
stop including "llvm/IR/Metadata.h" and broke the chain that led to
CommandLine.h.
2017-03-08 16:04:57 -08:00
Andrew Trick
c2b433bad6 Overhaul the AddressLowering pass to optimize projections and handle more cases.
This adds the underpinning for optimizing storage projections. When subobjects are composed in aggregate they no longer require individual copies.

Optimize copy->store sequences.

Added support for enums and existentials.

Added a mini design doc file comment.

Added -optimize-opaque-address-lowering unit tests.
2017-03-07 10:58:09 -08:00
practicalswift
17b6160115 [gardening] Remove unused method replaceValue(..., ...) 2017-03-02 16:19:57 +01:00
Andrew Trick
38d44c2164 AddressLowering: rewrite the call-site lowering logic.
This pass now canonicalizes results before lowering and handles all combinations
of direct and indirect multiple return values. The logic is much less ad-hoc and
more robust.

try_apply still isn't handled, but should be much easier now.

Add visitLoadInst, visitStoreInst, visitDebugValueInst, etc.
2017-02-26 13:52:50 -08:00
Xi Ge
daac020c61 Sema: Reject empty switch statements during type checking so that we can issue fixits to fill the unhandled switch cases. (#7766) 2017-02-25 08:01:13 -08:00
Xi Ge
d12d3c18ca FixCode: add a fixit to insert the missing enum element cases in switch statements. (#7759)
This doesn't work on entirely empty switch block because we reject such statement during parsing.
2017-02-24 18:09:30 -08:00
practicalswift
33a5601ad1 [gardening] Fix typos 2017-02-23 22:46:40 +01:00
Michael Gottesman
92cb1f3014 [di] Handle escapes from the new upcast+borrow+downcast pattern.
As a bonus, now DI properly errors on:

super.init(self)
2017-02-23 08:48:58 -08:00
Michael Gottesman
53b78a6a3c [gardening] Rename variable from inst => User to fit its... use. NFC. 2017-02-23 08:48:58 -08:00
Michael Gottesman
64c709cfe0 [gardening] Refactor load handling code from collectDelegatingClassInitSelfUses into its own function.
The new function is called collectDelegatingClassInitSelfLoadUses. This is just
a classical loop function extraction refactor.
2017-02-23 08:48:58 -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
81dcdba0a9 Revert "Make sure we always de-serialize transparent functions."
This reverts commit 821b365054.

It caused a bunch of execution time regressions.
2017-02-18 13:36:34 -08:00
Joe Groff
6752266798 Merge pull request #7534 from jckarter/covariant-self-init-delegation
Sema: Type-check initializer delegation as a covariant expression.
2017-02-17 17:32:03 -08:00
Erik Eckstein
821b365054 Make sure we always de-serialize transparent functions.
We didn’t do that if an optimization looked up a witness table.

Fixes rdar://problem/30544344

I couldn’t come up with an isolated test case, but this should be covered with our existing tests.
(The problem shows up when inlining of generics are enabled)
2017-02-16 17:04:58 -08:00
Joe Groff
eae044c07d Sema: Type-check initializer delegation as a covariant expression.
If a convenience initializer in a subclass delegated to an inherited initializer from its base, we would end up type-checking the reference to the base class constructor as returning the base type, leading to type mismatches in the result AST and downstream crashes. We can wrap up the synthesized OtherConstructorRefExpr in a CovariantFunctionConversionExpr, which will trick the type checker into propagating the covariant result that gets rebound to `self` on return, avoiding this problem. (For now, I'm avoiding making the constructor decl formally have a Self return type, since that exposes a bunch of downstream breakage in code paths that only expect FuncDecls to be covariant, and also affects the mangling of constructors, causing a bunch of test case thrash we really don't want to inflict on the 3.1 branch.)
2017-02-16 13:19:11 -08:00
Andrew Trick
4256112150 AddressLowering: fix handling of result tuples. 2017-02-16 11:04:42 -08:00
practicalswift
65b0219f7b [gardening] Fix typos 2017-02-14 20:04:08 +01:00
practicalswift
1c64f04997 [gardening] Fix header inconsistencies 2017-02-14 20:04:05 +01:00
practicalswift
b717bdc0f8 [gardening] Remove unused methods 2017-02-14 09:55:16 +01:00
Andrew Trick
10b118dfa9 [Lowering] Make the AddressLowering pass functional. 2017-02-13 17:10:02 -08:00
Andrew Trick
855918c620 [Lowering] Add an AddressLowering pass. 2017-02-13 17:10:02 -08: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
284a028e61 [sil] Add a new API SILModule::isNoReturnBuiltinOrIntrinsic(Identifier).
This is just refactoring code from DiagnoseUnreachable into a centralized
location.

rdar://29791263
2017-02-09 11:29:41 -08:00
practicalswift
e2f8af7762 [gardening] Fix clang-tidy warnings 2017-02-04 09:23:10 +01:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
practicalswift
a9d6d8938c [gardening] Fix recently introduced typos 2017-01-22 20:40:45 +01:00
swift-ci
6acd2610a7 Merge pull request #6716 from gottesmm/eliminate_deallocating_convention 2017-01-10 20:02:51 -08:00
Michael Gottesman
d944930591 Remove the deallocating convention.
This is dead code and can be re-added if it is needed. Right now though there
really isnt a ValueOwnershipKind that corresponds to deallocating and I do not
want to add a new ValueOwnershipKind for dead code.
2017-01-10 17:32:17 -08:00
Erik Eckstein
f8034ac7bf PredictableMemOpt: be more conservative about address_to_pointer
Handling address_to_pointer as a plain inout missed some mutations and lead to miscompiles.
We now treat address_to_pointer as escaping address.

Fixes SR-3554
2017-01-10 09:25:51 -08:00
practicalswift
f6b8bc2a5d [gardening] we’d → we'd 2017-01-07 21:07:14 +01:00
practicalswift
a2928fca2d [gardening] can’t → can't 2017-01-07 21:06:15 +01:00
Joe Shajrawi
e2bb8c177d Merge pull request #6635 from shajrawi/thick_func_fix_ref_counts
Mandatory Inlining: Fix a bug wherein we added thick function’s reference count fix-up code at the wrong location
2017-01-06 23:27:54 -08:00
Joe Shajrawi
4ea522bef6 Mandatory Inlining: Fix a bug wherein we added thick function’s reference count fix-up code at the wrong location 2017-01-06 18:41:01 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
786d87b9bb DI: Operate on substituted field types
When adding a designated initializer to a nominal type in another
module, we would call getType() on deserialized VarDecls, which
is not allowed.

Instead, it is more correct to use SILTypes throughout and call
SILType::getFieldType() to get a substituted field type.

Fixes <https://bugs.swift.org/browse/SR-3545>.
2017-01-04 21:30:21 -08:00