Skip to content

Prepare for OTP 28 #512

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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
```
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.

1 participant