Skip to content

Use new OTP28.1 :re.import in escaped regex AST #14720

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sabiwara
Copy link
Contributor

@sabiwara sabiwara commented Aug 21, 2025

Take 2 for #14719.

Leverages :re.import added in erlang/otp#9976.

Here I went for Macro.escape rather than :elixir_expand, because :elixir_expand is harder to work with since we're already in AST land and the AST for a struct is hard to pattern-match on.

This works since Macro.escape is used in ~r, and also fixes the escaping issue discussed previously. But this is violating the assumption that escape emits AST for a literal, which is probably a no-go.

Will work on supporting the :export option separately since this is not strictly needed for this.

@josevalim
Copy link
Member

Notes to self: how we're going to check that the __escape__ function is defined?

  • function_exported? is not enough because there is no guarantee the struct module will be loaded. For example, module Bar.foo may do %Foo{} which is inlined as a map, so when calling Bar.foo, the Foo module is not loaded
  • Code.ensure_loaded? should be enough, however. If there is a struct, then definition its module is available
  • Code.ensure_compiled? is problematic, as it can lead to deadlocks in the compiler

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

Successfully merging this pull request may close these issues.

2 participants