Commit Graph

45 Commits

Author SHA1 Message Date
Roman Levenstein
696da80ca0 [sil-devirtualizer] Support devirtualization of try_apply instructions.
rdar://21909405

Swift SVN r30710
2015-07-28 00:11:38 +00:00
Roman Levenstein
3d6477636e [sil-devirtualizer] Fix a bug with covariant optional return types.
rdar://22020428

Swift SVN r30704
2015-07-27 23:18:02 +00:00
Roman Levenstein
ec97f37a81 [sil-devirtualizer] Properly handle devirtualization of functions with tuple return types, e.g. materializeForSet.
rdar://21603216

Swift SVN r29828
2015-07-01 00:50:40 +00:00
Roman Levenstein
8cc9f3aa31 [sil-devirtualizer] Make sure that devirtualization maintain invariants of fragile functions.
Specifically, make sure that any all function_refs produced by the devirtualizer inside fragile functions never reference a private or hidden symbol.
For example, the transparent function body can’t expose private symbols to other modules that may try to inline it.

rdar://21408247

Swift SVN r29405
2015-06-16 22:22:46 +00:00
Roman Levenstein
5bdbd2f863 [sil-devirtualizer] Fix a verifier crash when a generic callee gets devirtualized and replaced by non-generic callee.
Swift SVN r29403
2015-06-16 22:22:43 +00:00
Roman Levenstein
93d29b91cd [sil-devirtualizer] Properly handle devirtualization of methods that differ in optionality.
The devirtualizer was not handling the case, where an overriding method would return a non-optional result, whereas the overridden method from a superclass returns an optional result.

This fixes a compiler crash when compiling the internal version of Adventure.

rdar://21254158.

Swift SVN r29329
2015-06-06 00:41:38 +00:00
Roman Levenstein
0651643858 [sil-devirtualizer] Support concrete subclasses of generic base classes.
We enabled support for concrete subclasses of generic base classes recently, but the devirtualizer was not aware of it and crashed in some cases. This patch fixes it and adds a test-case.

Swift SVN r28636
2015-05-15 19:30:29 +00:00
Roman Levenstein
e590a9b63d [sil-devirtualizer] Fix handling of covariant return types if they are optionals.
This fixes a crash compiling test/Interpreter/failable_initializers.swift with -O. The patch makes uses of newly allowed upcast instruction between optionals.

rdar://20869036

Swift SVN r28441
2015-05-11 20:43:16 +00:00
Roman Levenstein
212c6e3be2 [sil-devirtualizer] Improve devirtualization of generics classes with dependent types.
radar://20337006

Swift SVN r27608
2015-04-22 22:29:02 +00:00
Mark Lacey
014602d583 Reenable some devirtualization cases disabled in r26152.
In r26152 a crash was fixed that had been introduced by previous
improvements, but as a result of fixing the crash some cases where we
previously devirtualized were disabled with the intent that they would
be reenabled after further refactoring work was completed.

This commit restores that functionality and reenables the tests.

Swift SVN r27575
2015-04-22 08:24:33 +00:00
Joe Groff
b03795e5f7 Add a '@convention(xxx)' attribute for specifying function conventions.
This is new attribute we're using to coalesce @thin, @objc_block, and @cc, and to extend to new uses like C function pointer types. Parse the new attribute, but preserve support for the old attributes, and print with the old attributes for now to separate out test changes. Migration fixits and test updates to come. I did take the opportunity here to kill off the '@cc(cdecl)' hack for AST-level function pointer types, which are now only spelt with @convention(c).

Swift SVN r27247
2015-04-13 04:27:02 +00:00
Roman Levenstein
39ad4c996b Fix a spelling error. Calleee -> Callee. NFC.
Swift SVN r27173
2015-04-09 18:16:04 +00:00
Roman Levenstein
cd08e967f9 [sil-devirtualizer] Better handling of methods that have their own generic parameters.
Fixed the logic in getSubstitutionsForSuperclass and renamed it into getSubstitutionsForCalleee to better reflect what it does.

