Skip to content

Commit be86bd0

Browse files
authored
remove properties from statement node (#238)
fix #216 I'm not sure if this is the right simplification, but let's try and see if something bad happens. We can bring it back. Still want to see people's opinions before merging tho. cc: @weinbe58 @kaihsin @johnzl-777
1 parent 4312719 commit be86bd0

File tree

16 files changed

+37
-104
lines changed

16 files changed

+37
-104
lines changed

src/kirin/decl/emit/init.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ def _emit_params(self):
9595
if f.init:
9696
kw_params.append(self._init_param_value(f))
9797

98-
for f in self.fields.properties.values():
99-
if f.init:
100-
kw_params.append(self._init_param_value(f))
101-
10298
for f in self.fields.regions.values():
10399
if f.init:
104100
kw_params.append(self._init_param_value(f))
@@ -120,7 +116,6 @@ def _emit_field_init(self, has_args_groups: bool):
120116
f"successors={self._blocks_seq()},"
121117
f"result_types={self._result_types_seq()},"
122118
f"attributes={self._attribute_seq()},"
123-
f"properties={self._properties_seq()},"
124119
f"args_slice={self._args_slice(has_args_groups)}"
125120
")"
126121
)
@@ -212,15 +207,6 @@ def _attribute_value(self, f: info.AttributeField):
212207

213208
return value
214209

215-
def _properties_seq(self):
216-
props = ",".join(
217-
[
218-
f'"{name}": {self._attribute_value(f)}'
219-
for name, f in self.fields.properties.items()
220-
]
221-
)
222-
return "{" + props + "}"
223-
224210
def _regions_seq(self):
225211
regions = [self._regions_value(f) for f in self.fields.regions.values()]
226212
return self._tuple_str(regions)

src/kirin/decl/emit/property.py

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ def emit_property(self):
2626
getter, setter = self._emit_attribute_property(f)
2727
set_new_attribute(self.cls, name, property(getter, setter))
2828

29-
for name, f in self.fields.properties.items():
30-
getter, setter = self._emit_attribute_property(f)
31-
set_new_attribute(self.cls, name, property(getter, setter))
32-
3329
for i, (name, f) in enumerate(self.fields.blocks.items()):
3430
getter, setter = self._emit_successor_property(i, f)
3531
set_new_attribute(self.cls, name, property(getter, setter))
@@ -113,7 +109,7 @@ def _emit_result_property(self, index: int, f: info.ResultField):
113109
def _emit_attribute_property(self, f: info.AttributeField):
114110
from kirin.ir.attrs.py import PyAttr
115111

116-
storage = "properties" if f.property else "attributes"
112+
storage = "attributes"
117113
attr = f"{self._self_name}.{storage}['{f.name}']"
118114
getter = create_fn(
119115
f"_get_{f.name}",
@@ -123,33 +119,20 @@ def _emit_attribute_property(self, f: info.AttributeField):
123119
return_type=f.annotation,
124120
)
125121

126-
if f.property:
127-
setter = create_fn(
128-
f"_set_{f.name}",
129-
args=[self._self_name, "value: _value_hint"],
130-
body=[
131-
f"raise AttributeError('attribute property {f.name} is read-only')"
132-
],
133-
globals=self.globals,
134-
locals={"_value_hint": PyAttr if f.pytype else f.annotation},
135-
return_type=None,
136-
)
137-
else:
138-
139-
setter = create_fn(
140-
f"_set_{f.name}",
141-
args=[self._self_name, "value: _value_hint"],
142-
body=[
143-
(
144-
f"{attr} = value if isinstance(value, {self._KIRIN_PYATTR}) else {self._KIRIN_PYATTR}(value)"
145-
if f.pytype
146-
else f"{attr} = value"
147-
)
148-
],
149-
globals=self.globals,
150-
locals={"_value_hint": f.annotation},
151-
return_type=None,
152-
)
122+
setter = create_fn(
123+
f"_set_{f.name}",
124+
args=[self._self_name, "value: _value_hint"],
125+
body=[
126+
(
127+
f"{attr} = value if isinstance(value, {self._KIRIN_PYATTR}) else {self._KIRIN_PYATTR}(value)"
128+
if f.pytype
129+
else f"{attr} = value"
130+
)
131+
],
132+
globals=self.globals,
133+
locals={"_value_hint": PyAttr if f.pytype else f.annotation},
134+
return_type=None,
135+
)
153136

154137
return getter, setter
155138

