Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macro clashing with ProgressLogging.jl #54

Open
mileslucas opened this issue Jul 12, 2021 · 1 comment
Open

macro clashing with ProgressLogging.jl #54

mileslucas opened this issue Jul 12, 2021 · 1 comment

Comments

@mileslucas
Copy link

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
@hdavid16
Copy link
Member

hdavid16 commented Jul 13, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants