In order for the inlining trick to work, don't you need to run type 
inference after inlining (something that currently isn't done).

On Friday, February 19, 2016 at 7:53:36 PM UTC+1, Erik Schnetter wrote:
>
> You can keep type stability with a trick: 
>
> - Make the function I describe very small, calling only a worker 
> function that performs the actual work, and use `@inline` 
> - Use `Val{}` types in the worker function, and use dispatch instead 
> of if statements 
>
> Here's an example (untested): 
> ```Julia 
> type Impl1 end 
> type Impl2 end 
>
> @inline Impl(N) = getImpl(Val{N}) 
>
> getImpl(::Type{Val{1}}) = Impl1 
> getImpl(::Type{Val{2}}) = Impl2 
>
> ``` 
>
> The only type-unstable function is `Impl`, but if it is inlined, 
> everything is type-stable. 
>
> -erik 
>
>
>
> On Fri, Feb 19, 2016 at 1:12 PM, Davide Lasagna <[email protected] 
> <javascript:>> wrote: 
> > Wouldn't you loose type stability then? 
> > 
> > It might not matter, though. 
>
>
>
> -- 
> Erik Schnetter <[email protected] <javascript:>> 
> http://www.perimeterinstitute.ca/personal/eschnetter/ 
>

Reply via email to