Commit Graph

1051 Commits

Author SHA1 Message Date
Roman Levenstein
f1362a3a14 [generic-specializer] Code clean-ups 2017-04-20 08:16:24 -07:00
Roman Levenstein
686b83b6cb [generic-specializer] Improve comments 2017-04-20 08:16:24 -07:00
Roman Levenstein
0ba522f189 [generic-specializer] Fix comments 2017-04-20 08:16:24 -07:00
Roman Levenstein
f28e28c0a8 [generic-specializer] Big re-factoring of the partial specialization implementation
- Introduced a new helper class FunctionSignaturePartialSpecializer which provides most of the functionality required for producing a specialized generic signature based on the provided substitutions or requirements. The class consists of many small functions, which should make it easier to understand the code.

- Added a full support for partial specialization of generic parameters with generic substitutions (use flag `-Xllvm -sil-partial-specialization-with-generic-substitutions` to enable it)

- Removed the simpler version of the partial specializer which could partially specialize only generic parameters with non-generic substitutions. It is not needed anymore, because we can handle any substations now when performing the partial specialization.

- The functionality used by the EagerSpecializer to implement the partial specializations required by @_specialize is expressed in terms of FunctionSignaturePartialSpecializer as well. The code implementing it is much smaller now.

Partial specialization of generic parameters with generic substitutions is fully functional, but it is disabled by default, because it needs some tweaks when it comes to compile times and size of produced code. These issues will be addressed in the subsequent commits.
2017-04-20 08:16:24 -07:00
Roman Levenstein
ce8d986999 [generic-specializer] Rename OriginalF into Callee 2017-04-20 08:16:24 -07:00
Roman Levenstein
76b6647414 [generic-specializer] Fix bugs in the implementation of partial specialization for partial_apply
There were two bugs:
- A proper GenericContextScope was not set for type lowering
- Interface types were not mapped to contextual types before using them in SIL instructions
2017-04-20 08:16:24 -07:00
Roman Levenstein
3d24657b3b [generic-specializer] Fix the condition for bailing on generic substitutions
Also provide more descriptive debug information in this case.
2017-04-20 08:16:24 -07:00
Roman Levenstein
34e366a150 [generic-specializer] Improve debug prints 2017-04-20 08:16:24 -07:00
Roman Levenstein
c23b423bae [generic-specializer] Move checkSpecializationRequirements around 2017-04-20 08:16:24 -07:00
Roman Levenstein
3a9edac4fb [generic-specializer] Remove workarounds
GSB now checks internally that generic signatures it produces are idempotent.
2017-04-20 08:16:24 -07:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
practicalswift
7eb7d5b109 [gardening] Fix 100 typos. 2017-04-18 17:01:42 +02:00
Roman Levenstein
2c87f08e3f [sil-generic-specializer] Don’t build a new generic signature in case of a full specialization. NFC.
In case of a full specialization, the specialized function does not have a generic signature. Therefore there is no need to build it.
This speeds up the compilation by avoiding doing a useless work.
2017-04-14 19:45:04 -07:00
Roman Levenstein
998748e964 [sil-generic-specializer] Print more debug info when asserting 2017-04-14 19:42:04 -07:00
Doug Gregor
faa0401598 [GSB] Allow requirement inference for synthesized requirements. 2017-04-14 17:19:02 -07:00
Doug Gregor
9dde2d7527 [SIL generics utils] Drastically simplify remapRequirements().
remapRequirements() was doing a whole lot of substitution work by
itself that the GenericSignatureBuilder is already capable of
doing. Use the GSB's functionality instead.
2017-04-14 17:19:02 -07:00
Huon Wilson
b59f95418c [SIL] Extract ClassVisibility from SILFunction to SubclassScope in SILLinkage. 2017-04-13 14:17:29 -07:00
Doug Gregor
10ebdcd50a [GSB] Broaden the Boolean result of "add a constraint" operations.
Rather than true (an error occurred) or false (the constraint was
resolved), introduce ConstraintResult to better model what
happened. NFC for now, but the intent here is to report unresolved
constraints through this mechanism.
2017-04-11 14:15:45 -07:00
Arnold Schwaighofer
601b1e6bd4 SILOptimizer: Add a zero cost for inlining const_string_literal instructions 2017-04-11 10:11:17 -07:00
Roman Levenstein
7eafb4b75e [sil-devirtualizer] Fix devirtualization of partial_apply on generic witness_methods
Properly cast the result of a devirtualized partial_apply, because this may be required in case of classes implementing protocols. More specifically, it came up when there is a derived class of a class implementing an initializer required by the protocol.

Fixes rdar://31459426 (SR-4501) and rdar://31479426 (SR-3476)
2017-04-10 13:45:56 -07:00
Joe Groff
85ad6b355e Merge branch 'master' into keypaths 2017-04-06 18:02:07 -07:00
Erik Eckstein
1702b831e4 StackNesting: fix use-after-free problem.
rdar://problem/31470661
2017-04-06 08:40:31 -07:00
Erik Eckstein
a43a844838 StackNesting: use the right debug locations for inserted deallocation instructions
Fixes a crash because we used a return-location for a deallocation instruction.

