Devirtualization of inherited protocol conformances are not essential
for stdlib performance since in most cases the stdlib does not use class
types (in contrast to devirtualization of specialized protocol
conformances which /is/ essential). So for Seed 5 I am disabling this
for the reasons below:
We are not upcasting metatypes correctly and while debugging that I ran
into a case where in the protocol witness we had generic types as if
the protocol witness was potentially covariant in all arguments. This
caused the devirtualizer to subtitute in the witness type as
appropriate, but due to the covariant argument the devirtualizer did not
perform an upcast causing a verifier fail.
<rdar://problem/17823711>
Swift SVN r20612
Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:
- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.
Swift SVN r20418
In a few places we were calling into a function that just returned
T->hasArchetype(). This just changes those places to test it directly.
Swift SVN r19427
We fail devirtualizing a specialized protocol method because the number (1) of
substitutions obtained from looking in the witness table does not match up with
the number (2) of substitutions expected by the function signature substitution
code.
As a workaround until the type code is fixed, check for this condition and bail.
rdar://17399536
Swift SVN r19137
Dynamic languages are able to implement inline caches for virtual calls, but swift is statically compiled, so we have to guess the types at compile time. The early binding pass guesses that types at the bottom of the class hierarchy are not subclassed and emits direct calls to these passes. It converts class_method calls into the following code:
if (Instance is of time Foo) {
Foo::ping()
} else {
Instance->ping();
}
The check if an instance is of a specific type is inexpensive, it is simply a load+icmp sequence.
Swift SVN r18860
I added some helpers to ApplyInst that should hopefully linguistically eliminate
the issue by allowing users of the API to not need to remember that the self
substitution is first, but the self argument is last.
We should really just remove the dichotomy. But that is for after WWDC.
I also disabled devirtualization of inherited protocol conformances for
protocol_methods. This will be less likely to be used than specialized
protocol conformances protocol_method devirtualization (which is
currently).
<rdar://problem/16951124>
Swift SVN r18282
The only case which we were handling in the old code where the class
method was not dead was when we had an apply inst of the class method.
This commit simplifies all of the weird code therein by causing class
method optimization to go through the same optimization pathway as how
we optimize protocol methods and witness methods (i.e. we pattern match
on the apply and only replace the apply).
This makes the code much simpler and more readable.
Additionally while working on test cases I noticed that relying on
SILCombine to peephole convert_function creates phase ordering issues
since SILCombine does not cause additional optimizer iterations to run
implying that we can have a situation where we devirtualize, fail to
inline, then silcombine (which would allow us to optimize), but then
the pass manager does not go around another time. Thus I move that
operation into the devirtualizer itself since it is relatively simple to
do.
Also re-enable test/SILPasses/devirt_override.sil since we handle it
correctly now.
Swift SVN r17566
Revert "[devirtualization] Begin refactor devirtualization code into first simple cases and then the general case."
This reverts commit r17288.
This reverts commit r17287.
To unblock the submission.
Swift SVN r17310
This in general should make the code far more readable and
understandable.
I am going to re-enable the inherited/specialized devirtualization in
subsequent commits.
Swift SVN r17287
See rdar://16676020 for details.
r17101 tries to solve r16761933 by checking non-direct recursions in
the call graph. We are in discussion of solving it in a different way.
Todo: figure out why r17101 causes a preformance regression.
Swift SVN r17265
This is important since it enables one to analyze the type of the
conformance that the witness table implements which may be different
than the original type. This follows the precedent where we return the
Substitutions from the protocol conformance tree traversal.
Swift SVN r17220
conformance is specialized, the function we are attempting to substitute
will have a generic self type. Make sure to substitute in substitutions
from the origin type (if it has them) before attempting to perform the
comparison inbetween the self pointer on the target function of the
devirtualization from the alloc_ref of the self pointer on the CMI.
Swift SVN r16909