Skip to content

Commit

Permalink
Remove location macro from Beaver.Env module (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackalcooper authored Feb 13, 2024
1 parent c1a7165 commit f6932ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
16 changes: 0 additions & 16 deletions lib/beaver/dsl/env.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,4 @@ defmodule Beaver.Env do
end
end
end

@doc """
Create location from caller in the Elixir source
"""
defmacro location() do
file = __CALLER__.file
line = __CALLER__.line

quote do
Beaver.MLIR.Location.file(
name: unquote(file),
line: unquote(line),
ctx: Beaver.Env.context()
)
end
end
end
8 changes: 8 additions & 0 deletions lib/beaver/mlir/location.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ defmodule Beaver.MLIR.Location do
)
end

@doc """
Create an MLIR location from `Macro.Env`
"""
def from_env(env, opts \\ []) do
loc = Macro.Env.location(env)
file([name: loc[:file], line: loc[:line]] ++ opts)
end

def unknown(opts \\ []) do
Beaver.Deferred.from_opts(opts, &CAPI.mlirLocationUnknownGet/1)
end
Expand Down
4 changes: 2 additions & 2 deletions test/env_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ defmodule EnvTest do

test "location", test_context do
mlir ctx: test_context[:ctx] do
loc = %MLIR.Location{} = Beaver.Env.location()
assert loc |> MLIR.to_string() =~ ~r{env_test.exs:\d+:\d+}
loc = %MLIR.Location{} = MLIR.Location.from_env(__ENV__, ctx: Beaver.Env.context())
assert loc |> MLIR.to_string() =~ ~r{env_test.exs:\d+:0}
end
end
end

0 comments on commit f6932ff

Please sign in to comment.