forked from OSchip/llvm-project
[MLIR] [Python ODS] Use @builtins.property for cases where 'property' is already defined
In cases where an operation has an argument or result named 'property', the ODS-generated python fails on import because the `@property` resolves to the `property` operation argument instead of the builtin `@property` decorator. We should always use the fully qualified decorator name. Reviewed By: mikeurbach Differential Revision: https://reviews.llvm.org/D106106
This commit is contained in:
parent
b1ffa8fc61
commit
b4c93ece8e
|
@ -31,21 +31,21 @@ def AttrSizedOperandsOp : TestOp<"attr_sized_operands",
|
|||
// CHECK: attributes=attributes, results=results, operands=operands,
|
||||
// CHECK: loc=loc, ip=ip))
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def variadic1(self):
|
||||
// CHECK: operand_range = _ods_segmented_accessor(
|
||||
// CHECK: self.operation.operands,
|
||||
// CHECK: self.operation.attributes["operand_segment_sizes"], 0)
|
||||
// CHECK: return operand_range
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def non_variadic(self):
|
||||
// CHECK: operand_range = _ods_segmented_accessor(
|
||||
// CHECK: self.operation.operands,
|
||||
// CHECK: self.operation.attributes["operand_segment_sizes"], 1)
|
||||
// CHECK: return operand_range[0]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def variadic2(self):
|
||||
// CHECK: operand_range = _ods_segmented_accessor(
|
||||
// CHECK: self.operation.operands,
|
||||
|
@ -72,21 +72,21 @@ def AttrSizedResultsOp : TestOp<"attr_sized_results",
|
|||
// CHECK: attributes=attributes, results=results, operands=operands,
|
||||
// CHECK: loc=loc, ip=ip))
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def variadic1(self):
|
||||
// CHECK: result_range = _ods_segmented_accessor(
|
||||
// CHECK: self.operation.results,
|
||||
// CHECK: self.operation.attributes["result_segment_sizes"], 0)
|
||||
// CHECK: return result_range[0] if len(result_range) > 0 else None
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def non_variadic(self):
|
||||
// CHECK: result_range = _ods_segmented_accessor(
|
||||
// CHECK: self.operation.results,
|
||||
// CHECK: self.operation.attributes["result_segment_sizes"], 1)
|
||||
// CHECK: return result_range[0]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def variadic2(self):
|
||||
// CHECK: result_range = _ods_segmented_accessor(
|
||||
// CHECK: self.operation.results,
|
||||
|
@ -116,21 +116,21 @@ def AttributedOp : TestOp<"attributed_op"> {
|
|||
// CHECK: attributes=attributes, results=results, operands=operands,
|
||||
// CHECK: loc=loc, ip=ip))
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def i32attr(self):
|
||||
// CHECK: return _ods_ir.IntegerAttr(self.operation.attributes["i32attr"])
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def optionalF32Attr(self):
|
||||
// CHECK: if "optionalF32Attr" not in self.operation.attributes:
|
||||
// CHECK: return None
|
||||
// CHECK: return _ods_ir.FloatAttr(self.operation.attributes["optionalF32Attr"])
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def unitAttr(self):
|
||||
// CHECK: return "unitAttr" in self.operation.attributes
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def in_(self):
|
||||
// CHECK: return _ods_ir.IntegerAttr(self.operation.attributes["in"])
|
||||
let arguments = (ins I32Attr:$i32attr, OptionalAttr<F32Attr>:$optionalF32Attr,
|
||||
|
@ -156,11 +156,11 @@ def AttributedOpWithOperands : TestOp<"attributed_op_with_operands"> {
|
|||
// CHECK: attributes=attributes, results=results, operands=operands,
|
||||
// CHECK: loc=loc, ip=ip))
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def in_(self):
|
||||
// CHECK: return "in" in self.operation.attributes
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def is_(self):
|
||||
// CHECK: if "is" not in self.operation.attributes:
|
||||
// CHECK: return None
|
||||
|
@ -199,16 +199,16 @@ def MissingNamesOp : TestOp<"missing_names"> {
|
|||
// CHECK: attributes=attributes, results=results, operands=operands,
|
||||
// CHECK: loc=loc, ip=ip))
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def f32(self):
|
||||
// CHECK: return self.operation.operands[1]
|
||||
let arguments = (ins I32, F32:$f32, I64);
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def i32(self):
|
||||
// CHECK: return self.operation.results[0]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def i64(self):
|
||||
// CHECK: return self.operation.results[2]
|
||||
let results = (outs I32:$i32, F32, I64:$i64);
|
||||
|
@ -230,11 +230,11 @@ def OneVariadicOperandOp : TestOp<"one_variadic_operand"> {
|
|||
// CHECK: attributes=attributes, results=results, operands=operands,
|
||||
// CHECK: loc=loc, ip=ip))
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def non_variadic(self):
|
||||
// CHECK: return self.operation.operands[0]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def variadic(self):
|
||||
// CHECK: _ods_variadic_group_length = len(self.operation.operands) - 2 + 1
|
||||
// CHECK: return self.operation.operands[1:1 + _ods_variadic_group_length]
|
||||
|
@ -257,12 +257,12 @@ def OneVariadicResultOp : TestOp<"one_variadic_result"> {
|
|||
// CHECK: attributes=attributes, results=results, operands=operands,
|
||||
// CHECK: loc=loc, ip=ip))
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def variadic(self):
|
||||
// CHECK: _ods_variadic_group_length = len(self.operation.results) - 2 + 1
|
||||
// CHECK: return self.operation.results[0:0 + _ods_variadic_group_length]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def non_variadic(self):
|
||||
// CHECK: _ods_variadic_group_length = len(self.operation.results) - 2 + 1
|
||||
// CHECK: return self.operation.results[1 + _ods_variadic_group_length - 1]
|
||||
|
@ -282,7 +282,7 @@ def PythonKeywordOp : TestOp<"python_keyword"> {
|
|||
// CHECK: attributes=attributes, results=results, operands=operands,
|
||||
// CHECK: loc=loc, ip=ip))
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def in_(self):
|
||||
// CHECK: return self.operation.operands[0]
|
||||
let arguments = (ins AnyType:$in);
|
||||
|
@ -293,17 +293,17 @@ def PythonKeywordOp : TestOp<"python_keyword"> {
|
|||
// CHECK-LABEL: OPERATION_NAME = "test.same_variadic_operand"
|
||||
def SameVariadicOperandSizeOp : TestOp<"same_variadic_operand",
|
||||
[SameVariadicOperandSize]> {
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def variadic1(self):
|
||||
// CHECK: start, pg = _ods_equally_sized_accessor(operation.operands, 2, 0, 0)
|
||||
// CHECK: return self.operation.operands[start:start + pg]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def non_variadic(self):
|
||||
// CHECK: start, pg = _ods_equally_sized_accessor(operation.operands, 2, 0, 1)
|
||||
// CHECK: return self.operation.operands[start]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def variadic2(self):
|
||||
// CHECK: start, pg = _ods_equally_sized_accessor(operation.operands, 2, 1, 1)
|
||||
// CHECK: return self.operation.operands[start:start + pg]
|
||||
|
@ -316,17 +316,17 @@ def SameVariadicOperandSizeOp : TestOp<"same_variadic_operand",
|
|||
// CHECK-LABEL: OPERATION_NAME = "test.same_variadic_result"
|
||||
def SameVariadicResultSizeOp : TestOp<"same_variadic_result",
|
||||
[SameVariadicResultSize]> {
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def variadic1(self):
|
||||
// CHECK: start, pg = _ods_equally_sized_accessor(operation.results, 2, 0, 0)
|
||||
// CHECK: return self.operation.results[start:start + pg]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def non_variadic(self):
|
||||
// CHECK: start, pg = _ods_equally_sized_accessor(operation.results, 2, 0, 1)
|
||||
// CHECK: return self.operation.results[start]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def variadic2(self):
|
||||
// CHECK: start, pg = _ods_equally_sized_accessor(operation.results, 2, 1, 1)
|
||||
// CHECK: return self.operation.results[start:start + pg]
|
||||
|
@ -350,20 +350,20 @@ def SimpleOp : TestOp<"simple"> {
|
|||
// CHECK: attributes=attributes, results=results, operands=operands,
|
||||
// CHECK: loc=loc, ip=ip))
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def i32(self):
|
||||
// CHECK: return self.operation.operands[0]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def f32(self):
|
||||
// CHECK: return self.operation.operands[1]
|
||||
let arguments = (ins I32:$i32, F32:$f32);
|
||||
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def i64(self):
|
||||
// CHECK: return self.operation.results[0]
|
||||
//
|
||||
// CHECK: @property
|
||||
// CHECK: @builtins.property
|
||||
// CHECK: def f64(self):
|
||||
// CHECK: return self.operation.results[1]
|
||||
let results = (outs I64:$i64, F64:$f64);
|
||||
|
|
|
@ -25,4 +25,9 @@ def AttributedOp : TestOp<"attributed_op"> {
|
|||
UnitAttr:$unit);
|
||||
}
|
||||
|
||||
def PropertyOp : TestOp<"property_op"> {
|
||||
let arguments = (ins I32Attr:$property,
|
||||
I32:$idx);
|
||||
}
|
||||
|
||||
#endif // PYTHON_TEST_OPS
|
||||
|
|
|
@ -36,6 +36,8 @@ try:
|
|||
except ImportError:
|
||||
_ods_ext_module = None
|
||||
|
||||
import builtins
|
||||
|
||||
)Py";
|
||||
|
||||
/// Template for dialect class:
|
||||
|
@ -82,7 +84,7 @@ constexpr const char *opClassRegionSpecTemplate = R"Py(
|
|||
/// {1} is either 'operand' or 'result';
|
||||
/// {2} is the position in the element list.
|
||||
constexpr const char *opSingleTemplate = R"Py(
|
||||
@property
|
||||
@builtins.property
|
||||
def {0}(self):
|
||||
return self.operation.{1}s[{2}]
|
||||
)Py";
|
||||
|
@ -95,7 +97,7 @@ constexpr const char *opSingleTemplate = R"Py(
|
|||
/// This works for both a single variadic group (non-negative length) and an
|
||||
/// single optional element (zero length if the element is absent).
|
||||
constexpr const char *opSingleAfterVariableTemplate = R"Py(
|
||||
@property
|
||||
@builtins.property
|
||||
def {0}(self):
|
||||
_ods_variadic_group_length = len(self.operation.{1}s) - {2} + 1
|
||||
return self.operation.{1}s[{3} + _ods_variadic_group_length - 1]
|
||||
|
@ -107,7 +109,7 @@ constexpr const char *opSingleAfterVariableTemplate = R"Py(
|
|||
/// {2} is the total number of element groups;
|
||||
/// {3} is the position of the current group in the group list.
|
||||
constexpr const char *opOneOptionalTemplate = R"Py(
|
||||
@property
|
||||
@builtins.property
|
||||
def {0}(self):
|
||||
return self.operation.{1}s[{3}] if len(self.operation.{1}s) > {2} else None
|
||||
)Py";
|
||||
|
@ -118,7 +120,7 @@ constexpr const char *opOneOptionalTemplate = R"Py(
|
|||
/// {2} is the total number of element groups;
|
||||
/// {3} is the position of the current group in the group list.
|
||||
constexpr const char *opOneVariadicTemplate = R"Py(
|
||||
@property
|
||||
@builtins.property
|
||||
def {0}(self):
|
||||
_ods_variadic_group_length = len(self.operation.{1}s) - {2} + 1
|
||||
return self.operation.{1}s[{3}:{3} + _ods_variadic_group_length]
|
||||
|
@ -131,7 +133,7 @@ constexpr const char *opOneVariadicTemplate = R"Py(
|
|||
/// {3} is the number of non-variadic groups preceding the current group;
|
||||
/// {3} is the number of variadic groups preceding the current group.
|
||||
constexpr const char *opVariadicEqualPrefixTemplate = R"Py(
|
||||
@property
|
||||
@builtins.property
|
||||
def {0}(self):
|
||||
start, pg = _ods_equally_sized_accessor(operation.{1}s, {2}, {3}, {4}))Py";
|
||||
|
||||
|
@ -156,7 +158,7 @@ constexpr const char *opVariadicEqualVariadicTemplate = R"Py(
|
|||
/// {3} is a return suffix (expected [0] for single-element, empty for
|
||||
/// variadic, and opVariadicSegmentOptionalTrailingTemplate for optional).
|
||||
constexpr const char *opVariadicSegmentTemplate = R"Py(
|
||||
@property
|
||||
@builtins.property
|
||||
def {0}(self):
|
||||
{1}_range = _ods_segmented_accessor(
|
||||
self.operation.{1}s,
|
||||
|
@ -175,7 +177,7 @@ constexpr const char *opVariadicSegmentOptionalTrailingTemplate =
|
|||
/// {1} is the Python type of the attribute;
|
||||
/// {2} os the original name of the attribute.
|
||||
constexpr const char *attributeGetterTemplate = R"Py(
|
||||
@property
|
||||
@builtins.property
|
||||
def {0}(self):
|
||||
return {1}(self.operation.attributes["{2}"])
|
||||
)Py";
|
||||
|
@ -185,7 +187,7 @@ constexpr const char *attributeGetterTemplate = R"Py(
|
|||
/// {1} is the Python type of the attribute;
|
||||
/// {2} is the original name of the attribute.
|
||||
constexpr const char *optionalAttributeGetterTemplate = R"Py(
|
||||
@property
|
||||
@builtins.property
|
||||
def {0}(self):
|
||||
if "{2}" not in self.operation.attributes:
|
||||
return None
|
||||
|
@ -198,7 +200,7 @@ constexpr const char *optionalAttributeGetterTemplate = R"Py(
|
|||
/// {0} is the name of the attribute sanitized for Python,
|
||||
/// {1} is the original name of the attribute.
|
||||
constexpr const char *unitAttributeGetterTemplate = R"Py(
|
||||
@property
|
||||
@builtins.property
|
||||
def {0}(self):
|
||||
return "{1}" in self.operation.attributes
|
||||
)Py";
|
||||
|
|
Loading…
Reference in New Issue