Commit Graph

3321 Commits

Author SHA1 Message Date
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
123fee960e Merge pull request #23228 from slavapestov/type-lowering-is-trivial
Replace SILType::isTrivial(SILModule) with isTrivial(SILFunction)
2019-03-12 13:44:10 -04: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
Ravi Kandhadai
249b11a018 [SIL Diagnostics] Improve diagnostics for yield-once coroutines
when the coroutines yield in some paths but not in all paths.

<rdar://48184430>
2019-03-11 18:15:35 -07: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
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
bb97dbf243 SIL: Add asserts to isFormally{Passed,Returned}Indirectly()
We want to be sure to only use types lowerered with
ResilienceExpansion::Minimal when computing function
signatures.
2019-03-05 20:23:44 -05:00
Slava Pestov
8fbf3ab1a9 SIL: Reduce memory usage and small clean up for TypeLowering objects 2019-03-05 20:23:44 -05:00
Michael Gottesman
fd085504f6 [sil-builder] Teach SavedInsertionPointRAII how to handle builders inserting at the end of blocks.
I also fixed some variable naming issues. NFC.
2019-03-04 22:54:13 -08:00
Michael Gottesman
d0901dea79 Merge pull request #23068 from gottesmm/pr-2f8945ab6e6f259236689efe97127e060c1850f1
[cast-opt] Change optimize{Swift,ObjC}to{ObjC,Swift} to use SILDynami…
2019-03-04 21:50:48 -08:00
Slava Pestov
a4f560dc73 SIL: Use getLoweredRValueType() in various places 2019-03-04 20:33:19 -05:00
Slava Pestov
fe094c6254 SIL: Add TypeLowering::getLoweredRValueType()
In various places we want to get a lowered type, but ignoring the
SIL type category (object or address). Add a pair of utility methods
for this purpose.
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
ee02174f71 [cast-opt] Change optimize{Swift,ObjC}to{ObjC,Swift} to use SILDynamicCastInst.
I also debrided dead variables that resulted from eliminating the trampoline
argument code in optimizeBridgedCasts().
2019-03-04 10:48:13 -08:00
Michael Gottesman
e833d11720 [cast-opt] Change simplifyCheckedCast{,Value}BranchInst to use SILDynamicCastInst.
This is the last change needed to simplify the API of optimizeBridgedCasts to
take SILDynamicCastInst.
2019-03-03 16:33:11 -08:00
Michael Gottesman
807b187302 [cast-opt] Update simplifyCheckedCastAddrBranchInst to use SILDynamicCastInst.
This is another step towards eliminating the many argument call to
optimizeBridgedCasts.
2019-03-03 16:33:11 -08:00
Michael Gottesman
aaf464485b [cast-opt] Change CheckedCastBranch metatype opts to use SILDynamicCastInst. 2019-03-03 14:50:21 -08: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
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
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
Slava Pestov
2970334e80 SIL: Remove SILType::getReferentType() 2019-03-01 02:07:16 -05:00
Slava Pestov
d1cf8c9cf6 SIL: Add type lowering APIs to SILFunction
For now these just forward to methods on the module's TypeLowering,
but soon they will use the SILFunction's resilience expansion.
2019-02-28 23:12:08 -05:00
Slava Pestov
c970caedd5 SIL: Optimization remarks can take SILType by value
No need to pass a pointer to SILType; it is a pointer-sized value itself.
2019-02-28 21:28:16 -05:00
David Zarzycki
b6b5ea5faa [AST] Reference ownership macro fixes and cleanup
This simplifies some boilerplate, and in particular, some SIL verifier
logic; and fixes a couple bugs related to always loadable reference
storage types.
2019-02-28 20:52:19 -05:00
Michael Gottesman
98ed241ce5 [cast-optimizer] Add an "ApplySite" like data structure "SILDynamicCastInst" that abstracts over all dynamic cast instructions.
I am going to use this to refactor a bunch of the goop in the cast optimizer. At
a high level, we are really just performing a giant switch over the casts to
grab different state. We then take that state and we pass it into the bridge
cast optimizer.

To make such code more compact/easier to understand, I am adding in this commit
a type erased dynamic cast instruction type called "SILDynamicCastInst". In
subsequent commits, I wire up each of the individual instructions to it one at a
time.