rdar://problem/31458587
rdar://problem/31458617
2017-04-05 18:05:39 -07:00
swift-ci
024033cf97 Merge pull request #8533 from adrian-prantl/28311051 2017-04-05 11:52:50 -07:00
Saleem Abdulrasool
c5c5f4e417 SILOptimizier: add missing include (NFC) 2017-04-05 10:41:00 -07:00
Adrian Prantl
5ea2d13f5e Improve the performance of IRGenDebugInfo
This commit changes how inline information is stored in SILDebugScope
from a tree to a linear chain of inlined call sites (similar to what
LLVM is using). This makes creating inlined SILDebugScopes slightly
more expensive, but makes lowering SILDebugScopes into LLVM metadata
much faster because entire inlined-at chains can now be cached. This
means that SIL is no longer preserve the inlining history (i.e., ((a
was inlined into b) was inlined into c) is represented the same as (a
was inlined into (b was inlined into c)), but this information was not
used by anyone.

On my late 2012 i7 iMac, this saves about 4 seconds when compiling the
RelWithDebInfo x86_64 swift standard library — or 40% of IRGen time.

rdar://problem/28311051
2017-04-05 08:33:55 -07:00
Roman Levenstein
4aaa855da1 Merge pull request #8489 from swiftix/wip-func-sig-opt-generic-functions-3
[sil-function-signature-opt] Support FSO for generic functions
2017-04-04 17:47:22 -07:00
Roman Levenstein
64813b7b4f [sil-function-signature-opt] Support FSO for generic functions
In particular, support the following optimizations:
- owned-to-guaranteed
- dead argument elimination

Argument explosion is disabled for generics at the moment as it usually leads to a slower code.
2017-04-04 12:33:17 -07:00
Joe Groff
af34a326c4 SIL: Inlining cost for KeyPathInst. 2017-04-04 11:44:21 -07:00
Erik Eckstein
805960b0ac ValueLifetimeAnalysis: fix the lifetime computation in case the value definition is in a single-block loop.
This caused DeadObjectElimination to generate a memory leak in case a dead array is in a single-block loop.
rdar://problem/31420889
2017-04-04 10:43:53 -07:00
Slava Pestov
c78e561af9 SILOptimizer: Simplify ReabstractionInfo a bit 2017-04-03 20:41:31 -07:00
practicalswift
288cb35b36 Merge pull request #8495 from practicalswift/gardening-20170402
[gardening] Remove unused variables and methods. Fix \t. Use isa<T>(). Typos.
2017-04-03 09:58:44 +02:00
Michael Gottesman
bd225f9fc4 [capture-promotion] Update capture-promotion for semantic-sil.
rdar://29870610
2017-04-02 11:44:14 -07:00
practicalswift
00ba5dc248 [gardening] Fix typos 2017-04-02 16:23:45 +02:00
Slava Pestov
289428ca55 SILOptimizer: Always use Shared linkage for specializations of serialized things
With -sil-serialize-all, we might deserialize and specialize
a private function from multiple TUs which are then linked
together.

Since private symbols have unique mangling, this is fine.

It's hard to make a test for this since it only happens with
-sil-serialize-all, which I'd like to kill soon anyway.
2017-03-31 20:26:26 -07:00
Erik Eckstein
c41de405c4 fix a wrong assert in StackNesting 2017-03-30 09:33:00 -07:00
Slava Pestov
695a8d2065 Merge pull request #8407 from slavapestov/rename-everything-without-asking-permission
SIL: Terminology change: [fragile] => [serialized]
2017-03-29 20:08:15 -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
Erik Eckstein
607318e0c7 Utility for correcting the nesting of stack allocation/deallocation instructions in SIL.
This is useful for optimizations (like AllocBoxToStack) which create (de-)alloc_stack instructions.
They can just insert the new instructions anywhere without worrying about nesting and correct the nesting afterwards.
2017-03-29 15:41:04 -07:00
Roman Levenstein
a05cc2c8b5 Enable simple version of partial specialization by default
The simple version does not allow for partial specialization of generic parameters whose replacement types in a substitution are generic.
2017-03-28 15:56:40 -07:00
John McCall
57ecaa7fae Add begin_access and end_access instructions.
NFC because we're not actually emitting them.
2017-03-26 04:37:05 -04:00
Roman Levenstein
8082e820c9 [sil-optimizer] Make compile time concatenation of constant strings work again
This guaranteed optimization got lost when a + operator for Strings was made a static method on type String.

Fixes SR-4348
2017-03-24 15:55:50 -07:00
Saleem Abdulrasool
092650cad6 Merge pull request #8276 from compnerd/vars
SILOptimizer: remove unused variable
2017-03-23 19:16:37 -07:00
Saleem Abdulrasool
8669365feb SILOptimizer: remove unused variable
swift/lib/SILOptimizer/Utils/Generics.cpp:1429:9: warning: unused variable 'SM' [-Wunused-variable]
2017-03-22 11:46:27 -07:00
Saleem Abdulrasool
ccae6e81f8 SILOptimizer: avoid "deprecation" warnings
The `dump` method is meant for interactive use in debuggers only.  Use
the parameter form to avoid the warning.
2017-03-22 11:43:50 -07:00
Roman Levenstein
fae0628a97 Implement partial specialization which supports generic substitutions.
Use -sil-partial-specialization-with-generic-substitutions to enable the partial specialization even in cases of substitutions containing generic replacement types.
2017-03-21 08:46:40 -07:00
swift-ci
d12334301e Merge pull request #8236 from hughbe/clang-latest-error-fixes 2017-03-21 06:04:17 -07:00
Hugh Bellamy
d1849d7c28 Fix top of tree Clang compilation errors 2017-03-21 19:16:39 +07:00
Hugh Bellamy
d9879522fb Fix top of tree Clang unused lambda capture warnings 2017-03-21 19:15:08 +07:00