Commit Graph

4896 Commits

Author SHA1 Message Date
Joe Groff
c771a7e71b SILGen: Substitute away opaque types. 2019-04-17 14:43:32 -07:00
Slava Pestov
5062a81e3d AST: Start returning SelfProtocolConformances from ModuleDecl::lookupConformance()
Fixes <rdar://problem/49241923>, <https://bugs.swift.org/browse/SR-10015>.
2019-04-16 23:02:50 -04:00
Slava Pestov
189a38dea4 Merge pull request #23985 from slavapestov/dynamic-self-thunks
SILGen: Fix function conversions involving DynamicSelfType
2019-04-15 07:42:48 -04:00
Slava Pestov
39a22f3d6a AST: Remove ParameterTypeFlags::Escaping
Escapingness is a property of the type of a value, not a property of a function
parameter. Having it as a separate parameter flag just meant one more piece of
state that could get out of sync and cause weird problems.

Instead, always look at the noescape bit in a function type as the canonical
source of truth.

This does mean that '@escaping' is now printed in a few diagnostics where it was
not printed before; we can investigate these as separate issues, but it is
correct to print it there because the function types in question are, in fact,
escaping.

Fixes <https://bugs.swift.org/browse/SR-10256>, <rdar://problem/49522774>.
2019-04-15 00:25:03 -04:00
Slava Pestov
4093d5e364 SILOptimizer: Fix isPartialApplyOfReabstractionThunk() for thunks capturing DynamicSelfType
If a thunk's type involves DynamicSelfType, a second value must be captured
of metatype type.
2019-04-14 19:48:27 -04:00
ravikandhadai
28efe03fab Merge pull request #23456 from ravikandhadai/constexpr-local-allocation
[const evaluator] Parameterize allocation of symbolic values in the constant interpreter.
2019-04-11 15:14:09 -07:00
Michael Gottesman
6552a0221e [ownership] Fix a corner case in the linear lifetime checker.
Specifically, if we had a value that was consumed in the same block that it was
produced in, we ignored use-after-frees in subsequent blocks. We did check for
use-after-frees in the same block though. The general case was handled
correctly, this was just an incorrect early exit.

On master, this only found one problem (namely the one fixed in:
14d39c0cf9). I do not expect this corner case to
have more impact after cherry-picking to 5.1.

rdar://49794321
2019-04-10 16:06:47 -07:00
Ravi Kandhadai
bb7363da2e [const evaluator] Parameterize allocation of symbolic values in the
constant interpreter. Based on this, change to a short-lived bump
allocator for storing symbolic values in the pass that checks #assert.
2019-04-09 13:56:21 -07:00
Erik Eckstein
bee1d94003 SIL: fix a crash when constructing a debug location in mandatory inlining
There was one case which was not handled and that's inlining of a compiler intrinsic.
In this case there is a different location type on the function call.