rdar://20440616

Swift SVN r27166
2015-04-09 15:28:49 +00:00
Roman Levenstein
57c41a0e00 [sil-devirtualizer] If class contains archetypes, consider it unbound.
We should not try to devirtualize in such cases yet.

Swift SVN r27165
2015-04-09 15:28:48 +00:00
Mark Lacey
730ef41385 Make devirtualizer clients remove old applies.
This makes it feasible for clients to maintain the call graph.

Swift SVN r26997
2015-04-05 02:27:57 +00:00
Mark Lacey
c1dc4bf76a Reword a couple statistic descriptions.
Swift SVN r26970
2015-04-04 02:29:18 +00:00
Mark Lacey
07a5ebed66 Rename devirtualizeApply to tryDevirtualizeApply.
This is more consistent with the other naming in the devirtualization
code for things that might fail.

Swift SVN r26788
2015-04-01 02:10:52 +00:00
Mark Lacey
1f23ff27bb Remove the transparent bit from apply instructions.
We no longer need or use it since we can always refer to the same bit on
the applied function when deciding whether to inline during mandatory
inlining.

Resolves rdar://problem/19478366.

Swift SVN r26534
2015-03-25 08:36:34 +00:00
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
Mark Lacey
3f2716501b Remove the witness_method instruction during devirtualization.
If we have a witness_method that has no uses after removing the apply
that we've just devirtualized, then remove the witness_method as well.

Some small renaming as well, to be consistent with other functions.

Swift SVN r26342
2015-03-20 00:51:37 +00:00
Mark Lacey
957a0e5a04 Assert that we do not call isKnownFinal on methods marked final.
We only use this within the devirtualizer, and we should never see
devirtualizable calls to explicitly final methods (since we don't create
these during SILGen). This is just future proofing in case that changes.

Swift SVN r26242
2015-03-17 23:27:53 +00:00
Mark Lacey
ffa4e22da2 Another improvement to 'class func' devirtualization.
Directly devirtualize cases where we can prove the method being invoked
is 'final'.

Previously we were able to do direct devirtualization (as opposed to
speculative) only when we could prove we knew the dynamic
type (e.g. through seeing a metatype instruction).

The code removed from isKnownFinal here was a vestige of previous
mechanical refactoring which made apparent the fact that this case was
not previously being handled.

There were some cases where the speculative devirtualzation code was
also able to prove there was only one alternative, but we really want
cases like this handled through direct devirtualization. It's possible
that the speculative devirtualization code that was catching some cases
like this is no longer useful and could be removed.

Swift SVN r26221
2015-03-17 07:39:31 +00:00
Mark Lacey
ddc472e246 Minor comment update.
Swift SVN r26190
2015-03-16 21:13:11 +00:00
Mark Lacey
a30d13b0ce Simplify handling of metatypes in devirtualization.
Make the devirtualization functions take the actual type we're
devirtualizing (or speculatively devirutalizing) to, in order to
simplify the handling of metatypes. Remove the ClassDecl parameter from
these functions since it can always be derived from this type.

These changes set things up for more forthcoming improvements to
metatype handling.

As part of this I've simplified the function that determines if a member
is known to be 'final'. My expectation is that this can be further
simplified by removing the type parameter as part of other improvements
to metatype handling.

Swift SVN r26165
2015-03-15 22:04:46 +00:00
Mark Lacey
6664bd62d4 Fix crash during devirtualization.
This was exposed by a previous change that fixed two other issues, but
introduced this.

I've fixed the crash (rdar://problem/20165943) and added a test case for
it, but one result of the fix is that we'll currently miss a couple of
cases we could devirtualize, and will instead speculatively devirtualize
in these cases.

