diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 3f71a077..50bf2be8 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -36,10 +36,12 @@ jobs: matrix: runs-on: ["ubuntu-22.04"] otp: ["24.2", "25.0"] - elixir: ["1.13.0", "1.16.2", "1.17.2"] + elixir: ["1.14.0", "1.16.2", "1.17.2", "1.18.0"] exclude: - otp: "24.2" elixir: "1.17.2" + - otp: "24.2" + elixir: "1.18.0" include: - runs-on: "ubuntu-22.04" otp: "27.0.1" @@ -117,7 +119,7 @@ jobs: run: | mix test --force --only smoke - name: Check formatting of Elixir - if: matrix.elixir != '1.13.0' + if: matrix.elixir != '1.14.0' env: MIX_ENV: test run: | diff --git a/bench/enif_string_as_memref.ex b/bench/enif_string_as_memref.ex index a65770e4..d919c3dc 100644 --- a/bench/enif_string_as_memref.ex +++ b/bench/enif_string_as_memref.ex @@ -72,17 +72,12 @@ defmodule ENIFStringAsMemRef do term_ptr = LLVM.alloca(one, elem_type: ENIF.Type.term()) >>> ~t{!llvm.ptr} d_ptr = ENIF.make_new_binary(env, size, term_ptr) >>> :infer m = ENIF.ptr_to_memref(d_ptr, size) >>> :infer - loc = m |> MLIR.Value.owner!() |> MLIR.Operation.location() |> MLIR.to_string() MemRef.copy(msg, m) >>> [] msg = LLVM.load(term_ptr) >>> ENIF.Type.term() e = ENIF.raise_exception(env, msg) >>> [] Func.return(e) >>> [] end - unless loc =~ __ENV__.file do - raise "wrong location" - end - block successor() do b = LLVM.load(b_ptr) >>> ENIF.Type.binary() size = LLVM.extractvalue(b, position: ~a{array}) >>> Type.i64() diff --git a/lib/beaver/enif.ex b/lib/beaver/enif.ex index 0c58d6c6..22466ba0 100644 --- a/lib/beaver/enif.ex +++ b/lib/beaver/enif.ex @@ -38,8 +38,8 @@ defmodule Beaver.ENIF do @doc """ Retrieve the signatures of all available ENIF functions. """ - def signatures(%MLIR.Context{} = ctx) do - signatures = MLIR.CAPI.beaver_raw_enif_signatures(ctx.ref) + def signatures(%MLIR.Context{ref: ref}) do + signatures = MLIR.CAPI.beaver_raw_enif_signatures(ref) for {name, arg_types, ret_types} <- signatures do {name, Enum.map(arg_types, &wrap_mlir_t/1), Enum.map(ret_types, &wrap_mlir_t/1)} diff --git a/lib/beaver/mlir/block.ex b/lib/beaver/mlir/block.ex index 2df61983..4f125790 100644 --- a/lib/beaver/mlir/block.ex +++ b/lib/beaver/mlir/block.ex @@ -50,7 +50,7 @@ defmodule Beaver.MLIR.Block do _ -> nil end) - unless ctx do + if !ctx do raise "Requires MLIR Context to add arguments. Otherwise, use types or locations already created." end diff --git a/lib/beaver/mlir/capi.ex b/lib/beaver/mlir/capi.ex index 52ca69ab..abf5c200 100644 --- a/lib/beaver/mlir/capi.ex +++ b/lib/beaver/mlir/capi.ex @@ -46,12 +46,12 @@ defmodule Beaver.MLIR.CAPI do _op_name, _handler ), - do: raise("NIF not loaded") + do: :erlang.nif_error(:not_loaded) - def beaver_raw_logical_mutex_token_signal_success(_), do: raise("NIF not loaded") - def beaver_raw_logical_mutex_token_signal_failure(_), do: raise("NIF not loaded") - def beaver_raw_registered_ops(_ctx), do: raise("NIF not loaded") - def beaver_raw_registered_dialects(_ctx), do: raise("NIF not loaded") + def beaver_raw_logical_mutex_token_signal_success(_), do: :erlang.nif_error(:not_loaded) + def beaver_raw_logical_mutex_token_signal_failure(_), do: :erlang.nif_error(:not_loaded) + def beaver_raw_registered_ops(_ctx), do: :erlang.nif_error(:not_loaded) + def beaver_raw_registered_dialects(_ctx), do: :erlang.nif_error(:not_loaded) for f <- ~w{ StringRef @@ -69,21 +69,27 @@ defmodule Beaver.MLIR.CAPI do Diagnostic } do f = :"beaver_raw_to_string_#{f}" - def unquote(f)(_), do: raise("NIF not loaded") + def unquote(f)(_), do: :erlang.nif_error(:not_loaded) + {f, 1} end - def beaver_raw_get_string_ref(_), do: raise("NIF not loaded") - def beaver_raw_read_opaque_ptr(_, _), do: raise("NIF not loaded") - def beaver_raw_deallocate_opaque_ptr(_), do: raise("NIF not loaded") - def beaver_raw_get_null_ptr(), do: raise("NIF not loaded") - def beaver_raw_context_attach_diagnostic_handler(_, _), do: raise("NIF not loaded") - def beaver_raw_jit_invoke_with_terms(_jit, _name, _args), do: raise("NIF not loaded") - def beaver_raw_jit_invoke_with_terms_cpu_bound(_jit, _name, _args), do: raise("NIF not loaded") - def beaver_raw_jit_invoke_with_terms_io_bound(_jit, _name, _args), do: raise("NIF not loaded") - def beaver_raw_jit_register_enif(_jit), do: raise("NIF not loaded") - def beaver_raw_enif_signatures(_ctx), do: raise("NIF not loaded") - def beaver_raw_enif_functions(), do: raise("NIF not loaded") - def beaver_raw_mlir_type_of_enif_obj(_ctx, _obj), do: raise("NIF not loaded") - def beaver_raw_string_printer_callback(), do: raise("NIF not loaded") - def beaver_raw_string_printer_flush(_sp), do: raise("NIF not loaded") + def beaver_raw_get_string_ref(_), do: :erlang.nif_error(:not_loaded) + def beaver_raw_read_opaque_ptr(_, _), do: :erlang.nif_error(:not_loaded) + def beaver_raw_deallocate_opaque_ptr(_), do: :erlang.nif_error(:not_loaded) + def beaver_raw_get_null_ptr(), do: :erlang.nif_error(:not_loaded) + def beaver_raw_context_attach_diagnostic_handler(_, _), do: :erlang.nif_error(:not_loaded) + def beaver_raw_jit_invoke_with_terms(_jit, _name, _args), do: :erlang.nif_error(:not_loaded) + + def beaver_raw_jit_invoke_with_terms_cpu_bound(_jit, _name, _args), + do: :erlang.nif_error(:not_loaded) + + def beaver_raw_jit_invoke_with_terms_io_bound(_jit, _name, _args), + do: :erlang.nif_error(:not_loaded) + + def beaver_raw_jit_register_enif(_jit), do: :erlang.nif_error(:not_loaded) + def beaver_raw_enif_signatures(_ctx), do: :erlang.nif_error(:not_loaded) + def beaver_raw_enif_functions(), do: :erlang.nif_error(:not_loaded) + def beaver_raw_mlir_type_of_enif_obj(_ctx, _obj), do: :erlang.nif_error(:not_loaded) + def beaver_raw_string_printer_callback(), do: :erlang.nif_error(:not_loaded) + def beaver_raw_string_printer_flush(_sp), do: :erlang.nif_error(:not_loaded) end diff --git a/lib/beaver/walker.ex b/lib/beaver/walker.ex index 7621b6c4..8f8f4974 100644 --- a/lib/beaver/walker.ex +++ b/lib/beaver/walker.ex @@ -615,10 +615,8 @@ defmodule Beaver.Walker do case count(walker) do {:ok, count} -> {:ok, count, - fn start, length -> - pos_range = start..(start + length - 1) - - for pos <- pos_range do + fn start, length, step -> + for pos <- start..(start + length - 1)//step do get_element.(container, pos) end end} diff --git a/mix.exs b/mix.exs index 5d8b54bc..8d4213ca 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule Beaver.MixProject do [ app: :beaver, version: "0.4.1-dev", - elixir: "~> 1.12", + elixir: "~> 1.14", start_permanent: Mix.env() == :prod, elixirc_paths: elixirc_paths(Mix.env()), deps: deps(), diff --git a/mix.lock b/mix.lock index 644e193e..ea56f306 100644 --- a/mix.lock +++ b/mix.lock @@ -8,9 +8,9 @@ "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"}, "file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, - "kinda": {:hex, :kinda, "0.9.3", "936e1e7a6e54943b078366319af4de4cce5f2ff2a9462e03187fcf762278f93c", [:mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "6661b01420625474ebe1cbb592e8ea450d6434943c6c04800183ccee62fbfbd7"}, + "kinda": {:hex, :kinda, "0.9.4", "007e25491bcd3af8a95e0179d9044362dc336920bbe5dbd6515196a5e938b201", [:mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "a5ec71839edf88e52f3e68a2c2210b9a9a00ee414ff369e9801b1184b3844447"}, "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"}, "statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"}, diff --git a/test/block_test.exs b/test/block_test.exs index 0469125d..83a5c012 100644 --- a/test/block_test.exs +++ b/test/block_test.exs @@ -115,34 +115,41 @@ defmodule BlockTest do "branch has 1 operands for successor" end - describe "insert block to region" do - for action <- [:insert, :append] do - test "appending #{action}", %{ctx: ctx, diagnostic_server: diagnostic_server} do - mlir ctx: ctx do - module do - Func.func some_func(function_type: Type.function([], [Type.i(32)])) do - b = - block do - end - - region do - block do - v0 = Arith.constant(value: Attribute.integer(Type.i(32), 0)) >>> Type.i(32) - Func.return(v0) >>> [] - end - - case unquote(action) do - :append -> - MLIR.Region.append(Beaver.Env.region(), b) - - :insert -> - MLIR.Region.insert(Beaver.Env.region(), 1, b) - end + defmodule BlockHelper do + def create_ir_by_action(ctx, action) do + mlir ctx: ctx do + module do + Func.func some_func(function_type: Type.function([], [Type.i(32)])) do + b = + block do + end + + region do + block do + v0 = Arith.constant(value: Attribute.integer(Type.i(32), 0)) >>> Type.i(32) + Func.return(v0) >>> [] + end + + case action do + :append -> + MLIR.Region.append(Beaver.Env.region(), b) + + :insert -> + MLIR.Region.insert(Beaver.Env.region(), 1, b) end end end end - |> MLIR.verify() + end + |> MLIR.verify() + end + end + + @moduledoc false + describe "insert block to region" do + for action <- [:insert, :append] do + test "appending #{action}", %{ctx: ctx, diagnostic_server: diagnostic_server} do + BlockHelper.create_ir_by_action(ctx, unquote(action)) assert Beaver.Capturer.collect(diagnostic_server) =~ "expect at least a terminator"