rdar://problem/49651421
2019-04-09 10:46:40 -07:00
Michael Gottesman
8feb1a1000 [sil] Replace some nstances of SILBuilder(...) with SILBuilderWithScope(...).
The main thing to notice about these changes is that I always picked the debug
scope associated with the location we were using. They should always be in
sync.
2019-04-05 12:32:31 -07:00
Slava Pestov
c023e0f35e Merge pull request #23734 from slavapestov/subscript-default-arguments
Subscript default arguments
2019-04-03 08:10:45 -04:00
Slava Pestov
6bb36b5c01 Sema: Subscript default arguments
Fixes <https://bugs.swift.org/browse/SR-6118>.
2019-04-02 20:37:01 -04:00
Slava Pestov
8292cbe3b3 AST: Remove 'default argument resilience expansion'
This was a Swift 3 mode holdover.
2019-04-02 20:37:01 -04:00
Michael Gottesman
f2d7dcaffd [ownership] Create a generic makeEndBorrowRange that can find end_borrow of {begin,load}_borrow.
We had a version of this specially for BeginBorrow. Makes sense to generalize
it.
2019-04-02 16:00:24 -07:00
Slava Pestov
1864f6f679 AST: Introduce ClassDecl::isSuperclassOf() 2019-03-26 18:42:59 -04:00
Slava Pestov
a2049972ca AST: Add ModuleDecl::isResilient()
This cleans up some code. I'm keeping the ResilienceStrategy enum around
though, in case we want to use it to version the ABI in the future.
2019-03-26 18:42:59 -04:00
Michael Gottesman
72a093da52 [semantic-arc-opts] Teach the guaranteed copy_value peephole how to handle instructions that can forward either owned or guaranteed ownership.
This fixes issues exposed by my turning off the Nominal Type RValue peephole. It
should give us some nice ARC wins as well potentially.
2019-03-21 13:50:41 -07:00
Arnold Schwaighofer
051a6abe49 Default argument generator functions are not dynamically replaceable for now 2019-03-18 11:20:10 -07:00
Michael Gottesman
0dfaa19f9f [ownership] Rename enable-sil-ownership => verify-sil-ownership.
I have been meaning to do this change for a minute, but kept on putting it off.
This describes what is actually happening and is a better name for the option.
2019-03-18 01:31:44 -07:00
Slava Pestov
8195d5e792 SIL: Tweak SILModuleConventions to use more appropriate type lowering APIs
SILType::isAddressOnly(SILModule) is going away.
2019-03-13 02:12:29 -04:00
Slava Pestov
c93ec45e62 SIL: Plumb resilience expansion through when lowering capture types
For now this is NFC.
2019-03-13 02:08:32 -04:00
swift-ci
14f530ed0b Merge pull request #23239 from gottesmm/pr-e583ec89d59c41a88ee3d6cc7ed0d1a1acdb0b91 2019-03-12 13:37:05 -07:00
Michael Gottesman
abe5fa931f [ownership] init_existential_ref is not forwarding: it should only traffic in owned values. 2019-03-12 11:14:15 -07:00
Slava Pestov
8915f96e3e SIL: Replace SILType::isTrivial(SILModule) with isTrivial(SILFunction) 2019-03-12 01:16:04 -04:00
Slava Pestov
c791c4a137 SIL: SILUndef must be aware of the resilience expansion
The ownership kind is Any for trivial types, or Owned otherwise, but
whether a type is trivial or not will soon depend on the resilience
expansion.

This means that a SILModule now uniques two SILUndefs per type instead
of one, and serialization uses two distinct sentinel IDs for this
purpose as well.

For now, the resilience expansion is not actually used here, so this
change is NFC, other than changing the module format.
2019-03-12 00:30:35 -04:00
Slava Pestov
18f2d9294e SIL: Go back to using minimal resilience expansion in SILType::isTrivial() for now
I want to replace more call sites of isTrivial(SILModule) with
isTrivial(SILFunction) before "flipping the switch".
2019-03-12 00:30:35 -04:00
Slava Pestov
d02d49fb73 SIL: Add an assertion 2019-03-12 00:30:35 -04:00
Andrew Trick
f4c7d4611f Change the algorithm for the AccessEnforcementDom pass.
This adds a mostly flow-insensitive analysis that runs before the
dominator-based transformations. The analysis is simple and efficient
because it only needs to track data flow of currently in-scope
accesses. The original dominator tree walk remains simple, but it now
checks the flow insensitive analysis information to determine general
correctness. This is now correct in the presence of all kinds of nested
static and dynamic nested accesses, call sites, coroutines, etc.

This is a better compromise than:

(a) disabling the pass and taking a major performance loss.

(b) converting the pass itself to full-fledged data flow driven
optimization, which would be more optimal because it could remove
accesses when nesting is involved, but would be much more expensive
and complicated, and there's no indication that it's useful.

The new approach is also simpler than adding more complexity to
independently handle to each of many issues:

- Nested reads followed by a modify without a false conflict.
- Reads nested within a function call without a false conflict.
- Conflicts nested within a function call without dropping enforcement.
- Accesses within a generalized accessor.
- Conservative treatment of invalid storage locations.
- Conservative treatment of unknown apply callee.
- General analysis invalidation.

Some of these issues also needed to be considered in the
LoopDominatingAccess sub-pass. Rather than fix that sub-pass, I just
integrated it into the main pass. This is a simplification, is more
efficient, and also handles nested loops without creating more
redundant accesses. It is also generalized to:
- hoist non-uniquely identified accesses.
- Avoid unnecessarily promoting accesses inside the loop.

With this approach we can remove the scary warnings and caveats in the
comments.

While doing this I also took the opportunity to eliminate quadratic
behavior, make the domtree walk non-recursive, and eliminate cutoff
thresholds.

Note that simple nested dynamic reads to identical storage could very
easily be removed via separate logic, but it does not fit with the
dominator-based algorithm. For example, during the analysis phase, we
could simply mark the "fully nested" read scopes, then convert them to
[static] right after the analysis, removing them from the result
map. I didn't do this because I don't know if it happens in practice.
2019-03-07 12:39:53 -08:00
Slava Pestov
708129381b Merge pull request #23126 from slavapestov/begin-removing-fixme-expansions
More resilience expansion plumbing for type lowering
2019-03-06 22:13:54 -05:00
swift-ci
42d6c425df Merge pull request #23118 from shajrawi/stack_promote_fix 2019-03-06 15:17:04 -08:00
Joe Shajrawi
7760aa56de [SILOptimizer] Fix a bug in edge-splitting wherein we did not create a new phi argument for blocks
Exposed in stack promotion / when doing stack nesting