I've opened a radar so that I can go back and reenable these cases after
further refactoring that will make it simpler to handle these correctly
(rdar://problem/20166171).

Swift SVN r26152
2015-03-15 09:22:30 +00:00
Mark Lacey
c35123654e Refactor casting of self argument in devirtualization.
One test update due to swapping the order of the function_ref and upcast
generation.

Swift SVN r26059
2015-03-12 20:35:50 +00:00
Mark Lacey
5c52f40fc3 Refactor argument casting code in the devirtualizer.
Swift SVN r26055
2015-03-12 19:37:36 +00:00
Mark Lacey
0e122944f6 Use appropriate API to get the self type of a SILFunctionType.
Also update a naming convention issue by reusing the name we just
removed.

Swift SVN r26041
2015-03-12 07:46:11 +00:00
Mark Lacey
ffaa74bfbb Remove DevirtClassMethodInfo.
It turns out we're already at a point where we can easily pass the same
data along to the devirtualization functions, and were already passing
some of it.

Swift SVN r26040
2015-03-12 07:46:10 +00:00
Mark Lacey
b98f1cd51b Create a thinner coupling between devirtualization functions.
Redefine DevirtClassMethodInfo to carry fewer values in an effort to
reduce the coupling between these functions. Long term I expect this
structure to go away, but that is difficult to do without more
refactoring.

Swift SVN r26034
2015-03-12 05:09:47 +00:00
Mark Lacey
3b3dda5b51 Remove stale comment.
Determination of whether we can devirtualize was moved into a separate function.

Swift SVN r26026
2015-03-12 03:06:56 +00:00
Mark Lacey
838fdfe9ba Refactor to make the common case an early exit.
Having the same return type in an overridden class method is the common
case, so put that first, make it an early exit, removing the deeper
indentation on the less common case of different return types.

Swift SVN r26025
2015-03-12 03:06:55 +00:00
Mark Lacey
3bf752f211 Remove an obsolete parameter comment.
Swift SVN r26024
2015-03-12 03:06:54 +00:00
Mark Lacey
76eb2501b2 Shorten a \brief comment so that it is more to the point.
Swift SVN r26023
2015-03-12 03:06:53 +00:00
Mark Lacey
e917ec232b Small clean-up to reuse SILModule result.
Swift SVN r25918
2015-03-10 06:19:28 +00:00
Mark Lacey
742b7a6509 Move early exit earlier and bail out as soon as we have enough information.
Swift SVN r25917
2015-03-10 06:19:27 +00:00
Mark Lacey
1f521ef971 Fix coding style issue.
Swift SVN r25800
2015-03-06 06:56:57 +00:00
Mark Lacey
c26c15cc9f Don't pass arguments that can be easily derived from other arguments.
Swift SVN r25799
2015-03-06 06:56:56 +00:00
Mark Lacey
c1ae6372b0 Move updates to the DevirtClassMethodInfo parameter to the of the function.
Only update the structure once we've determined we can devirtualize.

NFC.

Swift SVN r25794
2015-03-06 00:54:49 +00:00
Mark Lacey
b72e453ec2 Separate collecting substitutions in devirtualization.
This is a separate step worthy of its own function.

NFC.

Swift SVN r25793
2015-03-06 00:54:47 +00:00
Mark Lacey
dcf433298d Simplify determination of substitutions in devirtualization.
Swift SVN r25792
2015-03-05 23:19:36 +00:00
Mark Lacey
40ffcc0148 Small refactoring clean-up.
Separate finding the superclass from determining substiutions.

NFC.

Swift SVN r25789
2015-03-05 22:22:34 +00:00
Mark Lacey
b76ad3a806 Small simplification to check for null type.
Swift SVN r25788
2015-03-05 22:22:33 +00:00
Mark Lacey
fcb313bbc9 Remove code that has no effect.
Swift SVN r25787
2015-03-05 22:22:31 +00:00
Mark Lacey
757ae5796e First step in splitting out a utility for devirtualizing from the pass.
No functional change here, and this is not in its final form. This is
just cut/paste/tweak to split the code apart in a first reasonable form.

Swift SVN r25769
2015-03-04 22:21:38 +00:00