Skip to content
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

Fix warning for Elixir 1.18 #36

Merged
merged 8 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ jobs:
matrix:
runs-on: ["ubuntu-latest"]
otp: ["24.2", "25.0"]
elixir: ["1.13.0", "1.16.2"]
elixir: ["1.13.0", "1.16.2", "1.18.0"]
exclude:
- otp: "24.2"
elixir: "1.18.0"
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
Expand All @@ -49,12 +52,17 @@ jobs:
restore-keys: ${{ runner.os }}-mix-example-
- name: Install dependencies
run: mix deps.get
- name: Check formatting of Elixir
run: mix format --check-formatted
- name: Run tests
run: |
mix test
- name: Install dependencies (example)
working-directory: ./kinda_example
run: mix deps.get
- name: Check formatting of Elixir
working-directory: ./kinda_example
run: mix format --check-formatted
- name: Run tests (example)
working-directory: ./kinda_example
run: |
Expand Down
6 changes: 4 additions & 2 deletions kinda_example/lib/kinda_example_nif.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule KindaExample.NIF do
use Kinda.CodeGen, with: KindaExample.CodeGen, root: __MODULE__, forward: KindaExample.Native

@nifs use Kinda.CodeGen,
with: KindaExample.CodeGen,
root: __MODULE__,
forward: KindaExample.Native
defmodule CInt do
use Kinda.ResourceKind, forward_module: KindaExample.Native
end
Expand Down
37 changes: 22 additions & 15 deletions lib/kinda_codegen.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ defmodule Kinda.CodeGen do
mod = Keyword.fetch!(unquote(opts), :with)
root = Keyword.fetch!(unquote(opts), :root)
forward = Keyword.fetch!(unquote(opts), :forward)

Kinda.CodeGen.nif_ast(mod.kinds(), mod.nifs(), root, forward)
|> then(&Module.eval_quoted(__MODULE__, &1))
{ast, mf} = Kinda.CodeGen.nif_ast(mod.kinds(), mod.nifs(), root, forward)
ast |> Code.eval_quoted([], __ENV__)
mf
end
end

Expand All @@ -27,7 +27,9 @@ defmodule Kinda.CodeGen do
|> Enum.map(&NIFDecl.from_resource_kind/1)
|> List.flatten()

for nif <- nifs ++ extra_kind_nifs do
nifs = nifs ++ extra_kind_nifs

for nif <- nifs do
nif =
case nif do
{wrapper_name, arity} when is_atom(wrapper_name) and is_integer(arity) ->
Expand All @@ -43,7 +45,7 @@ defmodule Kinda.CodeGen do

args_ast = Macro.generate_unique_arguments(nif.arity, __MODULE__)

%NIFDecl{wrapper_name: wrapper_name, nif_name: nif_name} = nif
%NIFDecl{wrapper_name: wrapper_name, nif_name: nif_name, arity: arity} = nif

wrapper_name =
if is_bitstring(wrapper_name) do
Expand All @@ -52,21 +54,26 @@ defmodule Kinda.CodeGen do
wrapper_name
end

wrapper_ast =
if nif_name != wrapper_name do
quote do
def unquote(wrapper_name)(unquote_splicing(args_ast)) do
refs = Kinda.unwrap_ref([unquote_splicing(args_ast)])
ret = apply(__MODULE__, unquote(nif_name), refs)
unquote(forward_module).check!(ret)
end
end
end

quote do
@doc false
def unquote(nif_name)(unquote_splicing(args_ast)),
do:
raise(
"NIF for resource kind is not implemented, or failed to load NIF library. Function: :\"#{unquote(nif_name)}\"/#{unquote(nif.arity)}"
)
do: :erlang.nif_error(:not_loaded)

def unquote(wrapper_name)(unquote_splicing(args_ast)) do
refs = Kinda.unwrap_ref([unquote_splicing(args_ast)])
ret = apply(__MODULE__, unquote(nif_name), refs)
unquote(forward_module).check!(ret)
end
unquote(wrapper_ast)
end
|> then(&{&1, {nif_name, arity}})
end
|> List.flatten()
|> Enum.unzip()
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Kinda.MixProject do
def project do
[
app: :kinda,
version: "0.9.4-dev",
version: "0.9.5-dev",
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"},
"ex_doc": {:hex, :ex_doc, "0.35.1", "de804c590d3df2d9d5b8aec77d758b00c814b356119b3d4455e4b8a8687aecaf", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "2121c6402c8d44b05622677b761371a759143b958c6c19f6558ff64d0aed40df"},
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
"makeup_elixir": {:hex, :makeup_elixir, "1.0.0", "74bb8348c9b3a51d5c589bf5aebb0466a84b33274150e3b6ece1da45584afc82", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "49159b7d7d999e836bedaf09dcf35ca18b312230cf901b725a64f3f42e407983"},
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
}
Loading