Skip to content

Fix escape rgx_map for Otp 28#514

Closed
bopm wants to merge 1 commit intopragdave:masterfrom
bopm:fix/otp-28
Closed

Fix escape rgx_map for Otp 28#514
bopm wants to merge 1 commit intopragdave:masterfrom
bopm:fix/otp-28

Conversation

@bopm
Copy link
Copy Markdown

@bopm bopm commented Jun 5, 2025

On Elixir 1.18.4 with Erlang/OTP 28 project fails to compile:

== Compilation error in file lib/earmark_parser/line_scanner.ex ==
** (ArgumentError) cannot inject attribute @rgx_map into function/macro because cannot escape #Reference<0.983345734.4272029698.15857>. The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, PIDs and remote functions in the format &Mod.fun/arity
    (elixir 1.18.4) lib/kernel.ex:3777: Kernel.do_at_escape/2
    (elixir 1.18.4) expanding macro: Kernel.@/1
    lib/earmark_parser/line_scanner.ex:334: Earmark.Parser.LineScanner.regex_run/3
    (elixir 1.18.4) expanding macro: Kernel.|>/2
    lib/earmark_parser/line_scanner.ex:335: Earmark.Parser.LineScanner.regex_run/3
    (elixir 1.18.4) expanding macro: Kernel.|>/2
    lib/earmark_parser/line_scanner.ex:336: Earmark.Parser.LineScanner.regex_run/3
could not compile dependency :earmark, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile earmark --force", update it with "mix deps.update earmark" or clean it with "mix deps.clean earmark"

This issue is similar to this and this.
This PR fixes that.

@walkr
Copy link
Copy Markdown

walkr commented Jun 6, 2025

I propose defp rgx_map be replaced by a private macro. It's faster since it avoids a function call (which might make a difference in tight loops):

defmacrop rgx_macro do
  quote do
   # ...
  end 
end

@walkr
Copy link
Copy Markdown

walkr commented Jun 6, 2025

Never mind, I've just run some benchmarks, and it appears that in this scenario the difference between the macro and the function is negligible.

@adamu
Copy link
Copy Markdown
Contributor

adamu commented Jun 19, 2025

I believe this is a subset of the changes from #512 that was opened in March.

@bopm bopm closed this Jun 20, 2025
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

Successfully merging this pull request may close these issues.

4 participants