Re: [swift-dev] Protocol Devirtualizer Pass

2018-01-17 Thread Raj Barik via swift-dev
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) :

Re: [swift-dev] Protocol Devirtualizer Pass

2017-12-21 Thread Michael Gottesman via swift-dev
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

Re: [swift-dev] Protocol Devirtualizer Pass

2017-12-21 Thread Raj Barik via swift-dev
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

Re: [swift-dev] Protocol Devirtualizer Pass

2017-12-20 Thread Raj Barik via swift-dev
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?{

Re: [swift-dev] Protocol Devirtualizer Pass

2017-12-13 Thread Arnold Schwaighofer via swift-dev
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 :

Re: [swift-dev] Protocol Devirtualizer Pass

2017-12-13 Thread Raj Barik via swift-dev
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 { //

Re: [swift-dev] Protocol Devirtualizer Pass

2017-12-12 Thread Raj Barik via swift-dev
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

Re: [swift-dev] Protocol Devirtualizer Pass

2017-11-29 Thread Slava Pestov via swift-dev
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

Re: [swift-dev] Protocol Devirtualizer Pass

2017-11-29 Thread Arnold Schwaighofer via swift-dev
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) {} }

[swift-dev] Protocol Devirtualizer Pass

2017-11-29 Thread Raj Barik via swift-dev
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