Skip to content

Commit

Permalink
docs: Fix several PyLance issues (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas authored Jan 31, 2023
1 parent 754bc80 commit 62cb4d4
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 118 deletions.
3 changes: 2 additions & 1 deletion tests/test_frontend_op_inserter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def test_raises_exception_on_op_with_no_regions():
op_with_no_region = Constant.from_int_and_width(1, i32)
with pytest.raises(FrontendProgramException) as err:
inserter.set_insertion_point_from_op(op_with_no_region)
assert err.value.msg == "Trying to set the insertion point for operation 'arith.constant' with no regions."
assert err.value.msg == ("Trying to set the insertion point for operation "
"'arith.constant' with no regions.")


def test_raises_exception_on_op_with_no_blocks():
Expand Down
2 changes: 0 additions & 2 deletions tests/test_rewriter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from io import StringIO
from typing import Callable
from conftest import assert_print_op

Expand All @@ -8,7 +7,6 @@
from xdsl.dialects.func import Func
from xdsl.ir import MLContext, Block
from xdsl.parser import Parser
from xdsl.printer import Printer
from xdsl.rewriter import Rewriter


Expand Down
51 changes: 38 additions & 13 deletions tests/test_ssa_value.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
from io import StringIO
from typing import Callable

import pytest

from xdsl.dialects.arith import Arith, Constant, Addi
from xdsl.dialects.builtin import ModuleOp, Builtin, i32
from xdsl.dialects.scf import Scf, Yield
from xdsl.dialects.func import Func
from xdsl.ir import MLContext, Block, SSAValue, OpResult, BlockArgument
from xdsl.parser import Parser
from xdsl.printer import Printer
from xdsl.rewriter import Rewriter
from typing import Annotated

from xdsl.dialects.builtin import i32, StringAttr
from xdsl.dialects.arith import Constant

from xdsl.ir import Block, Operation, OpResult, BlockArgument
from xdsl.irdl import irdl_op_definition


def test_ssa():
a = OpResult(i32, [], [])
c = Constant.from_int_and_width(1, i32)

with pytest.raises(TypeError):
_ = a.get([c])

b0 = Block.from_ops([c])
with pytest.raises(TypeError):
_ = a.get(b0)


@irdl_op_definition
class TwoResultOp(Operation):
name: str = "test.tworesults"

res1: Annotated[OpResult, StringAttr]
res2: Annotated[OpResult, StringAttr]


def test_var_mixed_builder():
op = TwoResultOp.build(result_types=[0, 2])
b = OpResult(i32, [], [])

with pytest.raises(ValueError):
_ = b.get(op)


@pytest.mark.parametrize("name,result", [
Expand All @@ -21,8 +45,9 @@
])
def test_ssa_value_name_hints(name, result):
"""
The rewriter assumes, that ssa value name hints (their .name field) does not end in a numeric value. If it does,
it will generate broken rewrites that potentially assign twice to an SSA value.
The rewriter assumes, that ssa value name hints (their .name field) does not end in
a numeric value. If it does, it will generate broken rewrites that potentially assign
twice to an SSA value.
Therefore, the SSAValue class prevents the setting of names ending in a number.
"""
Expand Down
37 changes: 0 additions & 37 deletions tests/test_ssavalue.py

This file was deleted.

1 change: 1 addition & 0 deletions xdsl/dialects/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class SignednessAttr(Data[Signedness]):

@staticmethod
def parse_parameter(parser: BaseParser) -> Signedness:
# Is this ever used? TOADD tests?
if parser.parse_optional_string("signless") is not None:
return Signedness.SIGNLESS
elif parser.parse_optional_string("signed") is not None:
Expand Down
26 changes: 15 additions & 11 deletions xdsl/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from frozenlist import FrozenList
from io import StringIO
from typing import (TYPE_CHECKING, Any, Callable, Generic, Optional, Protocol,
Sequence, TypeVar, cast, Iterator, Union, ClassVar)
Sequence, TypeVar, cast, Iterator, ClassVar)
import sys

# Used for cyclic dependencies in type hints
if TYPE_CHECKING:
from xdsl.parser import Parser, BaseParser
from xdsl.parser import BaseParser
from xdsl.printer import Printer
from xdsl.irdl import OpDef, ParamAttrDef

Expand All @@ -38,7 +38,8 @@ def attributes(self) -> Iterator[type[Attribute]]:

def __call__(self, ctx: MLContext) -> None:
print(
"Calling a dialect in order to register it is deprecated and will soon be removed.",
"Calling a dialect in order to register it is deprecated "
"and will soon be removed.",
file=sys.stderr)
# TODO; Remove this function in a future release.
assert isinstance(ctx, MLContext)
Expand Down Expand Up @@ -585,8 +586,9 @@ def is_structurally_equivalent(
context: Optional[dict[IRNode, IRNode]] = None) -> bool:
"""
Check if two operations are structurally equivalent.
The context is a mapping of IR nodes to IR nodes that are already known to be equivalent.
This enables checking whether the use dependencies and successors are equivalent.
The context is a mapping of IR nodes to IR nodes that are already known "
"to be equivalent. This enables checking whether the use dependencies and "
"successors are equivalent.
"""
if context is None:
context = {}
Expand All @@ -598,7 +600,7 @@ def is_structurally_equivalent(
len(self.results) != len(other.results) or \
len(self.regions) != len(other.regions) or \
len(self.successors) != len(other.successors) or \
self.attributes != other.attributes:
self.attributes != other.attributes:
return False
if self.parent and other.parent and context.get(
self.parent) != other.parent:
Expand Down Expand Up @@ -853,15 +855,16 @@ def is_structurally_equivalent(
context: Optional[dict[IRNode, IRNode]] = None) -> bool:
"""
Check if two blocks are structurally equivalent.
The context is a mapping of IR nodes to IR nodes that are already known to be equivalent.
This enables checking whether the use dependencies and successors are equivalent.
The context is a mapping of IR nodes to IR nodes that are already known "
"to be equivalent. This enables checking whether the use dependencies and "
"successors are equivalent.
"""
if context is None:
context = {}
if not isinstance(other, Block):
return False
if len(self.args) != len(other.args) or \
len(self.ops) != len(other.ops):
len(self.ops) != len(other.ops):
return False
for arg, other_arg in zip(self.args, other.args):
if arg.typ != other_arg.typ:
Expand Down Expand Up @@ -1088,8 +1091,9 @@ def is_structurally_equivalent(
context: Optional[dict[IRNode, IRNode]] = None) -> bool:
"""
Check if two regions are structurally equivalent.
The context is a mapping of IR nodes to IR nodes that are already known to be equivalent.
This enables checking whether the use dependencies and successors are equivalent.
The context is a mapping of IR nodes to IR nodes that are already known "
"to be equivalent. This enables checking whether the use dependencies and "
"successors are equivalent.
"""
if context is None:
context = {}
Expand Down
Loading

0 comments on commit 62cb4d4

Please sign in to comment.