As an additional advantage it will enable us to take advantage of covered
switches when ever in the future we introduce new casts.
2019-02-26 13:23:54 -08:00
Joe Groff
bb67cf815c Merge pull request #21355 from technicated/tuple-keypaths-2
Tuple KeyPaths
2019-02-25 12:56:05 -08:00
Arnold Schwaighofer
8d9b9f328b SILGen: Fix the logic of dynamic replacements for class constructors
To correctly call designated super class initializers the designated
intializer (and not the allocator) is dynamically replaceable.
Convenience allocators are dynamically replaceable as before.
2019-02-22 10:15:06 -08:00
Slava Pestov
f6cb10b9fa SIL: Plumb ResilienceExpansion through TypeLowering more carefully
The basic theory here is as follows:

- The resilience expansion never changes the lowered type, only the
  SIL type category (object or address). This means that function
  types always pass resilient values indirectly regardless of
  expansion, etc.

- The getTypeLowering() methods all take an optional 'forExpansion'
  parameter. Soon, these will become non-optional and I'll audit all
  call sites to pass the right expansion; for convenience, the
  entry points on SILFunction will pass the right expansion.

Places I need to revisit and pass the right expansion in are marked
as 'FIXME: Expansion'.

For now, this just fixes a SILCombiner bug. After some more plumbing
this will enable SILGen to produce better code.

Progress on <rdar://problem/24057844>,
<https://bugs.swift.org/browse/SR-261>.
2019-02-22 02:34:36 -05:00
Slava Pestov
4d5a691090 SIL: Remove some obsolete mentions of 'uncurry level' from TypeLowering 2019-02-22 02:34:36 -05:00
Slava Pestov
a1b75cac54 SIL: Remove unused getSemanticType{,Lowering}() 2019-02-22 02:34:36 -05:00
Slava Pestov
5b3056cc28 SILBuilder: Fix incorrect logic in isLoadableOrOpaque() 2019-02-22 02:34:36 -05:00
Michael Gottesman
6ddc8589e8 [ownership] Treat mark_dependence as forwarding in its first parameter.
Previously, we only did this for the first parameter if it was converting from
escape to no-escape. We want to /always/ do this.
2019-02-20 21:44:18 -08:00
Slava Pestov
69d1cafd1c AST: Add AvailabilityContext parameter to Decl::isWeakImported()
For now, it's not used, but we do try to pass the right value down from
our various call sites.

Progress on <rdar://problem/46674512>.
2019-02-19 18:58:44 -05:00
Michael Gottesman
42d184995e [ownership] Update emitIndirectConditionalCastWithScalar for ownership.
This comes up because when we perform mandatory inlining, we perform the
transform as we inline. So the tests for this are in mandatory_inlining
naturally.
2019-02-18 16:16:44 -08:00
technicated
a0ed29d326 🎄 Improved tuple key path support in SIL ~ Merry Christmas 🎄
Using an anonymous union in KeyPathPatternComponent instead of the weird void * in SetterAndIdKind
Added TupleElement kind to KeyPathComponentKindEncoding
Written basic SIL keypath serialization tests
Deleted or edited some old Swift-level tuple key path tests
2019-02-18 10:15:58 +01:00
Andrea Tomarelli
17cf1360c4 Very minimal POC of tuple KP feature 2019-02-18 09:04:43 +01:00
Andrea Tomarelli
aab138dcea Barebone implementation of TupleElement in SIL 2019-02-18 09:04:42 +01:00
swift-ci
d7d1a2ba78 Merge pull request #21827 from Azoy/sr-9466 2019-02-13 20:37:14 -08:00
Michael Gottesman
0cdc2d6a35 [sil] Teach constant folding how to handle destructures and multiple value instructions.
I also ported the constant_propagation.sil tests over for ownership and updated
a few parts of the cast optimizer so that those tests pass with and without
ownership. I purposely only updated the parts of the cast optimizer that crashed
with ownership in the relevant test so that I can add new sil code coverage for
those uncovered code paths.
2019-02-12 20:15:02 -08:00
Azoy
5af2663c57 Textualize assign init kind
Rename [assign] to [reassign]

fix some tests

AssignOwnershipQualifier

formatting

moar formatting
2019-02-12 20:16:25 -06:00
Azoy
397b96c917 [SILOptimizer] Don't lower AssignInst in DI 2019-02-12 18:10:17 -06:00