Open johnnychen94 opened 6 years ago
I'd propose a slightly different implementation:
@progress function foo(args...)
#...
end
expands to the normal definition of foo
and another one, say foo#with_progress
with PogressMeter instrumentation added. Then @showprogress foo(50)
just becomes foo#with_progress(50)
(possibly with some code to check foo#with_progress
is defined provide a useful error message if not.)
Note that this (like the original proposal) solves
- In some situations one does need a silent execution, and in some situations one doesn't.
but does not solve
- Some package authors don't intend to give any additional execution information other than the results
Currently,
@showprogress
doesn't work for functions, e.g.,Why we need this?
At present, we could manually do something like this... Not complicated, but this requires some document reading, and when the real kernel function is nested deeply, this requires a bunch of modifications on the APIs.
Take the case of this
foo
, I think the reason@showprogress
won't work for this is because we can't directly get the definition offoo
when calling it so that unable to parse the expression. (Ref: https://github.com/JuliaLang/julia/issues/2625, https://github.com/JuliaLang/julia/issues/24347)I'm wondering if the following alternative procedure is practical to support this feature. (please excuse me for my current status of lacking of experiences in macros, I'm just plotting the general idea)
1. use a
@progress
macro to generate two functions: a wrapper and a kernelLet
generate
By doing this, calling
foo(n)
is still works as usual -- noProgress
is involved. But this gives the possibility to parse the function expressions.2. write a parser to
foo_
Let
parse(foo_(50))
returns3. modify
@showprogress
to support calling ofparse(foo_(50))
let
@showprogress foo(50)
actually callingeval(parse(foo_(50)))
, so that this feature is supportedAs a summary,
the package author can simply add a
@progress
notation to support the featureand the package user uses
@showprogress
notation to plot progressThis's a solution I think is possible. However, since I'm currently not very familiar with macro writing, I'm not very sure of it.