Should a.b lower to getproperty(a, Val{:b})?

I am very happy that in 0.7 the expression a.b lowers to an overloadable function. But I am a bit surprised that it lowers to Base.getproperty(a, :b) and not Base.getproperty(a, Val{:b}). It seems that the latter would be much better for taking advantage of Julia’s powerful dispatch. In the PR that introduced the new lowering, @kristoffer.carlsson makes a similar point and @jeff.bezanson acknowledges the possibility of using Val{:b}, but it seems the discussion of this particular point went no further.

(Similar comments apply to Base.setproperty!).

The feature came combined with compiler enhancements that made it possible for it to properly infer getproperty(a, :b) (as long as the field argument is constant). Val{:b} would force method specialization that is generally not desired here. Of course it is always possible to implement getproperty(a::MyType, b::Symbol) = getproperty(a, Val{b}()) if you want that for some reason.


Why do you say that specialization is generally undesired? From a programming perspective, I think I would almost always want different methods for different properties. And in the rare case I didn’t it would be easy to forward to a common method.

I think specialisation is unwanted from a compiler standpoint - not from the user perspective.
We already have compile time problems in Julia and specialisation is expensive. Making a much used feature like getfield heavily specialize on a symbol would add a lot of compilation overhead.

1 Like

That makes sense. Now that I know there is a good reason for using symbols, and that doing so will not incur a dispatch overhead, I am content to use the workaround suggested by @Keno for those types whose properties I want to specialize.