Skip to content

Commit

Permalink
Merge branch 'origin/sasha/kim/declarative-assembly-parser/add-region…
Browse files Browse the repository at this point in the history
…s' into kim/declarative-assembly-parser/add-regions. Remove casts.
  • Loading branch information
kimxworrall committed Aug 19, 2024
2 parents b53ee3d + a7ba1d4 commit 72a9e35
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions xdsl/irdl/declarative_assembly_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
TypedAttribute,
)
from xdsl.irdl import (
Block,
ConstraintContext,
IRDLOperation,
IRDLOperationInvT,
OpDef,
Operation,
OptionalDef,
VariadicDef,
VarIRConstruct,
Expand All @@ -51,7 +49,7 @@ class ParsingState:
operands: list[UnresolvedOperand | None | list[UnresolvedOperand | None]]
operand_types: list[Attribute | None | list[Attribute | None]]
result_types: list[Attribute | None | list[Attribute | None]]
regions: list[Region | None | list[Region | None]]
regions: list[Region | None | list[Region]]
attributes: dict[str, Attribute]
properties: dict[str, Attribute]
constraint_context: ConstraintContext
Expand Down Expand Up @@ -164,24 +162,12 @@ def parse(
else:
properties = op_def.split_properties(state.attributes)

# Get the regions and cast them to the type needed in op_type
regions = cast(
Sequence[
Region
| Sequence[Operation]
| Sequence[Block]
| Sequence[Region | Sequence[Operation] | Sequence[Block]]
| None
],
state.regions,
)

return op_type.build(
result_types=result_types,
operands=operands,
attributes=state.attributes,
properties=properties,
regions=regions,
regions=state.regions,
)

def assign_constraint_variables(
Expand Down Expand Up @@ -783,7 +769,7 @@ def parse_optional(self, parser: Parser, state: ParsingState) -> bool:
regions.append(current_region)
current_region = parser.parse_optional_region()

state.regions[self.index] = cast(list[Region | None], regions)
state.regions[self.index] = regions
return bool(regions)

def print(self, printer: Printer, state: PrintingState, op: IRDLOperation) -> None:
Expand All @@ -806,7 +792,7 @@ class OptionalRegionVariable(OptionalVariable, OptionallyParsableDirective):
def parse_optional(self, parser: Parser, state: ParsingState) -> bool:
region = parser.parse_optional_region()
if region is None:
region = list[Region | None]()
region = list[Region]()
state.regions[self.index] = region
return bool(region)

Expand Down

0 comments on commit 72a9e35

Please sign in to comment.