Skip to content

Commit 6b03c85

Browse files
committed
Support Elixir 1.18 (#849)
1.18 support. Updated elixir_sense to support 1.18. Noticed some slowdowns pertaining to the version checks we do internally, so I cached them in persistent_term, since the erlang or elixir versions can't change while the VM is running. Co-authored-by: scohen <scohen@users.noreply.github.com>
1 parent d0f3d1c commit 6b03c85

File tree

26 files changed

+524
-461
lines changed

26 files changed

+524
-461
lines changed

.github/workflows/elixir.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ jobs:
154154
# and running the workflow steps.
155155
matrix:
156156
include:
157+
- elixir: "1.18.1"
158+
otp: "27"
159+
- elixir: "1.18.1"
160+
otp: "26"
157161
- elixir: "1.17"
158162
otp: "27"
159163
- elixir: "1.17"

apps/common/lib/elixir/features.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ defmodule Elixir.Features do
66
end
77

88
def compile_keeps_current_directory? do
9-
Version.match?(System.version(), ">= 1.15.0")
9+
Versions.current_elixir_matches?(">= 1.15.0")
1010
end
1111

1212
def after_verify? do
13-
Version.match?(System.version(), ">= 1.14.0")
13+
Versions.current_elixir_matches?(">= 1.14.0")
1414
end
1515

1616
def details_in_context? do
17-
Version.match?(System.version(), ">= 1.16.0")
17+
Versions.current_elixir_matches?(">= 1.16.0")
1818
end
1919

2020
def span_in_diagnostic? do
21-
Version.match?(System.version(), ">= 1.16.0")
21+
Versions.current_elixir_matches?(">= 1.16.0")
2222
end
2323

2424
def contains_set_theoretic_types? do
25-
Version.match?(System.version(), ">= 1.17.0")
25+
Versions.current_elixir_matches?(">= 1.17.0")
2626
end
2727

2828
@doc """

apps/common/lib/lexical/vm/versions.ex

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ defmodule Lexical.VM.Versions do
1616
@type t :: %{elixir: version_string(), erlang: version_string()}
1717
@type versioned_t :: %{elixir: Version.t(), erlang: Version.t()}
1818

19+
defmacrop cache_in_persistent_term(key, do: materializer) do
20+
quote do
21+
with :not_found <- :persistent_term.get(unquote(key), :not_found) do
22+
result = unquote(materializer)
23+
:persistent_term.put(unquote(key), result)
24+
result
25+
end
26+
end
27+
end
28+
1929
@doc """
2030
Returns the versions of elixir and erlang in the currently running VM
2131
"""
@@ -27,6 +37,15 @@ defmodule Lexical.VM.Versions do
2737
}
2838
end
2939

40+
@doc """
41+
Returns true if the current version of elixir matches the requirement
42+
"""
43+
def current_elixir_matches?(requirement) do
44+
cache_in_persistent_term {:current_elixir_matches?, requirement} do
45+
Version.match?(elixir_version(), requirement)
46+
end
47+
end
48+
3049
@doc """
3150
Returns the compiled-in versions of elixir and erlang.
3251
@@ -138,32 +157,26 @@ defmodule Lexical.VM.Versions do
138157
end
139158

140159
defp elixir_version do
141-
System.version()
160+
cache_in_persistent_term {__MODULE__, :current_elixir} do
161+
System.version()
162+
end
142163
end
143164

144165
defp erlang_version do
145-
case :persistent_term.get({__MODULE__, :current_erlang}, :not_found) do
146-
:not_found ->
147-
major = :otp_release |> :erlang.system_info() |> List.to_string()
148-
version_file = Path.join([:code.root_dir(), "releases", major, "OTP_VERSION"])
149-
150-
erlang_version =
151-
try do
152-
{:ok, contents} = read_file(version_file)
153-
String.split(contents, "\n", trim: true)
154-
else
155-
[full] -> full
156-
_ -> major
157-
catch
158-
:error ->
159-
major
160-
end
161-
162-
:persistent_term.put({__MODULE__, :current_erlang}, erlang_version)
163-
erlang_version()
164-
165-
erlang_version ->
166-
erlang_version
166+
cache_in_persistent_term {__MODULE__, :current_erlang} do
167+
major = :otp_release |> :erlang.system_info() |> List.to_string()
168+
version_file = Path.join([:code.root_dir(), "releases", major, "OTP_VERSION"])
169+
170+
try do
171+
{:ok, contents} = read_file(version_file)
172+
String.split(contents, "\n", trim: true)
173+
else
174+
[full] -> full
175+
_ -> major
176+
catch
177+
:error ->
178+
major
179+
end
167180
end
168181
end
169182

apps/common/mix.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ defmodule Common.MixProject do
3636
{:lexical_shared, path: "../../projects/lexical_shared"},
3737
{:lexical_test, path: "../../projects/lexical_test", only: :test},
3838
{:snowflake, "~> 1.0"},
39-
{:sourceror, "~> 1.4"},
40-
{:stream_data, "~> 0.6", only: [:test], runtime: false},
41-
{:patch, "~> 0.12", only: [:test], optional: true, runtime: false}
39+
{:sourceror, "~> 1.7"},
40+
{:stream_data, "~> 1.1", only: [:test], runtime: false},
41+
{:patch, "~> 0.15", only: [:test], optional: true, runtime: false}
4242
]
4343
end
4444
end

apps/common/test/lexical/math_test.exs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ defmodule Lexical.MathTest do
2828
end
2929

3030
property "clamp works with all integers" do
31-
check all(
32-
ints <- uniq_list_of(integer(-100_000..100_000), min_length: 5, max_length: 20),
33-
[low, mid, high] = low_mid_high(ints)
34-
) do
31+
check all(ints <- uniq_list_of(integer(-100_000..100_000), min_length: 5, max_length: 20)) do
32+
[low, mid, high] = low_mid_high(ints)
3533
assert Math.clamp(mid, low, high) == mid
3634
assert Math.clamp(low, mid, high) == mid
3735
assert Math.clamp(high, low, mid) == mid

apps/protocol/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defmodule Lexical.Protocol.MixProject do
3434
{:lexical_test, path: "../../projects/lexical_test", only: :test},
3535
{:common, in_umbrella: true},
3636
{:jason, "~> 1.4", optional: true},
37-
{:patch, "~> 0.12", only: [:test]},
37+
{:patch, "~> 0.15", only: [:test]},
3838
{:proto, in_umbrella: true}
3939
]
4040
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
alias Lexical.VM.Versions
2+
3+
Benchee.run(%{
4+
"versions" => fn ->
5+
Version.match?(Versions.current().elixir, ">=1.15.0")
6+
end,
7+
"current_versions_matches" => fn ->
8+
Versions.current_elixir_matches?(">=1.15.0")
9+
end
10+
})

0 commit comments

Comments
 (0)