diff --git a/pyproject.toml b/pyproject.toml index 85f01a6fda..2a677edd06 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -109,17 +109,19 @@ ignore = [ max-line-length = 300 [tool.ruff.lint.flake8-tidy-imports.banned-api] -"xdsl.parser.core".msg = "Use xdsl.parser instead." -"xdsl.parser.attribute_parser".msg = "Use xdsl.parser instead." -"xdsl.parser.affine_parser".msg = "Use xdsl.parser instead." +"xdsl.dialects.utils.fast_math".msg = "Use xdsl.dialects.utils instead" +"xdsl.dialects.utils.format".msg = "Use xdsl.dialects.utils instead" +"xdsl.ir.affine.affine_expr".msg = "Use xdsl.ir.affine instead" +"xdsl.ir.affine.affine_map".msg = "Use xdsl.ir.affine instead" +"xdsl.ir.affine.affine_set".msg = "Use xdsl.ir.affine instead" "xdsl.ir.core".msg = "Use xdsl.ir instead." +"xdsl.irdl.attributes".msg = "Use xdsl.irdl instead" "xdsl.irdl.common".msg = "Use xdsl.irdl instead" "xdsl.irdl.constraints".msg = "Use xdsl.irdl instead" -"xdsl.irdl.attributes".msg = "Use xdsl.irdl instead" "xdsl.irdl.operations".msg = "Use xdsl.irdl instead" -"xdsl.ir.affine.affine_expr".msg = "Use xdsl.ir.affine instead" -"xdsl.ir.affine.affine_map".msg = "Use xdsl.ir.affine instead" -"xdsl.ir.affine.affine_set".msg = "Use xdsl.ir.affine instead" +"xdsl.parser.affine_parser".msg = "Use xdsl.parser instead." +"xdsl.parser.attribute_parser".msg = "Use xdsl.parser instead." +"xdsl.parser.core".msg = "Use xdsl.parser instead." [tool.ruff.lint.per-file-ignores] diff --git a/xdsl/dialects/utils/__init__.py b/xdsl/dialects/utils/__init__.py new file mode 100644 index 0000000000..97cc7a2b6f --- /dev/null +++ b/xdsl/dialects/utils/__init__.py @@ -0,0 +1,4 @@ +# TID 251 enforces to not import from those +# We need to skip it here to allow importing from here instead. +from .fast_math import * # noqa: TID251 +from .format import * # noqa: TID251 diff --git a/xdsl/dialects/utils/fast_math.py b/xdsl/dialects/utils/fast_math.py new file mode 100644 index 0000000000..c12b8b5878 --- /dev/null +++ b/xdsl/dialects/utils/fast_math.py @@ -0,0 +1,29 @@ +from abc import ABC +from dataclasses import dataclass + +from xdsl.ir import BitEnumAttribute +from xdsl.utils.str_enum import StrEnum + + +class FastMathFlag(StrEnum): + """ + Values specifying fast math behaviour of an arithmetic operation. + """ + + REASSOC = "reassoc" + NO_NANS = "nnan" + NO_INFS = "ninf" + NO_SIGNED_ZEROS = "nsz" + ALLOW_RECIP = "arcp" + ALLOW_CONTRACT = "contract" + APPROX_FUNC = "afn" + + +@dataclass(frozen=True, init=False) +class FastMathAttrBase(BitEnumAttribute[FastMathFlag], ABC): + """ + Base class for attributes defining fast math behavior of arithmetic operations. + """ + + none_value = "none" + all_value = "fast" diff --git a/xdsl/dialects/utils.py b/xdsl/dialects/utils/format.py similarity index 93% rename from xdsl/dialects/utils.py rename to xdsl/dialects/utils/format.py index 5b5fb8b0f9..ae7965d213 100644 --- a/xdsl/dialects/utils.py +++ b/xdsl/dialects/utils/format.py @@ -1,6 +1,4 @@ -from abc import ABC from collections.abc import Iterable, Sequence -from dataclasses import dataclass from typing import Generic from xdsl.dialects.builtin import ( @@ -14,7 +12,6 @@ from xdsl.ir import ( Attribute, AttributeInvT, - BitEnumAttribute, BlockArgument, Operation, Region, @@ -23,7 +20,6 @@ from xdsl.irdl import IRDLOperation, var_operand_def from xdsl.parser import Parser, UnresolvedOperand from xdsl.printer import Printer -from xdsl.utils.str_enum import StrEnum def print_call_op_like( @@ -345,33 +341,3 @@ def parse_dynamic_index_list_without_types( values.append(value_or_index) return values, indices - - -# region Fast Math Flags - - -class FastMathFlag(StrEnum): - """ - Values specifying fast math behaviour of an arithmetic operation. - """ - - REASSOC = "reassoc" - NO_NANS = "nnan" - NO_INFS = "ninf" - NO_SIGNED_ZEROS = "nsz" - ALLOW_RECIP = "arcp" - ALLOW_CONTRACT = "contract" - APPROX_FUNC = "afn" - - -@dataclass(frozen=True, init=False) -class FastMathAttrBase(BitEnumAttribute[FastMathFlag], ABC): - """ - Base class for attributes defining fast math behavior of arithmetic operations. - """ - - none_value = "none" - all_value = "fast" - - -# endregion