Open dabrahams opened 4 years ago
This is a limitation of the @differentiable
function type attribute. Supporting a where-clause within a function type attribute may involve a non-trivial implementation given that there's no precedence of function type attributes containing generic constraints and because @differentiable
/@differentiable(linear)
is currently just a two-bit flag in AnyFunctionType::ExtInfo
. Besides the potential implementation difficulty, function types with such constraints could be long and difficult to read:
@differentiable(where Element: Differentiable, E: Differentiable) (_ myX: inout Element, _ aX: E) -> Void
Have you tried defining additional update(elementwiseWith::🙂
overloads with more specific generic requirements such that the most specific one will win in overload resolution? What's the specific use case of this method?
@rxwei @_specialize
supports where
clauses so it should be possible to extract some code and reuse here, if you decide to go with this.
@theblixguy If I remember correctly, @_specialize
is a DeclAttr
. And we did port @_specialize
's support for where-clauses to the @differentiable
declaration attribute, but this issue in this radar is mainly about the @differentiable
function type attribute like @convention
. Are you saying there also exists a @_specialize
function type attribute today?
Oh, I see. Sorry, I overlooked the “function type” bit. I don’t think we have any function type attributes with where clauses at the moment. I suppose it should still be relatively straightforward to parse the where clause in such a context (with possibility to share code) but I haven’t given it much thought.
@theblixguy Thanks for the pointer!
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Swift for TensorFlow | |Labels | Bug, AutoDiff | |Assignee | None | |Priority | Medium | md5: 2bdd7e64a6b7e0424705c091ca000b07Issue Description:
This method won't compile:
The fundamental limitation is that we have no way to say thats
updateElement
andcombine
are@differentiable(where: Element: Differentiable, E: Differentiable)
(that's a syntax error).