Skip to content

Commit e3599fc

Browse files
committed
Do not precompile regexes on Erlang/OTP 28
1 parent b077989 commit e3599fc

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6471,29 +6471,37 @@ defmodule Kernel do
64716471
"""
64726472
defmacro sigil_r(term, modifiers)
64736473

6474-
defmacro sigil_r({:<<>>, _meta, [string]}, options) when is_binary(string) do
6475-
binary = :elixir_interpolation.unescape_string(string, &regex_unescape_map/1)
6476-
regex = Regex.compile!(binary, :binary.list_to_bin(options))
6477-
Macro.escape(regex)
6474+
defmacro sigil_r({:<<>>, _meta, [binary]}, options) when is_binary(binary) do
6475+
binary = :elixir_interpolation.unescape_string(binary, &regex_unescape_map/1)
6476+
compile_regex(binary, options)
64786477
end
64796478

64806479
defmacro sigil_r({:<<>>, meta, pieces}, options) do
6481-
binary = {:<<>>, meta, unescape_tokens(pieces, &regex_unescape_map/1)}
6482-
quote(do: Regex.compile!(unquote(binary), unquote(:binary.list_to_bin(options))))
6480+
tuple = {:<<>>, meta, unescape_tokens(pieces, &regex_unescape_map/1)}
6481+
compile_regex(tuple, options)
64836482
end
64846483

64856484
defp regex_unescape_map(:newline), do: true
64866485
defp regex_unescape_map(_), do: false
64876486

64886487
@doc false
6489-
defmacro sigil_R({:<<>>, _meta, [string]}, options) when is_binary(string) do
6488+
defmacro sigil_R({:<<>>, _meta, [binary]}, options) when is_binary(binary) do
64906489
IO.warn(
64916490
"~R/.../ is deprecated, use ~r/.../ instead",
64926491
Macro.Env.stacktrace(__CALLER__)
64936492
)
64946493

6495-
regex = Regex.compile!(string, :binary.list_to_bin(options))
6496-
Macro.escape(regex)
6494+
compile_regex(binary, options)
6495+
end
6496+
6497+
defp compile_regex(binary_or_tuple, options) do
6498+
case is_binary(binary_or_tuple) and :erlang.system_info(:otp_release) < [?2, ?8] do
6499+
true ->
6500+
Macro.escape(Regex.compile!(binary_or_tuple, :binary.list_to_bin(options)))
6501+
6502+
false ->
6503+
quote(do: Regex.compile!(unquote(binary_or_tuple), unquote(:binary.list_to_bin(options))))
6504+
end
64976505
end
64986506

64996507
@doc ~S"""

lib/ex_unit/lib/ex_unit/doc_test.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ defmodule ExUnit.DocTest do
149149
suite run.
150150
"""
151151

152-
@opaque_type_regex ~r/#[\w\.]+</
153-
154152
defmodule Error do
155153
@moduledoc """
156154
Exception raised when there's an error with the syntax or semantics of a doctest.
@@ -554,7 +552,7 @@ defmodule ExUnit.DocTest do
554552
message = "Doctest did not compile, got: #{ex_message}"
555553

556554
message =
557-
if e.__struct__ == TokenMissingError and expr =~ @opaque_type_regex do
555+
if e.__struct__ == TokenMissingError and expr =~ ~r/#[\w\.]+</ do
558556
message <>
559557
"""
560558
\nIf you are planning to assert on the result of an iex> expression \

0 commit comments

Comments
 (0)