Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upWIP: Staged functions #7474
Conversation
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
JeffBezanson
Jun 30, 2014
Member
I don't think we should use staged. Not worth taking a dictionary word for this.
|
I don't think we should use |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Jun 30, 2014
Member
Hmm, that is odd behavior. It seems to suggest that the specifically-compiled variants are not getting inserted into the methods table properly. What does methods(foo) say after you call foo(1,2)? What does it say at the end after defining bar and baz?
|
Hmm, that is odd behavior. It seems to suggest that the specifically-compiled variants are not getting inserted into the methods table properly. What does |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Jun 30, 2014
Member
Also, am I right in guessing that more needs to be done to handle splatted arguments?
|
Also, am I right in guessing that more needs to be done to handle splatted arguments? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
JeffBezanson
Jun 30, 2014
Member
A rule of thumb is that the system should behave as if the code generator did not exist, and all of its possible outputs have been written manually in a magic infinite source file.
|
A rule of thumb is that the system should behave as if the code generator did not exist, and all of its possible outputs have been written manually in a magic infinite source file. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Keno
Jun 30, 2014
Member
I'm not sure about splatted arguments. Haven't tried. About the method cache, I think it is being entered correctly (see the second call to foo). The problem is probably inlining.
@JeffBezanson That analogy doesn't really work though, unless you want to add the generated methods to mt->defs and even then they would only be there after being called.
|
I'm not sure about splatted arguments. Haven't tried. About the method cache, I think it is being entered correctly (see the second call to foo). The problem is probably inlining. @JeffBezanson That analogy doesn't really work though, unless you want to add the generated methods to mt->defs and even then they would only be there after being called. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
JeffBezanson
Jun 30, 2014
Member
The rule of thumb should be followed to the extent possible. It's there to resolve design decisions that could go either way.
|
The rule of thumb should be followed to the extent possible. It's there to resolve design decisions that could go either way. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Jul 1, 2014
Member
Looks like we're super-close, but that splatting seems to be a problem. Check this out (we are so close to having awesome array views!):
A = rand(5,5,3);
B = slice(A, 1:3, 2, 1:3);
stagedfunction mygetindex(S::SubArray, indexes::Real...)
println(S)
T, N, A, I = S.parameters
if N != length(indexes)
error("Wrong number of indexes supplied")
end
NP = length(I)
indexexprs = Array(Expr, NP)
j = 1
for i = 1:NP
println(i)
println(j)
println(I[i])
if I[i] == Int
indexexprs[i] = :(S.indexes[$i])
else
indexexprs[i] = :(S.indexes[$i][indexes[$j]])
j += 1
end
end
println(indexexprs)
ex = :(S[$(indexexprs...)])
println(ex)
ex
end
julia> mygetindex(B, 2, 2)
SubArray{Float64,2,Array{Float64,3},(UnitRange{Int64},Int64,UnitRange{Int64})}
1
1
UnitRange{Int64}
2
2
Int64
3
2
UnitRange{Int64}
[:(S.indexes[1][indexes[1]]),:(S.indexes[2]),:(S.indexes[3][indexes[2]])]
S[S.indexes[1][indexes[1]],S.indexes[2],S.indexes[3][indexes[2]]]
ERROR: syntax: "Array{Any, 1}" is not a valid function argument name
Ideally the compiled function should have a signature like this:
mygetindex(S::SubArray{Float64,2,Array{Float64,3},(UnitRange{Int64},Int64,UnitRange{Int64})}, indexes_1::Int, indexes_2::Int)
but I think it's just the naming that's causing problems.
|
Looks like we're super-close, but that splatting seems to be a problem. Check this out (we are so close to having awesome array views!):
Ideally the compiled function should have a signature like this:
but I think it's just the naming that's causing problems. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
porterjamesj
Jul 1, 2014
Member
just wanted to register my excitement and say it was very cool to see the initial prototype work on Saturday :)
|
just wanted to register my excitement and say it was very cool to see the initial prototype work on Saturday :) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
porterjamesj
Jul 1, 2014
Member
also is this going to make it into 0.3 or will it be an 0.4-pre thing?
|
also is this going to make it into 0.3 or will it be an 0.4-pre thing? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Definitely not 0.3 material. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
lstagner
Jul 1, 2014
Contributor
While this can legitimately be called a staged function, I feel that the concept of staged functions is much more broad then how they are being applied here. Calling this a stage function would be presumptuous since there could be other functions that fit the definition of what a staged function is.
Since this is a function/macro that operates on types why not have the syntax be
typefunction foo(a,b) #or tfunction foo(a,b)
or
typemacro foo(a,b) #or tmacro foo(a,b)
|
While this can legitimately be called a staged function, I feel that the concept of staged functions is much more broad then how they are being applied here. Calling this a stage function would be presumptuous since there could be other functions that fit the definition of what a staged function is. Since this is a function/macro that operates on types why not have the syntax be
or
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
IainNZ
Jul 1, 2014
Member
typemacro does have some good things going to for it too on top of that, in that its not likely to be wanted in user code, reduces possible confusion with plain old functions, and is short
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
quinnj
Jul 1, 2014
Member
typemacro has a nice ring to it. What about call site syntax? Do we want to visually distinguish, like macros, that "something funny is going on here"? I think Jeff mentioned @@foo(a,b) syntax is available for something.
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
JeffBezanson
Jul 1, 2014
Member
I fail to see how it's presumptuous to apply a term to something that fits its definition. What would it mean for another design or implementation to be "more staged" than this?
This can't have different syntax; the whole point is that it's part of the behavior of a generic function. Some methods might be staged, others not, transparently.
|
I fail to see how it's presumptuous to apply a term to something that fits its definition. What would it mean for another design or implementation to be "more staged" than this? This can't have different syntax; the whole point is that it's part of the behavior of a generic function. Some methods might be staged, others not, transparently. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
JeffBezanson
Jul 1, 2014
Member
I would also be ok with a more concrete, less-jargony name possibly evoking "code generator". or "generated method", or something along those lines.
|
I would also be ok with a more concrete, less-jargony name possibly evoking "code generator". or "generated method", or something along those lines. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
quinnj
Jul 1, 2014
Member
Ah, I didn't catch that these will mesh with generic functions. Very cool.
|
Ah, I didn't catch that these will mesh with generic functions. Very cool. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
lstagner
Jul 1, 2014
Contributor
@JeffBezanson The presumptuous bit is to allocate a piece of syntax for something that describes a family of functions. I would be a bit like a language defining sin(x) as trigfunction(x) . If the stagedfunction syntax could be applied to all types of staged functions it would be fine.
I think the syntax
typemacro foo(a,b)
println(a,b)
end
foo(1,2)
would be fine since in your initial mailing list post you say
"These are a lot like macros, except they operate on types instead of
expressions. " -Jeff Bezanson
This may however cause confusion with people trying to call them like macros.(which is why I also suggested typefunction)
|
@JeffBezanson The presumptuous bit is to allocate a piece of syntax for something that describes a family of functions. I would be a bit like a language defining I think the syntax
would be fine since in your initial mailing list post you say
This may however cause confusion with people trying to call them like macros.(which is why I also suggested |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
JeffBezanson
Jul 1, 2014
Member
I hope we can find a better name. type function or t function is a term of art used elsewhere in the system to refer to functions that operate within the type domain, used by inference.
|
I hope we can find a better name. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
lstagner
Jul 1, 2014
Contributor
Also something to consider would be something like type annotations but for functions. Like
function foo{typed}(a,b) #or foo::typed(a,b)
end
something that describes what aspects of the arguments are passed into the function e.g. in a normal function their values are passed but in a typed function their types are passed.
|
Also something to consider would be something like type annotations but for functions. Like
something that describes what aspects of the arguments are passed into the function e.g. in a normal function their values are passed but in a |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Both
and
already have a meaning. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
lstagner
Jul 1, 2014
Contributor
@Keno then perhaps something like
function{Type} foo(a,b)
I kinda like this idea. Instead of Type where it passes the argument's type it could be Symbol where it just passes the argument's symbol. Default would where it passes the argument's Value
Anyway I've said my piece. I realize this is a bike shed issue so I am going to shut up about it now and let you experts take care of it.
|
@Keno then perhaps something like
I kinda like this idea. Instead of Anyway I've said my piece. I realize this is a bike shed issue so I am going to shut up about it now and let you experts take care of it. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
StefanKarpinski
Jul 1, 2014
Member
typemacro or type macro (one less keyword plus more readable) strike me as good.
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
porterjamesj
Jul 1, 2014
Member
typemacro or similar seems like it might be confusing to some in that you don't invoke these like macros; they just generate functions and lodge them in the method table for you.
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mlubin
Jul 1, 2014
Member
typemacro seems confusing on the part of the user, because these functions are called like functions and not with the @ prefix. My vote is for stagedfunction.
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
jinx @porterjamesj |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
yurivish
Jul 1, 2014
Contributor
What about genfunction or functiongen? These are like stagedfunction, but are a little shorter and capture the idea that what you're defining is a function generator.
|
What about |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
@yurivish +1 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
stevengj
Jul 1, 2014
Member
@mlubin, since they generate expressions, they are seem more like macros than functions, and hence I like typemacro. Couldn't the patch be changed to call them with @?
|
@mlubin, since they generate expressions, they are seem more like macros than functions, and hence I like |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
That way you couldn't have some methods of |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ihnorton
Jul 1, 2014
Member
How about annotating function or the function name: function @foo() function ~foo() @function foo, etc. (I think the last one captures the duality quite well).
|
How about annotating function or the function name: |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
JeffBezanson
Jul 1, 2014
Member
To me this is quite distinct from macros. I think the best approach is something that straightforwardly describes what the thing is. To that end genfunction is not bad.
|
To me this is quite distinct from macros. I think the best approach is something that straightforwardly describes what the thing is. To that end |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mlubin
Jul 1, 2014
Member
@stevengj, from the user's perspective, whether a function is staged or not is really just an implementation detail. I don't think it deserves the @ syntax which is a warning that anything can happen.
|
@stevengj, from the user's perspective, whether a function is staged or not is really just an implementation detail. I don't think it deserves the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
lstagner
Jul 2, 2014
Contributor
These suggestions are just for fun
funcro # FUNction maCRO
maction #MACro funcTION
tycro # TYpe maCRO
tytion #TYpe funcTION
macrope #MACRO tyPE
funpe #FUNction tyPE
|
These suggestions are just for fun
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tknopp
Jul 2, 2014
Contributor
I think its pretty obvious that we have to chose funcro :-)
Its such a nice word creation.
|
I think its pretty obvious that we have to chose |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Jul 2, 2014
Member
Regarding splatting, I see two paths forward. The first is to declare a convention:
stagedfunction myfunc(a, b...)
blah blah
end
myfunc("Hi", 3, 7)generates a function with the following signature:
myfunc(a::ASCIIString, b_1::Int, b_2::Int)The "convention" part is that _i gets tacked on to the name of the ith splatted argument. Naturally, the person implementing the body of this function has to be aware of this convention in order to write the body. (FYI this is the same naming convention that Cartesian uses.)
The second option is to declare that the returned expression needs to contain the full function definition (including signature), not just the body. @Keno, @jakebolewski, and I discussed this and all think it has some potential downsides. But if you don't like the idea of magical naming conventions, this seems to be the only alternative.
Personally I vote for the naming convention approach, but I'm curious what others think.
|
Regarding splatting, I see two paths forward. The first is to declare a convention: stagedfunction myfunc(a, b...)
blah blah
end
myfunc("Hi", 3, 7)generates a function with the following signature: myfunc(a::ASCIIString, b_1::Int, b_2::Int)The "convention" part is that The second option is to declare that the returned expression needs to contain the full function definition (including signature), not just the body. @Keno, @jakebolewski, and I discussed this and all think it has some potential downsides. But if you don't like the idea of magical naming conventions, this seems to be the only alternative. Personally I vote for the naming convention approach, but I'm curious what others think. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Jul 2, 2014
Member
I looked into the inlining thing. code_native indeed shows these are beautifully inlined. However, I still find this a little weird:
julia> stagedfunction foo(a,b)
println(a,b)
:(a+b)
end
foo (generic function with 1 method)
julia> methods(foo)
# 1 method for generic function "foo":
foo(a,b) at none:2
julia> foo(1,2)
Int64Int64
3
julia> methods(foo)
# 1 method for generic function "foo":
foo(a,b) at none:2
I would have expected to see a foo(a::Int, b::Int) method showing up upon the second call to methods. @JeffBezanson?
|
I looked into the inlining thing.
I would have expected to see a |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Keno
Jul 2, 2014
Member
methods shows method definitions, which we aren't adding. We're adding an entry in the method cache instead. I'm not sure what to do about the varargs thing. We can't really change the signature. Maybe that needs to be resolved in codegen in general?
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mlubin
Jul 2, 2014
Member
Relating to my request in #7311:
Ideally we'd like to write staged functions where the inputs are typed expression trees, or some transformation thereof. Is this feasible?
Jeff responded:
The macro can generate a call to a staged function, passing the expression trees and, separately, all of its leaves.
How precisely would this work, given this implementation? Staged functions take only types, so we couldn't pass the expression tree as a value. Could you encode the value of the expression tree as a type?
|
Relating to my request in #7311:
Jeff responded:
How precisely would this work, given this implementation? Staged functions take only types, so we couldn't pass the expression tree as a value. Could you encode the value of the expression tree as a type? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Just |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Nov 21, 2014
Member
I like generated function, i.e., the past-tense. "generate" is imperative, suggesting the compiler should "do it right now," but that's not at all what's happening---each instantiation gets generated when the user needs it. In contrast, generated function implies that this is a declaration of type, and it would be grammatically incorrect to use the present tense for that.
But I'll join the chorus and just say that Jeff & Stefan should talk for 5 minutes and just make a decision.
I think it's fair to say that the rest of us are 95% likely to accept it.
|
I like But I'll join the chorus and just say that Jeff & Stefan should talk for 5 minutes and just make a decision. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
johnmyleswhite
Nov 21, 2014
Member
I do really like generated function as well. I'm not that opposed to whitespace keywords.
Agree that Jeff, Stefan and Viral should decide.
|
I do really like Agree that Jeff, Stefan and Viral should decide. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
amitmurthy
Nov 21, 2014
Member
Do whitespace keywords mean that generated continues to be a usable identifier on its own? That's a win.
|
Do whitespace keywords mean that |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
It certainly means more whitespace magic in the parser, no? ;-) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
toivoh
Nov 21, 2014
Member
Or generator function? I like generated function as well, but most of all I
like the functionality :)
On 21 Nov 2014 13:34, "Tobias Knopp" notifications@github.com wrote:
It certainly means more whitespace magic in the parser, no? ;-)
—
Reply to this email directly or view it on GitHub
#7474 (comment).
|
Or generator function? I like generated function as well, but most of all I
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Though generator is a pretty useful variable name otoh. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Nov 21, 2014
Member
See above for concerns about generator.
The reason for the whitespace: we'll surely have generated type and generated immutable someday. Using the whitespace means that only one new keyword needs to be added to the parser, not three.
Also, I highlighted Jeff and Stefan above because I thought I remembered that Stefan seems the least happy of anyone with these recent name proposals. But then I just re-read some of the discussion, and Stefan said he'd go for generated function, so it seems there's really quite a lot of agreement on that name. However, since the parser is not my strong suit
|
See above for concerns about The reason for the whitespace: we'll surely have Also, I highlighted Jeff and Stefan above because I thought I remembered that Stefan seems the least happy of anyone with these recent name proposals. But then I just re-read some of the discussion, and Stefan said he'd go for |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
johnmyleswhite
Nov 21, 2014
Member
Man, DataFrames could be so much better if we had generated type.
|
Man, DataFrames could be so much better if we had |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
StefanKarpinski
Nov 21, 2014
Member
It's bit the prettiest but how about just a @generated macro? No syntax changes required.
On Nov 21, 2014, at 9:01 AM, Tim Holy notifications@github.com wrote:
See above for concerns about generator.
The reason for the whitespace: we'll surely have generated type and generated immutable someday. Using the whitespace means that only one new keyword needs to be added to the parser, not three.
Also, I highlighted Jeff and Stefan above because I thought I remembered that Stefan seems the least happy of anyone with these recent name proposals. But then I just re-read some of the discussion, and Stefan said he'd go for generated function, so it seems there's really quite a lot of agreement on that name. However, since the parser is not my strong suit it won't be me who makes that change.
—
Reply to this email directly or view it on GitHub.
|
It's bit the prettiest but how about just a @generated macro? No syntax changes required.
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
MikeInnes
Nov 21, 2014
Member
If we're using white space anyway, seems reasonable to just use a macro – @generated function ... or @gen function... (edit: ok, Stefan got there first)
I also quite liked fucro, but that's probably why I'm not making the decisions around here.
|
If we're using white space anyway, seems reasonable to just use a macro – I also quite liked |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
toivoh
Nov 21, 2014
Member
Oh, forgot about python generators :) (which I indeed hope that we will have at some point)
|
Oh, forgot about python generators :) (which I indeed hope that we will have at some point) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
+1 for |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Jutho
Nov 21, 2014
Contributor
Generated types can be implemented right now using the tricks used in #8432. Not perfect, but still very convenient until we have the full thing. In fact, it shouldn't be to hard to implement a general scheme for this using a macro, which could then be called @generate(d). This could provide a unified approach towards generated functions and types. However, what transformation should @generate(d) apply to :function, i.e. the child still needs a name, unless the generated/staged aspect is indicated using the :meta mechanism.
With respect to name: I would also prefer generated if it is a keyword, but most macros seem to have a name which is a verb in the present tense. Also compare to the original @ngenerate macro in Base.Cartesian. No strong preference from my side.
|
Generated types can be implemented right now using the tricks used in #8432. Not perfect, but still very convenient until we have the full thing. In fact, it shouldn't be to hard to implement a general scheme for this using a macro, which could then be called With respect to name: I would also prefer |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Although |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
StefanKarpinski
Nov 21, 2014
Member
I agree with the argument that it should be @generated. There are two flavors of macro: imperatives and annotations – this is more of an annotation than an imperative.
|
I agree with the argument that it should be |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
JeffBezanson
Nov 21, 2014
Member
I like @generated too. It has all the virtues of generated function plus avoids adding a new keyword. Macro names certainly do not need to be verbs in the present tense. This is not past tense either; it's a participle, as in "functions are generated on demand".
|
I like |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Jutho
Nov 21, 2014
Contributor
On 21 Nov 2014, at 16:18, Tim Holy notifications@github.com wrote:
Although @ngenerate is imperative: generate them now, at parsing time.
—
Indeed. I agree 100%. +1 for @generated.
Indeed. I agree 100%. +1 for |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ViralBShah
Nov 22, 2014
Member
+1 for @generated. No whitespace in keywords is nice too. Visually, the macro syntax it also alerts you that something will run at an earlier stage.
|
+1 for @generated. No whitespace in keywords is nice too. Visually, the macro syntax it also alerts you that something will run at an earlier stage. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
johnmyleswhite
Nov 22, 2014
Member
If we make this look like a macro, what will macroexpand produce? I'm not sure I like the idea that this looks like a macro, but doesn't work like other macros.
|
If we make this look like a macro, what will |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
amitmurthy
Nov 22, 2014
Member
I agree with John. The @ convention is that code is generated when it is used. While defining the generator plain keyword macro is used. +1 for generated function.
|
I agree with John. The |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tonyhffong
Nov 22, 2014
Member
How about using an empty curly?
function f{}( ... )
endNo new reserved word. No need to change editor model. The empty curly suggests that, Instead of parametrizing the function outside, we do that inside...
Edit: ok, f{}{ T<: AbstractArray }( x::T ) ... doesn't look quite right. Never mind me.
|
How about using an empty curly? function f{}( ... )
endNo new reserved word. No need to change editor model. The empty curly suggests that, Instead of parametrizing the function outside, we do that inside... Edit: ok, |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
MikeInnes
Nov 22, 2014
Member
@johnmyleswhite The idea isn't to pretend it's a macro, but for it to actually be a macro. @generated would be a very simple macro that inserts some metadata into the (function/type/whatever) expression for the compiler to pick up on.
We have @inline already doing this, so it's not exactly unprecedented (although admittedly @generated would change the semantics a lot more than @inline).
|
@johnmyleswhite The idea isn't to pretend it's a macro, but for it to actually be a macro. We have |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Nov 22, 2014
Member
To follow up on @one-more-minute's point, see http://docs.julialang.org/en/latest/devdocs/meta/
|
To follow up on @one-more-minute's point, see http://docs.julialang.org/en/latest/devdocs/meta/ |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
porterjamesj
Nov 30, 2014
Member
I think the crucial point is that it's the definition of a generated function that involves a macro rather than the callsite—end users don't have to care. +1 for @generated from me.
|
I think the crucial point is that it's the definition of a generated function that involves a macro rather than the callsite—end users don't have to care. +1 for |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Hornéd hat of shame for the lack of documentation on this.... |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Dec 30, 2014
Member
As I believe you noted elsewhere, it's hard to write documentation for something whose very name is likely to change.
|
As I believe you noted elsewhere, it's hard to write documentation for something whose very name is likely to change. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
lstagner
Dec 31, 2014
Contributor
It seems like the consensus that was reached was for calling them generated (functions|types|...) using the @generated (function|type|...) syntax.
|
It seems like the consensus that was reached was for calling them generated (functions|types|...) using the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Dec 31, 2014
Member
I agree, but until the syntax change happens it seems very strange to document it (with either name choice).
|
I agree, but until the syntax change happens it seems very strange to document it (with either name choice). |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ViralBShah
Jan 1, 2015
Member
Why not document it with the current name, and then just update the documentation with the name change? I think a lot of people want to use staged functions and learn about them (on master), but going through the issues is a bit cumbersome for many.
|
Why not document it with the current name, and then just update the documentation with the name change? I think a lot of people want to use staged functions and learn about them (on master), but going through the issues is a bit cumbersome for many. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
aviks
Jan 1, 2015
Member
Why not document it with the current name, and then just update the documentation with the name change
I realise this is more work, and I am in no position to help, but I (and I'm sure many others) would really appreciate something on those lines. Maybe even a gist with some docs and examples?
I realise this is more work, and I am in no position to help, but I (and I'm sure many others) would really appreciate something on those lines. Maybe even a gist with some docs and examples? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Jan 1, 2015
Member
I also confess some reluctance before #8504 gets fixed---it's a nasty problem, and it's holding even me back from using stagedfunctions more pervasively.
But, let's go for it and see what happens. If nothing else it might be more incentive to at least get some discussion about my proposed fix.
|
I also confess some reluctance before #8504 gets fixed---it's a nasty problem, and it's holding even me back from using stagedfunctions more pervasively. But, let's go for it and see what happens. If nothing else it might be more incentive to at least get some discussion about my proposed fix. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tonyhffong
Jan 8, 2015
Member
I wonder if we should treat function-typed argument differently in a stagedfunction. When testing types, we most likely want to do method_exists or even code_typed to see if the function supports the input/output signature in the staging phase. Having just Function at this stage isn't that helpful.
That said, it should be illegal to actually call the function-value argument at the staging phase.
|
I wonder if we should treat function-typed argument differently in a stagedfunction. When testing types, we most likely want to do That said, it should be illegal to actually call the function-value argument at the staging phase. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timholy
Jan 9, 2015
Member
It's an interesting idea. Can you expand on your goal, why checking the signature during staging is better than just trying it and seeing what error you get?
But one point is that in principle your suggestion could provide a mechanism for "function-valued argument inlining" (#3440 and perhaps #1864).
|
It's an interesting idea. Can you expand on your goal, why checking the signature during staging is better than just trying it and seeing what error you get? But one point is that in principle your suggestion could provide a mechanism for "function-valued argument inlining" (#3440 and perhaps #1864). |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tonyhffong
Jan 9, 2015
Member
I'm playing with the idea of Functors and Monads using Traits.jl and notice the ideas are not trivial. (PR# mauro3/Traits.jl#4 (comment)). I was trying to see if I can generate associated types with the package. Let's take Functor. A Functor must support a fmap function. In Haskell it imposes that fmap :: (a->b) -> f a -> f b. So we would write something like this:
using Traits
immutable FuncFullSig{TI, TO}
f::Function
end
@traitdef Functor{X{Y}} begin
fmap( FuncFullSig{Y,Z}, X{Y} ) -> X{Z}
endSo when we do
a = Float64[1.0,2.0] # assume we assert Array is a Functor
b = fmap( FuncFullSig{Float64,Float64}( sin ), a ) # b should be provably Array{Float64}It would do away with many boilerplate codes, as many types are just Functors in disguise (Nullable, Associative{K}, DataArray, etc.) . But writing FuncFullSig is a bit cumbersome. It would be really nice, when we do just b = fmap( sin, c ), the following intermediate steps happen:
- ask if
typeof(c)is a Functor? (already do-able now with Traits.jl) - if so, check if the method
sin( x::T )exists? (Tis the Functor parameter oftypeof(c)) - (bonus) provide type inference info that b must be a Functor of the result type
Ideally, all these would be better done only once per (Function, ArgTypes...) tuple, or the performance penalty would be massive. Stagedfunction would be an interesting place to put it, but
we are in a strange place right now, when we only know the types of arguments but not the signatures of function arguments, a challenge that is a by-product of julia's multiple-dispatch feature. (Ironically, multiple-dispatch is exactly what makes Traits.jl work.)
|
I'm playing with the idea of Functors and Monads using Traits.jl and notice the ideas are not trivial. (PR# mauro3/Traits.jl#4 (comment)). I was trying to see if I can generate associated types with the package. Let's take Functor. A Functor must support a fmap function. In Haskell it imposes that using Traits
immutable FuncFullSig{TI, TO}
f::Function
end
@traitdef Functor{X{Y}} begin
fmap( FuncFullSig{Y,Z}, X{Y} ) -> X{Z}
endSo when we do a = Float64[1.0,2.0] # assume we assert Array is a Functor
b = fmap( FuncFullSig{Float64,Float64}( sin ), a ) # b should be provably Array{Float64}It would do away with many boilerplate codes, as many types are just Functors in disguise (Nullable, Associative{K}, DataArray, etc.) . But writing
Ideally, all these would be better done only once per (Function, ArgTypes...) tuple, or the performance penalty would be massive. Stagedfunction would be an interesting place to put it, but |
Keno commentedJun 30, 2014
This is my work in progress for staged functions (#7311). It almost works, but there's a few things left to discuss.
stagedfunction foo(); end. @JeffBezanson proposedstaged foo(); end, though there's the question if we want to reserve that keywordHopefully calling the staged function that many times can be avoided. In any case, this point isn't critical.
Thanks to @timholy and @jakebolewski for hacking on this with me on Saturday.