ResumableFunctions.jl icon indicating copy to clipboard operation
ResumableFunctions.jl copied to clipboard

macro clashing with ProgressLogging.jl

Open mileslucas opened this issue 4 years ago • 1 comments

I'm running into some issues using this package alongside another macro-based package, ProgressLogging.jl

My goal is to add optional progress bars to a package which uses ResumableFunctions.jl, the original function definition looks straightforward, for example

@resumable function f1(x)
   for xi in x
       @yield xi
   end
end

which compiles and operates perfectly as expected.

The first attempt at progress logging, using the @progress macro fails already due to the rewriting:

@resumable function f2(x)
   @progress for xi in x
       @yield xi
   end
end

ERROR: LoadError: LoadError: @progress requires a for loop (for i in irange, j in jrange, ...; <body> end) or array comprehension with assignment (x = [<body> for i in irange, j in jrange, ...])

okay, that's fine, let's try the more flexible approach using @withprogress

@resumable function f2(x)
   @withprogress begin
        i = 1; N = length(x)
        for xi in x
           @yield xi
           @logprogress i/N
           i += 1
       end
   end
end

ERROR: syntax: cannot goto label "_STATE_1" inside try/catch block

so in both cases, something is clashing between the two macros. I tried looking into the source code, both here and the code produced by @macroexpand but it's so complicated I can't gleam any information from it.

version info:

julia> versioninfo()
Julia Version 1.6.0
Commit f9720dc2eb* (2021-03-24 12:55 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin20.3.0)
  CPU: Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_PKG_DEVDIR = /Users/miles/dev/julia
  JULIA_NUM_THREADS = 4
pkg> st --manifest
      Status `/private/var/folders/g2/n_lg14f56k776c2p35gktr000000gn/T/jl_8WDmZ0/Manifest.toml`
  [1914dd2f] MacroTools v0.5.6
  [33c8b6b6] ProgressLogging v0.1.4
  [c5292f4c] ResumableFunctions v0.6.0
  [2a0f44e3] Base64
  [56ddb016] Logging
  [d6f4376e] Markdown
  [9a3f8284] Random
  [ea8e919c] SHA
  [9e88b42a] Serialization
  [cf7118a7] UUIDs

mileslucas avatar Jul 12 '21 20:07 mileslucas

If I'm not mistaken, in the first attempt, it fails because @resumable takes for loops and converts them into a while loop. In the second attempt, nested @yield tend to fail with ResumableFunctions.jl. @resumable must be converting the begin block into some try/catch.

I agree, not much can be gleaned from the source code in this package.

hdavid16 avatar Jul 13 '22 14:07 hdavid16