Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: split dialects.utils into multiple files #3472

Merged
merged 8 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pyproject.toml
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorted this list

Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions xdsl/dialects/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions xdsl/dialects/utils/fast_math.py
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 0 additions & 34 deletions xdsl/dialects/utils.py → xdsl/dialects/utils/format.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from abc import ABC
from collections.abc import Iterable, Sequence
from dataclasses import dataclass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if format is really the best name to characterise these helpers. Have you thought about further splitting them into printer utils and parsing utils?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tend to be quite coupled to each other, so it made sense to keep them together. I agree that the name isn't great, but I can't think of a better one... We could also go with the irdl and ir route and ban the sub files of the utils, and expose it all via xdsl.dialects.utils

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try that quickly, will result in smaller diff and probably a better experience

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the point of the irdl approach, just seems to cause loads of linting errors for me

Copy link
Member Author

@superlopuh superlopuh Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, the local development experience is worse than for clients, Pylance automatically inserts the correct import if you pip install xdsl.

from typing import Generic

from xdsl.dialects.builtin import (
Expand All @@ -14,7 +12,6 @@
from xdsl.ir import (
Attribute,
AttributeInvT,
BitEnumAttribute,
BlockArgument,
Operation,
Region,
Expand All @@ -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(
Expand Down Expand Up @@ -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
Loading