diff --git a/nada_dsl/ast_util.py b/nada_dsl/ast_util.py index f045947..078c743 100644 --- a/nada_dsl/ast_util.py +++ b/nada_dsl/ast_util.py @@ -43,8 +43,8 @@ class ASTOperation(ABC): source_ref: SourceRef ty: NadaTypeRepr - def inner_operations(self) -> List[int]: - """Returns the list of identifiers of all the parent operations of this operation.""" + def child_operations(self) -> List[int]: + """Returns the list of identifiers of all the child operations of this operation.""" return [] def to_mir(self): @@ -68,7 +68,7 @@ class BinaryASTOperation(ASTOperation): left: int right: int - def inner_operations(self) -> List[int]: + def child_operations(self) -> List[int]: return [self.left, self.right] def to_mir(self): @@ -88,17 +88,17 @@ class UnaryASTOperation(ASTOperation): """Superclass of all the unary operations in AST representation""" name: str - parent: int + this: int - def inner_operations(self): - return [self.parent] + def child_operations(self): + return [self.this] def to_mir(self): return { self.name: { "id": self.id, - "this": self.parent, + "this": self.this, "type": self.ty, "source_ref_index": self.source_ref.to_index(), } @@ -113,7 +113,7 @@ class IfElseASTOperation(ASTOperation): arg_0: int arg_1: int - def inner_operations(self): + def child_operations(self): return [self.this, self.arg_0, self.arg_1] def to_mir(self): @@ -133,7 +133,7 @@ def to_mir(self): class RandomASTOperation(ASTOperation): """AST Representation of a Random operation.""" - def inner_operations(self): + def child_operations(self): return [] def to_mir(self): @@ -215,19 +215,19 @@ def to_mir(self): class ReduceASTOperation(ASTOperation): """AST Representation of a Reduce operation.""" - parent: int + child: int fn: int initial: int - def inner_operations(self): - return [self.parent, self.initial] + def child_operations(self): + return [self.child, self.initial] def to_mir(self): return { "Reduce": { "id": self.id, "fn": self.fn, - "parent": self.parent, + "child": self.child, "initial": self.initial, "type": self.ty, "source_ref_index": self.source_ref.to_index(), @@ -239,18 +239,18 @@ def to_mir(self): class MapASTOperation(ASTOperation): """AST representation of a Map operation.""" - parent: int + child: int fn: int - def inner_operations(self): - return [self.parent] + def child_operations(self): + return [self.child] def to_mir(self): return { "Map": { "id": self.id, "fn": self.fn, - "parent": self.parent, + "child": self.child, "type": self.ty, "source_ref_index": self.source_ref.to_index(), } @@ -264,7 +264,7 @@ class NewASTOperation(ASTOperation): name: str elements: List[int] - def inner_operations(self): + def child_operations(self): return self.elements def to_mir(self): @@ -285,7 +285,7 @@ class NadaFunctionCallASTOperation(ASTOperation): args: List[int] fn: int - def inner_operations(self): + def child_operations(self): return self.args def to_mir(self): @@ -326,7 +326,7 @@ class NadaFunctionASTOperation(ASTOperation): name: str args: List[int] - parent: int + child: int # pylint: disable=arguments-differ def to_mir(self, operations): @@ -346,7 +346,7 @@ def to_mir(self, operations): for arg in arg_operations ], "function": self.name, - "return_operation_id": self.parent, + "return_operation_id": self.child, "operations": operations, "return_type": self.ty, "source_ref_index": self.source_ref.to_index(), @@ -363,7 +363,7 @@ class CastASTOperation(ASTOperation): target: int - def inner_operations(self): + def child_operations(self): return [self.target] def to_mir(self): diff --git a/nada_dsl/compiler_frontend.py b/nada_dsl/compiler_frontend.py index e857b36..033e867 100644 --- a/nada_dsl/compiler_frontend.py +++ b/nada_dsl/compiler_frontend.py @@ -81,7 +81,7 @@ def nada_dsl_to_nada_mir(outputs: List[Output]) -> Dict[str, Any]: timer.start( f"nada_dsl.compiler_frontend.nada_dsl_to_nada_mir.{output.name}.process_operation" ) - out_operation_id = output.parent.parent.id + out_operation_id = output.child.child.id extra_fns = traverse_and_process_operations( out_operation_id, operations, FUNCTIONS ) @@ -184,7 +184,7 @@ def to_mir_function_list(functions: Dict[int, NadaFunctionASTOperation]) -> List function_operations = {} extra_functions = traverse_and_process_operations( - function.parent, + function.child, function_operations, functions, ) @@ -255,7 +255,7 @@ def traverse_and_process_operations( extra_functions[wrapped_operation.extra_function.id] = ( wrapped_operation.extra_function ) - stack.extend(operation.inner_operations()) + stack.extend(operation.child_operations()) return extra_functions diff --git a/nada_dsl/nada_types/__init__.py b/nada_dsl/nada_types/__init__.py index cb90b8b..2e7ab0f 100644 --- a/nada_dsl/nada_types/__init__.py +++ b/nada_dsl/nada_types/__init__.py @@ -121,7 +121,7 @@ class NadaType: This is the parent class of all nada types. In Nada, all the types wrap Operations. For instance, an addition between two integers - is represented like this SecretInteger(parent=Addition(...)). + is represented like this SecretInteger(child=Addition(...)). In MIR, the representation is based around operations. A MIR operation points to other operations and has a return type. @@ -130,23 +130,23 @@ class NadaType: MIR-friendly format, as subclasses of ASTOperation. Whenever the Python interpreter constructs an instance of NadaType, it will also store - in memory the corresponding parent operation. In order to do so, the ASTOperation will + in memory the corresponding child operation. In order to do so, the ASTOperation will need the type in MIR format. Which is why all instances of `NadaType` provide an implementation of `to_mir()`. """ - parent: OperationType + child: OperationType - def __init__(self, parent: OperationType): + def __init__(self, child: OperationType): """NadaType default constructor Args: - parent (OperationType): The parent operation of this Data type + child (OperationType): The child operation of this Data type """ - self.parent = parent - if self.parent is not None: - self.parent.store_in_ast(self.to_mir()) + self.child = child + if self.child is not None: + self.child.store_in_ast(self.to_mir()) def to_mir(self): """Default implementation for the Conversion of a type into MIR representation.""" diff --git a/nada_dsl/nada_types/collections.py b/nada_dsl/nada_types/collections.py index 07d7227..a248741 100644 --- a/nada_dsl/nada_types/collections.py +++ b/nada_dsl/nada_types/collections.py @@ -81,7 +81,7 @@ def to_mir(self): ) def retrieve_inner_type(self): - """Retrieves the parent type of this collection""" + """Retrieves the child type of this collection""" if isinstance(self.contained_types, TypeVar): return "T" if inspect.isclass(self.contained_types): @@ -92,18 +92,18 @@ def retrieve_inner_type(self): class Map(Generic[T, R]): """The Map operation""" - parent: OperationType + child: OperationType fn: NadaFunction[T, R] source_ref: SourceRef def __init__( self, - parent: OperationType, + child: OperationType, fn: NadaFunction[T, R], source_ref: SourceRef, ): self.id = next_operation_id() - self.parent = parent + self.child = child self.fn = fn self.source_ref = source_ref @@ -111,7 +111,7 @@ def store_in_ast(self, ty): """Store MP in AST""" AST_OPERATIONS[self.id] = MapASTOperation( id=self.id, - parent=self.parent.parent.id, + child=self.child.child.id, fn=self.fn.id, source_ref=self.source_ref, ty=ty, @@ -122,20 +122,20 @@ def store_in_ast(self, ty): class Reduce(Generic[T, R]): """The Nada Reduce operation.""" - parent: OperationType + child: OperationType fn: NadaFunction[T, R] initial: R source_ref: SourceRef def __init__( self, - parent: OperationType, + child: OperationType, fn: NadaFunction[T, R], initial: R, source_ref: SourceRef, ): self.id = next_operation_id() - self.parent = parent + self.child = child self.fn = fn self.initial = initial self.source_ref = source_ref @@ -144,9 +144,9 @@ def store_in_ast(self, ty): """Store a reduce object in AST""" AST_OPERATIONS[self.id] = ReduceASTOperation( id=self.id, - parent=self.parent.parent.id, + child=self.child.child.id, fn=self.fn.id, - initial=self.initial.parent.id, + initial=self.initial.child.id, source_ref=self.source_ref, ty=ty, ) @@ -175,11 +175,11 @@ class Tuple(Generic[T, U], Collection): left_type: T right_type: U - def __init__(self, parent, left_type: T, right_type: U): + def __init__(self, child, left_type: T, right_type: U): self.left_type = left_type self.right_type = right_type - self.parent = parent - super().__init__(self.parent) + self.child = child + super().__init__(self.child) @classmethod def new(cls, left_type: T, right_type: U) -> "Tuple[T, U]": @@ -187,8 +187,8 @@ def new(cls, left_type: T, right_type: U) -> "Tuple[T, U]": return Tuple( left_type=left_type, right_type=right_type, - parent=TupleNew( - parent=(left_type, right_type), + child=TupleNew( + child=(left_type, right_type), source_ref=SourceRef.back_frame(), ), ) @@ -219,18 +219,18 @@ class NTuple(NadaType): types: List[NadaType] - def __init__(self, parent, types: List[NadaType]): + def __init__(self, child, types: List[NadaType]): self.types = types - self.parent = parent - super().__init__(self.parent) + self.child = child + super().__init__(self.child) @classmethod def new(cls, types: List[NadaType]) -> "NTuple": """Constructs a new NTuple.""" return NTuple( types=types, - parent=NTupleNew( - parent=types, + child=NTupleNew( + child=types, source_ref=SourceRef.back_frame(), ), ) @@ -265,18 +265,18 @@ class Object(NadaType): types: Dict[str, NadaType] - def __init__(self, parent, types: Dict[str, NadaType]): + def __init__(self, child, types: Dict[str, NadaType]): self.types = types - self.parent = parent - super().__init__(self.parent) + self.child = child + super().__init__(self.child) @classmethod def new(cls, types: Dict[str, NadaType]) -> "Object": """Constructs a new Object.""" return Object( types=types, - parent=ObjectNew( - parent=types, + child=ObjectNew( + child=types, source_ref=SourceRef.back_frame(), ), ) @@ -296,9 +296,9 @@ def to_mir(self): def get_inner_type(contained_types): - """Utility that returns the parent type for a composite type.""" + """Utility that returns the child type for a composite type.""" contained_types = copy.copy(contained_types) - setattr(contained_types, "parent", None) + setattr(contained_types, "child", None) return contained_types @@ -316,8 +316,8 @@ def store_in_ast(self, ty: NadaTypeRepr): AST_OPERATIONS[self.id] = BinaryASTOperation( id=self.id, name="Zip", - left=self.left.parent.id, - right=self.right.parent.id, + left=self.left.child.id, + right=self.right.child.id, source_ref=self.source_ref, ty=ty, ) @@ -326,9 +326,9 @@ def store_in_ast(self, ty: NadaTypeRepr): class Unzip: """The Unzip operation.""" - def __init__(self, parent: AllTypes, source_ref: SourceRef): + def __init__(self, child: AllTypes, source_ref: SourceRef): self.id = next_operation_id() - self.parent = parent + self.child = child self.source_ref = source_ref def store_in_ast(self, ty: NadaTypeRepr): @@ -336,7 +336,7 @@ def store_in_ast(self, ty: NadaTypeRepr): AST_OPERATIONS[self.id] = UnaryASTOperation( id=self.id, name="Unzip", - parent=self.parent.parent.id, + child=self.child.child.id, source_ref=self.source_ref, ty=ty, ) @@ -356,8 +356,8 @@ def store_in_ast(self, ty: NadaTypeRepr): AST_OPERATIONS[self.id] = BinaryASTOperation( id=self.id, name="InnerProduct", - left=self.left.parent.id, - right=self.right.parent.id, + left=self.left.child.id, + right=self.right.child.id, source_ref=self.source_ref, ty=ty, ) @@ -390,8 +390,8 @@ class Array(Generic[T], Collection): ---------- contained_types: T The type of the array - parent: - The optional parent operation + child: + The optional child operation size: int The size of the array """ @@ -399,18 +399,18 @@ class Array(Generic[T], Collection): contained_types: T size: int - def __init__(self, parent, size: int, contained_types: T = None): + def __init__(self, child, size: int, contained_types: T = None): self.contained_types = ( contained_types - if (parent is None or contained_types is not None) - else get_inner_type(parent) + if (child is None or contained_types is not None) + else get_inner_type(child) ) self.size = size - self.parent = ( - parent if contained_types is not None else getattr(parent, "parent", None) + self.child = ( + child if contained_types is not None else getattr(child, "child", None) ) - if self.parent is not None: - self.parent.store_in_ast(self.to_mir()) + if self.child is not None: + self.child.store_in_ast(self.to_mir()) def __iter__(self): raise NotAllowedException( @@ -425,9 +425,7 @@ def map(self: "Array[T]", function) -> "Array": return Array( size=self.size, contained_types=nada_function.return_type, - parent=Map( - parent=self, fn=nada_function, source_ref=SourceRef.back_frame() - ), + child=Map(child=self, fn=nada_function, source_ref=SourceRef.back_frame()), ) def reduce(self: "Array[T]", function, initial: R) -> R: @@ -436,7 +434,7 @@ def reduce(self: "Array[T]", function, initial: R) -> R: function = nada_fn(function) return function.return_type( Reduce( - parent=self, + child=self, fn=function, initial=initial, source_ref=SourceRef.back_frame(), @@ -452,16 +450,16 @@ def zip(self: "Array[T]", other: "Array[U]") -> "Array[Tuple[T, U]]": contained_types=Tuple( left_type=self.contained_types, right_type=other.contained_types, - parent=None, + child=None, ), - parent=Zip(left=self, right=other, source_ref=SourceRef.back_frame()), + child=Zip(left=self, right=other, source_ref=SourceRef.back_frame()), ) def inner_product(self: "Array[T]", other: "Array[T]") -> T: - """The parent product operation for arrays""" + """The child product operation for arrays""" if self.size != other.size: raise IncompatibleTypesError( - "Cannot do parent product of arrays of different size" + "Cannot do child product of arrays of different size" ) if is_primitive_integer(self.retrieve_inner_type()) and is_primitive_integer( @@ -473,7 +471,7 @@ def inner_product(self: "Array[T]", other: "Array[T]") -> T: else self.contained_types.__class__ ) return contained_types( - parent=InnerProduct( + child=InnerProduct( left=self, right=other, source_ref=SourceRef.back_frame() ) ) # type: ignore @@ -495,8 +493,8 @@ def new(cls, *args) -> "Array[T]": return Array( contained_types=first_arg, size=len(args), - parent=ArrayNew( - parent=args, + child=ArrayNew( + child=args, source_ref=SourceRef.back_frame(), ), ) @@ -508,8 +506,8 @@ def generic_type(cls, contained_types: T, size: int) -> ArrayType: @classmethod def init_as_template_type(cls, contained_types) -> "Array[T]": - """Construct an empty template array with the given parent type.""" - return Array(parent=None, contained_types=contained_types, size=None) + """Construct an empty template array with the given child type.""" + return Array(child=None, contained_types=contained_types, size=None) @dataclass @@ -532,15 +530,15 @@ class Vector(Generic[T], Collection): contained_types: T size: int - def __init__(self, parent, size, contained_types=None): + def __init__(self, child, size, contained_types=None): self.contained_types = ( contained_types - if (parent is None or contained_types is not None) - else get_inner_type(parent) + if (child is None or contained_types is not None) + else get_inner_type(child) ) self.size = size - self.parent = parent if contained_types else getattr(parent, "parent", None) - self.parent.store_in_ast(self.to_mir()) + self.child = child if contained_types else getattr(child, "child", None) + self.child.store_in_ast(self.to_mir()) def __iter__(self): raise NotAllowedException( @@ -553,7 +551,7 @@ def map(self: "Vector[T]", function: NadaFunction[T, R]) -> "Vector[R]": return Vector( size=self.size, contained_types=function.return_type, - parent=(Map(parent=self, fn=function, source_ref=SourceRef.back_frame())), + child=(Map(child=self, fn=function, source_ref=SourceRef.back_frame())), ) def zip(self: "Vector[T]", other: "Vector[R]") -> "Vector[Tuple[T, R]]": @@ -563,7 +561,7 @@ def zip(self: "Vector[T]", other: "Vector[R]") -> "Vector[Tuple[T, R]]": contained_types=Tuple.generic_type( self.contained_types, other.contained_types ), - parent=Zip(left=self, right=other, source_ref=SourceRef.back_frame()), + child=Zip(left=self, right=other, source_ref=SourceRef.back_frame()), ) def reduce( @@ -572,7 +570,7 @@ def reduce( """The reduce operation for Nada Vectors.""" return function.return_type( Reduce( - parent=self, + child=self, fn=function, initial=initial, source_ref=SourceRef.back_frame(), @@ -581,13 +579,13 @@ def reduce( @classmethod def generic_type(cls, contained_types: T) -> VectorType: - """Returns the generic type for a Vector with the given parent type.""" - return VectorType(parent=None, contained_types=contained_types) + """Returns the generic type for a Vector with the given child type.""" + return VectorType(child=None, contained_types=contained_types) @classmethod def init_as_template_type(cls, contained_types) -> "Vector[T]": - """Construct an empty Vector with the given parent type.""" - return Vector(parent=None, contained_types=contained_types, size=None) + """Construct an empty Vector with the given child type.""" + return Vector(child=None, contained_types=contained_types, size=None) class TupleNew(Generic[T, U]): @@ -596,12 +594,12 @@ class TupleNew(Generic[T, U]): Represents the creation of a new Tuple. """ - parent: typing.Tuple[T, U] + child: typing.Tuple[T, U] source_ref: SourceRef - def __init__(self, parent: typing.Tuple[T, U], source_ref: SourceRef): + def __init__(self, child: typing.Tuple[T, U], source_ref: SourceRef): self.id = next_operation_id() - self.parent = parent + self.child = child self.source_ref = source_ref def store_in_ast(self, ty: object): @@ -609,7 +607,7 @@ def store_in_ast(self, ty: object): AST_OPERATIONS[self.id] = NewASTOperation( id=self.id, name=self.__class__.__name__, - elements=[element.parent.id for element in self.parent], + elements=[element.child.id for element in self.child], source_ref=self.source_ref, ty=ty, ) @@ -621,12 +619,12 @@ class NTupleNew: Represents the creation of a new Tuple. """ - parent: typing.Tuple + child: typing.Tuple source_ref: SourceRef - def __init__(self, parent: typing.Tuple, source_ref: SourceRef): + def __init__(self, child: typing.Tuple, source_ref: SourceRef): self.id = next_operation_id() - self.parent = parent + self.child = child self.source_ref = source_ref def store_in_ast(self, ty: object): @@ -634,7 +632,7 @@ def store_in_ast(self, ty: object): AST_OPERATIONS[self.id] = NewASTOperation( id=self.id, name=self.__class__.__name__, - elements=[element.parent.id for element in self.parent], + elements=[element.child.id for element in self.child], source_ref=self.source_ref, ty=ty, ) @@ -646,12 +644,12 @@ class ObjectNew: Represents the creation of a new Object. """ - parent: typing.Dict + child: typing.Dict source_ref: SourceRef - def __init__(self, parent: typing.Dict, source_ref: SourceRef): + def __init__(self, child: typing.Dict, source_ref: SourceRef): self.id = next_operation_id() - self.parent = parent + self.child = child self.source_ref = source_ref def store_in_ast(self, ty: object): @@ -659,7 +657,7 @@ def store_in_ast(self, ty: object): AST_OPERATIONS[self.id] = NewASTOperation( id=self.id, name=self.__class__.__name__, - elements=[element.parent.id for element in self.parent.values()], + elements=[element.child.id for element in self.child.values()], source_ref=self.source_ref, ty=ty, ) @@ -677,7 +675,7 @@ def unzip(array: Array[Tuple[T, R]]) -> Tuple[Array[T], Array[R]]: return Tuple( right_type=right_type, left_type=left_type, - parent=Unzip(parent=array, source_ref=SourceRef.back_frame()), + child=Unzip(child=array, source_ref=SourceRef.back_frame()), ) @@ -685,12 +683,12 @@ def unzip(array: Array[Tuple[T, R]]) -> Tuple[Array[T], Array[R]]: class ArrayNew(Generic[T]): """MIR Array new operation""" - parent: List[T] + child: List[T] source_ref: SourceRef - def __init__(self, parent: List[T], source_ref: SourceRef): + def __init__(self, child: List[T], source_ref: SourceRef): self.id = next_operation_id() - self.parent = parent + self.child = child self.source_ref = source_ref def store_in_ast(self, ty: NadaType): @@ -698,7 +696,7 @@ def store_in_ast(self, ty: NadaType): AST_OPERATIONS[self.id] = NewASTOperation( id=self.id, name=self.__class__.__name__, - elements=[element.parent.id for element in self.parent], + elements=[element.child.id for element in self.child], source_ref=self.source_ref, ty=ty, ) diff --git a/nada_dsl/nada_types/function.py b/nada_dsl/nada_types/function.py index 34cfd67..c72bab1 100644 --- a/nada_dsl/nada_types/function.py +++ b/nada_dsl/nada_types/function.py @@ -70,7 +70,7 @@ def __init__( function: Callable[[T], R], return_type: R, source_ref: SourceRef, - parent: NadaType, + child: NadaType, ): if issubclass(return_type, ScalarType) and return_type.mode == Mode.CONSTANT: raise NotAllowedException( @@ -86,7 +86,7 @@ def __init__( raise NotAllowedException( "Nada functions with literal argument types are not allowed" ) - self.parent = parent + self.child = child self.id = function_id self.args = args self.function = function @@ -103,12 +103,12 @@ def store_in_ast(self): id=self.id, ty=self.return_type.class_to_type(), source_ref=self.source_ref, - parent=self.parent.parent.id, + child=self.child.child.id, ) def __call__(self, *args, **kwargs) -> R: return self.return_type( - parent=NadaFunctionCall(self, args, source_ref=SourceRef.back_frame()) + child=NadaFunctionCall(self, args, source_ref=SourceRef.back_frame()) ) @@ -131,7 +131,7 @@ def store_in_ast(self, ty): """Store this function call in the AST.""" AST_OPERATIONS[self.id] = NadaFunctionCallASTOperation( id=self.id, - args=[arg.parent.id for arg in self.args], + args=[arg.child.id for arg in self.args], fn=self.fn.id, source_ref=self.source_ref, ty=ty, @@ -139,7 +139,7 @@ def store_in_ast(self, ty): def contained_types(ty): - """Utility function that calculates the parent type for a function argument.""" + """Utility function that calculates the child type for a function argument.""" origin_ty = getattr(ty, "__origin__", ty) if not issubclass(origin_ty, ScalarType): @@ -148,7 +148,7 @@ def contained_types(ty): return origin_ty.init_as_template_type(inner_ty) if origin_ty.mode == Mode.CONSTANT: return origin_ty(value=0) - return origin_ty(parent=None) + return origin_ty(child=None) def nada_fn(fn, args_ty=None, return_ty=None) -> NadaFunction[T, R]: @@ -181,17 +181,17 @@ def nada_fn(fn, args_ty=None, return_ty=None) -> NadaFunction[T, R]: for arg in nada_args: arg_type = copy(arg.type) - arg_type.parent = arg + arg_type.child = arg nada_args_type_wrapped.append(arg_type) - parent = fn(*nada_args_type_wrapped) + child = fn(*nada_args_type_wrapped) return_type = return_ty if return_ty else args.annotations["return"] return NadaFunction( function_id, function=fn, args=nada_args, - parent=parent, + child=child, return_type=return_type, source_ref=SourceRef.back_frame(), ) diff --git a/nada_dsl/nada_types/scalar_types.py b/nada_dsl/nada_types/scalar_types.py index f27915f..f9c12d4 100644 --- a/nada_dsl/nada_types/scalar_types.py +++ b/nada_dsl/nada_types/scalar_types.py @@ -57,8 +57,8 @@ class ScalarType(NadaType): based on the typing rules of the Nada model. """ - def __init__(self, parent: OperationType, base_type: BaseType, mode: Mode): - super().__init__(parent=parent) + def __init__(self, child: OperationType, base_type: BaseType, mode: Mode): + super().__init__(child=child) self.base_type = base_type self.mode = mode @@ -96,12 +96,12 @@ def equals_operation( operation = globals()[operation]( left=left, right=right, source_ref=SourceRef.back_frame() ) - return PublicBoolean(parent=operation) + return PublicBoolean(child=operation) case Mode.SECRET: operation = globals()[operation]( left=left, right=right, source_ref=SourceRef.back_frame() ) - return SecretBoolean(parent=operation) + return SecretBoolean(child=operation) def register_scalar_type(mode: Mode, base_type: BaseType): @@ -167,8 +167,8 @@ def __pow__(self, other): if mode == Mode.CONSTANT: return new_scalar_type(mode, base_type)(self.value**other.value) if mode == Mode.PUBLIC: - parent = Power(left=self, right=other, source_ref=SourceRef.back_frame()) - return new_scalar_type(mode, base_type)(parent) + child = Power(left=self, right=other, source_ref=SourceRef.back_frame()) + return new_scalar_type(mode, base_type)(child) raise TypeError(f"Invalid operation: {self} ** {other}") def __lshift__(self, other): @@ -226,10 +226,10 @@ def binary_arithmetic_operation( case Mode.CONSTANT: return new_scalar_type(mode, base_type)(f(left.value, right.value)) case Mode.PUBLIC | Mode.SECRET: - parent = globals()[operation]( + child = globals()[operation]( left=left, right=right, source_ref=SourceRef.back_frame() ) - return new_scalar_type(mode, base_type)(parent) + return new_scalar_type(mode, base_type)(child) def shift_operation( @@ -248,10 +248,10 @@ def shift_operation( case Mode.CONSTANT: return new_scalar_type(mode, base_type)(f(left.value, right.value)) case Mode.PUBLIC | Mode.SECRET: - parent = globals()[operation]( + child = globals()[operation]( left=left, right=right, source_ref=SourceRef.back_frame() ) - return new_scalar_type(mode, base_type)(parent) + return new_scalar_type(mode, base_type)(child) def binary_relational_operation( @@ -266,10 +266,10 @@ def binary_relational_operation( case Mode.CONSTANT: return new_scalar_type(mode, BaseType.BOOLEAN)(f(left.value, right.value)) # type: ignore case Mode.PUBLIC | Mode.SECRET: - parent = globals()[operation]( + child = globals()[operation]( left=left, right=right, source_ref=SourceRef.back_frame() ) - return new_scalar_type(mode, BaseType.BOOLEAN)(parent) # type: ignore + return new_scalar_type(mode, BaseType.BOOLEAN)(child) # type: ignore def public_equals_operation(left: ScalarType, right: ScalarType) -> "PublicBoolean": @@ -281,7 +281,7 @@ def public_equals_operation(left: ScalarType, right: ScalarType) -> "PublicBoole raise TypeError(f"Invalid operation: {left}.public_equals({right})") return PublicBoolean( - parent=PublicOutputEquality( + child=PublicOutputEquality( left=left, right=right, source_ref=SourceRef.back_frame() ) # type: ignore ) @@ -318,12 +318,12 @@ def if_else(self, arg_0: _AnyScalarType, arg_1: _AnyScalarType) -> _AnyScalarTyp ): raise TypeError(f"Invalid operation: {self}.IfElse({arg_0}, {arg_1})") mode = Mode(max([self.mode.value, arg_0.mode.value, arg_1.mode.value])) - parent = IfElse( + child = IfElse( this=self, arg_0=arg_0, arg_1=arg_1, source_ref=SourceRef.back_frame() ) if mode == Mode.CONSTANT: mode = Mode.PUBLIC - return new_scalar_type(mode, base_type)(parent) + return new_scalar_type(mode, base_type)(child) def binary_logical_operation( @@ -340,12 +340,12 @@ def binary_logical_operation( operation = globals()[operation]( left=left, right=right, source_ref=SourceRef.back_frame() ) - return PublicBoolean(parent=operation) + return PublicBoolean(child=operation) operation = globals()[operation]( left=left, right=right, source_ref=SourceRef.back_frame() ) - return SecretBoolean(parent=operation) + return SecretBoolean(child=operation) @register_scalar_type(Mode.CONSTANT, BaseType.INTEGER) @@ -435,8 +435,8 @@ class PublicInteger(NumericType): Represents a public unsigned integer in a program. This is a public variable evaluated at runtime.""" - def __init__(self, parent: NadaType): - super().__init__(parent, BaseType.INTEGER, Mode.PUBLIC) + def __init__(self, child: NadaType): + super().__init__(child, BaseType.INTEGER, Mode.PUBLIC) def __eq__(self, other) -> AnyBoolean: return ScalarType.__eq__(self, other) @@ -455,8 +455,8 @@ class PublicUnsignedInteger(NumericType): Represents a public integer in a program. This is a public variable evaluated at runtime.""" - def __init__(self, parent: NadaType): - super().__init__(parent, BaseType.UNSIGNED_INTEGER, Mode.PUBLIC) + def __init__(self, child: NadaType): + super().__init__(child, BaseType.UNSIGNED_INTEGER, Mode.PUBLIC) def __eq__(self, other) -> AnyBoolean: return ScalarType.__eq__(self, other) @@ -476,15 +476,15 @@ class PublicBoolean(BooleanType): Represents a public boolean in a program. This is a public variable evaluated at runtime.""" - def __init__(self, parent: NadaType): - super().__init__(parent, BaseType.BOOLEAN, Mode.PUBLIC) + def __init__(self, child: NadaType): + super().__init__(child, BaseType.BOOLEAN, Mode.PUBLIC) def __eq__(self, other) -> AnyBoolean: return ScalarType.__eq__(self, other) def __invert__(self: "PublicBoolean") -> "PublicBoolean": operation = Not(this=self, source_ref=SourceRef.back_frame()) - return PublicBoolean(parent=operation) + return PublicBoolean(child=operation) def public_equals( self, other: Union["PublicUnsignedInteger", "SecretUnsignedInteger"] @@ -498,8 +498,8 @@ def public_equals( class SecretInteger(NumericType): """The Nada secret integer type.""" - def __init__(self, parent: NadaType): - super().__init__(parent, BaseType.INTEGER, Mode.SECRET) + def __init__(self, child: NadaType): + super().__init__(child, BaseType.INTEGER, Mode.SECRET) def __eq__(self, other) -> AnyBoolean: return ScalarType.__eq__(self, other) @@ -518,24 +518,24 @@ def trunc_pr( operation = TruncPr( left=self, right=other, source_ref=SourceRef.back_frame() ) - return SecretInteger(parent=operation) + return SecretInteger(child=operation) if isinstance(other, PublicUnsignedInteger): operation = TruncPr( left=self, right=other, source_ref=SourceRef.back_frame() ) - return SecretInteger(parent=operation) + return SecretInteger(child=operation) raise TypeError(f"Invalid operation: {self}.trunc_pr({other})") @classmethod def random(cls) -> "SecretInteger": """Random operation for Secret integers.""" - return SecretInteger(parent=Random(source_ref=SourceRef.back_frame())) + return SecretInteger(child=Random(source_ref=SourceRef.back_frame())) def to_public(self: "SecretInteger") -> "PublicInteger": """Convert this secret integer into a public variable.""" operation = Reveal(this=self, source_ref=SourceRef.back_frame()) - return PublicInteger(parent=operation) + return PublicInteger(child=operation) @dataclass @@ -543,8 +543,8 @@ def to_public(self: "SecretInteger") -> "PublicInteger": class SecretUnsignedInteger(NumericType): """The Nada Secret Unsigned integer type.""" - def __init__(self, parent: NadaType): - super().__init__(parent, BaseType.UNSIGNED_INTEGER, Mode.SECRET) + def __init__(self, child: NadaType): + super().__init__(child, BaseType.UNSIGNED_INTEGER, Mode.SECRET) def __eq__(self, other) -> AnyBoolean: return ScalarType.__eq__(self, other) @@ -563,26 +563,26 @@ def trunc_pr( operation = TruncPr( left=self, right=other, source_ref=SourceRef.back_frame() ) - return SecretUnsignedInteger(parent=operation) + return SecretUnsignedInteger(child=operation) if isinstance(other, PublicUnsignedInteger): operation = TruncPr( left=self, right=other, source_ref=SourceRef.back_frame() ) - return SecretUnsignedInteger(parent=operation) + return SecretUnsignedInteger(child=operation) raise TypeError(f"Invalid operation: {self}.trunc_pr({other})") @classmethod def random(cls) -> "SecretUnsignedInteger": """Generate a random secret unsigned integer.""" - return SecretUnsignedInteger(parent=Random(source_ref=SourceRef.back_frame())) + return SecretUnsignedInteger(child=Random(source_ref=SourceRef.back_frame())) def to_public( self: "SecretUnsignedInteger", ) -> "PublicUnsignedInteger": """Convert this secret into a public variable.""" operation = Reveal(this=self, source_ref=SourceRef.back_frame()) - return PublicUnsignedInteger(parent=operation) + return PublicUnsignedInteger(child=operation) @dataclass @@ -590,52 +590,52 @@ def to_public( class SecretBoolean(BooleanType): """The SecretBoolean Nada MIR type.""" - def __init__(self, parent: NadaType): - super().__init__(parent, BaseType.BOOLEAN, Mode.SECRET) + def __init__(self, child: NadaType): + super().__init__(child, BaseType.BOOLEAN, Mode.SECRET) def __eq__(self, other) -> AnyBoolean: return ScalarType.__eq__(self, other) def __invert__(self: "SecretBoolean") -> "SecretBoolean": operation = Not(this=self, source_ref=SourceRef.back_frame()) - return SecretBoolean(parent=operation) + return SecretBoolean(child=operation) def to_public(self: "SecretBoolean") -> "PublicBoolean": """Convert this secret into a public variable.""" operation = Reveal(this=self, source_ref=SourceRef.back_frame()) - return PublicBoolean(parent=operation) + return PublicBoolean(child=operation) @classmethod def random(cls) -> "SecretBoolean": """Generate a random secret boolean.""" - return SecretBoolean(parent=Random(source_ref=SourceRef.back_frame())) + return SecretBoolean(child=Random(source_ref=SourceRef.back_frame())) @dataclass class EcdsaSignature(NadaType): """The EcdsaSignature Nada MIR type.""" - def __init__(self, parent: OperationType): - super().__init__(parent=parent) + def __init__(self, child: OperationType): + super().__init__(child=child) @dataclass class EcdsaDigestMessage(NadaType): """The EcdsaDigestMessage Nada MIR type.""" - def __init__(self, parent: OperationType): - super().__init__(parent=parent) + def __init__(self, child: OperationType): + super().__init__(child=child) @dataclass class EcdsaPrivateKey(NadaType): """The EcdsaPrivateKey Nada MIR type.""" - def __init__(self, parent: OperationType): - super().__init__(parent=parent) + def __init__(self, child: OperationType): + super().__init__(child=child) def ecdsa_sign(self, digest: "EcdsaDigestMessage") -> "EcdsaSignature": """Random operation for Secret integers.""" return EcdsaSignature( - parent=EcdsaSign(left=self, right=digest, source_ref=SourceRef.back_frame()) + child=EcdsaSign(left=self, right=digest, source_ref=SourceRef.back_frame()) ) diff --git a/nada_dsl/operations.py b/nada_dsl/operations.py index b1c3fad..6427ef4 100644 --- a/nada_dsl/operations.py +++ b/nada_dsl/operations.py @@ -29,8 +29,8 @@ def store_in_ast(self, ty: object): AST_OPERATIONS[self.id] = BinaryASTOperation( id=self.id, name=self.__class__.__name__, - left=self.left.parent.id, - right=self.right.parent.id, + left=self.left.child.id, + right=self.right.child.id, source_ref=self.source_ref, ty=ty, ) @@ -39,9 +39,9 @@ def store_in_ast(self, ty: object): class UnaryOperation: """Superclass of all the unary operations.""" - def __init__(self, parent: AllTypes, source_ref: SourceRef): + def __init__(self, child: AllTypes, source_ref: SourceRef): self.id = next_operation_id() - self.parent = parent + self.child = child self.source_ref = source_ref def store_in_ast(self, ty: object): @@ -49,7 +49,7 @@ def store_in_ast(self, ty: object): AST_OPERATIONS[self.id] = UnaryASTOperation( id=self.id, name=self.__class__.__name__, - parent=self.parent.parent.id, + child=self.child.child.id, source_ref=self.source_ref, ty=ty, ) @@ -167,9 +167,9 @@ def store_in_ast(self, ty): """Store object in AST.""" AST_OPERATIONS[self.id] = IfElseASTOperation( id=self.id, - this=self.this.parent.id, - arg_0=self.arg_0.parent.id, - arg_1=self.arg_1.parent.id, + this=self.this.child.id, + arg_0=self.arg_0.child.id, + arg_1=self.arg_1.child.id, ty=ty, source_ref=self.source_ref, ) @@ -179,7 +179,7 @@ class Reveal(UnaryOperation): """Reveal (i.e. make public) operation.""" def __init__(self, this: AllTypes, source_ref: SourceRef): - super().__init__(parent=this, source_ref=source_ref) + super().__init__(child=this, source_ref=source_ref) class TruncPr(BinaryOperation): @@ -190,7 +190,7 @@ class Not(UnaryOperation): """Not (!) Operation""" def __init__(self, this: AllTypes, source_ref: SourceRef): - super().__init__(parent=this, source_ref=source_ref) + super().__init__(child=this, source_ref=source_ref) class EcdsaSign(BinaryOperation): diff --git a/nada_dsl/program_io.py b/nada_dsl/program_io.py index 3177466..7d23d26 100644 --- a/nada_dsl/program_io.py +++ b/nada_dsl/program_io.py @@ -39,9 +39,9 @@ def __init__(self, name, party, doc=""): self.name = name self.party = party self.doc = doc - self.parent = None + self.child = None self.source_ref = SourceRef.back_frame() - super().__init__(self.parent) + super().__init__(self.child) def store_in_ast(self, ty: object): """Store object in AST""" @@ -70,8 +70,8 @@ def __init__(self, value, source_ref): self.id = next_operation_id() self.value = value self.source_ref = source_ref - self.parent = None - super().__init__(self.parent) + self.child = None + super().__init__(self.child) def store_in_ast(self, ty: object): """Store object in AST""" @@ -90,24 +90,24 @@ class Output: Represents an output from the computation. Attributes: - parent (AllTypes): The type of the output. + child (AllTypes): The type of the output. party (Party): The party receiving the output. name (str): The name of the output. """ - parent: AllTypes + child: AllTypes party: Party name: str source_ref: SourceRef - def __init__(self, parent, name, party): + def __init__(self, child, name, party): self.source_ref = SourceRef.back_frame() - if not issubclass(type(parent), NadaType): + if not issubclass(type(child), NadaType): raise InvalidTypeError( f"{self.source_ref.file}:{self.source_ref.lineno}: Output value " - f"{parent} of type {type(parent)} is not " + f"{child} of type {type(child)} is not " f"a Nada type so it isn't a valid output" ) - self.parent = parent + self.child = child self.name = name self.party = party diff --git a/nada_mir/src/nada_mir_proto/nillion/nada/mir/v1/__init__.py b/nada_mir/src/nada_mir_proto/nillion/nada/mir/v1/__init__.py index cb7d192..d5d4a46 100644 --- a/nada_mir/src/nada_mir_proto/nillion/nada/mir/v1/__init__.py +++ b/nada_mir/src/nada_mir_proto/nillion/nada/mir/v1/__init__.py @@ -123,7 +123,7 @@ class Output(betterproto.Message): """Output name""" operation_id: int = betterproto.int64_field(2) - """Output parent operation""" + """Output child operation""" party: str = betterproto.string_field(3) """Party contains this output""" diff --git a/nada_mir/src/nada_mir_proto/nillion/nada/operations/v1/__init__.py b/nada_mir/src/nada_mir_proto/nillion/nada/operations/v1/__init__.py index a85dea7..f17cbe4 100644 --- a/nada_mir/src/nada_mir_proto/nillion/nada/operations/v1/__init__.py +++ b/nada_mir/src/nada_mir_proto/nillion/nada/operations/v1/__init__.py @@ -237,7 +237,7 @@ class MapOperation(betterproto.Message): fn: int = betterproto.uint64_field(2) """Function to execute""" - parent: int = betterproto.uint64_field(3) + child: int = betterproto.uint64_field(3) """Map operation input""" @@ -249,7 +249,7 @@ class ReduceOperation(betterproto.Message): fn: int = betterproto.uint64_field(2) """Function to execute""" - parent: int = betterproto.uint64_field(3) + child: int = betterproto.uint64_field(3) """Map operation input""" initial: int = betterproto.uint64_field(4) diff --git a/tests/compile_test.py b/tests/compile_test.py index 611d5f6..986d7c2 100644 --- a/tests/compile_test.py +++ b/tests/compile_test.py @@ -154,7 +154,7 @@ def test_compile_map_simple(): operations_found += 1 elif name == "Map": assert op["fn"] == function_id - map_inner = op["parent"] + map_inner = op["child"] function_op_id = op["id"] operations_found += 1 else: diff --git a/tests/compiler_frontend_test.py b/tests/compiler_frontend_test.py index 0e133e1..278660b 100644 --- a/tests/compiler_frontend_test.py +++ b/tests/compiler_frontend_test.py @@ -145,7 +145,7 @@ def test_zip(input_type, input_name): right = create_collection(input_type, inner_input, 10, **{}) zipped = left.zip(right) assert isinstance(zipped, Array) - zip_ast = AST_OPERATIONS[zipped.parent.id] + zip_ast = AST_OPERATIONS[zipped.child.id] op = process_operation(zip_ast, {}).mir assert list(op.keys()) == ["Zip"] @@ -174,14 +174,14 @@ def test_unzip(input_type: type[Array]): right = create_collection(input_type, inner_input, 10, **{}) unzipped = unzip(left.zip(right)) assert isinstance(unzipped, Tuple) - unzip_ast = AST_OPERATIONS[unzipped.parent.id] + unzip_ast = AST_OPERATIONS[unzipped.child.id] assert isinstance(unzip_ast, UnaryASTOperation) assert unzip_ast.name == "Unzip" - op = process_operation(AST_OPERATIONS[unzipped.parent.id], {}).mir + op = process_operation(AST_OPERATIONS[unzipped.child.id], {}).mir unzip_mir = op["Unzip"] - # Check that the parent operation points to a Zip + # Check that the child operation points to a Zip zip_ast = AST_OPERATIONS[unzip_mir["this"]] assert isinstance(zip_ast, BinaryASTOperation) assert zip_ast.name == "Zip" @@ -204,21 +204,21 @@ def test_map(input_type, input_name): def nada_function(a: SecretInteger) -> SecretInteger: return a + a - inner_input = create_input(SecretInteger, "parent", "party", **{}) + inner_input = create_input(SecretInteger, "child", "party", **{}) left = create_collection(input_type, inner_input, 10, **{}) map_operation = left.map(nada_function) - process_output = process_operation(AST_OPERATIONS[map_operation.parent.id], {}) + process_output = process_operation(AST_OPERATIONS[map_operation.child.id], {}) op = process_output.mir extra_fn = process_output.extra_function assert list(op.keys()) == ["Map"] - parent = op["Map"] - assert parent["fn"] == extra_fn.id - assert list(parent["type"].keys()) == [input_name] - inner_inner = AST_OPERATIONS[parent["parent"]] - assert inner_inner.name == "parent" - assert parent["type"][input_name]["contained_types"] == "SecretInteger" + child = op["Map"] + assert child["fn"] == extra_fn.id + assert list(child["type"].keys()) == [input_name] + inner_inner = AST_OPERATIONS[child["child"]] + assert inner_inner.name == "child" + assert child["type"][input_name]["contained_types"] == "SecretInteger" @pytest.mark.parametrize( @@ -234,23 +234,23 @@ def test_reduce(input_type: type[Array]): def nada_function(a: SecretInteger, b: SecretInteger) -> SecretInteger: return a + b - inner_input = create_input(SecretInteger, "parent", "party", **{}) + inner_input = create_input(SecretInteger, "child", "party", **{}) left = create_collection(input_type, inner_input, 10, **{}) reduce_operation = left.reduce(nada_function, c) - reduce_ast = AST_OPERATIONS[reduce_operation.parent.id] + reduce_ast = AST_OPERATIONS[reduce_operation.child.id] assert isinstance(reduce_ast, ReduceASTOperation) process_output = process_operation(reduce_ast, {}) op = process_output.mir extra_fn = process_output.extra_function assert list(op.keys()) == ["Reduce"] - parent = op["Reduce"] - assert parent["fn"] == extra_fn.id - assert parent["type"] == "SecretInteger" - inner_inner = AST_OPERATIONS[parent["parent"]] - assert inner_inner.name == "parent" + child = op["Reduce"] + assert child["fn"] == extra_fn.id + assert child["type"] == "SecretInteger" + inner_inner = AST_OPERATIONS[child["child"]] + assert inner_inner.name == "child" def check_arg(arg: NadaFunctionArg, arg_name, arg_type): @@ -269,7 +269,7 @@ def nada_function_to_mir(function_name: str): nada_function: NadaFunctionASTOperation = find_function_in_ast(function_name) assert isinstance(nada_function, NadaFunctionASTOperation) fn_ops = {} - traverse_and_process_operations(nada_function.parent, fn_ops, {}) + traverse_and_process_operations(nada_function.child, fn_ops, {}) return nada_function.to_mir(fn_ops) @@ -346,7 +346,7 @@ def nada_function(a: SecretInteger, b: SecretInteger) -> SecretInteger: nada_fn_call_return = nada_function(c, d) nada_fn_type = nada_function_to_mir("nada_function") - nada_function_call = nada_fn_call_return.parent + nada_function_call = nada_fn_call_return.child assert isinstance(nada_function_call, NadaFunctionCall) assert nada_function_call.fn.id == nada_fn_type["id"] @@ -436,13 +436,13 @@ def matrix_addition( reduce_op["function_id"] = add_fn["id"] reduce_op["type"] = "SecretInteger" - reduce_op_inner = operations[reduce_op["parent"]] + reduce_op_inner = operations[reduce_op["child"]] assert list(reduce_op_inner.keys()) == ["Map"] map_op = reduce_op_inner["Map"] map_op["function_id"] = add_fn["id"] map_op["type"] = {input_name: {"contained_types": "SecretInteger", "size": None}} - map_op_inner = operations[map_op["parent"]] + map_op_inner = operations[map_op["child"]] assert list(map_op_inner.keys()) == ["Zip"] zip_op = map_op_inner["Zip"] @@ -457,18 +457,18 @@ def test_array_new(): second_input = create_input(SecretInteger, "second", "party", **{}) array = Array.new(first_input, second_input) - op = process_operation(AST_OPERATIONS[array.parent.id], {}).mir + op = process_operation(AST_OPERATIONS[array.child.id], {}).mir assert list(op.keys()) == ["New"] - parent = op["New"] + child = op["New"] - first: InputASTOperation = AST_OPERATIONS[parent["elements"][0]] # type: ignore - second: InputASTOperation = AST_OPERATIONS[parent["elements"][1]] # type: ignore + first: InputASTOperation = AST_OPERATIONS[child["elements"][0]] # type: ignore + second: InputASTOperation = AST_OPERATIONS[child["elements"][1]] # type: ignore assert first.name == "first" assert second.name == "second" - assert parent["type"]["Array"] == { + assert child["type"]["Array"] == { "contained_types": "SecretInteger", "size": 2, } @@ -493,19 +493,19 @@ def test_tuple_new(): first_input = create_input(SecretInteger, "first", "party", **{}) second_input = create_input(PublicInteger, "second", "party", **{}) tuple = Tuple.new(first_input, second_input) - array_ast = AST_OPERATIONS[tuple.parent.id] + array_ast = AST_OPERATIONS[tuple.child.id] op = process_operation(array_ast, {}).mir assert list(op.keys()) == ["New"] - parent = op["New"] + child = op["New"] - left_ast = AST_OPERATIONS[parent["elements"][0]] - right_ast = AST_OPERATIONS[parent["elements"][1]] + left_ast = AST_OPERATIONS[child["elements"][0]] + right_ast = AST_OPERATIONS[child["elements"][1]] assert left_ast.name == "first" assert right_ast.name == "second" - assert parent["type"]["Tuple"] == { + assert child["type"]["Tuple"] == { "left_type": "SecretInteger", "right_type": "Integer", } @@ -525,22 +525,22 @@ def test_n_tuple_new(): second_input = create_input(PublicInteger, "second", "party", **{}) third_input = create_input(SecretInteger, "third", "party", **{}) tuple = NTuple.new([first_input, second_input, third_input]) - array_ast = AST_OPERATIONS[tuple.parent.id] + array_ast = AST_OPERATIONS[tuple.child.id] op = process_operation(array_ast, {}).mir assert list(op.keys()) == ["New"] - parent = op["New"] + child = op["New"] - first_ast = AST_OPERATIONS[parent["elements"][0]] - second_ast = AST_OPERATIONS[parent["elements"][1]] - third_ast = AST_OPERATIONS[parent["elements"][2]] + first_ast = AST_OPERATIONS[child["elements"][0]] + second_ast = AST_OPERATIONS[child["elements"][1]] + third_ast = AST_OPERATIONS[child["elements"][2]] assert first_ast.name == "first" assert second_ast.name == "second" assert third_ast.name == "third" - print(f"parent = {parent}") - assert parent["type"]["NTuple"] == { + print(f"child = {child}") + assert child["type"]["NTuple"] == { "types": ["SecretInteger", "Integer", "SecretInteger"], } @@ -550,22 +550,22 @@ def test_object_new(): second_input = create_input(PublicInteger, "second", "party", **{}) third_input = create_input(SecretInteger, "third", "party", **{}) object = Object.new({"a": first_input, "b": second_input, "c": third_input}) - array_ast = AST_OPERATIONS[object.parent.id] + array_ast = AST_OPERATIONS[object.child.id] op = process_operation(array_ast, {}).mir assert list(op.keys()) == ["New"] - parent = op["New"] + child = op["New"] - first_ast = AST_OPERATIONS[parent["elements"][0]] - second_ast = AST_OPERATIONS[parent["elements"][1]] - third_ast = AST_OPERATIONS[parent["elements"][2]] + first_ast = AST_OPERATIONS[child["elements"][0]] + second_ast = AST_OPERATIONS[child["elements"][1]] + third_ast = AST_OPERATIONS[child["elements"][2]] assert first_ast.name == "first" assert second_ast.name == "second" assert third_ast.name == "third" - print(f"parent = {parent}") - assert parent["type"]["Object"] == { + print(f"child = {child}") + assert child["type"]["Object"] == { "types": {"a": "SecretInteger", "b": "Integer", "c": "SecretInteger"}, } @@ -591,11 +591,11 @@ def test_binary_operator_integer_integer(binary_operator, name, ty): right = create_literal(Integer, -2) program_operation = binary_operator(left, right) # recover operation from AST - ast_operation = AST_OPERATIONS[program_operation.parent.id] + ast_operation = AST_OPERATIONS[program_operation.child.id] op = process_operation(ast_operation, {}).mir assert list(op.keys()) == [name] - parent = op[name] - assert parent["type"] == to_mir(ty) + child = op[name] + assert child["type"] == to_mir(ty) @pytest.mark.parametrize( @@ -619,17 +619,17 @@ def test_binary_operator_integer_publicinteger(operator, name, ty): right = create_input(PublicInteger, "right", "party") program_operation = operator(left, right) # recover operation from AST - ast_operation = AST_OPERATIONS[program_operation.parent.id] + ast_operation = AST_OPERATIONS[program_operation.child.id] op = process_operation(ast_operation, {}).mir assert list(op.keys()) == [name] - parent = op[name] - left_ast = AST_OPERATIONS[parent["left"]] - right_ast = AST_OPERATIONS[parent["right"]] + child = op[name] + left_ast = AST_OPERATIONS[child["left"]] + right_ast = AST_OPERATIONS[child["right"]] assert isinstance(left_ast, LiteralASTOperation) assert left_ast.value == -3 assert isinstance(right_ast, InputASTOperation) assert right_ast.name == "right" - assert parent["type"] == to_mir(ty) + assert child["type"] == to_mir(ty) def test_logical_operations(): @@ -660,13 +660,13 @@ def test_not(): party1 = Party(name="Party1") bool1 = SecretBoolean(Input(name="my_bool_1", party=party1)) operation = ~bool1 - ast = AST_OPERATIONS[operation.parent.id] + ast = AST_OPERATIONS[operation.child.id] op = process_operation(ast, {}).mir assert list(op.keys()) == ["Not"] bool1 = PublicBoolean(Input(name="my_bool_1", party=party1)) operation = ~bool1 - ast = AST_OPERATIONS[operation.parent.id] + ast = AST_OPERATIONS[operation.child.id] op = process_operation(ast, {}).mir assert list(op.keys()) == ["Not"]