I created a pull request for the protocol devirtualizer and the peephole
optimizer at https://github.com/apple/swift/pull/13991.
Really appreciate all the help from Arnold and Slava.
Here is an example of what the transformation achieves (in conjunction with
other existing passes of swift) :
Is it possible to merge them?
> On Dec 21, 2017, at 11:07 AM, Raj Barik via swift-dev
> wrote:
>
> Hi,
>
> Thanks.
>
>
> Are you implementing it as a separate pass, or is it part of function
> signature specialization?
>
>
> I am currently implementing this as a
Hi,
Thanks.
> Are you implementing it as a separate pass, or is it part of function
> signature specialization?
>
I am currently implementing this as a separate pass. There is some code
overlap between the two (FunctionSignatureOpt and ProtocolDevirtualizerOpt)
in terms of checking which
Thank you Arnold & Slava! The protocol devirtualizer pass works fine now
for most cases. I should be creating a PR soon (after some more testing).
I am thinking about extending this to Optional types as well, i.e.,
@inline(never) internal func wrap_inc_optional(a:SumProtocol?, val:Int) ->
Int?{
You don’t need a second open_existential_ref in the _wrap_inc
function. It should look something like this:
sil @_wrap_inc : $@convention(thin) (@owned T, Int)
-> Int {
bb0(%0 : $T, %1 : $Int):
%5 = witness_method $T, #SumProtocol.inc!1 :
(Self) -> (Int) -> Int :
Slava,
I have two (clarification) questions in your proposed implementation:
*Original Function:*
@inline(never) internal func wrap_inc(a:SumProtocol, val:Int) -> Int{
return a.increment(i:val)
}
*Transformed code:*
@inline(always) internal func wrap_inc(a: SumProtocol, val: Int) -> Int {
//
Thanks for the recommendations, Slava. Although I am able to create both
the generic function and the wrapper thunk, I get a crash in the existing
performance inliner pass while iterating over the apply instruction and
trying to perform substitution. Here is the SIL that I generate:
sil hidden
Hi Raj,
The way I would approach this problem is first, turn a function taking a
protocol value into one taking a protocol-constrained generic parameter. So
@inline(never) internal func wrap_inc(a:SumProtocol, val:Int) -> Int{
return a.increment(i:val)
}
Would become
@inline(always) internal
The issue I raised is when we truly replace the type in an existing function:
protocol Proto :class {}
class SingleImpl : Proto {}
class User {
func useProto(p: Proto) {}
}
If i understand you correctly your pass changes this program to:
class User {
func useProto(p: SingleImpl) {}
}
Hi,
I am thinking about writing a Protocol Devirtualizer Pass that specializes
functions that take Protocols as arguments to transform them with concrete
types instead of protocol types when the concrete types can be determined
statically by some compiler analysis. This is the first step of the
10 matches
Mail list logo