Commit Graph

20516 Commits

Author SHA1 Message Date
Xi Ge
139d898658 Parser: properly handle token receiver in back tracking scope 2019-03-07 23:45:34 -08:00
Andrew Trick
404cf73ca6 Merge pull request #23111 from atrick/dominating-access-algo
Change the algorithm for the AccessEnforcementDom pass.
2019-03-07 16:51:18 -08:00
Nate Cook
968783f66c Revise error for incorrect subscript parameters. (#22713)
* Revise error for incorrect subscript parameters.

We use subscripts for more than just indexes in Swift these days, so
the error message needs to be a bit more general.

* Use the term 'argument' instead of 'value'
2019-03-07 18:10:01 -06:00
Mike Ash
c4434fe2a9 Merge pull request #23064 from mikeash/dynamically-select-is-swift-bit
[Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
2019-03-07 16:48:15 -05: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
Harlan Haskins
366bbf48b9 [ParseableInterface] Add ‘forwarding modules’
A ‘forwarding module’ is a YAML file that’s meant to stand in for a .swiftmodule file and provide an up-to-date description of its dependencies, always using modification times.

When a ‘prebuilt module’ is first loaded, we verify that it’s up-to-date by hashing all of its dependencies. Since this is orders of magnitude slower than reading mtimes, we’ll install a `forwarding module` containing the mtimes of the now-validated dependencies.
2019-03-07 11:36:15 -08:00
eeckstein
ae189efcfb Merge pull request #23131 from eeckstein/runtime-malloc-removal
Avoid malloc allocations in the runtime
2019-03-07 10:13:43 -08:00
Mike Ash
fbe990481b [Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
Recent Swift uses 2 as the is-Swift bit when running on newer versions, and 1 on older versions. Since it's difficult or impossible to know what we'll be running on at build time, make the selection at runtime.
2019-03-07 10:12:27 -05:00
Slava Pestov
2e2c12f9cb Merge pull request #22822 from theblixguy/fix/SR-6022
[Typechecker] Warn when casting a function type to an existential or archetype type
2019-03-06 22:16:39 -05: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
Erik Eckstein
d7fd45d74a Remangler: Use a bump-pointer allocated string instead of std::string
Done by replacing DemanglerPrinter with a bump-pointer allocated CharVector buffer.
This avoids malloc calls.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08:00
Erik Eckstein
3bd7f027f8 Runtime: use SmallVector instead of std::vector to avoid memory allocations in most cases.
This dramatically reduces the number of needed malloc calls.
Unfortunately I had to add the implementation of SmallVectorBase::grow_pod to the runtime, as we don't link LLVM. This is a bad hack, but better than re-inventing a new SmallVector implementation.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08:00
Erik Eckstein
de51f8cac6 Remangler: use the bump pointer allocator instead of std::vector for internal substitution data structures
This avoids mallocs in the runtime.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08:00
Gwen Mittertreiner
8a6d28c7d0 Fix the Rest of the Windows Driver Tests 2019-03-06 14:23:49 -08:00
David Zarzycki
b6517c50a1 Merge pull request #23014 from davezarzycki/faster_simpler_nominaltype_get
[AST] NFC: Improve non-generic nominal type memory efficiency
2019-03-06 15:35:19 -05:00
David Zarzycki
0ece008cc4 Merge pull request #23109 from davezarzycki/revert_gsb_opt
Revert gsb opt
2019-03-06 11:34:15 -05:00
David Zarzycki
236a0dcfe2 Revert "[GSB] NFC: Precompute or cache DependentMemberType when possible"
This reverts commit 8876c9e78f, which has
a memory leak.
2019-03-06 10:01:37 -05: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
Suyash Srijan
a2460b8892 Merge branch 'master' into fix/SR-6022 2019-03-05 20:57:31 +00:00
Harlan Haskins
67a447f15f [Frontend] Add flag to use hash-based dependencies
Since prebuilt modules are going to use hashes for their dependencies, we need a flag to turn that behavior on. By default, we use modification times.
2019-03-05 11:46:21 -08:00
Harlan Haskins
7d71579950 [Serialization] Allow either hash-based or mtime-based deps
Add a bit to the module to determine whether the dependency’s stored bit pattern is a hash or an mtime.

Prebuilt modules store a hash of their dependencies because we can’t be sure their dependencies will have the same modtime as when they were built.
2019-03-05 11:46:21 -08:00
Arnold Schwaighofer
8732287cab Merge pull request #23074 from aschwaighofer/private_import_internal_storage_private_accessor
Serialization: Also serialize the filename for internal storage decls with private accessors
2019-03-05 10:24:19 -08:00
Nate Cook
5bd2b3e639 Use the term 'argument' instead of 'value' 2019-03-05 08:31:42 -06: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
Arnold Schwaighofer
1719f0cdf1 Serialization: Also serialize the filename for internal storage decls with private accessors
If a value decl is internal hasTestableOrPrivateImport will succeed (or
fail) without looking at the filename. However this breaks when we query
an internal storage decl with private formal access for a private
setter: the query would fail because no filename was serialized for the
decl (we only serialize filenames for private decls). So in the special
case of a internal storage with private accessor also serialize the
filename.

rdar://48516545
2019-03-04 13:12:39 -08: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
David Zarzycki
c13c752045 Merge pull request #23025 from davezarzycki/local_DependentMemberType_caching
[GSB] NFC: Improve performance with local DependentMemberType caching
2019-03-04 06:58:07 -05:00
Michael Gottesman
fa4c38bf0c [cast-opt] Now that all users of optimizeBridgedCasts use the SILDynamicCastInst entrypoint, delete the old entrypoint and inline its body into the new entrypoint. 2019-03-03 16:33:12 -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
David Zarzycki
8876c9e78f [GSB] NFC: Precompute or cache DependentMemberType when possible
Calling DependentMemberType::get() repeatedly pollutes the processor
caches because the global hash table can be quite large. With this
change, we either precompute DependentMemberTypes or cache them on
demand. This change makes the release/no-assert build of
Swift.swiftmodule 4.1% faster.
2019-03-02 10:14:49 -05:00
adrian-prantl
173318262e Merge pull request #23009 from adrian-prantl/rename
Rename swift::Demangle::archetypeName() to swift::Demangle::genericPa…
2019-03-01 20:06:04 -08:00
Saleem Abdulrasool
56a73c9b97 Merge pull request #22982 from compnerd/prepare-for-extraction
Reflection: add PE/COFF magic checking for inspection
2019-03-01 17:58:41 -08:00
Slava Pestov
2813912c48 Merge pull request #23010 from pschuh/s-5
FloatLiteralExpr now is lowered directly into SIL.
2019-03-01 17:32:23 -05:00
Parker Schuh
5160da6a2e FloatLiteralExpr now is lowered directly into SIL.
For context, String, Nil, Bool, and Int already behave this way.

Note: Swift can compile against 80 or 64 bit floats as the builtin
literal type. Thus, it was necessary to capture this bit somehow in the
FloatLiteralExpr. This was done as another Type field capturing this
info.
2019-03-01 09:01:30 -08:00
Adrian Prantl
4b1532cddc Rename swift::Demangle::archetypeName() to swift::Demangle::genericParameterName(). 2019-03-01 08:02:28 -08:00