Skip to content

Commit

Permalink
Use Keyword.get in Context.create/1
Browse files Browse the repository at this point in the history
  • Loading branch information
jackalcooper committed Nov 8, 2024
1 parent b8e3fa6 commit aaeaa14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/beaver/mlir/context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ defmodule Beaver.MLIR.Context do

@type context_option :: {:allow_unregistered, boolean()} | {:all_dialects, boolean()}
@spec create(context_option()) :: __MODULE__.t()
@default_context_option [allow_unregistered: false, all_dialects: true]
@doc """
Create a MLIR context. By default it registers and loads all dialects.
"""
def create(opts \\ @default_context_option) do
allow_unregistered = opts[:allow_unregistered] || @default_context_option[:allow_unregistered]
all_dialects = opts[:all_dialects] || @default_context_option[:all_dialects]
def create(opts \\ []) do
allow_unregistered = Keyword.get(opts, :allow_unregistered, false)
all_dialects = Keyword.get(opts, :all_dialects, true)

mlirContextCreate()
|> tap(fn ctx -> if all_dialects, do: load_all_dialects(ctx) end)
Expand Down
File renamed without changes.
13 changes: 11 additions & 2 deletions test/load_ir_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ defmodule LoadIRTest do
use Beaver.Case, async: true
alias Beaver.MLIR
import Beaver.Sigils

@example "test/fixtures/br_example.mlir"
test "example from upstream with br", %{ctx: ctx} do
content = File.read!("test/br_example.mlir")
content = File.read!(@example)

~m"""
#{content}
""".(ctx)
|> MLIR.verify!()
end

test "generic form", %{ctx: ctx} do
use Beaver
txt = File.read!(@example)
txt = MLIR.Module.create(txt, ctx: ctx) |> MLIR.to_string(generic: true)
ctx = MLIR.Context.create(allow_unregistered: true, all_dialects: false)
assert MLIR.Module.create(txt, ctx: ctx) |> MLIR.to_string() =~ "function_type = ()"
ctx |> MLIR.Context.destroy()
end
end

0 comments on commit aaeaa14

Please sign in to comment.