rdar://problem/48603037
2019-03-06 14:10:03 -08:00
Slava Pestov
268f780a64 SIL: Type lowering propagates recursive properties in all cases
We were calling isResilent() to check if a type's layout contained a
type that was resilient in some resilience domain. This was used to
determine if we should re-lower the type when the desired resilience
expansion does not match the given resilence expansion.

However this bit was only getting set on address only types. This
means if a resilient type was lowered with maximal expansion first,
and this produced a non-address only type lowering, we would not
lower it again when minimal expansion was requested.

This can't be triggered with the existing tests, but upcoming changes
result in regressions from this.
2019-03-06 02:26:26 -05:00
Slava Pestov
0cd9eb21a6 SIL: Fix incorrect type lowering behavior with multiple resilience expansions
When calling getTypeLowering() for the first time with a new type that did not
appear in the cache under _any_ resilience expansion, we would incorrectly take
the unlowered type and treat it as a lowered type, incorrectly skipping the
computeLoweredRValueType() call.
2019-03-06 02:26:26 -05:00
Slava Pestov
a3d8d9c9c8 SIL: Add a new overload of SILType::isTrivial() taking a SILFunction 2019-03-06 02:26:26 -05:00
Slava Pestov
ced5548deb SIL: Add resilience expansion parameter to TypeConverter::countNumberOfFields() 2019-03-06 02:26:26 -05:00
Slava Pestov
980fb7c437 SIL: Remove default resilience expansion from isTypeABIAccessible() 2019-03-06 02:26:26 -05:00
Slava Pestov
d04c335478 SIL: Remove default arguments from resilience expansion parameters
Each call site will soon have to think about passing in the right expansion
instead of just assuming the default will be OK. But there are now only a
few call sites left, because most have been refactored to use convenience
APIs that pass in the right resilience expansion already.
2019-03-05 21:04:30 -05:00
Slava Pestov
b7ef5c7d42 SIL: Pass resilience expansion down to getTypeLowering() calls from lowerChildren()
NFC for now.
2019-03-05 21:00:01 -05:00
Slava Pestov
5847e163c1 SIL: Use better type lowering APIs in a couple of spots 2019-03-05 20:59:58 -05:00
Slava Pestov
8fbf3ab1a9 SIL: Reduce memory usage and small clean up for TypeLowering objects 2019-03-05 20:23:44 -05:00
Andrew Trick
eda86d03eb Merge pull request #22962 from atrick/remove-keypath-attr
Remove references to the unused "keypath.entry" attribute.
2019-03-05 13:15:05 -08:00
Slava Pestov
a4f560dc73 SIL: Use getLoweredRValueType() in various places 2019-03-04 20:33:19 -05:00
Slava Pestov
35e67db83a SIL: Rename some methods in TypeLowering.cpp 2019-03-04 20:33:19 -05:00
Michael Gottesman
e80c394e82 [cast-opt] Update optimization of unconditional checked cast to use SILDynamicCastInst. 2019-03-03 14:50:21 -08:00
Michael Gottesman
d4e910ce5c [cast-opt] Update optimizeUnconditionalCheckedCastAddrInst to use SILDynamicCastInst. 2019-03-03 13:42:04 -08:00
Slava Pestov
c84553cc33 SIL: Fix crash when enum is nested inside a fully-constrained extension
Fixes <https://bugs.swift.org/browse/SR-10023>.
2019-03-01 21:01:51 -05:00
Slava Pestov
7b0d10e2c7 Merge pull request #23004 from slavapestov/sil-resilience-expansion-plumbing
Continue plumbing resilience expansion through SIL type lowering
2019-03-01 07:32:01 -05:00
David Zarzycki
4dc48797d4 Merge pull request #23003 from davezarzycki/fix_always_loadable_ref_stor_types
[AST] Reference ownership macro fixes and cleanup
2019-03-01 06:41:39 -05:00
Slava Pestov
a9841e844f SIL: Add resilience expansion parameter to SILModule::isTypeABIAccessible() 2019-03-01 02:07:16 -05:00
Slava Pestov
903721cdc5 SIL: Remove SILType::getMetatypeInstanceType() 2019-03-01 02:07:16 -05:00