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

Better type hints for attribute definitions #103

Merged
merged 36 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2d1f865
Make `Data` generic over the contained type.
math-fehr Apr 9, 2022
12ad8a9
Add .vscode to .gitignore
math-fehr Apr 13, 2022
1139c8c
Improve ParameterDef to have better type hints
math-fehr Apr 13, 2022
1f308d4
Set python version to 3.10 in the CI
math-fehr Apr 14, 2022
30cb3f4
Moved to ArrayAttr(Data[List[A]])
michel-steuwer Apr 25, 2022
192b3cc
Remove commented code
math-fehr Apr 26, 2022
47c7688
Make Data an ABC class
math-fehr Apr 27, 2022
2b6b364
Make IRDL extensible with new generic coercions
math-fehr Apr 27, 2022
38d73cc
Fix ArrayAttr generic coercion
math-fehr Apr 27, 2022
65ee8f0
Rename IRDLGenericCoercion
math-fehr Apr 27, 2022
90895b6
Add error message when GenericData should be used
math-fehr Apr 27, 2022
a0cd4ae
Fix typo
math-fehr May 4, 2022
9f440ee
Fix typo
math-fehr May 4, 2022
20c21c1
Move verify method to base Attribute class
math-fehr Apr 30, 2022
97349f4
Derive verifiers for Data definitions
math-fehr Apr 30, 2022
de79c20
Add verifier in ArrayAttr
math-fehr May 4, 2022
f0df0c3
Add check that Data parameter is a class
math-fehr May 4, 2022
c81c0a7
Fix punctuation
math-fehr May 4, 2022
20d6211
Fix verify function in ParametrizedAttribute
math-fehr May 5, 2022
dc1bff5
Add base file for testing attribute definition
math-fehr May 5, 2022
c33560e
Fix TupleType implementation
math-fehr May 5, 2022
e8649e6
Remove type errors in attribute definition test
math-fehr May 5, 2022
d1b5030
Add new test
math-fehr May 5, 2022
a0553a8
Add documentation in attribute definition tests
math-fehr May 5, 2022
0c9a10e
Fix bug in irdl
math-fehr May 5, 2022
e306d57
Add test cases for all IRDL constraints
math-fehr May 5, 2022
26c8f3d
Add support for TypeVar in ParametrizedAttribute
math-fehr May 6, 2022
a783d4d
Cleanup a bit affine dialect
math-fehr May 12, 2022
a990fd9
Cleanup a bit arith dialect
math-fehr May 12, 2022
66814a1
Make some attribute generic
math-fehr May 12, 2022
1b2c7c8
Cleanup a bit cf
math-fehr May 12, 2022
fecbc71
Cleanup a bit func dialect
math-fehr May 12, 2022
3383ffd
Make MemRefTypeElement generic
math-fehr May 12, 2022
a17b7c2
Cleanup a bit scf dialect
math-fehr May 12, 2022
fc328b7
Support PyRight strict typing
math-fehr Jun 4, 2022
3de15ba
Fix rebase
math-fehr Jun 4, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ dmypy.json
cython_debug/

# PyCharm IDE
*.idea/
*.idea/
.vscode/settings.json
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"
build-backend = "setuptools.build_meta"

[tool.pyright]
reportImportCycles = false
reportUnnecessaryIsInstance = false
15 changes: 8 additions & 7 deletions src/xdsl/diagnostic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import Dict, List
from typing import Dict, List, Union, Type
from dataclasses import dataclass, field

from xdsl.ir import Block, Operation, Region
Expand All @@ -18,10 +18,11 @@ def add_message(self, op: Operation, message: str) -> None:
"""Add a message to an operation."""
self.op_messages.setdefault(op, []).append(message)

