Skip to content

Commit

Permalink
Merge branch 'main' into update-uv
Browse files Browse the repository at this point in the history
  • Loading branch information
superlopuh committed Dec 19, 2024
2 parents cc95819 + 0e1cec0 commit d2f4c63
Show file tree
Hide file tree
Showing 36 changed files with 1,172 additions and 291 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/update-bot.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/update-lockfile-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Update Lockfile Bot

on:
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
lock:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Set up Python
run: uv python install 3.12

- name: Install the package locally and update lockfile
run: |
# Install all default extras.
XDSL_VERSION_OVERRIDE="0+dynamic" make venv
- uses: EndBug/add-and-commit@v9
with:
add: uv.lock
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ COVERAGE_FILE ?= .coverage

# allow overriding the name of the venv directory
VENV_DIR ?= .venv
UV_PROJECT_ENVIRONMENT=${VENV_DIR}

# use activated venv if any
export UV_PROJECT_ENVIRONMENT=$(if $(VIRTUAL_ENV),$(VIRTUAL_ENV),$(VENV_DIR))

# allow overriding which extras are installed
VENV_EXTRAS ?= --extra gui --extra dev --extra jax --extra riscv
Expand Down
41 changes: 39 additions & 2 deletions tests/dialects/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@

from xdsl.builder import Builder, ImplicitBuilder
from xdsl.dialects.arith import AddiOp, ConstantOp
from xdsl.dialects.builtin import IntegerAttr, IntegerType, ModuleOp, i32, i64
from xdsl.dialects.builtin import (
IntegerAttr,
IntegerType,
ModuleOp,
StringAttr,
i32,
i64,
)
from xdsl.dialects.func import CallOp, FuncOp, ReturnOp
from xdsl.ir import Block, Region
from xdsl.traits import CallableOpInterface
from xdsl.irdl import (
IRDLOperation,
attr_def,
irdl_op_definition,
traits_def,
)
from xdsl.traits import CallableOpInterface, SymbolOpInterface
from xdsl.utils.exceptions import VerifyException


Expand Down Expand Up @@ -261,6 +274,30 @@ def test_call_II():
assert_print_op(mod, expected, None)


def test_call_III():
"""Call a symbol that is not func.func"""

@irdl_op_definition
class SymbolOp(IRDLOperation):
name = "test.symbol"

sym_name = attr_def(StringAttr)

traits = traits_def(SymbolOpInterface())

def __init__(self, name: str):
return super().__init__(attributes={"sym_name": StringAttr(name)})

symop = SymbolOp("foo")
call0 = CallOp("foo", [], [])
mod = ModuleOp([symop, call0])

with pytest.raises(
VerifyException, match="'@foo' does not reference a valid function"
):
mod.verify()


def test_return():
# Create two constants and add them, then return
a = ConstantOp.from_int_and_width(1, i32)
Expand Down
136 changes: 136 additions & 0 deletions tests/dialects/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
from xdsl.dialects.vector import (
BroadcastOp,
CreatemaskOp,
ExtractElementOp,
FMAOp,
InsertElementOp,
LoadOp,
MaskedloadOp,
MaskedstoreOp,
Expand Down Expand Up @@ -517,3 +519,137 @@ def test_vector_create_mask_verify_indexing_exception():
match="Expected an operand value for each dimension of resultant mask.",
):
create_mask.verify()


def test_vector_extract_element_verify_vector_rank_0_or_1():
vector_type = VectorType(IndexType(), [3, 3])

vector = TestSSAValue(vector_type)
position = TestSSAValue(IndexType())
extract_element = ExtractElementOp(vector, position)

with pytest.raises(Exception, match="Unexpected >1 vector rank."):
extract_element.verify()


def test_vector_extract_element_construction_1d():
vector_type = VectorType(IndexType(), [3])

vector = TestSSAValue(vector_type)
position = TestSSAValue(IndexType())

extract_element = ExtractElementOp(vector, position)

assert extract_element.vector is vector
assert extract_element.position is position
assert extract_element.result.type == vector_type.element_type


def test_vector_extract_element_1d_verify_non_empty_position():
vector_type = VectorType(IndexType(), [3])

vector = TestSSAValue(vector_type)

extract_element = ExtractElementOp(vector)

with pytest.raises(Exception, match="Expected position for 1-D vector."):
extract_element.verify()


def test_vector_extract_element_construction_0d():
vector_type = VectorType(IndexType(), [])

vector = TestSSAValue(vector_type)

extract_element = ExtractElementOp(vector)

assert extract_element.vector is vector
assert extract_element.position is None
assert extract_element.result.type == vector_type.element_type


def test_vector_extract_element_0d_verify_empty_position():
vector_type = VectorType(IndexType(), [])

vector = TestSSAValue(vector_type)
position = TestSSAValue(IndexType())

extract_element = ExtractElementOp(vector, position)

with pytest.raises(
Exception, match="Expected position to be empty with 0-D vector."
):
extract_element.verify()


def test_vector_insert_element_verify_vector_rank_0_or_1():
vector_type = VectorType(IndexType(), [3, 3])

source = TestSSAValue(IndexType())
dest = TestSSAValue(vector_type)
position = TestSSAValue(IndexType())

insert_element = InsertElementOp(source, dest, position)