src/kirin/decl/info.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class AttributeField(Field):
2828
repr: bool
2929
default_factory: Optional[Callable[[], Attribute]]
3030
type: types.TypeAttribute
31-
property: bool
3231
pytype: bool = False
3332
"if `True`, annotation is a python type hint instead of `TypeAttribute`"
3433

@@ -45,7 +44,6 @@ def attribute(
4544
default_factory: Optional[Callable[[], Any]] = None,
4645
kw_only: bool = True,
4746
alias: Optional[str] = None,
48-
property: bool = False,
4947
) -> Any:
5048
if kw_only is False:
5149
raise TypeError("attribute fields must be keyword-only")
@@ -58,7 +56,6 @@ def attribute(
5856
default_factory=default_factory,
5957
kw_only=kw_only,
6058
alias=alias,
61-
property=property,
6259
)
6360

6461

@@ -242,8 +239,6 @@ class StatementFields:
242239
"""blocks of the statement."""
243240
attributes: dict[str, AttributeField] = field(default_factory=dict)
244241
"""attributes of the statement."""
245-
properties: dict[str, AttributeField] = field(default_factory=dict)
246-
"""properties of the statement."""
247242

248243
class Args:
249244
def __init__(self, fields: "StatementFields"):
@@ -299,7 +294,6 @@ def __contains__(self, name):
299294
or name in self.regions
300295
or name in self.blocks
301296
or name in self.attributes
302-
or name in self.properties
303297
)
304298

305299
def __setitem__(self, name, value):
@@ -312,10 +306,7 @@ def __setitem__(self, name, value):
312306
elif isinstance(value, BlockField):
313307
self.blocks[name] = value
314308
elif isinstance(value, AttributeField):
315-
if value.property:
316-
self.properties[name] = value
317-
else:
318-
self.attributes[name] = value
309+
self.attributes[name] = value
319310
else:
320311
raise TypeError(f"unknown field type {value}")
321312

@@ -326,7 +317,6 @@ def __iter__(self):
326317
yield from self.regions.values()
327318
yield from self.blocks.values()
328319
yield from self.attributes.values()
329-
yield from self.properties.values()
330320

331321
def __len__(self):
332322
return (
@@ -335,20 +325,18 @@ def __len__(self):
335325
+ len(self.regions)
336326
+ len(self.blocks)
337327
+ len(self.attributes)
338-
+ len(self.properties)
339328
)
340329

341330
@cached_property
342331
def attr_or_props(self):
343-
return set(list(self.attributes.keys()) + list(self.properties.keys()))
332+
return set(self.attributes.keys())
344333

345334
@cached_property
346335
def required_names(self):
347336
"""set of all fields that do not have a default value."""
348337
return set(
349338
list(self.args.keys())
350339
+ [name for name, f in self.attributes.items() if f.has_no_default()]
351-
+ [name for name, f in self.properties.items() if f.has_no_default()]
352340
+ [name for name, f in self.blocks.items() if f.has_no_default()]
353341
+ [name for name, f in self.regions.items() if f.has_no_default()]
354342
)

src/kirin/decl/verify.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class Verify(BaseModifier):
2525
"regions",
2626
"successors",
2727
"attributes",
28-
"properties",
2928
}
3029

3130
def verify_mro(self):

src/kirin/dialects/func/stmts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Function(Statement):
4444
SSACFGRegion(),
4545
}
4646
)
47-
sym_name: str = info.attribute(property=True)
47+
sym_name: str = info.attribute()
4848
"""The symbol name of the function."""
4949
signature: Signature = info.attribute()
5050
body: Region = info.region(multi=True)
@@ -77,7 +77,7 @@ class Call(Statement):
7777
# not a fixed type here so just any
7878
callee: SSAValue = info.argument()
7979
inputs: tuple[SSAValue, ...] = info.argument()
80-
kwargs: tuple[str, ...] = info.attribute(default_factory=lambda: (), property=True)
80+
kwargs: tuple[str, ...] = info.attribute(default_factory=lambda: ())
8181
result: ResultValue = info.result()
8282
purity: bool = info.attribute(default=False)
8383

