Skip to content

Prepare for OTP 28#512

Merged
RobertDober merged 1 commit intopragdave:masterfrom
wojtekmach:wm-otp28
Jun 21, 2025
Merged

Prepare for OTP 28#512
RobertDober merged 1 commit intopragdave:masterfrom
wojtekmach:wm-otp28

Conversation

@wojtekmach
Copy link
Contributor

OTP 28 is using a new regexp engine, PCRE2. Prior to OTP 28, Erlang regexps were using a binary:

iex> ~r// |> Map.from_struct()
%{
  re_pattern: {:re_pattern, 0, 0, 0,
   <<69, 82, 67, 80, 71, 0, 0, 0, 0, 0, 0, 0, 1, 128, 0, 0, 255, 255, 255, 255,
     255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0,
     0, 0, ...>>},
  opts: [],
  source: "",
  re_version: {"8.44 2020-02-12", :little}
}

Now it's:

iex> ~r// |> Map.from_struct()
%{
  re_pattern: {:re_pattern, 0, 0, 0, #Reference<0.3488040677.452067330.62636>},
  opts: [],
  source: ""
}

Having reference as part of term is problematic, this now crashes during compilation:

defmodule Main do
  @regexp ~r//

  def main do
    @regexp
  end
end
** (ArgumentError) cannot inject attribute @regexp into function/macro because cannot escape #Reference<0.3597165861.3136946177.250217>. The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, PIDs and remote functions in the format &Mod.fun/arity

OTP 28 is using a new regexp engine, PCRE2. Prior to OTP 28, Erlang regexps were using a binary:

```elixir
iex> ~r// |> Map.from_struct()
%{
  re_pattern: {:re_pattern, 0, 0, 0,
   <<69, 82, 67, 80, 71, 0, 0, 0, 0, 0, 0, 0, 1, 128, 0, 0, 255, 255, 255, 255,
     255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0,
     0, 0, ...>>},
  opts: [],
  source: "",
  re_version: {"8.44 2020-02-12", :little}
}
```

Now it's:

```elixir
iex> ~r// |> Map.from_struct()
%{
  re_pattern: {:re_pattern, 0, 0, 0, #Reference<0.3488040677.452067330.62636>},
  opts: [],
  source: ""
}
```

Having reference as part of term is problematic, this now crashes during
compilation:

```elixir
defmodule Main do
  @regexp ~r//

  def main do
    @regexp
  end
end
```

```
** (ArgumentError) cannot inject attribute @regexp into function/macro because cannot escape #Reference<0.3597165861.3136946177.250217>. The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, PIDs and remote functions in the format &Mod.fun/arity
```
@mayel
Copy link

mayel commented May 22, 2025

Would be great if this can be merged and released now that OTP 28 is out 🙏

@RobertDober
Copy link
Collaborator

Sorry for the delay I guess I have to take care of Earmark again @amit-chaudhari1 are you still willing to maintain Earmark. There is absolutely no shame not to find the time, but it would be good to know.

@RobertDober RobertDober merged commit 0cc7032 into pragdave:master Jun 21, 2025
6 checks passed
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.

3 participants