with pytest.raises(Exception, match="Unexpected >1 vector rank."):
insert_element.verify()


def test_vector_insert_element_construction_1d():
vector_type = VectorType(IndexType(), [3])

source = TestSSAValue(IndexType())
dest = TestSSAValue(vector_type)
position = TestSSAValue(IndexType())

insert_element = InsertElementOp(source, dest, position)

assert insert_element.source is source
assert insert_element.dest is dest
assert insert_element.position is position
assert insert_element.result.type == vector_type


def test_vector_insert_element_1d_verify_non_empty_position():
vector_type = VectorType(IndexType(), [3])

source = TestSSAValue(IndexType())
dest = TestSSAValue(vector_type)

insert_element = InsertElementOp(source, dest)

with pytest.raises(
Exception,
match="Expected position for 1-D vector.",
):
insert_element.verify()


def test_vector_insert_element_construction_0d():
vector_type = VectorType(IndexType(), [])

source = TestSSAValue(IndexType())
dest = TestSSAValue(vector_type)

insert_element = InsertElementOp(source, dest)

assert insert_element.source is source
assert insert_element.dest is dest
assert insert_element.position is None
assert insert_element.result.type == vector_type


def test_vector_insert_element_0d_verify_empty_position():
vector_type = VectorType(IndexType(), [])

source = TestSSAValue(IndexType())
dest = TestSSAValue(vector_type)
position = TestSSAValue(IndexType())

insert_element = InsertElementOp(source, dest, position)

with pytest.raises(
Exception,
match="Expected position to be empty with 0-D vector.",
):
insert_element.verify()
10 changes: 10 additions & 0 deletions tests/filecheck/dialects/arith/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,13 @@ func.func @test_const_var_const() {
%9 = arith.cmpi uge, %int, %int : i32

"test.op"(%0, %1, %2, %3, %4, %5, %6, %7, %8, %9, %int) : (i1, i1, i1, i1, i1, i1, i1, i1, i1, i1, i32) -> ()

// Subtraction is not commutative so should not have the constant swapped to the right
// CHECK: arith.subi %c2, %a : i32
%10 = arith.subi %c2, %a : i32
"test.op"(%10) : (i32) -> ()

// CHECK: %{{.*}} = arith.constant false
%11 = arith.constant true
%12 = arith.addi %11, %11 : i1
"test.op"(%12) : (i1) -> ()
57 changes: 57 additions & 0 deletions tests/filecheck/dialects/func/func_invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,60 @@ builtin.module {

// CHECK: Operation does not verify: Unexpected nested symbols in FlatSymbolRefAttr
// CHECK-NEXT: Underlying verification failure: expected empty array, but got ["invalid"]

// -----

func.func @bar() {
%1 = "test.op"() : () -> !test.type<"int">
%2 = func.call @foo(%1) : (!test.type<"int">) -> !test.type<"int">
func.return
}

// CHECK: '@foo' could not be found in symbol table

// -----

func.func @foo(%0 : !test.type<"int">) -> !test.type<"int">

func.func @bar() {
%1 = func.call @foo() : () -> !test.type<"int">
func.return
}

// CHECK: incorrect number of operands for callee

// -----

func.func @foo(%0 : !test.type<"int">)

func.func @bar() {
%1 = "test.op"() : () -> !test.type<"int">
%2 = func.call @foo(%1) : (!test.type<"int">) -> !test.type<"int">
func.return
}

// CHECK: incorrect number of results for callee

// -----

func.func @foo(%0 : !test.type<"int">) -> !test.type<"int">

func.func @bar() {
%1 = "test.op"() : () -> !test.type<"foo">
%2 = func.call @foo(%1) : (!test.type<"foo">) -> !test.type<"int">
func.return
}

// CHECK: operand type mismatch: expected operand type !test.type<"int">, but provided !test.type<"foo"> for operand number 0

// -----

func.func @foo(%0 : !test.type<"int">) -> !test.type<"int">

func.func @bar() {
%1 = "test.op"() : () -> !test.type<"int">
%2 = func.call @foo(%1) : (!test.type<"int">) -> !test.type<"foo">
func.return
}

// CHECK: result type mismatch: expected result type !test.type<"int">, but provided !test.type<"foo"> for result number 0
21 changes: 20 additions & 1 deletion tests/filecheck/dialects/llvm/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,29 @@ builtin.module {
// CHECK: Varargs specifier `...` must be at the end of the argument definition

// -----
// CHECK: -----

builtin.module {
%cc = "test.op"() {"cconv" = #llvm.cconv<invalid>} : () -> ()
}

// CHECK: Unknown calling convention

// -----

func.func public @main() {
%0 = "test.op"() : () -> (!llvm.struct<(i32)>)
%1 = "llvm.extractvalue"(%0) {"position" = array<i32: 0>} : (!llvm.struct<(i32)>) -> i32
func.return
}

// CHECK: Expected attribute i64 but got i32

// -----

func.func public @main() {
%0, %1 = "test.op"() : () -> (!llvm.struct<(i32)>, i32)
%2 = "llvm.insertvalue"(%0, %1) {"position" = array<i32: 0>} : (!llvm.struct<(i32)>, i32) -> !llvm.struct<(i32)>
func.return
}

// CHECK: Expected attribute i64 but got i32
Loading

0 comments on commit d2f4c63

Please sign in to comment.