def raise_exception(self,
message,
ir: Union[Operation, Block, Region],
exception_type=DiagnosticException) -> None:
def raise_exception(
self,
message: str,
ir: Union[Operation, Block, Region],
exception_type: Type[Exception] = DiagnosticException) -> None:
"""Raise an exception, that will also print all messages in the IR."""
from xdsl.printer import Printer
f = StringIO()
Expand All @@ -30,9 +31,9 @@ def raise_exception(self,
if isinstance(toplevel, Operation):
p.print_op(toplevel)
elif isinstance(toplevel, Block):
p._print_named_block(toplevel)
p._print_named_block(toplevel) # type: ignore
elif isinstance(toplevel, Region):
p._print_region(toplevel)
p._print_region(toplevel) # type: ignore
else:
assert "xDSL internal error: get_toplevel_object returned unknown construct"

Expand Down
16 changes: 9 additions & 7 deletions src/xdsl/dialects/affine.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations
from typing import Union

from xdsl.ir import Operation, SSAValue
from typing import Union, List
from dataclasses import dataclass
from xdsl.dialects.builtin import IntegerAttr, IndexType
from xdsl.irdl import irdl_op_definition, AttributeDef, OperandDef, RegionDef, VarResultDef, VarOperandDef, AnyAttr

from xdsl.ir import Operation, SSAValue, MLContext, Block, Region
from xdsl.dialects.builtin import IntegerAttr, IndexType, IndexType
from xdsl.irdl import irdl_op_definition, AttributeDef, RegionDef, VarResultDef, VarOperandDef, AnyAttr


@dataclass
Expand Down Expand Up @@ -68,7 +69,7 @@ def from_region(operands: List[Union[Operation, SSAValue]],
def from_callable(operands: List[Union[Operation, SSAValue]],
lower_bound: Union[int, IntegerAttr],
upper_bound: Union[int, IntegerAttr],
body: Callable[[BlockArgument, ...], List[Operation]],
body: Block.BlockCallback,
step: Union[int, IntegerAttr] = 1) -> For:
arg_types = [IndexType()] + [SSAValue.get(op).typ for op in operands]
return For.from_region(
Expand All @@ -83,5 +84,6 @@ class Yield(Operation):
arguments = VarOperandDef(AnyAttr())

@staticmethod
def get(*operands: Union[Operation, SSAValue]) -> Yield:
return Yield.create(operands=[operand for operand in operands])
def get(*operands: SSAValue | Operation) -> Yield:
return Yield.create(
operands=[SSAValue.get(operand) for operand in operands])
26 changes: 13 additions & 13 deletions src/xdsl/dialects/arith.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from xdsl.ir import *
from xdsl.irdl import *
from xdsl.util import *
from xdsl.dialects.builtin import IntegerType, Float32Type, IntegerAttr, FlatSymbolRefAttr
from xdsl.dialects.builtin import IntegerType, Float32Type, IntegerAttr


@dataclass
Expand Down Expand Up @@ -125,9 +125,9 @@ def verify_(self) -> None:

@staticmethod
def get(operand1: Union[Operation, SSAValue],
operand2: Union[Operation, SSAValue]) -> FloordiviSigned:
return FloordiviSigned.build(operands=[operand1, operand2],
result_types=[IntegerType.from_width(32)])
operand2: Union[Operation, SSAValue]) -> FloorDiviSI:
return FloorDiviSI.build(operands=[operand1, operand2],
result_types=[IntegerType.from_width(32)])


@irdl_op_definition
Expand All @@ -145,9 +145,9 @@ def verify_(self) -> None:

@staticmethod
def get(operand1: Union[Operation, SSAValue],
operand2: Union[Operation, SSAValue]) -> RemiSigned:
return RemiSigned.build(operands=[operand1, operand2],
result_types=[IntegerType.from_width(32)])
operand2: Union[Operation, SSAValue]) -> RemSI:
return RemSI.build(operands=[operand1, operand2],
result_types=[IntegerType.from_width(32)])


@irdl_op_definition
Expand Down Expand Up @@ -185,10 +185,10 @@ def verify_(self) -> None:

@staticmethod
def get(operand1: Union[Operation, SSAValue],
operand2: Union[Operation, SSAValue]) -> Or:
operand2: Union[Operation, SSAValue]) -> OrI:

return Or.build(operands=[operand1, operand2],
result_types=[SSAValue.get(operand1).typ])
return OrI.build(operands=[operand1, operand2],
result_types=[SSAValue.get(operand1).typ])


@irdl_op_definition
Expand All @@ -206,9 +206,9 @@ def verify_(self) -> None:

@staticmethod
def get(operand1: Union[Operation, SSAValue],
operand2: Union[Operation, SSAValue]) -> Xor:
return Xor.build(operands=[operand1, operand2],
result_types=[SSAValue.get(operand1).typ])
operand2: Union[Operation, SSAValue]) -> XOrI:
return XOrI.build(operands=[operand1, operand2],
result_types=[SSAValue.get(operand1).typ])


@irdl_op_definition
Expand Down
Loading