@@ -149,7 +149,7 @@ class Lambda(Statement):
149149
traits = frozenset(
150150
{Pure(), SymbolOpInterface(), FuncOpCallableInterface(), SSACFGRegion()}
151151
)
152-
sym_name: str = info.attribute(property=True)
152+
sym_name: str = info.attribute()
153153
signature: Signature = info.attribute()
154154
captured: tuple[SSAValue, ...] = info.argument()
155155
body: Region = info.region(multi=True)
@@ -185,7 +185,7 @@ class GetField(Statement):
185185
name = "getfield"
186186
traits = frozenset({Pure()})
187187
obj: SSAValue = info.argument(MethodType)
188-
field: int = info.attribute(property=True)
188+
field: int = info.attribute()
189189
# NOTE: mypy somehow doesn't understand default init=False
190190
result: ResultValue = info.result(init=False)
191191

@@ -203,9 +203,9 @@ def print_impl(self, printer: Printer) -> None:
203203
class Invoke(Statement):
204204
name = "invoke"
205205
traits = frozenset({MaybePure()})
206-
callee: Method = info.attribute(property=True)
206+
callee: Method = info.attribute()
207207
inputs: tuple[SSAValue, ...] = info.argument()
208-
kwargs: tuple[str, ...] = info.attribute(property=True)
208+
kwargs: tuple[str, ...] = info.attribute()
209209
result: ResultValue = info.result()
210210
purity: bool = info.attribute(default=False)
211211

src/kirin/dialects/module.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class Module(ir.Statement):
2121
traits = frozenset(
2222
{ir.IsolatedFromAbove(), ir.SymbolTable(), ir.SymbolOpInterface()}
2323
)
24-
sym_name: str = info.attribute(property=True)
25-
entry: str = info.attribute(property=True)
24+
sym_name: str = info.attribute()
25+
entry: str = info.attribute()
2626
body: ir.Region = info.region(multi=False)
2727

2828

@@ -37,9 +37,9 @@ class Invoke(ir.Statement):
3737
after looking up the symbol table.
3838
"""
3939

40-
callee: str = info.attribute(property=True)
40+
callee: str = info.attribute()
4141
inputs: tuple[ir.SSAValue, ...] = info.argument()
42-
kwargs: tuple[str, ...] = info.attribute(property=True)
42+
kwargs: tuple[str, ...] = info.attribute()
4343
result: ir.ResultValue = info.result()
4444

4545
def print_impl(self, printer: Printer) -> None:

src/kirin/dialects/py/assign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Alias(ir.Statement):
2525
name = "alias"
2626
traits = frozenset({ir.Pure(), ir.FromPythonCall()})
2727
value: ir.SSAValue = info.argument(T)
28-
target: ir.PyAttr[str] = info.attribute(property=True)
28+
target: ir.PyAttr[str] = info.attribute()
2929
result: ir.ResultValue = info.result(T)
3030

3131
def print_impl(self, printer: Printer) -> None:

src/kirin/dialects/py/attr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GetAttr(ir.Statement):
2222
name = "getattr"
2323
traits = frozenset({ir.FromPythonCall()})
2424
obj: ir.SSAValue = info.argument(print=False)
25-
attrname: str = info.attribute(property=True)
25+
attrname: str = info.attribute()
2626
result: ir.ResultValue = info.result()
2727

2828

src/kirin/dialects/py/constant.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
class Constant(ir.Statement, Generic[T]):
2828
name = "constant"
2929
traits = frozenset({ir.Pure(), ir.ConstantLike(), ir.FromPythonCall()})
30-
value: T = info.attribute(property=True)
30+
value: T = info.attribute()
3131
result: ir.ResultValue = info.result()
3232

3333
# NOTE: we allow py.Constant take data.PyAttr too
3434
def __init__(self, value: T | ir.PyAttr[T]) -> None:
3535
if not isinstance(value, ir.PyAttr):
3636
value = ir.PyAttr(value)
3737
super().__init__(
38-
properties={"value": value},
38+
attributes={"value": value},
3939
result_types=(value.type,),
4040
)
4141

src/kirin/dialects/py/unpack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
@statement(dialect=dialect, init=False)
2323
class Unpack(ir.Statement):
2424
value: ir.SSAValue = info.argument(types.Any)
25-
names: tuple[str | None, ...] = info.attribute(property=True)
25+
names: tuple[str | None, ...] = info.attribute()
2626

2727
def __init__(self, value: ir.SSAValue, names: tuple[str | None, ...]):
2828
result_types = [types.Any] * len(names)
2929
super().__init__(
3030
args=(value,),
3131
result_types=result_types,
3232
args_slice={"value": 0},
33-
properties={"names": ir.PyAttr(names)},
33+
attributes={"names": ir.PyAttr(names)},
3434
)
3535
for result, name in zip(self.results, names):
3636
result.name = name

0 commit comments

Comments
 (0)