diff --git a/docs/manual/basics.ipynb b/docs/manual/basics.ipynb index c75b22d225..05d218396d 100644 --- a/docs/manual/basics.ipynb +++ b/docs/manual/basics.ipynb @@ -272,7 +272,7 @@ " var first: Int\n", " var second: Int\n", "\n", - " fn __init__(inout self, first: Int, second: Int):\n", + " fn __init__(out self, first: Int, second: Int):\n", " self.first = first\n", " self.second = second\n", "\n", diff --git a/docs/manual/decorators/nonmaterializable.ipynb b/docs/manual/decorators/nonmaterializable.ipynb index 494a9880a1..4e88c205ae 100644 --- a/docs/manual/decorators/nonmaterializable.ipynb +++ b/docs/manual/decorators/nonmaterializable.ipynb @@ -48,11 +48,11 @@ "struct HasBool:\n", " var x: Bool\n", "\n", - " fn __init__(inout self, x: Bool):\n", + " fn __init__(out self, x: Bool):\n", " self.x = x\n", "\n", " @always_inline(\"nodebug\")\n", - " fn __init__(inout self, nms: NmStruct):\n", + " fn __init__(out self, nms: NmStruct):\n", " self.x = True if (nms.x == 77) else False\n", "\n", "@value\n", diff --git a/docs/manual/decorators/register-passable.ipynb b/docs/manual/decorators/register-passable.ipynb index 31c31d8e4d..174418abaa 100644 --- a/docs/manual/decorators/register-passable.ipynb +++ b/docs/manual/decorators/register-passable.ipynb @@ -42,11 +42,11 @@ " var a: Int\n", " var b: Int\n", "\n", - " fn __init__(inout self, one: Int, two: Int):\n", + " fn __init__(out self, one: Int, two: Int):\n", " self.a = one\n", " self.b = two\n", "\n", - " fn __copyinit__(inout self, existing: Self):\n", + " fn __copyinit__(out self, existing: Self):\n", " self.a = existing.a\n", " self.b = existing.b\n", "\n", diff --git a/docs/manual/decorators/staticmethod.ipynb b/docs/manual/decorators/staticmethod.ipynb index 84ff19d90d..bcd9a4d2e5 100644 --- a/docs/manual/decorators/staticmethod.ipynb +++ b/docs/manual/decorators/staticmethod.ipynb @@ -38,10 +38,10 @@ "struct MyStruct:\n", " var data: List[UInt8]\n", "\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " self.data = List[UInt8]()\n", "\n", - " fn __moveinit__(inout self, owned existing: Self):\n", + " fn __moveinit__(out self, owned existing: Self):\n", " self.data = existing.data ^\n", "\n", " @staticmethod\n", diff --git a/docs/manual/decorators/value.ipynb b/docs/manual/decorators/value.ipynb index 807bd962cb..f82a54a21b 100644 --- a/docs/manual/decorators/value.ipynb +++ b/docs/manual/decorators/value.ipynb @@ -58,15 +58,15 @@ " var name: String\n", " var age: Int\n", "\n", - " fn __init__(inout self, owned name: String, age: Int):\n", + " fn __init__(out self, owned name: String, age: Int):\n", " self.name = name^\n", " self.age = age\n", "\n", - " fn __copyinit__(inout self, existing: Self):\n", + " fn __copyinit__(out self, existing: Self):\n", " self.name = existing.name\n", " self.age = existing.age\n", "\n", - " fn __moveinit__(inout self, owned existing: Self):\n", + " fn __moveinit__(out self, owned existing: Self):\n", " self.name = existing.name^\n", " self.age = existing.age" ] diff --git a/docs/manual/functions.ipynb b/docs/manual/functions.ipynb index 420d13aa46..6f24f70e0d 100755 --- a/docs/manual/functions.ipynb +++ b/docs/manual/functions.ipynb @@ -794,7 +794,7 @@ "source": [ "@value\n", "struct MyString:\n", - " fn __init__(inout self, string: StringLiteral):\n", + " fn __init__(out self, string: StringLiteral):\n", " pass\n", "\n", "fn foo(name: String):\n", diff --git a/docs/manual/lifecycle/death.ipynb b/docs/manual/lifecycle/death.ipynb index 74cfb1e86e..9329b7aebb 100644 --- a/docs/manual/lifecycle/death.ipynb +++ b/docs/manual/lifecycle/death.ipynb @@ -186,7 +186,7 @@ " var name: String\n", " var age: Int\n", "\n", - " fn __init__(inout self, name: String, age: Int):\n", + " fn __init__(out self, name: String, age: Int):\n", " self.name = name\n", " self.age = age" ] @@ -216,7 +216,7 @@ " var data: UnsafePointer[Int]\n", " var size: Int\n", "\n", - " fn __init__(inout self, size: Int, val: Int):\n", + " fn __init__(out self, size: Int, val: Int):\n", " self.size = size\n", " self.data = UnsafePointer[Int].alloc(self.size)\n", " for i in range(self.size):\n", @@ -272,7 +272,7 @@ " var name: String\n", " var age: Int\n", "\n", - " fn __init__(inout self, name: String, age: Int):\n", + " fn __init__(out self, name: String, age: Int):\n", " self.name = name\n", " self.age = age\n", "\n", @@ -398,7 +398,7 @@ "\n", "```mojo\n", "struct TwoStrings:\n", - " fn __moveinit__(inout self, owned existing: Self):\n", + " fn __moveinit__(out self, owned existing: Self):\n", " # Initializes a new `self` by consuming the contents of `existing`\n", " fn __del__(owned self):\n", " # Destroys all resources in `self`\n", @@ -448,11 +448,11 @@ " var str1: String\n", " var str2: String\n", "\n", - " fn __init__(inout self, one: String):\n", + " fn __init__(out self, one: String):\n", " self.str1 = one\n", " self.str2 = String(\"bar\")\n", "\n", - " fn __moveinit__(inout self, owned existing: Self):\n", + " fn __moveinit__(out self, owned existing: Self):\n", " self.str1 = existing.str1\n", " self.str2 = existing.str2\n", "\n", diff --git a/docs/manual/lifecycle/life.ipynb b/docs/manual/lifecycle/life.ipynb index ef262ef54b..6c64745fdc 100644 --- a/docs/manual/lifecycle/life.ipynb +++ b/docs/manual/lifecycle/life.ipynb @@ -104,7 +104,7 @@ " var name: String\n", " var age: Int\n", "\n", - " fn __init__(inout self, name: String, age: Int):\n", + " fn __init__(out self, name: String, age: Int):\n", " self.name = name\n", " self.age = age" ] @@ -181,11 +181,11 @@ " var name: String\n", " var age: Int\n", "\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " self.name = \"\"\n", " self.age = 0\n", "\n", - " fn __init__(inout self, name: String):\n", + " fn __init__(out self, name: String):\n", " self = MyPet()\n", " self.name = name" ] @@ -218,7 +218,7 @@ " var name: String\n", " var age: Int\n", "\n", - " fn __init__(inout self, name: String, age: Int, cond: Bool):\n", + " fn __init__(out self, name: String, age: Int, cond: Bool):\n", " self.name = name\n", " if cond:\n", " self.age = age\n", @@ -254,7 +254,7 @@ "\n", "```mojo\n", "struct Target:\n", - " fn __init__(inout self, s: Source): ...\n", + " fn __init__(out self, s: Source): ...\n", "```\n", "\n", "With implicit conversion, the assignment above is essentially identical to:\n", @@ -269,7 +269,7 @@ "\n", "```mojo\n", "struct Target:\n", - " fn __init__(inout self, s: Source, reverse: Bool = False): ...\n", + " fn __init__(out self, s: Source, reverse: Bool = False): ...\n", "```\n", "\n", "Implicit conversion also occurs if the type doesn't declare its own constructor,\n", @@ -293,14 +293,14 @@ "\n", "```mojo\n", "struct A: \n", - " fn __init__(inout self, s: Source): ...\n", + " fn __init__(out self, s: Source): ...\n", "\n", "struct B: \n", - " fn __init__(inout self, s: Source): ...\n", + " fn __init__(out self, s: Source): ...\n", "\n", "struct Target:\n", - " fn __init__(inout self, a: A): ...\n", - " fn __init__(inout self, b: B): ...\n", + " fn __init__(out self, a: A): ...\n", + " fn __init__(out self, b: B): ...\n", "\n", "# Fails\n", "var t = Target(Source())\n", @@ -316,7 +316,7 @@ "```mojo\n", "struct Target:\n", " # does not support implicit conversion\n", - " fn __init__(inout self, *, source: Source): ...\n", + " fn __init__(out self, *, source: Source): ...\n", "\n", "# the constructor must be called with a keyword\n", "var t = Target(source=a)\n", @@ -363,11 +363,11 @@ " var name: String\n", " var age: Int\n", "\n", - " fn __init__(inout self, name: String, age: Int):\n", + " fn __init__(out self, name: String, age: Int):\n", " self.name = name\n", " self.age = age\n", "\n", - " fn __copyinit__(inout self, existing: Self):\n", + " fn __copyinit__(out self, existing: Self):\n", " self.name = existing.name\n", " self.age = existing.age" ] @@ -433,14 +433,14 @@ " var size: Int\n", " var cap: Int\n", "\n", - " fn __init__(inout self, size: Int, val: Int):\n", + " fn __init__(out self, size: Int, val: Int):\n", " self.size = size\n", " self.cap = size * 2\n", " self.data = UnsafePointer[Int].alloc(self.cap)\n", " for i in range(self.size):\n", " (self.data + i).init_pointee_copy(val)\n", "\n", - " fn __copyinit__(inout self, existing: Self):\n", + " fn __copyinit__(out self, existing: Self):\n", " # Deep-copy the existing value\n", " self.size = existing.size\n", " self.cap = existing.cap\n", @@ -600,14 +600,14 @@ " var cap: Int\n", "\n", "\n", - " fn __init__(inout self, size: Int, val: Int):\n", + " fn __init__(out self, size: Int, val: Int):\n", " self.size = size\n", " self.cap = size * 2\n", " self.data = UnsafePointer[Int].alloc(self.size)\n", " for i in range(self.size):\n", " (self.data + i).init_pointee_copy(val)\n", "\n", - " fn __copyinit__(inout self, existing: Self):\n", + " fn __copyinit__(out self, existing: Self):\n", " # Deep-copy the existing value\n", " self.size = existing.size\n", " self.cap = existing.cap\n", @@ -616,7 +616,7 @@ " (self.data + i).init_pointee_copy(existing.data[i])\n", " # The lifetime of `existing` continues unchanged\n", "\n", - " fn __moveinit__(inout self, owned existing: Self):\n", + " fn __moveinit__(out self, owned existing: Self):\n", " print(\"move\")\n", " # Shallow copy the existing value\n", " self.size = existing.size\n", @@ -771,15 +771,15 @@ " var name: String\n", " var age: Int\n", "\n", - " fn __init__(inout self, owned name: String, age: Int):\n", + " fn __init__(out self, owned name: String, age: Int):\n", " self.name = name^\n", " self.age = age\n", "\n", - " fn __copyinit__(inout self, existing: Self):\n", + " fn __copyinit__(out self, existing: Self):\n", " self.name = existing.name\n", " self.age = existing.age\n", "\n", - " fn __moveinit__(inout self, owned existing: Self):\n", + " fn __moveinit__(out self, owned existing: Self):\n", " self.name = existing.name^\n", " self.age = existing.age" ] @@ -809,7 +809,7 @@ " var name: String\n", " var age: Int\n", "\n", - " fn __init__(inout self, owned name: String):\n", + " fn __init__(out self, owned name: String):\n", " self.name = name^\n", " self.age = 0\n" ] diff --git a/docs/manual/parameters/index.ipynb b/docs/manual/parameters/index.ipynb index cbf61f4f7f..358f846ff3 100644 --- a/docs/manual/parameters/index.ipynb +++ b/docs/manual/parameters/index.ipynb @@ -233,7 +233,7 @@ " var data: UnsafePointer[ElementType]\n", " var size: Int\n", "\n", - " fn __init__(inout self, *elements: ElementType):\n", + " fn __init__(out self, *elements: ElementType):\n", " self.size = len(elements)\n", " self.data = UnsafePointer[ElementType].alloc(self.size)\n", " for i in range(self.size):\n", @@ -438,7 +438,7 @@ " var value: … # Some low-level MLIR stuff here\n", "\n", " # Create a new SIMD from a number of scalars\n", - " fn __init__(inout self, *elems: SIMD[type, 1]): ...\n", + " fn __init__(out self, *elems: SIMD[type, 1]): ...\n", "\n", " # Fill a SIMD with a duplicated scalar value.\n", " @staticmethod\n", @@ -536,7 +536,7 @@ " var value: Int\n", "\n", " @always_inline(\"nodebug\")\n", - " fn __init__(inout self, _a: Int):\n", + " fn __init__(out self, _a: Int):\n", " self.value = _a\n", "\n", "fn foo[x: MyInt, a: Int]():\n", @@ -569,7 +569,7 @@ "parameter_overloads[1, 2, MyInt(3)]()\n", "\n", "struct MyStruct:\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " pass\n", "\n", " fn foo(inout self):\n", @@ -730,7 +730,7 @@ "struct One[Type: StringableCollectionElement]:\n", " var value: Type\n", "\n", - " fn __init__(inout self, value: Type):\n", + " fn __init__(out self, value: Type):\n", " self.value = value\n", "\n", "def use_one():\n", @@ -768,7 +768,7 @@ " var val1: Type\n", " var val2: Type\n", "\n", - " fn __init__(inout self, one: One[Type], another: One[Type]):\n", + " fn __init__(out self, one: One[Type], another: One[Type]):\n", " self.val1 = one.value\n", " self.val2 = another.value\n", " print(str(self.val1), str(self.val2))\n", @@ -886,7 +886,7 @@ "outputs": [], "source": [ "struct KwParamStruct[greeting: String = \"Hello\", name: String = \"🔥mojo🔥\"]:\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " print(greeting, name)\n", "\n", "fn use_kw_params():\n", @@ -1193,7 +1193,7 @@ " var data: UnsafePointer[T]\n", " var size: Int\n", "\n", - " fn __init__(inout self, size: Int, value: T):\n", + " fn __init__(out self, size: Int, value: T):\n", " self.size = size\n", " self.data = UnsafePointer[T].alloc(self.size)\n", " for i in range(self.size):\n", diff --git a/docs/manual/structs.ipynb b/docs/manual/structs.ipynb index ba46521ccd..aff69827b1 100644 --- a/docs/manual/structs.ipynb +++ b/docs/manual/structs.ipynb @@ -81,7 +81,7 @@ " var first: Int\n", " var second: Int\n", "\n", - " fn __init__(inout self, first: Int, second: Int):\n", + " fn __init__(out self, first: Int, second: Int):\n", " self.first = first\n", " self.second = second" ] @@ -153,7 +153,7 @@ " var first: Int\n", " var second: Int\n", "\n", - " fn __init__(inout self, first: Int, second: Int):\n", + " fn __init__(out self, first: Int, second: Int):\n", " self.first = first\n", " self.second = second\n", "\n", @@ -223,7 +223,7 @@ "source": [ "struct Logger:\n", "\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " pass\n", "\n", " @staticmethod\n", @@ -408,15 +408,15 @@ " var name: String\n", " var age: Int\n", "\n", - " fn __init__(inout self, owned name: String, age: Int):\n", + " fn __init__(out self, owned name: String, age: Int):\n", " self.name = name^\n", " self.age = age\n", "\n", - " fn __copyinit__(inout self, existing: Self):\n", + " fn __copyinit__(out self, existing: Self):\n", " self.name = existing.name\n", " self.age = existing.age\n", "\n", - " fn __moveinit__(inout self, owned existing: Self):\n", + " fn __moveinit__(out self, owned existing: Self):\n", " self.name = existing.name^\n", " self.age = existing.age" ] diff --git a/docs/manual/traits.ipynb b/docs/manual/traits.ipynb index a0b665410f..ef9fbd824e 100755 --- a/docs/manual/traits.ipynb +++ b/docs/manual/traits.ipynb @@ -391,7 +391,7 @@ "outputs": [], "source": [ "trait DefaultConstructible:\n", - " fn __init__(inout self): ...\n", + " fn __init__(out self): ...\n", "\n", "trait MassProducible(DefaultConstructible, Movable):\n", " pass\n", @@ -402,10 +402,10 @@ "struct Thing(MassProducible):\n", " var id: Int\n", "\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " self.id = 0\n", "\n", - " fn __moveinit__(inout self, owned existing: Self):\n", + " fn __moveinit__(out self, owned existing: Self):\n", " self.id = existing.id\n", "\n", "var thing = factory[Thing]()" @@ -504,7 +504,7 @@ " var size: Int\n", " # ...\n", "\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " self.size = 0\n", "\n", " fn __len__(self) -> Int:\n", diff --git a/docs/manual/values/lifetimes.ipynb b/docs/manual/values/lifetimes.ipynb index 0c350dac66..314e186c81 100644 --- a/docs/manual/values/lifetimes.ipynb +++ b/docs/manual/values/lifetimes.ipynb @@ -229,7 +229,7 @@ "struct BoxedString:\n", " var box: OwnedPointer[String]\n", "\n", - " fn __init__(inout self, value: String):\n", + " fn __init__(out self, value: String):\n", " self.box = OwnedPointer(value)\n", "\n", " fn as_ptr(self) -> Pointer[String, __origin_of(self.box)]:\n", @@ -259,7 +259,7 @@ "its `origin` value from the list:\n", "\n", "```mojo\n", - " fn __init__(inout self, ref [origin]list: List[T, *_]):\n", + " fn __init__(out self, ref [origin]list: List[T, *_]):\n", " \"\"\"Construct a Span from a List.\n", "\n", " Args:\n", @@ -422,7 +422,7 @@ "struct NameList:\n", " var names: List[String]\n", "\n", - " def __init__(inout self, *names: String):\n", + " def __init__(out self, *names: String):\n", " self.names = List[String]()\n", " for name in names:\n", " self.names.append(name[])\n", diff --git a/docs/manual/variables.ipynb b/docs/manual/variables.ipynb index e4f676b0cd..68b87ce68e 100644 --- a/docs/manual/variables.ipynb +++ b/docs/manual/variables.ipynb @@ -312,7 +312,7 @@ "As shown above, value assignment can be converted into a constructor call if the \n", "target type has a constructor that takes a single argument that matches the\n", "value being assigned. So, this code uses the `Float64` constructor that takes an\n", - "integer: `__init__(inout self, value: Int)`.\n", + "integer: `__init__(out self, value: Int)`.\n", "\n", "In general, implicit conversions should only be supported where the conversion\n", "is lossless.\n", diff --git a/examples/mandelbrot.mojo b/examples/mandelbrot.mojo index a2a7d12a43..9603e31c70 100644 --- a/examples/mandelbrot.mojo +++ b/examples/mandelbrot.mojo @@ -39,7 +39,7 @@ alias max_y = 1.5 struct Matrix[type: DType, rows: Int, cols: Int]: var data: UnsafePointer[Scalar[type]] - fn __init__(inout self): + fn __init__(out self): self.data = UnsafePointer[Scalar[type]].alloc(rows * cols) fn store[nelts: Int](self, row: Int, col: Int, val: SIMD[type, nelts]): diff --git a/examples/matmul.mojo b/examples/matmul.mojo index 4b1a08e7cd..44cc91f097 100644 --- a/examples/matmul.mojo +++ b/examples/matmul.mojo @@ -52,12 +52,12 @@ struct Matrix[rows: Int, cols: Int]: var data: UnsafePointer[Scalar[type]] # Initialize zeroing all values - fn __init__(inout self): + fn __init__(out self): self.data = UnsafePointer[Scalar[type]].alloc(rows * cols) memset_zero(self.data, rows * cols) # Initialize taking a pointer, don't set any elements - fn __init__(inout self, data: UnsafePointer[Scalar[type]]): + fn __init__(out self, data: UnsafePointer[Scalar[type]]): self.data = data ## Initialize with random values diff --git a/examples/notebooks/BoolMLIR.ipynb b/examples/notebooks/BoolMLIR.ipynb index 2e4a6a09b3..355dc77909 100644 --- a/examples/notebooks/BoolMLIR.ipynb +++ b/examples/notebooks/BoolMLIR.ipynb @@ -133,7 +133,7 @@ "struct OurBool:\n", " var value: __mlir_type.i1\n", "\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " self.value = __mlir_op.`index.bool.constant`[\n", " value=__mlir_attr.false,\n", " ]()" @@ -191,7 +191,7 @@ "struct OurBool:\n", " var value: __mlir_type.i1\n", "\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " self.value = __mlir_op.`index.bool.constant`[\n", " value=__mlir_attr.false,\n", " ]()" @@ -239,7 +239,7 @@ "\n", " # ...\n", "\n", - " fn __init__(inout self, value: __mlir_type.i1):\n", + " fn __init__(out self, value: __mlir_type.i1):\n", " self.value = value" ] }, @@ -303,10 +303,10 @@ " var value: __mlir_type.i1\n", "\n", " # We can simplify our no-argument constructor:\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " self = OurFalse\n", "\n", - " fn __init__(inout self, value: __mlir_type.i1):\n", + " fn __init__(out self, value: __mlir_type.i1):\n", " self.value = value" ] }, @@ -369,7 +369,7 @@ "\n", " # ...\n", "\n", - " fn __init__(inout self, value: __mlir_type.i1):\n", + " fn __init__(out self, value: __mlir_type.i1):\n", " self.value = value\n", "\n", " # Our new method converts `OurBool` to `Bool`:\n", @@ -441,7 +441,7 @@ "struct OurBool:\n", " var value: __mlir_type.i1\n", "\n", - " fn __init__(inout self, value: __mlir_type.i1):\n", + " fn __init__(out self, value: __mlir_type.i1):\n", " self.value = value\n", "\n", " # Our new method converts `OurBool` to `i1`:\n", @@ -507,7 +507,7 @@ "struct OurBool:\n", " var value: __mlir_type.i1\n", "\n", - " fn __init__(inout self, value: __mlir_type.i1):\n", + " fn __init__(out self, value: __mlir_type.i1):\n", " self.value = value\n", "\n", " # ...\n", diff --git a/examples/notebooks/Mandelbrot.ipynb b/examples/notebooks/Mandelbrot.ipynb index ad269046ce..4dcec04c6a 100644 --- a/examples/notebooks/Mandelbrot.ipynb +++ b/examples/notebooks/Mandelbrot.ipynb @@ -100,7 +100,7 @@ "struct Matrix[type: DType, rows: Int, cols: Int]:\n", " var data: UnsafePointer[Scalar[type]]\n", "\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " self.data = UnsafePointer[Scalar[type]].alloc(rows * cols)\n", "\n", " fn __getitem__(self, row: Int, col: Int) -> Scalar[type]:\n", diff --git a/examples/notebooks/Matmul.ipynb b/examples/notebooks/Matmul.ipynb index f7a4a796a4..239654bf5e 100644 --- a/examples/notebooks/Matmul.ipynb +++ b/examples/notebooks/Matmul.ipynb @@ -416,12 +416,12 @@ " var data: UnsafePointer[Scalar[type]]\n", "\n", " # Initialize zeroeing all values\n", - " fn __init__(inout self):\n", + " fn __init__(out self):\n", " self.data = UnsafePointer[Scalar[type]].alloc(rows * cols)\n", " memset_zero(self.data, rows * cols)\n", "\n", " # Initialize taking a pointer, don't set any elements\n", - " fn __init__(inout self, data: UnsafePointer[Scalar[type]]):\n", + " fn __init__(out self, data: UnsafePointer[Scalar[type]]):\n", " self.data = data\n", "\n", " # Initialize with random values\n", diff --git a/examples/notebooks/RayTracing.ipynb b/examples/notebooks/RayTracing.ipynb index a6d9d221ba..1ce972b6b4 100644 --- a/examples/notebooks/RayTracing.ipynb +++ b/examples/notebooks/RayTracing.ipynb @@ -81,11 +81,11 @@ " var data: SIMD[DType.float32, 4]\n", "\n", " @always_inline\n", - " fn __init__(inout self, x: Float32, y: Float32, z: Float32):\n", + " fn __init__(out self, x: Float32, y: Float32, z: Float32):\n", " self.data = SIMD[DType.float32, 4](x, y, z, 0)\n", "\n", " @always_inline\n", - " fn __init__(inout self, data: SIMD[DType.float32, 4]):\n", + " fn __init__(out self, data: SIMD[DType.float32, 4]):\n", " self.data = data\n", "\n", " @always_inline\n", @@ -207,14 +207,14 @@ " var height: Int\n", " var width: Int\n", "\n", - " fn __init__(inout self, height: Int, width: Int):\n", + " fn __init__(out self, height: Int, width: Int):\n", " self.height = height\n", " self.width = width\n", " self.pixels = UnsafePointer[Vec3f].alloc(self.height * self.width)\n", " self.rc = UnsafePointer[Int].alloc(1)\n", " self.rc[] = 1\n", "\n", - " fn __copyinit__(inout self, other: Self):\n", + " fn __copyinit__(out self, other: Self):\n", " other._inc_rc()\n", " self.pixels = other.pixels\n", " self.rc = other.rc\n", @@ -401,7 +401,7 @@ " var albedo: Vec3f\n", " var specular_component: Float32\n", "\n", - " fn __init__(inout self, color: Vec3f, albedo: Vec3f = Vec3f(0, 0, 0),\n", + " fn __init__(out self, color: Vec3f, albedo: Vec3f = Vec3f(0, 0, 0),\n", " specular_component: Float32 = 0):\n", " self.color = color\n", " self.albedo = albedo\n", diff --git a/stdlib/src/builtin/_closure.mojo b/stdlib/src/builtin/_closure.mojo index b456d1405a..c5465bdf09 100644 --- a/stdlib/src/builtin/_closure.mojo +++ b/stdlib/src/builtin/_closure.mojo @@ -21,11 +21,11 @@ struct __ParameterClosureCaptureList[ # Parameter closure invariant requires this function be marked 'capturing'. @parameter @always_inline - fn __init__(inout self): + fn __init__(out self): self.value = __mlir_op.`kgen.capture_list.create`[callee=fn_ref]() @always_inline - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): self.value = __mlir_op.`kgen.capture_list.copy`[callee=fn_ref]( existing.value ) diff --git a/stdlib/src/builtin/_format_float.mojo b/stdlib/src/builtin/_format_float.mojo index 31a48829d5..2686917119 100644 --- a/stdlib/src/builtin/_format_float.mojo +++ b/stdlib/src/builtin/_format_float.mojo @@ -50,7 +50,7 @@ struct _MulParity: var parity: Bool var is_integer: Bool - fn __init__(inout self, parity: Bool, is_integer: Bool): + fn __init__(out self, parity: Bool, is_integer: Bool): self.parity = parity self.is_integer = is_integer diff --git a/stdlib/src/builtin/_location.mojo b/stdlib/src/builtin/_location.mojo index a79adfc33d..0940e49f8e 100644 --- a/stdlib/src/builtin/_location.mojo +++ b/stdlib/src/builtin/_location.mojo @@ -23,7 +23,7 @@ struct _SourceLocation(Writable, Stringable): var col: Int var file_name: StringLiteral - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self = other @no_inline diff --git a/stdlib/src/builtin/_stubs.mojo b/stdlib/src/builtin/_stubs.mojo index bdb830bece..92e661dc00 100644 --- a/stdlib/src/builtin/_stubs.mojo +++ b/stdlib/src/builtin/_stubs.mojo @@ -68,7 +68,7 @@ struct _ParamForIterator[IteratorT: Copyable]: var value: Int var stop: Bool - fn __init__(inout self, next_it: IteratorT, value: Int, stop: Bool): + fn __init__(out self, next_it: IteratorT, value: Int, stop: Bool): self.next_it = next_it self.value = value self.stop = stop diff --git a/stdlib/src/builtin/anytype.mojo b/stdlib/src/builtin/anytype.mojo index c54a4e1745..03da7a124d 100644 --- a/stdlib/src/builtin/anytype.mojo +++ b/stdlib/src/builtin/anytype.mojo @@ -46,7 +46,7 @@ trait AnyType: var p: UnsafePointer[Int] var size: Int - fn __init__(inout self, size: Int): + fn __init__(out self, size: Int): self.p = UnsafePointer[Int].alloc(size) self.size = size diff --git a/stdlib/src/builtin/bool.mojo b/stdlib/src/builtin/bool.mojo index aebc43a7a8..06ccff6578 100644 --- a/stdlib/src/builtin/bool.mojo +++ b/stdlib/src/builtin/bool.mojo @@ -116,12 +116,12 @@ struct Bool( """The underlying storage of the boolean value.""" @always_inline("nodebug") - fn __init__(inout self): + fn __init__(out self): """Construct a default, `False` Bool.""" self = False @always_inline("nodebug") - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicitly construct a deep copy of the provided value. Args: @@ -131,7 +131,7 @@ struct Bool( @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.i1): + fn __init__(out self, value: __mlir_type.i1): """Construct a Bool value given a __mlir_type.i1 value. Args: @@ -141,7 +141,7 @@ struct Bool( @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.`!pop.scalar`): + fn __init__(out self, value: __mlir_type.`!pop.scalar`): """Construct a Bool value given a `!pop.scalar` value. Args: @@ -164,7 +164,7 @@ struct Bool( self = value.__bool__() @always_inline("nodebug") - fn __init__(inout self, value: SIMD[DType.bool, 1]): + fn __init__(out self, value: SIMD[DType.bool, 1]): """Convert a scalar SIMD value to a Bool. Args: diff --git a/stdlib/src/builtin/builtin_list.mojo b/stdlib/src/builtin/builtin_list.mojo index 9ea758583d..7541b4f9c4 100644 --- a/stdlib/src/builtin/builtin_list.mojo +++ b/stdlib/src/builtin/builtin_list.mojo @@ -40,7 +40,7 @@ struct ListLiteral[*Ts: CollectionElement](Sized, CollectionElement): # ===-------------------------------------------------------------------===# @always_inline - fn __init__(inout self, owned *args: *Ts): + fn __init__(out self, owned *args: *Ts): """Construct the list literal from the given values. Args: @@ -49,7 +49,7 @@ struct ListLiteral[*Ts: CollectionElement](Sized, CollectionElement): self.storage = Tuple(storage=args^) @always_inline - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): """Copy construct the tuple. Args: @@ -57,7 +57,7 @@ struct ListLiteral[*Ts: CollectionElement](Sized, CollectionElement): """ self.storage = existing.storage - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """Move construct the list. Args: @@ -164,7 +164,7 @@ struct VariadicList[type: AnyTrivialRegType](Sized): alias IterType = _VariadicListIter[type] @always_inline - fn __init__(inout self, *value: type): + fn __init__(out self, *value: type): """Constructs a VariadicList from a variadic list of arguments. Args: @@ -175,7 +175,7 @@ struct VariadicList[type: AnyTrivialRegType](Sized): @doc_private @always_inline - fn __init__(inout self, value: Self._mlir_type): + fn __init__(out self, value: Self._mlir_type): """Constructs a VariadicList from a variadic argument type. Args: @@ -327,7 +327,7 @@ struct VariadicListMem[ # Provide support for borrowed variadic arguments. @doc_private @always_inline - fn __init__(inout self, value: Self._mlir_type): + fn __init__(out self, value: Self._mlir_type): """Constructs a VariadicList from a variadic argument type. Args: @@ -344,7 +344,7 @@ struct VariadicListMem[ ] @always_inline - fn __init__(inout self, value: Self._inout_variadic_type): + fn __init__(out self, value: Self._inout_variadic_type): """Constructs a VariadicList from a variadic argument type. Args: @@ -364,7 +364,7 @@ struct VariadicListMem[ ] @always_inline - fn __init__(inout self, value: Self._owned_variadic_type): + fn __init__(out self, value: Self._owned_variadic_type): """Constructs a VariadicList from a variadic argument type. Args: @@ -377,7 +377,7 @@ struct VariadicListMem[ self._is_owned = True @always_inline - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """Moves constructor. Args: @@ -509,7 +509,7 @@ struct VariadicPack[ @doc_private @always_inline("nodebug") - fn __init__(inout self, value: Self._mlir_type, is_owned: Bool): + fn __init__(out self, value: Self._mlir_type, is_owned: Bool): """Constructs a VariadicPack from the internal representation. Args: diff --git a/stdlib/src/builtin/builtin_slice.mojo b/stdlib/src/builtin/builtin_slice.mojo index 77d7811c01..cc5a6d2f1a 100644 --- a/stdlib/src/builtin/builtin_slice.mojo +++ b/stdlib/src/builtin/builtin_slice.mojo @@ -53,7 +53,7 @@ struct Slice( # ===-------------------------------------------------------------------===# @always_inline - fn __init__(inout self, start: Int, end: Int): + fn __init__(out self, start: Int, end: Int): """Construct slice given the start and end values. Args: @@ -82,7 +82,7 @@ struct Slice( self.end = end self.step = step - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Creates a deep copy of the Slice. Args: diff --git a/stdlib/src/builtin/coroutine.mojo b/stdlib/src/builtin/coroutine.mojo index 1246e099fa..4c8517d687 100644 --- a/stdlib/src/builtin/coroutine.mojo +++ b/stdlib/src/builtin/coroutine.mojo @@ -120,7 +120,7 @@ struct Coroutine[type: AnyType, origins: OriginSet]: ) @always_inline - fn __init__(inout self, handle: AnyCoroutine): + fn __init__(out self, handle: AnyCoroutine): """Construct a coroutine object from a handle. Args: @@ -200,7 +200,7 @@ struct RaisingCoroutine[type: AnyType, origins: OriginSet]: ) @always_inline - fn __init__(inout self, handle: AnyCoroutine): + fn __init__(out self, handle: AnyCoroutine): """Construct a coroutine object from a handle. Args: diff --git a/stdlib/src/builtin/dtype.mojo b/stdlib/src/builtin/dtype.mojo index 26ae8cd003..e0b81dadc7 100644 --- a/stdlib/src/builtin/dtype.mojo +++ b/stdlib/src/builtin/dtype.mojo @@ -93,7 +93,7 @@ struct DType( on the system.""" @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy this DType. Args: diff --git a/stdlib/src/builtin/error.mojo b/stdlib/src/builtin/error.mojo index a974d6a8c2..482f4aa454 100644 --- a/stdlib/src/builtin/error.mojo +++ b/stdlib/src/builtin/error.mojo @@ -59,13 +59,13 @@ struct Error( # ===-------------------------------------------------------------------===# @always_inline - fn __init__(inout self): + fn __init__(out self): """Default constructor.""" self.data = UnsafePointer[UInt8]() self.loaded_length = 0 @always_inline - fn __init__(inout self, value: StringLiteral): + fn __init__(out self, value: StringLiteral): """Construct an Error object with a given string literal. Args: @@ -74,7 +74,7 @@ struct Error( self.data = value.unsafe_ptr() self.loaded_length = len(value) - fn __init__(inout self, src: String): + fn __init__(out self, src: String): """Construct an Error object with a given string. Args: @@ -91,7 +91,7 @@ struct Error( self.data = dest self.loaded_length = -length - fn __init__(inout self, src: StringRef): + fn __init__(out self, src: StringRef): """Construct an Error object with a given string ref. Args: @@ -108,7 +108,7 @@ struct Error( self.data = dest self.loaded_length = -length - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy the object. Args: @@ -121,7 +121,7 @@ struct Error( if self.loaded_length < 0: self.data.free() - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): """Creates a deep copy of an existing error. Args: diff --git a/stdlib/src/builtin/file.mojo b/stdlib/src/builtin/file.mojo index 6fd4aac2c8..0803d4f3e0 100644 --- a/stdlib/src/builtin/file.mojo +++ b/stdlib/src/builtin/file.mojo @@ -44,7 +44,7 @@ struct _OwnedStringRef(Boolable): var data: UnsafePointer[UInt8] var length: Int - fn __init__(inout self): + fn __init__(out self): self.data = UnsafePointer[UInt8]() self.length = 0 @@ -73,11 +73,11 @@ struct FileHandle: var handle: OpaquePointer """The underlying pointer to the file handle.""" - fn __init__(inout self): + fn __init__(out self): """Default constructor.""" self.handle = OpaquePointer() - fn __init__(inout self, path: String, mode: String) raises: + fn __init__(out self, path: String, mode: String) raises: """Construct the FileHandle using the file path and mode. Args: @@ -86,7 +86,7 @@ struct FileHandle: """ self.__init__(path.as_string_slice(), mode.as_string_slice()) - fn __init__(inout self, path: StringSlice, mode: StringSlice) raises: + fn __init__(out self, path: StringSlice, mode: StringSlice) raises: """Construct the FileHandle using the file path and string. Args: @@ -126,7 +126,7 @@ struct FileHandle: self.handle = OpaquePointer() - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """Moves constructor for the file handle. Args: diff --git a/stdlib/src/builtin/file_descriptor.mojo b/stdlib/src/builtin/file_descriptor.mojo index 0745273a9a..e4132603bc 100644 --- a/stdlib/src/builtin/file_descriptor.mojo +++ b/stdlib/src/builtin/file_descriptor.mojo @@ -38,7 +38,7 @@ struct FileDescriptor(Writer): var value: Int """The underlying value of the file descriptor.""" - fn __init__(inout self, value: Int = 1): + fn __init__(out self, value: Int = 1): """Constructs the file descriptor from an integer. Args: @@ -46,7 +46,7 @@ struct FileDescriptor(Writer): """ self.value = value - fn __init__(inout self, f: FileHandle): + fn __init__(out self, f: FileHandle): """Constructs the file descriptor from a file handle. Args: diff --git a/stdlib/src/builtin/float_literal.mojo b/stdlib/src/builtin/float_literal.mojo index d6a19e9595..c3da23fcbc 100644 --- a/stdlib/src/builtin/float_literal.mojo +++ b/stdlib/src/builtin/float_literal.mojo @@ -49,7 +49,7 @@ struct FloatLiteral( # ===------------------------------------------------------------------===# @always_inline("nodebug") - fn __init__(inout self, value: Self.fp_type): + fn __init__(out self, value: Self.fp_type): """Create a FloatLiteral value from a kgen.float_literal value. Args: @@ -58,7 +58,7 @@ struct FloatLiteral( self.value = value @always_inline("nodebug") - fn __init__(inout self, value: IntLiteral): + fn __init__(out self, value: IntLiteral): """Convert an IntLiteral to a FloatLiteral value. Args: diff --git a/stdlib/src/builtin/int.mojo b/stdlib/src/builtin/int.mojo index 9c97d71359..aa6bd7de8b 100644 --- a/stdlib/src/builtin/int.mojo +++ b/stdlib/src/builtin/int.mojo @@ -308,11 +308,11 @@ struct Int( # ===------------------------------------------------------------------=== # @always_inline("nodebug") - fn __init__(inout self): + fn __init__(out self): """Default constructor that produces zero.""" self.value = __mlir_op.`index.constant`[value = __mlir_attr.`0:index`]() - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicitly copy the provided value. Args: @@ -322,7 +322,7 @@ struct Int( @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.index): + fn __init__(out self, value: __mlir_type.index): """Construct Int from the given index value. Args: @@ -332,7 +332,7 @@ struct Int( @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.`!pop.scalar`): + fn __init__(out self, value: __mlir_type.`!pop.scalar`): """Construct Int from the given Int16 value. Args: @@ -346,7 +346,7 @@ struct Int( @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.`!pop.scalar`): + fn __init__(out self, value: __mlir_type.`!pop.scalar`): """Construct Int from the given Int32 value. Args: @@ -360,7 +360,7 @@ struct Int( @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.`!pop.scalar`): + fn __init__(out self, value: __mlir_type.`!pop.scalar`): """Construct Int from the given Int64 value. Args: @@ -374,7 +374,7 @@ struct Int( @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.`!pop.scalar`): + fn __init__(out self, value: __mlir_type.`!pop.scalar`): """Construct Int from the given Index value. Args: @@ -385,7 +385,7 @@ struct Int( ) @always_inline("nodebug") - fn __init__(inout self, value: IntLiteral): + fn __init__(out self, value: IntLiteral): """Construct Int from the given IntLiteral value. Args: @@ -406,7 +406,7 @@ struct Int( self = value.__index__() @always_inline("nodebug") - fn __init__(inout self, value: UInt): + fn __init__(out self, value: UInt): """Construct Int from the given UInt value. Args: diff --git a/stdlib/src/builtin/int_literal.mojo b/stdlib/src/builtin/int_literal.mojo index 90b3850ddb..326759e115 100644 --- a/stdlib/src/builtin/int_literal.mojo +++ b/stdlib/src/builtin/int_literal.mojo @@ -53,13 +53,13 @@ struct IntLiteral( # ===-------------------------------------------------------------------===# @always_inline("nodebug") - fn __init__(inout self): + fn __init__(out self): """Default constructor.""" self.value = __mlir_attr.`#kgen.int_literal<0> : !kgen.int_literal` @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.`!kgen.int_literal`): + fn __init__(out self, value: __mlir_type.`!kgen.int_literal`): """Construct IntLiteral from the given mlir !kgen.int_literal value. Args: diff --git a/stdlib/src/builtin/io.mojo b/stdlib/src/builtin/io.mojo index 696730e94d..d605324b1c 100644 --- a/stdlib/src/builtin/io.mojo +++ b/stdlib/src/builtin/io.mojo @@ -43,7 +43,7 @@ from utils import StringRef, StaticString, StringSlice struct _fdopen[mode: StringLiteral = "a"]: var handle: OpaquePointer - fn __init__(inout self, stream_id: FileDescriptor): + fn __init__(out self, stream_id: FileDescriptor): """Creates a file handle to the stdout/stderr stream. Args: diff --git a/stdlib/src/builtin/math.mojo b/stdlib/src/builtin/math.mojo index 2506699f9d..eb1b088242 100644 --- a/stdlib/src/builtin/math.mojo +++ b/stdlib/src/builtin/math.mojo @@ -269,7 +269,7 @@ trait Powable: var numerator: Float64 var denominator: Float64 - fn __init__(inout self, numerator: Float64, denominator: Float64): + fn __init__(out self, numerator: Float64, denominator: Float64): self.numerator = numerator self.denominator = denominator diff --git a/stdlib/src/builtin/none.mojo b/stdlib/src/builtin/none.mojo index a5e85d39a8..966525ef95 100644 --- a/stdlib/src/builtin/none.mojo +++ b/stdlib/src/builtin/none.mojo @@ -33,12 +33,12 @@ struct NoneType( var _value: Self._mlir_type @always_inline - fn __init__(inout self): + fn __init__(out self): """Construct an instance of the `None` type.""" self._value = None @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicit copy constructor. Args: diff --git a/stdlib/src/builtin/object.mojo b/stdlib/src/builtin/object.mojo index f7587a8ac6..2d0cef2c92 100644 --- a/stdlib/src/builtin/object.mojo +++ b/stdlib/src/builtin/object.mojo @@ -32,7 +32,7 @@ from utils import StringRef, Variant struct _NoneMarker(CollectionElementNew): """This is a trivial class to indicate that an object is `None`.""" - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): pass @@ -50,12 +50,12 @@ struct _ImmutableString(CollectionElement, CollectionElementNew): """The length of the string.""" @always_inline - fn __init__(inout self, data: UnsafePointer[UInt8], length: Int): + fn __init__(out self, data: UnsafePointer[UInt8], length: Int): self.data = data self.length = length @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self = other @always_inline @@ -78,7 +78,7 @@ struct _RefCountedList: var impl: Arc[List[_ObjectImpl]] """The list value.""" - fn __init__(inout self): + fn __init__(out self): self.impl = Arc[List[_ObjectImpl]](List[_ObjectImpl]()) @@ -89,13 +89,13 @@ struct _RefCountedListRef(CollectionElement, CollectionElementNew): """The reference to the list.""" @always_inline - fn __init__(inout self): + fn __init__(out self): var ptr = UnsafePointer[_RefCountedList].alloc(1) __get_address_as_uninit_lvalue(ptr.address) = _RefCountedList() self.lst = ptr.bitcast[NoneType]() @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.lst = other.lst @always_inline @@ -118,7 +118,7 @@ struct _RefCountedAttrsDict: var impl: Arc[Dict[StringLiteral, _ObjectImpl]] """The implementation of the map.""" - fn __init__(inout self): + fn __init__(out self): self.impl = Arc[Dict[StringLiteral, _ObjectImpl]]( Dict[StringLiteral, _ObjectImpl]() ) @@ -159,7 +159,7 @@ struct Attr: """The value of the attribute.""" @always_inline - fn __init__(inout self, key: StringLiteral, owned value: object): + fn __init__(out self, key: StringLiteral, owned value: object): """Initializes the attribute with a key and value. Args: @@ -178,7 +178,7 @@ struct _RefCountedAttrsDictRef(CollectionElement, CollectionElementNew): """The reference to the dictionary.""" @always_inline - fn __init__(inout self, values: VariadicListMem[Attr, _]): + fn __init__(out self, values: VariadicListMem[Attr, _]): var ptr = UnsafePointer[_RefCountedAttrsDict].alloc(1) __get_address_as_uninit_lvalue(ptr.address) = _RefCountedAttrsDict() # Elements can only be added on construction. @@ -188,7 +188,7 @@ struct _RefCountedAttrsDictRef(CollectionElement, CollectionElementNew): self.attrs = ptr.bitcast[Int8]() @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self = other @always_inline @@ -216,7 +216,7 @@ struct _Function(CollectionElement, CollectionElementNew): self.value = f @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.value = other.value alias fn0 = fn () raises -> object @@ -305,15 +305,15 @@ struct _ObjectImpl( # ===------------------------------------------------------------------=== # @always_inline - fn __init__(inout self, value: Self.type): + fn __init__(out self, value: Self.type): self.value = value @always_inline - fn __init__(inout self): + fn __init__(out self): self.value = Self.type(_NoneMarker {}) @always_inline - fn __init__(inout self, value: Bool): + fn __init__(out self, value: Bool): self.value = Self.type(value) @always_inline @@ -325,23 +325,23 @@ struct _ObjectImpl( self.value = Self.type(value) @always_inline - fn __init__(inout self, value: _ImmutableString): + fn __init__(out self, value: _ImmutableString): self.value = Self.type(value) @always_inline - fn __init__(inout self, value: _RefCountedListRef): + fn __init__(out self, value: _RefCountedListRef): self.value = Self.type(value) @always_inline - fn __init__(inout self, value: _Function): + fn __init__(out self, value: _Function): self.value = Self.type(value) @always_inline - fn __init__(inout self, value: _RefCountedAttrsDictRef): + fn __init__(out self, value: _RefCountedAttrsDictRef): self.value = Self.type(value) @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy the object. Args: @@ -350,11 +350,11 @@ struct _ObjectImpl( self = other.value @always_inline - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): self = existing.value @always_inline - fn __moveinit__(inout self, owned other: Self): + fn __moveinit__(out self, owned other: Self): self = other.value^ @always_inline @@ -720,12 +720,12 @@ struct object( # ===------------------------------------------------------------------=== # @always_inline - fn __init__(inout self): + fn __init__(out self): """Initializes the object with a `None` value.""" self._value = _ObjectImpl() @always_inline - fn __init__(inout self, impl: _ObjectImpl): + fn __init__(out self, impl: _ObjectImpl): """Initializes the object with an implementation value. This is meant for internal use only. @@ -735,7 +735,7 @@ struct object( self._value = impl @always_inline - fn __init__(inout self, none: NoneType): + fn __init__(out self, none: NoneType): """Initializes a none value object from a `None` literal. Args: @@ -744,7 +744,7 @@ struct object( self._value = _ObjectImpl() @always_inline - fn __init__(inout self, value: Int): + fn __init__(out self, value: Int): """Initializes the object with an integer value. Args: @@ -753,7 +753,7 @@ struct object( self._value = Int64(value) @always_inline - fn __init__(inout self, value: Float64): + fn __init__(out self, value: Float64): """Initializes the object with an floating-point value. Args: @@ -781,7 +781,7 @@ struct object( self._value = value @always_inline - fn __init__(inout self, value: Bool): + fn __init__(out self, value: Bool): """Initializes the object from a bool. Args: @@ -790,7 +790,7 @@ struct object( self._value = value @always_inline - fn __init__(inout self, value: StringLiteral): + fn __init__(out self, value: StringLiteral): """Initializes the object from a string literal. Args: @@ -799,7 +799,7 @@ struct object( self = object(StringRef(value)) @always_inline - fn __init__(inout self, value: StringRef): + fn __init__(out self, value: StringRef): """Initializes the object from a string reference. Args: @@ -850,7 +850,7 @@ struct object( ]() @always_inline - fn __init__(inout self, func: Self.nullary_function): + fn __init__(out self, func: Self.nullary_function): """Initializes an object from a function that takes no arguments. Args: @@ -859,7 +859,7 @@ struct object( self._value = _Function(func) @always_inline - fn __init__(inout self, func: Self.unary_function): + fn __init__(out self, func: Self.unary_function): """Initializes an object from a function that takes one argument. Args: @@ -868,7 +868,7 @@ struct object( self._value = _Function(func) @always_inline - fn __init__(inout self, func: Self.binary_function): + fn __init__(out self, func: Self.binary_function): """Initializes an object from a function that takes two arguments. Args: @@ -877,7 +877,7 @@ struct object( self._value = _Function(func) @always_inline - fn __init__(inout self, func: Self.ternary_function): + fn __init__(out self, func: Self.ternary_function): """Initializes an object from a function that takes three arguments. Args: @@ -886,7 +886,7 @@ struct object( self._value = _Function(func) @always_inline - fn __init__(inout self, *attrs: Attr): + fn __init__(out self, *attrs: Attr): """Initializes the object with a sequence of zero or more attributes. Args: @@ -895,7 +895,7 @@ struct object( self._value = _RefCountedAttrsDictRef(attrs) @always_inline - fn __moveinit__(inout self, owned existing: object): + fn __moveinit__(out self, owned existing: object): """Move the value of an object. Args: @@ -905,7 +905,7 @@ struct object( existing._value = _ObjectImpl() @always_inline - fn __copyinit__(inout self, existing: object): + fn __copyinit__(out self, existing: object): """Copies the object. This clones the underlying string value and increases the refcount of lists or dictionaries. diff --git a/stdlib/src/builtin/range.mojo b/stdlib/src/builtin/range.mojo index ccc01436db..2b9e691e42 100644 --- a/stdlib/src/builtin/range.mojo +++ b/stdlib/src/builtin/range.mojo @@ -48,7 +48,7 @@ struct _ZeroStartingRange(Sized, ReversibleRange, _IntIterable): var end: Int @always_inline - fn __init__(inout self, end: Int): + fn __init__(out self, end: Int): self.curr = max(0, end) self.end = self.curr @@ -149,7 +149,7 @@ struct _StridedRange(Sized, ReversibleRange, _StridedIterable): var step: Int @always_inline - fn __init__(inout self, start: Int, end: Int): + fn __init__(out self, start: Int, end: Int): self.start = start self.end = end self.step = 1 @@ -324,7 +324,7 @@ struct _UIntZeroStartingRange(UIntSized): var end: UInt @always_inline - fn __init__(inout self, end: UInt): + fn __init__(out self, end: UInt): self.curr = max(0, end) self.end = self.curr @@ -382,7 +382,7 @@ struct _UIntStridedRange(UIntSized, _UIntStridedIterable): var step: UInt @always_inline - fn __init__(inout self, start: UInt, end: UInt, step: UInt): + fn __init__(out self, start: UInt, end: UInt, step: UInt): self.start = start self.end = end debug_assert( @@ -464,7 +464,7 @@ struct _ZeroStartingScalarRange[type: DType]: var end: Scalar[type] @always_inline - fn __init__(inout self, end: Scalar[type]): + fn __init__(out self, end: Scalar[type]): self.curr = max(0, end) self.end = self.curr diff --git a/stdlib/src/builtin/simd.mojo b/stdlib/src/builtin/simd.mojo index fb4fc32fca..3ae36ad548 100644 --- a/stdlib/src/builtin/simd.mojo +++ b/stdlib/src/builtin/simd.mojo @@ -227,7 +227,7 @@ struct SIMD[type: DType, size: Int]( # ===-------------------------------------------------------------------===# @always_inline("nodebug") - fn __init__(inout self): + fn __init__(out self): """Default initializer of the SIMD vector. By default the SIMD vectors are initialized to all zeros. @@ -237,7 +237,7 @@ struct SIMD[type: DType, size: Int]( # FIXME(MOCO-1291): Can't implement this due to ambiguity. # @always_inline("nodebug") - # fn __init__(inout self, *, other: SIMD[type, size]): + # fn __init__(out self, *, other: SIMD[type, size]): # """Explicitly copy the provided value. # Args: @@ -246,7 +246,7 @@ struct SIMD[type: DType, size: Int]( # self.__copyinit__(other) @always_inline("nodebug") - fn __init__(inout self, value: UInt): + fn __init__(out self, value: UInt): """Initializes the SIMD vector with an unsigned integer. The unsigned integer value is splatted across all the elements of the SIMD @@ -258,7 +258,7 @@ struct SIMD[type: DType, size: Int]( self = Self(value.value) @always_inline("nodebug") - fn __init__(inout self, value: Int): + fn __init__(out self, value: Int): """Initializes the SIMD vector with a signed integer. The signed integer value is splatted across all the elements of the SIMD @@ -271,7 +271,7 @@ struct SIMD[type: DType, size: Int]( @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.index): + fn __init__(out self, value: __mlir_type.index): _simd_construction_checks[type, size]() var t0 = __mlir_op.`pop.cast_from_builtin`[ @@ -285,7 +285,7 @@ struct SIMD[type: DType, size: Int]( ](casted) @always_inline("nodebug") - fn __init__(inout self, value: IntLiteral): + fn __init__(out self, value: IntLiteral): """Initializes the SIMD vector with an integer. The integer value is splatted across all the elements of the SIMD @@ -310,7 +310,7 @@ struct SIMD[type: DType, size: Int]( ](casted) @always_inline("nodebug") - fn __init__(inout self: SIMD[DType.bool, size], value: Bool, /): + fn __init__(out self: SIMD[DType.bool, size], value: Bool, /): """Initializes the SIMD vector with a bool value. The bool value is splatted across all elements of the SIMD vector. @@ -341,7 +341,7 @@ struct SIMD[type: DType, size: Int]( self.value = value @always_inline("nodebug") - fn __init__(inout self, value: Scalar[type], /): + fn __init__(out self, value: Scalar[type], /): """Constructs a SIMD vector by splatting a scalar value. The input value is splatted across all elements of the SIMD vector. @@ -357,7 +357,7 @@ struct SIMD[type: DType, size: Int]( ](value.value) @always_inline("nodebug") - fn __init__(inout self, *elems: Scalar[type]): + fn __init__(out self, *elems: Scalar[type]): """Constructs a SIMD vector via a variadic list of elements. The input values are assigned to the corresponding elements of the SIMD @@ -396,7 +396,7 @@ struct SIMD[type: DType, size: Int]( self[i] = elems[i] @always_inline - fn __init__(inout self, value: FloatLiteral): + fn __init__(out self, value: FloatLiteral): """Initializes the SIMD vector with a float. The value is splatted across all the elements of the SIMD diff --git a/stdlib/src/builtin/sort.mojo b/stdlib/src/builtin/sort.mojo index df93331427..77d00ecc3e 100644 --- a/stdlib/src/builtin/sort.mojo +++ b/stdlib/src/builtin/sort.mojo @@ -34,7 +34,7 @@ alias insertion_sort_threshold = 32 struct _SortWrapper[type: CollectionElement](CollectionElement): var data: type - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.data = other.data diff --git a/stdlib/src/builtin/string_literal.mojo b/stdlib/src/builtin/string_literal.mojo index 7f358cdd6c..2974eadbb7 100644 --- a/stdlib/src/builtin/string_literal.mojo +++ b/stdlib/src/builtin/string_literal.mojo @@ -70,7 +70,7 @@ struct StringLiteral( # ===-------------------------------------------------------------------===# @always_inline("nodebug") - fn __init__(inout self, value: Self.type): + fn __init__(out self, value: Self.type): """Create a string literal from a builtin string type. Args: @@ -79,7 +79,7 @@ struct StringLiteral( self.value = value @always_inline("nodebug") - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy constructor. Args: diff --git a/stdlib/src/builtin/tuple.mojo b/stdlib/src/builtin/tuple.mojo index 963b605af4..8984289bb6 100644 --- a/stdlib/src/builtin/tuple.mojo +++ b/stdlib/src/builtin/tuple.mojo @@ -47,7 +47,7 @@ struct Tuple[*element_types: CollectionElement](Sized, CollectionElement): """The underlying storage for the tuple.""" @always_inline("nodebug") - fn __init__(inout self, owned *args: *element_types): + fn __init__(out self, owned *args: *element_types): """Construct the tuple. Args: @@ -92,7 +92,7 @@ struct Tuple[*element_types: CollectionElement](Sized, CollectionElement): UnsafePointer.address_of(self[i]).destroy_pointee() @always_inline("nodebug") - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): """Copy construct the tuple. Args: @@ -108,7 +108,7 @@ struct Tuple[*element_types: CollectionElement](Sized, CollectionElement): UnsafePointer.address_of(self[i]).init_pointee_copy(existing[i]) @always_inline("nodebug") - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """Move construct the tuple. Args: diff --git a/stdlib/src/builtin/uint.mojo b/stdlib/src/builtin/uint.mojo index 9c744052df..cc9f9b8d22 100644 --- a/stdlib/src/builtin/uint.mojo +++ b/stdlib/src/builtin/uint.mojo @@ -54,13 +54,13 @@ struct UInt(IntLike, _HashableWithHasher): """ @always_inline("nodebug") - fn __init__(inout self): + fn __init__(out self): """Default constructor that produces zero.""" self.value = __mlir_op.`index.constant`[value = __mlir_attr.`0:index`]() @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.index): + fn __init__(out self, value: __mlir_type.index): """Construct UInt from the given index value. Args: @@ -70,7 +70,7 @@ struct UInt(IntLike, _HashableWithHasher): @doc_private @always_inline("nodebug") - fn __init__(inout self, value: __mlir_type.`!pop.scalar`): + fn __init__(out self, value: __mlir_type.`!pop.scalar`): """Construct UInt from the given Index value. Args: @@ -81,7 +81,7 @@ struct UInt(IntLike, _HashableWithHasher): ) @always_inline("nodebug") - fn __init__(inout self, value: Int): + fn __init__(out self, value: Int): """Construct UInt from the given index value. Args: @@ -90,7 +90,7 @@ struct UInt(IntLike, _HashableWithHasher): self.value = value.value @always_inline("nodebug") - fn __init__(inout self, value: IntLiteral): + fn __init__(out self, value: IntLiteral): """Construct UInt from the given IntLiteral value. Args: diff --git a/stdlib/src/builtin/value.mojo b/stdlib/src/builtin/value.mojo index 74e033330b..d8e6d8e5ea 100644 --- a/stdlib/src/builtin/value.mojo +++ b/stdlib/src/builtin/value.mojo @@ -24,10 +24,10 @@ trait Movable: ```mojo struct Foo(Movable): - fn __init__(inout self): + fn __init__(out self): pass - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): print("moving") ``` @@ -47,7 +47,7 @@ trait Movable: ``` """ - fn __moveinit__(inout self, owned existing: Self, /): + fn __moveinit__(out self, owned existing: Self, /): """Create a new instance of the value by moving the value of another. Args: @@ -66,10 +66,10 @@ trait Copyable: struct Foo(Copyable): var s: String - fn __init__(inout self, s: String): + fn __init__(out self, s: String): self.s = s - fn __copyinit__(inout self, other: Self): + fn __copyinit__(out self, other: Self): print("copying value") self.s = other.s ``` @@ -90,7 +90,7 @@ trait Copyable: ``` """ - fn __copyinit__(inout self, existing: Self, /): + fn __copyinit__(out self, existing: Self, /): """Create a new instance of the value by copying an existing one. Args: @@ -117,10 +117,10 @@ trait ExplicitlyCopyable: struct Foo(ExplicitlyCopyable): var s: String - fn __init__(inout self, s: String): + fn __init__(out self, s: String): self.s = s - fn __init__(inout self, copy: Self): + fn __init__(out self, copy: Self): print("explicitly copying value") self.s = copy.s ``` @@ -145,7 +145,7 @@ trait ExplicitlyCopyable: # `other` is a required named argument for the time being to minimize # implicit conversion overload ambiguity errors, particularly # with SIMD and Int. - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicitly construct a deep copy of the provided value. Args: @@ -164,7 +164,7 @@ trait Defaultable: struct Foo(Defaultable): var s: String - fn __init__(inout self): + fn __init__(out self): self.s = "default" ``` @@ -183,7 +183,7 @@ trait Defaultable: ``` """ - fn __init__(inout self): + fn __init__(out self): """Create a default instance of the value.""" ... diff --git a/stdlib/src/collections/counter.mojo b/stdlib/src/collections/counter.mojo index b65076d9e0..64db6a205a 100644 --- a/stdlib/src/collections/counter.mojo +++ b/stdlib/src/collections/counter.mojo @@ -51,12 +51,12 @@ struct Counter[V: KeyElement](Sized, CollectionElement, Boolable): # Life cycle methods # ===------------------------------------------------------------------=== # - fn __init__(inout self): + fn __init__(out self): """Create a new, empty Counter object.""" self._data = Dict[V, Int]() # TODO: Change List to Iterable when it is supported in Mojo - fn __init__(inout self, items: List[V, *_]): + fn __init__(out self, items: List[V, *_]): """Create a from an input iterable. Args: @@ -68,7 +68,7 @@ struct Counter[V: KeyElement](Sized, CollectionElement, Boolable): self._data[item] = self._data.get(item, 0) + 1 @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Create a new Counter by copying another Counter. Args: @@ -616,7 +616,7 @@ struct CountTuple[V: KeyElement]( # Life cycle methods # ===------------------------------------------------------------------=== # - fn __init__(inout self, value: V, count: Int): + fn __init__(out self, value: V, count: Int): """Create a new CountTuple. Args: @@ -626,7 +626,7 @@ struct CountTuple[V: KeyElement]( self._value = value self._count = count - fn __copyinit__(inout self, other: Self): + fn __copyinit__(out self, other: Self): """Create a new CountTuple by copying another CountTuple. Args: @@ -635,7 +635,7 @@ struct CountTuple[V: KeyElement]( self._value = other._value self._count = other._count - fn __moveinit__(inout self, owned other: Self): + fn __moveinit__(out self, owned other: Self): """Create a new CountTuple by moving another CountTuple. Args: diff --git a/stdlib/src/collections/deque.mojo b/stdlib/src/collections/deque.mojo index c52991fa85..b619c4bb5a 100644 --- a/stdlib/src/collections/deque.mojo +++ b/stdlib/src/collections/deque.mojo @@ -132,7 +132,7 @@ struct Deque[ElementType: CollectionElement]( if elements is not None: self.extend(elements.value()) - fn __init__(inout self, owned *values: ElementType): + fn __init__(out self, owned *values: ElementType): """Constructs a deque from the given values. Args: @@ -167,7 +167,7 @@ struct Deque[ElementType: CollectionElement]( self._tail = args_length - fn __init__(inout self, other: Self): + fn __init__(out self, other: Self): """Creates a deepcopy of the given deque. Args: @@ -185,7 +185,7 @@ struct Deque[ElementType: CollectionElement]( self._tail = len(other) - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """Moves data of an existing deque into a new one. Args: diff --git a/stdlib/src/collections/dict.mojo b/stdlib/src/collections/dict.mojo index 8cbd4b6357..bd9cdb5687 100644 --- a/stdlib/src/collections/dict.mojo +++ b/stdlib/src/collections/dict.mojo @@ -220,7 +220,7 @@ struct DictEntry[K: KeyElement, V: CollectionElement]( var value: V """The value associated with the key.""" - fn __init__(inout self, owned key: K, owned value: V): + fn __init__(out self, owned key: K, owned value: V): """Create an entry from a key and value, computing the hash. Args: @@ -231,7 +231,7 @@ struct DictEntry[K: KeyElement, V: CollectionElement]( self.key = key^ self.value = value^ - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy an existing entry. Args: @@ -270,7 +270,7 @@ struct _DictIndex: var data: OpaquePointer @always_inline - fn __init__(inout self, reserved: Int): + fn __init__(out self, reserved: Int): if reserved <= 128: var data = UnsafePointer[Int8].alloc(reserved) for i in range(reserved): @@ -312,7 +312,7 @@ struct _DictIndex: memcpy(new_data, data, reserved) return index^ - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): self.data = existing.data fn get_index(self, reserved: Int, slot: Int) -> Int: @@ -472,7 +472,7 @@ struct Dict[K: KeyElement, V: CollectionElement]( # ===-------------------------------------------------------------------===# @always_inline - fn __init__(inout self): + fn __init__(out self): """Initialize an empty dictiontary.""" self.size = 0 self._n_entries = 0 @@ -480,7 +480,7 @@ struct Dict[K: KeyElement, V: CollectionElement]( self._index = _DictIndex(len(self._entries)) @always_inline - fn __init__(inout self, *, power_of_two_initial_capacity: Int): + fn __init__(out self, *, power_of_two_initial_capacity: Int): """Initialize an empty dictiontary with a pre-reserved initial capacity. Args: @@ -513,7 +513,7 @@ struct Dict[K: KeyElement, V: CollectionElement]( return len(self._entries) @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy an existing dictiontary. Args: @@ -555,7 +555,7 @@ struct Dict[K: KeyElement, V: CollectionElement]( """ return Dict[K, Optional[V]].fromkeys(keys, value) - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): """Copy an existing dictiontary. Args: @@ -566,7 +566,7 @@ struct Dict[K: KeyElement, V: CollectionElement]( self._index = existing._index.copy(existing._reserved()) self._entries = existing._entries - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """Move data of an existing dict into a new one. Args: @@ -1083,11 +1083,11 @@ struct OwnedKwargsDict[V: CollectionElement]( # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self): + fn __init__(out self): """Initialize an empty keyword dictionary.""" self._dict = Dict[Self.key_type, V]() - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy an existing keyword dictionary. Args: @@ -1095,7 +1095,7 @@ struct OwnedKwargsDict[V: CollectionElement]( """ self._dict = other._dict - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): """Copy an existing keyword dictionary. Args: @@ -1103,7 +1103,7 @@ struct OwnedKwargsDict[V: CollectionElement]( """ self._dict = existing._dict - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """Move data of an existing keyword dictionary into a new one. Args: diff --git a/stdlib/src/collections/inline_array.mojo b/stdlib/src/collections/inline_array.mojo index 0721f33e6f..7aab9d4618 100644 --- a/stdlib/src/collections/inline_array.mojo +++ b/stdlib/src/collections/inline_array.mojo @@ -67,7 +67,7 @@ struct InlineArray[ # ===------------------------------------------------------------------===# @always_inline - fn __init__(inout self): + fn __init__(out self): """This constructor will always cause a compile time error if used. It is used to steer users away from uninitialized memory. """ @@ -85,7 +85,7 @@ struct InlineArray[ ]() @always_inline - fn __init__(inout self, *, unsafe_uninitialized: Bool): + fn __init__(out self, *, unsafe_uninitialized: Bool): """Create an InlineArray with uninitialized memory. Note that this is highly unsafe and should be used with caution. @@ -139,7 +139,7 @@ struct InlineArray[ ) @always_inline - fn __init__(inout self, fill: Self.ElementType): + fn __init__(out self, fill: Self.ElementType): """Constructs an empty array where each element is the supplied `fill`. Args: @@ -157,7 +157,7 @@ struct InlineArray[ ptr.init_pointee_copy(fill) @always_inline - fn __init__(inout self, owned *elems: Self.ElementType): + fn __init__(out self, owned *elems: Self.ElementType): """Constructs an array given a set of arguments. Args: @@ -194,7 +194,7 @@ struct InlineArray[ # Mark the elements as already destroyed. storage._is_owned = False - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicitly copy the provided value. Args: @@ -207,7 +207,7 @@ struct InlineArray[ var ptr = self.unsafe_ptr() + idx ptr.init_pointee_copy(other[idx]) - fn __copyinit__(inout self, other: Self): + fn __copyinit__(out self, other: Self): """Copy construct the array. Args: diff --git a/stdlib/src/collections/inline_list.mojo b/stdlib/src/collections/inline_list.mojo index 0922999700..792635f427 100644 --- a/stdlib/src/collections/inline_list.mojo +++ b/stdlib/src/collections/inline_list.mojo @@ -100,7 +100,7 @@ struct InlineList[ElementType: CollectionElementNew, capacity: Int = 16](Sized): # ===-------------------------------------------------------------------===# @always_inline - fn __init__(inout self): + fn __init__(out self): """This constructor creates an empty InlineList.""" self._array = InlineArray[ UnsafeMaybeUninitialized[ElementType], capacity @@ -109,7 +109,7 @@ struct InlineList[ElementType: CollectionElementNew, capacity: Int = 16](Sized): # TODO: Avoid copying elements in once owned varargs # allow transfers. - fn __init__(inout self, *values: ElementType): + fn __init__(out self, *values: ElementType): """Constructs a list from the given values. Args: diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index 6fa162fd2e..301825d0a7 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -109,13 +109,13 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self): + fn __init__(out self): """Constructs an empty list.""" self.data = UnsafePointer[T]() self.size = 0 self.capacity = 0 - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Creates a deep copy of the given list. Args: @@ -125,7 +125,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( for e in other: self.append(e[]) - fn __init__(inout self, *, capacity: Int): + fn __init__(out self, *, capacity: Int): """Constructs a list with the given capacity. Args: @@ -135,7 +135,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( self.size = 0 self.capacity = capacity - fn __init__(inout self, owned *values: T): + fn __init__(out self, owned *values: T): """Constructs a list from the given values. Args: @@ -143,7 +143,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( """ self = Self(variadic_list=values^) - fn __init__(inout self, *, owned variadic_list: VariadicListMem[T, _]): + fn __init__(out self, *, owned variadic_list: VariadicListMem[T, _]): """Constructs a list from the given values. Args: @@ -164,7 +164,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( self.size = length - fn __init__(inout self, span: Span[T]): + fn __init__(out self, span: Span[T]): """Constructs a list from the a Span of values. Args: @@ -188,7 +188,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( self.size = length self.capacity = capacity - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """Move data of an existing list into a new one. Args: @@ -198,7 +198,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( self.size = existing.size self.capacity = existing.capacity - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): """Creates a deepcopy of the given list. Args: diff --git a/stdlib/src/collections/optional.mojo b/stdlib/src/collections/optional.mojo index b4a1b00c74..d9326aa4cc 100644 --- a/stdlib/src/collections/optional.mojo +++ b/stdlib/src/collections/optional.mojo @@ -38,7 +38,7 @@ from utils import Variant # TODO(27780): NoneType can't currently conform to traits @value struct _NoneType(CollectionElement, CollectionElementNew): - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): pass @@ -88,11 +88,11 @@ struct Optional[T: CollectionElement]( # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self): + fn __init__(out self): """Construct an empty Optional.""" self._value = Self._type(_NoneType()) - fn __init__(inout self, owned value: T): + fn __init__(out self, owned value: T): """Construct an Optional containing a value. Args: @@ -104,7 +104,7 @@ struct Optional[T: CollectionElement]( # This initializer should not be necessary, we should need # only the initilaizer from a `NoneType`. @doc_private - fn __init__(inout self, value: NoneType._mlir_type): + fn __init__(out self, value: NoneType._mlir_type): """Construct an empty Optional. Args: @@ -112,7 +112,7 @@ struct Optional[T: CollectionElement]( """ self = Self(value=NoneType(value)) - fn __init__(inout self, value: NoneType): + fn __init__(out self, value: NoneType): """Construct an empty Optional. Args: @@ -120,7 +120,7 @@ struct Optional[T: CollectionElement]( """ self = Self() - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy construct an Optional. Args: @@ -403,11 +403,11 @@ struct OptionalReg[T: AnyTrivialRegType](Boolable): # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self): + fn __init__(out self): """Create an optional with a value of None.""" self = Self(None) - fn __init__(inout self, value: T): + fn __init__(out self, value: T): """Create an optional with a value. Args: @@ -421,7 +421,7 @@ struct OptionalReg[T: AnyTrivialRegType](Boolable): # This initializer should not be necessary, we should need # only the initilaizer from a `NoneType`. @doc_private - fn __init__(inout self, value: NoneType._mlir_type): + fn __init__(out self, value: NoneType._mlir_type): """Construct an empty Optional. Args: @@ -429,7 +429,7 @@ struct OptionalReg[T: AnyTrivialRegType](Boolable): """ self = Self(value=NoneType(value)) - fn __init__(inout self, value: NoneType): + fn __init__(out self, value: NoneType): """Create an optional without a value from a None literal. Args: diff --git a/stdlib/src/collections/set.mojo b/stdlib/src/collections/set.mojo index 8d9f6d60f0..809d838a55 100644 --- a/stdlib/src/collections/set.mojo +++ b/stdlib/src/collections/set.mojo @@ -54,7 +54,7 @@ struct Set[T: KeyElement](Sized, Comparable, Hashable, Boolable): # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self, *ts: T): + fn __init__(out self, *ts: T): """Construct a set from initial elements. Args: @@ -64,7 +64,7 @@ struct Set[T: KeyElement](Sized, Comparable, Hashable, Boolable): for t in ts: self.add(t[]) - fn __init__(inout self, elements: Self): + fn __init__(out self, elements: Self): """Explicitly copy another Set instance. Args: @@ -74,7 +74,7 @@ struct Set[T: KeyElement](Sized, Comparable, Hashable, Boolable): for e in elements: self.add(e[]) - fn __init__(inout self, elements: List[T, *_]): + fn __init__(out self, elements: List[T, *_]): """Construct a set from a List of elements. Args: @@ -84,7 +84,7 @@ struct Set[T: KeyElement](Sized, Comparable, Hashable, Boolable): for e in elements: self.add(e[]) - fn __moveinit__(inout self, owned other: Self): + fn __moveinit__(out self, owned other: Self): """Move constructor. Args: diff --git a/stdlib/src/collections/vector.mojo b/stdlib/src/collections/vector.mojo index b371c7ec05..6fd87dd51e 100644 --- a/stdlib/src/collections/vector.mojo +++ b/stdlib/src/collections/vector.mojo @@ -114,7 +114,7 @@ struct InlinedFixedVector[ """The maximum number of elements that can fit in the vector.""" @always_inline - fn __init__(inout self, capacity: Int): + fn __init__(out self, capacity: Int): """Constructs `InlinedFixedVector` with the given capacity. The dynamically allocated portion is `capacity - size`. @@ -130,7 +130,7 @@ struct InlinedFixedVector[ self.capacity = capacity @always_inline - fn __init__(inout self, existing: Self): + fn __init__(out self, existing: Self): """ Copy constructor. @@ -148,7 +148,7 @@ struct InlinedFixedVector[ self.capacity = existing.capacity @always_inline - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """ Move constructor. diff --git a/stdlib/src/documentation/documentation.mojo b/stdlib/src/documentation/documentation.mojo index 76892d3c6c..69ea07675c 100644 --- a/stdlib/src/documentation/documentation.mojo +++ b/stdlib/src/documentation/documentation.mojo @@ -34,7 +34,7 @@ fn doc_private(): ```mojo struct Foo: @doc_private - fn __init__(inout self): + fn __init__(out self): "This should not be called directly, use `Foo.create` instead." return diff --git a/stdlib/src/hashlib/_ahash.mojo b/stdlib/src/hashlib/_ahash.mojo index d54036d0fe..7dccb4dd9d 100644 --- a/stdlib/src/hashlib/_ahash.mojo +++ b/stdlib/src/hashlib/_ahash.mojo @@ -93,7 +93,7 @@ struct AHasher[key: U256](_Hasher): var pad: UInt64 var extra_keys: U128 - fn __init__(inout self): + fn __init__(out self): """Initialize the hasher.""" alias pi_key = key ^ U256( 0x243F_6A88_85A3_08D3, diff --git a/stdlib/src/hashlib/_hasher.mojo b/stdlib/src/hashlib/_hasher.mojo index 505ae4fc0a..7bd278d5e9 100644 --- a/stdlib/src/hashlib/_hasher.mojo +++ b/stdlib/src/hashlib/_hasher.mojo @@ -21,7 +21,7 @@ trait _HashableWithHasher: trait _Hasher: - fn __init__(inout self): + fn __init__(out self): ... fn _update_with_bytes(inout self, data: UnsafePointer[UInt8], length: Int): diff --git a/stdlib/src/memory/arc.mojo b/stdlib/src/memory/arc.mojo index d07383f165..9863d700b0 100644 --- a/stdlib/src/memory/arc.mojo +++ b/stdlib/src/memory/arc.mojo @@ -54,7 +54,7 @@ struct _ArcInner[T: Movable]: var refcount: Atomic[DType.uint64] var payload: T - fn __init__(inout self, owned value: T): + fn __init__(out self, owned value: T): """Create an initialized instance of this with a refcount of 1.""" self.refcount = 1 self.payload = value^ @@ -88,7 +88,7 @@ struct Arc[T: Movable](CollectionElement, CollectionElementNew, Identifiable): alias _inner_type = _ArcInner[T] var _inner: UnsafePointer[Self._inner_type] - fn __init__(inout self, owned value: T): + fn __init__(out self, owned value: T): """Construct a new thread-safe, reference-counted smart pointer, and move the value into heap memory managed by the new pointer. @@ -101,7 +101,7 @@ struct Arc[T: Movable](CollectionElement, CollectionElementNew, Identifiable): value^ ) - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy the object. Args: @@ -110,7 +110,7 @@ struct Arc[T: Movable](CollectionElement, CollectionElementNew, Identifiable): other._inner[].add_ref() self._inner = other._inner - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): """Copy an existing reference. Increment the refcount to the object. Args: diff --git a/stdlib/src/memory/maybe_uninitialized.mojo b/stdlib/src/memory/maybe_uninitialized.mojo index 33689c6260..010822a602 100644 --- a/stdlib/src/memory/maybe_uninitialized.mojo +++ b/stdlib/src/memory/maybe_uninitialized.mojo @@ -34,7 +34,7 @@ struct UnsafeMaybeUninitialized[ElementType: AnyType](CollectionElementNew): var _array: Self.type @always_inline - fn __init__(inout self): + fn __init__(out self): """The memory is now considered uninitialized.""" self._array = __mlir_op.`kgen.param.constant`[ _type = Self.type, @@ -43,7 +43,7 @@ struct UnsafeMaybeUninitialized[ElementType: AnyType](CollectionElementNew): @doc_private @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """It is not possible to call this method. Trying to call this method will abort. @@ -77,7 +77,7 @@ struct UnsafeMaybeUninitialized[ElementType: AnyType](CollectionElementNew): self.write(value^) @always_inline - fn __copyinit__(inout self, other: Self): + fn __copyinit__(out self, other: Self): """Copy another object. This method should never be called as implicit copy should not @@ -131,7 +131,7 @@ struct UnsafeMaybeUninitialized[ElementType: AnyType](CollectionElementNew): self.unsafe_ptr().init_pointee_explicit_copy(other) @always_inline - fn __moveinit__(inout self, owned other: Self): + fn __moveinit__(out self, owned other: Self): """Move another object. This method should never be called as implicit moves should not diff --git a/stdlib/src/memory/owned_pointer.mojo b/stdlib/src/memory/owned_pointer.mojo index 3976fc8c6d..4f00050e89 100644 --- a/stdlib/src/memory/owned_pointer.mojo +++ b/stdlib/src/memory/owned_pointer.mojo @@ -85,7 +85,7 @@ struct OwnedPointer[T: AnyType]: """ self.__init__(copy_value=other[]) - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """Move this OwnedPointer[]. Args: diff --git a/stdlib/src/memory/unsafe_pointer.mojo b/stdlib/src/memory/unsafe_pointer.mojo index 4b128170bd..772199ed5f 100644 --- a/stdlib/src/memory/unsafe_pointer.mojo +++ b/stdlib/src/memory/unsafe_pointer.mojo @@ -98,13 +98,13 @@ struct UnsafePointer[ # ===-------------------------------------------------------------------===# @always_inline - fn __init__(inout self): + fn __init__(out self): """Create a null pointer.""" self.address = __mlir_attr[`#interp.pointer<0> : `, Self._mlir_type] @doc_private @always_inline - fn __init__(inout self, value: Self._mlir_type): + fn __init__(out self, value: Self._mlir_type): """Create a pointer with the input value. Args: @@ -113,7 +113,7 @@ struct UnsafePointer[ self.address = value @always_inline - fn __init__(inout self, other: UnsafePointer[type, address_space, *_, **_]): + fn __init__(out self, other: UnsafePointer[type, address_space, *_, **_]): """Exclusivity parameter cast a pointer. Args: @@ -124,7 +124,7 @@ struct UnsafePointer[ ) @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy the object. Args: diff --git a/stdlib/src/os/_linux_aarch64.mojo b/stdlib/src/os/_linux_aarch64.mojo index b8e8740068..9647be1218 100644 --- a/stdlib/src/os/_linux_aarch64.mojo +++ b/stdlib/src/os/_linux_aarch64.mojo @@ -48,7 +48,7 @@ struct _c_stat(Stringable): var st_birthtimespec: _CTimeSpec # time of file creation(birth) var unused: InlineArray[Int64, 2] # RESERVED: DO NOT USE! - fn __init__(inout self): + fn __init__(out self): self.st_dev = 0 self.st_mode = 0 self.st_nlink = 0 diff --git a/stdlib/src/os/_linux_x86.mojo b/stdlib/src/os/_linux_x86.mojo index 472e16c61d..d2872d8a1a 100644 --- a/stdlib/src/os/_linux_x86.mojo +++ b/stdlib/src/os/_linux_x86.mojo @@ -47,7 +47,7 @@ struct _c_stat(Stringable): var st_birthtimespec: _CTimeSpec # time of file creation(birth) var unused: InlineArray[Int64, 3] # RESERVED: DO NOT USE! - fn __init__(inout self): + fn __init__(out self): self.st_dev = 0 self.st_mode = 0 self.st_nlink = 0 diff --git a/stdlib/src/os/_macos.mojo b/stdlib/src/os/_macos.mojo index faeb23f686..1d1a7d11d3 100644 --- a/stdlib/src/os/_macos.mojo +++ b/stdlib/src/os/_macos.mojo @@ -50,7 +50,7 @@ struct _c_stat(Stringable): var st_lspare: Int32 # RESERVED: DO NOT USE! var st_qspare: InlineArray[Int64, 2] # RESERVED: DO NOT USE! - fn __init__(inout self): + fn __init__(out self): self.st_dev = 0 self.st_mode = 0 self.st_nlink = 0 diff --git a/stdlib/src/os/atomic.mojo b/stdlib/src/os/atomic.mojo index 6b7bd43d90..f7902c1cf4 100644 --- a/stdlib/src/os/atomic.mojo +++ b/stdlib/src/os/atomic.mojo @@ -41,7 +41,7 @@ struct Atomic[type: DType]: """ @always_inline - fn __init__(inout self, value: Scalar[type]): + fn __init__(out self, value: Scalar[type]): """Constructs a new atomic value. Args: diff --git a/stdlib/src/os/os.mojo b/stdlib/src/os/os.mojo index ba00c1b447..c00532ff9a 100644 --- a/stdlib/src/os/os.mojo +++ b/stdlib/src/os/os.mojo @@ -95,7 +95,7 @@ struct _DirHandle: var _handle: OpaquePointer - fn __init__(inout self, path: String) raises: + fn __init__(out self, path: String) raises: """Construct the _DirHandle using the path provided. Args: diff --git a/stdlib/src/pathlib/path.mojo b/stdlib/src/pathlib/path.mojo index 45a8c9aacf..e77c305081 100644 --- a/stdlib/src/pathlib/path.mojo +++ b/stdlib/src/pathlib/path.mojo @@ -80,11 +80,11 @@ struct Path( var path: String """The underlying path string representation.""" - fn __init__(inout self) raises: + fn __init__(out self) raises: """Initializes a path with the current directory.""" self = cwd() - fn __init__(inout self, path: String): + fn __init__(out self, path: String): """Initializes a path with the provided path. Args: @@ -92,7 +92,7 @@ struct Path( """ self.path = path - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy the object. Args: diff --git a/stdlib/src/python/_cpython.mojo b/stdlib/src/python/_cpython.mojo index b908306ddf..9e7983cfbe 100644 --- a/stdlib/src/python/_cpython.mojo +++ b/stdlib/src/python/_cpython.mojo @@ -160,7 +160,7 @@ struct PyObjectPtr: # ===-------------------------------------------------------------------===# @always_inline - fn __init__(inout self): + fn __init__(out self): """Initialize a null PyObjectPtr.""" self.unsized_obj_ptr = UnsafePointer[PyObject]() @@ -259,7 +259,7 @@ struct PythonVersion: var patch: Int """The patch version number.""" - fn __init__(inout self, version: StringRef): + fn __init__(out self, version: StringRef): """Initialize a PythonVersion object from a version string. Args: @@ -333,7 +333,7 @@ struct PyMethodDef: # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self): + fn __init__(out self): """Constructs a zero initialized PyModuleDef. This is suitable for use terminating an array of PyMethodDef values. @@ -343,7 +343,7 @@ struct PyMethodDef: self.method_flags = 0 self.method_docstring = UnsafePointer[c_char]() - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicitly construct a deep copy of the provided value. Args: @@ -465,7 +465,7 @@ struct PyObject(Stringable, Representable, Writable): var object_ref_count: Int var object_type: UnsafePointer[PyTypeObject] - fn __init__(inout self): + fn __init__(out self): self.object_ref_count = 0 self.object_type = UnsafePointer[PyTypeObject]() @@ -541,13 +541,13 @@ struct PyModuleDef_Base(Stringable, Representable, Writable): # Life cycle methods # ===------------------------------------------------------------------=== # - fn __init__(inout self): + fn __init__(out self): self.object_base = PyObject() self.init_fn = _null_fn_ptr[Self._init_fn_type]() self.index = 0 self.dict_copy = UnsafePointer[PyObject]() - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): self.object_base = existing.object_base self.init_fn = existing.init_fn self.index = existing.index @@ -647,7 +647,7 @@ struct PyModuleDef(Stringable, Representable, Writable): alias _free_fn_type = fn (OpaquePointer) -> OpaquePointer var free_fn: Self._free_fn_type - fn __init__(inout self, name: String): + fn __init__(out self, name: String): self.base = PyModuleDef_Base() self.name = name.unsafe_cstr_ptr() self.docstring = UnsafePointer[c_char]() @@ -661,7 +661,7 @@ struct PyModuleDef(Stringable, Representable, Writable): self.clear_fn = _null_fn_ptr[Self._clear_fn_type]() self.free_fn = _null_fn_ptr[Self._free_fn_type]() - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): self.base = existing.base^ self.name = existing.name self.docstring = existing.docstring @@ -748,7 +748,7 @@ struct CPython: # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self): + fn __init__(out self): var logging_enabled = getenv("MODULAR_CPYTHON_LOGGING") == "ON" if logging_enabled: print("CPython init") diff --git a/stdlib/src/python/python.mojo b/stdlib/src/python/python.mojo index a0c0878228..f2fb0237b9 100644 --- a/stdlib/src/python/python.mojo +++ b/stdlib/src/python/python.mojo @@ -59,10 +59,10 @@ fn _get_global_python_itf() -> _PythonInterfaceImpl: struct _PythonInterfaceImpl: var _cpython: UnsafePointer[CPython] - fn __init__(inout self, cpython: UnsafePointer[CPython]): + fn __init__(out self, cpython: UnsafePointer[CPython]): self._cpython = cpython - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): self._cpython = existing._cpython fn cpython(self) -> CPython: @@ -79,11 +79,11 @@ struct Python: # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self): + fn __init__(out self): """Default constructor.""" self.impl = _get_global_python_itf() - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): """Copy constructor. Args: diff --git a/stdlib/src/python/python_object.mojo b/stdlib/src/python/python_object.mojo index 05397a1c75..a7089fc8f5 100644 --- a/stdlib/src/python/python_object.mojo +++ b/stdlib/src/python/python_object.mojo @@ -50,7 +50,7 @@ struct _PyIter(Sized): # Life cycle methods # ===-------------------------------------------------------------------===# - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): """Copy another iterator. Args: @@ -60,7 +60,7 @@ struct _PyIter(Sized): self.preparedNextItem = existing.preparedNextItem self.isDone = existing.isDone - fn __init__(inout self, iter: PythonObject): + fn __init__(out self, iter: PythonObject): """Initialize an iterator. Args: @@ -76,7 +76,7 @@ struct _PyIter(Sized): self.preparedNextItem = PythonObject(maybeNextItem) self.isDone = False - fn __init__(inout self): + fn __init__(out self): """Initialize an empty iterator.""" self.iterator = PythonObject(PyObjectPtr()) self.isDone = True @@ -145,7 +145,7 @@ struct TypedPythonObject[type_hint: StringLiteral]( # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self, *, owned unsafe_unchecked_from: PythonObject): + fn __init__(out self, *, owned unsafe_unchecked_from: PythonObject): """Construct a TypedPythonObject without any validation that the given object is of the specified hinted type. @@ -155,7 +155,7 @@ struct TypedPythonObject[type_hint: StringLiteral]( """ self._obj = unsafe_unchecked_from^ - fn __copyinit__(inout self, other: Self): + fn __copyinit__(out self, other: Self): """Copy an instance of this type. Args: @@ -249,11 +249,11 @@ struct PythonObject( # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self): + fn __init__(out self): """Initialize the object with a `None` value.""" self.__init__(None) - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy the object. Args: @@ -261,7 +261,7 @@ struct PythonObject( """ self = other - fn __init__(inout self, ptr: PyObjectPtr): + fn __init__(out self, ptr: PyObjectPtr): """Initialize this object from an owned reference-counted Python object pointer. @@ -308,7 +308,7 @@ struct PythonObject( return PythonObject(borrowed_ptr) - fn __init__(inout self, owned typed_obj: TypedPythonObject[_]): + fn __init__(out self, owned typed_obj: TypedPythonObject[_]): """Construct a PythonObject from a typed object, dropping the type hint information. @@ -330,7 +330,7 @@ struct PythonObject( # This initializer should not be necessary, we should need # only the initilaizer from a `NoneType`. @doc_private - fn __init__(inout self, none: NoneType._mlir_type): + fn __init__(out self, none: NoneType._mlir_type): """Initialize a none value object from a `None` literal. Args: @@ -338,7 +338,7 @@ struct PythonObject( """ self = Self(none=NoneType()) - fn __init__(inout self, none: NoneType): + fn __init__(out self, none: NoneType): """Initialize a none value object from a `None` literal. Args: @@ -348,7 +348,7 @@ struct PythonObject( self.py_object = cpython.Py_None() cpython.Py_IncRef(self.py_object) - fn __init__(inout self, value: Bool): + fn __init__(out self, value: Bool): """Initialize the object from a bool. Args: @@ -357,7 +357,7 @@ struct PythonObject( cpython = _get_global_python_itf().cpython() self.py_object = cpython.PyBool_FromLong(int(value)) - fn __init__(inout self, integer: Int): + fn __init__(out self, integer: Int): """Initialize the object with an integer value. Args: @@ -389,7 +389,7 @@ struct PythonObject( fp_val = value.cast[DType.float64]() self.py_object = cpython.PyFloat_FromDouble(fp_val) - fn __init__(inout self, value: StringLiteral): + fn __init__(out self, value: StringLiteral): """Initialize the object from a string literal. Args: @@ -397,7 +397,7 @@ struct PythonObject( """ self = PythonObject(str(value)) - fn __init__(inout self, strref: StringRef): + fn __init__(out self, strref: StringRef): """Initialize the object from a string reference. Args: @@ -406,7 +406,7 @@ struct PythonObject( cpython = _get_global_python_itf().cpython() self.py_object = cpython.PyUnicode_DecodeUTF8(strref) - fn __init__(inout self, string: String): + fn __init__(out self, string: String): """Initialize the object from a string. Args: @@ -500,7 +500,7 @@ struct PythonObject( cpython.Py_IncRef(obj.py_object) _ = cpython.PyTuple_SetItem(self.py_object, i, obj.py_object) - fn __init__(inout self, slice: Slice): + fn __init__(out self, slice: Slice): """Initialize the object from a Mojo Slice. Args: @@ -508,7 +508,7 @@ struct PythonObject( """ self.py_object = _slice_to_py_object_ptr(slice) - fn __init__(inout self, value: Dict[Self, Self]): + fn __init__(out self, value: Dict[Self, Self]): """Initialize the object from a dictionary of PythonObjects. Args: @@ -521,7 +521,7 @@ struct PythonObject( self.py_object, entry[].key.py_object, entry[].value.py_object ) - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): """Copy the object. This increments the underlying refcount of the existing object. diff --git a/stdlib/src/sys/ffi.mojo b/stdlib/src/sys/ffi.mojo index ad4058b1e5..b3c86e6373 100644 --- a/stdlib/src/sys/ffi.mojo +++ b/stdlib/src/sys/ffi.mojo @@ -117,7 +117,7 @@ struct DLHandle(CollectionElement, CollectionElementNew, Boolable): # TODO(#15590): Implement support for windows and remove the always_inline. @always_inline - fn __init__(inout self, path: String, flags: Int = DEFAULT_RTLD): + fn __init__(out self, path: String, flags: Int = DEFAULT_RTLD): """Initialize a DLHandle object by loading the dynamic library at the given path. @@ -136,7 +136,7 @@ struct DLHandle(CollectionElement, CollectionElementNew, Boolable): else: self.handle = OpaquePointer() - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy the object. Args: diff --git a/stdlib/src/sys/intrinsics.mojo b/stdlib/src/sys/intrinsics.mojo index d5ceafdfb0..b60eecbbc5 100644 --- a/stdlib/src/sys/intrinsics.mojo +++ b/stdlib/src/sys/intrinsics.mojo @@ -279,7 +279,7 @@ struct PrefetchLocality: """Extremely local locality (keep in cache).""" @always_inline("nodebug") - fn __init__(inout self, value: Int): + fn __init__(out self, value: Int): """Constructs a prefetch locality option. Args: @@ -301,7 +301,7 @@ struct PrefetchRW: """Write prefetch.""" @always_inline("nodebug") - fn __init__(inout self, value: Int): + fn __init__(out self, value: Int): """Constructs a prefetch read-write option. Args: @@ -324,7 +324,7 @@ struct PrefetchCache: """The data prefetching option.""" @always_inline("nodebug") - fn __init__(inout self, value: Int): + fn __init__(out self, value: Int): """Constructs a prefetch option. Args: @@ -359,7 +359,7 @@ struct PrefetchOptions: """Indicates i-cache or d-cache prefetching.""" @always_inline("nodebug") - fn __init__(inout self): + fn __init__(out self): """Constructs an instance of PrefetchOptions with default params.""" self.rw = PrefetchRW.READ self.locality = PrefetchLocality.HIGH diff --git a/stdlib/src/tempfile/tempfile.mojo b/stdlib/src/tempfile/tempfile.mojo index d33c41f867..7f3c2dd09d 100644 --- a/stdlib/src/tempfile/tempfile.mojo +++ b/stdlib/src/tempfile/tempfile.mojo @@ -350,7 +350,7 @@ struct NamedTemporaryFile: if self._delete: os.remove(self.name) - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): """Moves constructor for the file handle. Args: diff --git a/stdlib/src/testing/testing.mojo b/stdlib/src/testing/testing.mojo index 79369bea7c..5dff04c458 100644 --- a/stdlib/src/testing/testing.mojo +++ b/stdlib/src/testing/testing.mojo @@ -526,7 +526,7 @@ struct assert_raises: """Assigned the value returned by __call_locations() at Self.__init__.""" @always_inline - fn __init__(inout self, *, location: Optional[_SourceLocation] = None): + fn __init__(out self, *, location: Optional[_SourceLocation] = None): """Construct a context manager with no message pattern. Args: diff --git a/stdlib/src/time/time.mojo b/stdlib/src/time/time.mojo index 39cca3aff6..b964a3f85c 100644 --- a/stdlib/src/time/time.mojo +++ b/stdlib/src/time/time.mojo @@ -63,7 +63,7 @@ struct _CTimeSpec(Stringable): var tv_sec: Int # Seconds var tv_subsec: Int # subsecond (nanoseconds on linux and usec on mac) - fn __init__(inout self): + fn __init__(out self): self.tv_sec = 0 self.tv_subsec = 0 @@ -85,7 +85,7 @@ struct _FILETIME: var dwLowDateTime: UInt32 var dwHighDateTime: UInt32 - fn __init__(inout self): + fn __init__(out self): self.dwLowDateTime = 0 self.dwHighDateTime = 0 diff --git a/stdlib/src/utils/index.mojo b/stdlib/src/utils/index.mojo index 93eb5dbc8d..26c8620f26 100644 --- a/stdlib/src/utils/index.mojo +++ b/stdlib/src/utils/index.mojo @@ -194,13 +194,13 @@ struct IndexList[ """The underlying storage of the tuple value.""" @always_inline - fn __init__(inout self): + fn __init__(out self): """Constructs a static int tuple of the given size.""" self = 0 @doc_private @always_inline - fn __init__(inout self, value: __mlir_type.index): + fn __init__(out self, value: __mlir_type.index): """Constructs a sized 1 static int tuple of given the element value. Args: @@ -210,7 +210,7 @@ struct IndexList[ self = Int(value) @always_inline - fn __init__(inout self, elems: (Int, Int)): + fn __init__(out self, elems: (Int, Int)): """Constructs a static int tuple given a tuple of integers. Args: @@ -235,7 +235,7 @@ struct IndexList[ self = tup @always_inline - fn __init__(inout self, elems: (Int, Int, Int)): + fn __init__(out self, elems: (Int, Int, Int)): """Constructs a static int tuple given a tuple of integers. Args: @@ -260,7 +260,7 @@ struct IndexList[ self = tup @always_inline - fn __init__(inout self, elems: (Int, Int, Int, Int)): + fn __init__(out self, elems: (Int, Int, Int, Int)): """Constructs a static int tuple given a tuple of integers. Args: @@ -285,7 +285,7 @@ struct IndexList[ self = tup @always_inline - fn __init__(inout self, *elems: Int): + fn __init__(out self, *elems: Int): """Constructs a static int tuple given a set of arguments. Args: @@ -308,7 +308,7 @@ struct IndexList[ self = tup @always_inline - fn __init__(inout self, elem: Int): + fn __init__(out self, elem: Int): """Constructs a static int tuple given a set of arguments. Args: @@ -321,7 +321,7 @@ struct IndexList[ ] ](Self._int_type(elem)) - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy constructor. Args: @@ -330,7 +330,7 @@ struct IndexList[ self.data = other.data @always_inline - fn __init__(inout self, values: VariadicList[Int]): + fn __init__(out self, values: VariadicList[Int]): """Creates a tuple constant using the specified values. Args: diff --git a/stdlib/src/utils/inline_string.mojo b/stdlib/src/utils/inline_string.mojo index 42d04f19d4..e163727f51 100644 --- a/stdlib/src/utils/inline_string.mojo +++ b/stdlib/src/utils/inline_string.mojo @@ -53,12 +53,12 @@ struct InlineString(Sized, Stringable, CollectionElement, CollectionElementNew): # Life cycle methods # ===------------------------------------------------------------------===# - fn __init__(inout self): + fn __init__(out self): """Constructs a new empty string.""" var fixed = _FixedString[Self.SMALL_CAP]() self._storage = Self.Layout(fixed^) - fn __init__(inout self, literal: StringLiteral): + fn __init__(out self, literal: StringLiteral): """Constructs a InlineString value given a string literal. Args: @@ -82,7 +82,7 @@ struct InlineString(Sized, Stringable, CollectionElement, CollectionElementNew): var heap = String(literal) self._storage = Self.Layout(heap^) - fn __init__(inout self, owned heap_string: String): + fn __init__(out self, owned heap_string: String): """Construct a new small string by taking ownership of an existing heap-allocated String. @@ -91,7 +91,7 @@ struct InlineString(Sized, Stringable, CollectionElement, CollectionElementNew): """ self._storage = Self.Layout(heap_string^) - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy the object. Args: @@ -328,12 +328,12 @@ struct _FixedString[CAP: Int]( # Life cycle methods # ===------------------------------------------------------------------===# - fn __init__(inout self): + fn __init__(out self): """Constructs a new empty string.""" self.buffer = InlineArray[UInt8, CAP](unsafe_uninitialized=True) self.size = 0 - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy the object. Args: @@ -341,7 +341,7 @@ struct _FixedString[CAP: Int]( """ self = other - fn __init__(inout self, literal: StringLiteral) raises: + fn __init__(out self, literal: StringLiteral) raises: """Constructs a FixedString value given a string literal. Args: diff --git a/stdlib/src/utils/lock.mojo b/stdlib/src/utils/lock.mojo index 18cdeef46b..e7529401d7 100644 --- a/stdlib/src/utils/lock.mojo +++ b/stdlib/src/utils/lock.mojo @@ -29,7 +29,7 @@ struct SpinWaiter: var storage: OpaquePointer """Pointer to the underlying SpinWaiter instance.""" - fn __init__(inout self: Self): + fn __init__(out self: Self): """Initializes a SpinWaiter instance.""" self.storage = external_call[ "KGEN_CompilerRT_AsyncRT_InitializeSpinWaiter", @@ -60,7 +60,7 @@ struct BlockingSpinLock: var counter: Atomic[DType.int64] """The atomic counter implementing the spin lock.""" - fn __init__(inout self: Self): + fn __init__(out self: Self): """Default constructor.""" self.counter = Atomic[DType.int64](Self.UNLOCKED) diff --git a/stdlib/src/utils/numerics.mojo b/stdlib/src/utils/numerics.mojo index b5c006aef4..72dea362b3 100644 --- a/stdlib/src/utils/numerics.mojo +++ b/stdlib/src/utils/numerics.mojo @@ -421,7 +421,7 @@ struct FlushDenormals: """The current state.""" @always_inline - fn __init__(inout self): + fn __init__(out self): """Initializes the FlushDenormals.""" self.state = Self._current_state() diff --git a/stdlib/src/utils/span.mojo b/stdlib/src/utils/span.mojo index e413dc4e42..c2a5fee6c0 100644 --- a/stdlib/src/utils/span.mojo +++ b/stdlib/src/utils/span.mojo @@ -114,7 +114,7 @@ struct Span[ # ===------------------------------------------------------------------===# @always_inline - fn __init__(inout self, *, ptr: UnsafePointer[T], length: Int): + fn __init__(out self, *, ptr: UnsafePointer[T], length: Int): """Unsafe construction from a pointer and length. Args: @@ -125,7 +125,7 @@ struct Span[ self._len = length @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicitly construct a deep copy of the provided Span. Args: @@ -135,7 +135,7 @@ struct Span[ self._len = other._len @always_inline - fn __init__(inout self, ref [origin]list: List[T, *_]): + fn __init__(out self, ref [origin]list: List[T, *_]): """Construct a Span from a List. Args: diff --git a/stdlib/src/utils/static_tuple.mojo b/stdlib/src/utils/static_tuple.mojo index 3f009988f7..f4066c9a4e 100644 --- a/stdlib/src/utils/static_tuple.mojo +++ b/stdlib/src/utils/static_tuple.mojo @@ -126,7 +126,7 @@ struct StaticTuple[element_type: AnyTrivialRegType, size: Int](Sized): """The underlying storage for the static tuple.""" @always_inline - fn __init__(inout self): + fn __init__(out self): """Constructs an empty (undefined) tuple.""" _static_tuple_construction_checks[size]() self.array = __mlir_op.`kgen.param.constant`[ @@ -135,7 +135,7 @@ struct StaticTuple[element_type: AnyTrivialRegType, size: Int](Sized): ]() @always_inline - fn __init__(inout self, *elems: Self.element_type): + fn __init__(out self, *elems: Self.element_type): """Constructs a static tuple given a set of arguments. Args: @@ -145,7 +145,7 @@ struct StaticTuple[element_type: AnyTrivialRegType, size: Int](Sized): self.array = _create_array[size](elems) @always_inline - fn __init__(inout self, values: VariadicList[Self.element_type]): + fn __init__(out self, values: VariadicList[Self.element_type]): """Creates a tuple constant using the specified values. Args: @@ -154,7 +154,7 @@ struct StaticTuple[element_type: AnyTrivialRegType, size: Int](Sized): _static_tuple_construction_checks[size]() self.array = _create_array[size, Self.element_type](values) - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicitly copy the provided StaticTuple. Args: diff --git a/stdlib/src/utils/string_slice.mojo b/stdlib/src/utils/string_slice.mojo index 1c270d6983..c0e38d5f42 100644 --- a/stdlib/src/utils/string_slice.mojo +++ b/stdlib/src/utils/string_slice.mojo @@ -267,7 +267,7 @@ struct StringSlice[is_mutable: Bool, //, origin: Origin[is_mutable].type,]( # ===------------------------------------------------------------------===# @always_inline - fn __init__(inout self: StaticString, lit: StringLiteral): + fn __init__(out self: StaticString, lit: StringLiteral): """Construct a new `StringSlice` from a `StringLiteral`. Args: @@ -288,7 +288,7 @@ struct StringSlice[is_mutable: Bool, //, origin: Origin[is_mutable].type,]( self = StaticString(unsafe_from_utf8=lit.as_bytes()) @always_inline - fn __init__(inout self, *, owned unsafe_from_utf8: Span[Byte, origin]): + fn __init__(out self, *, owned unsafe_from_utf8: Span[Byte, origin]): """Construct a new `StringSlice` from a sequence of UTF-8 encoded bytes. Args: @@ -300,7 +300,7 @@ struct StringSlice[is_mutable: Bool, //, origin: Origin[is_mutable].type,]( self._slice = unsafe_from_utf8^ - fn __init__(inout self, *, unsafe_from_utf8_strref: StringRef): + fn __init__(out self, *, unsafe_from_utf8_strref: StringRef): """Construct a new StringSlice from a `StringRef` pointing to UTF-8 encoded bytes. @@ -323,7 +323,7 @@ struct StringSlice[is_mutable: Bool, //, origin: Origin[is_mutable].type,]( self = Self(unsafe_from_utf8=byte_slice) @always_inline - fn __init__(inout self, *, ptr: UnsafePointer[Byte], length: Int): + fn __init__(out self, *, ptr: UnsafePointer[Byte], length: Int): """Construct a `StringSlice` from a pointer to a sequence of UTF-8 encoded bytes and a length. @@ -340,7 +340,7 @@ struct StringSlice[is_mutable: Bool, //, origin: Origin[is_mutable].type,]( self._slice = Span[Byte, origin](ptr=ptr, length=length) @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicitly construct a deep copy of the provided `StringSlice`. Args: @@ -1162,7 +1162,7 @@ struct _FormatCurlyEntry(CollectionElement, CollectionElementNew): alias _args_t = VariadicPack[element_trait=_CurlyEntryFormattable, *_] """Args types that are formattable by curly entry.""" - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.first_curly = other.first_curly self.last_curly = other.last_curly self.conversion_flag = other.conversion_flag diff --git a/stdlib/src/utils/stringref.mojo b/stdlib/src/utils/stringref.mojo index 4d9e427580..8406c7451e 100644 --- a/stdlib/src/utils/stringref.mojo +++ b/stdlib/src/utils/stringref.mojo @@ -69,12 +69,12 @@ struct StringRef( # ===-------------------------------------------------------------------===# @always_inline - fn __init__(inout self): + fn __init__(out self): """Construct a StringRef value with length zero.""" self = StringRef(UnsafePointer[UInt8](), 0) @always_inline - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Copy the object. Args: @@ -84,7 +84,7 @@ struct StringRef( self.length = other.length @always_inline - fn __init__(inout self, str: StringLiteral): + fn __init__(out self, str: StringLiteral): """Construct a StringRef value given a constant string. Args: @@ -93,7 +93,7 @@ struct StringRef( self = StringRef(str.unsafe_ptr(), len(str)) @always_inline - fn __init__(inout self, ptr: UnsafePointer[c_char], len: Int): + fn __init__(out self, ptr: UnsafePointer[c_char], len: Int): """Construct a StringRef value given a (potentially non-0 terminated string). @@ -112,7 +112,7 @@ struct StringRef( self.length = len @always_inline - fn __init__(inout self, *, ptr: UnsafePointer[UInt8]): + fn __init__(out self, *, ptr: UnsafePointer[UInt8]): """Construct a StringRef value given a null-terminated string. Args: @@ -126,7 +126,7 @@ struct StringRef( self = StringRef(ptr, len) @always_inline - fn __init__(inout self, ptr: UnsafePointer[c_char]): + fn __init__(out self, ptr: UnsafePointer[c_char]): """Construct a StringRef value given a null-terminated string. Note that you should use the constructor from `UnsafePointer[UInt8]` instead diff --git a/stdlib/src/utils/variant.mojo b/stdlib/src/utils/variant.mojo index 34546cba4b..e26cd537fc 100644 --- a/stdlib/src/utils/variant.mojo +++ b/stdlib/src/utils/variant.mojo @@ -115,7 +115,7 @@ struct Variant[*Ts: CollectionElement]( # Life cycle methods # ===-------------------------------------------------------------------===# - fn __init__(inout self, *, unsafe_uninitialized: ()): + fn __init__(out self, *, unsafe_uninitialized: ()): """Unsafely create an uninitialized Variant. Args: @@ -138,7 +138,7 @@ struct Variant[*Ts: CollectionElement]( self._get_discr() = idx self._get_ptr[T]().init_pointee_move(value^) - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicitly creates a deep copy of an existing variant. Args: @@ -154,7 +154,7 @@ struct Variant[*Ts: CollectionElement]( self._get_ptr[T]().init_pointee_move(other._get_ptr[T]()[]) return - fn __copyinit__(inout self, other: Self): + fn __copyinit__(out self, other: Self): """Creates a deep copy of an existing variant. Args: @@ -164,7 +164,7 @@ struct Variant[*Ts: CollectionElement]( # Delegate to explicit copy initializer. self = Self(other=other) - fn __moveinit__(inout self, owned other: Self): + fn __moveinit__(out self, owned other: Self): """Move initializer for the variant. Args: diff --git a/stdlib/src/utils/write.mojo b/stdlib/src/utils/write.mojo index 5329ab296e..8e3e55579d 100644 --- a/stdlib/src/utils/write.mojo +++ b/stdlib/src/utils/write.mojo @@ -228,7 +228,7 @@ struct _WriteBufferHeap[W: MovableWriter, //, capacity: Int](Writer): var pos: Int var writer: W - fn __init__(inout self, owned writer: W): + fn __init__(out self, owned writer: W): self.data = UnsafePointer[ UInt8, address_space = AddressSpace.GENERIC, @@ -275,7 +275,7 @@ struct _WriteBufferStack[W: MovableWriter, //, capacity: Int](Writer): var pos: Int var writer: W - fn __init__(inout self, owned writer: W): + fn __init__(out self, owned writer: W): self.data = InlineArray[UInt8, capacity](unsafe_uninitialized=True) self.pos = 0 self.writer = writer^ diff --git a/stdlib/test/builtin/test_none.mojo b/stdlib/test/builtin/test_none.mojo index 028471881c..9d588bb7d4 100644 --- a/stdlib/test/builtin/test_none.mojo +++ b/stdlib/test/builtin/test_none.mojo @@ -37,10 +37,10 @@ def test_format_to(): struct FromNone: var value: Int - fn __init__(inout self, none: NoneType): + fn __init__(out self, none: NoneType): self.value = -1 - fn __init__(inout self, value: Int): + fn __init__(out self, value: Int): self.value = value diff --git a/stdlib/test/builtin/test_print.mojo b/stdlib/test/builtin/test_print.mojo index d17765bf88..ca3b03afcc 100644 --- a/stdlib/test/builtin/test_print.mojo +++ b/stdlib/test/builtin/test_print.mojo @@ -47,7 +47,7 @@ struct PrintChecker: var call_location: _SourceLocation @always_inline - fn __init__(inout self) raises: + fn __init__(out self) raises: self.tmp = NamedTemporaryFile("rw") self.call_location = __call_location() self.cursor = 0 @@ -55,7 +55,7 @@ struct PrintChecker: fn __enter__(owned self) -> Self: return self^ - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): self.tmp = existing.tmp^ self.cursor = existing.cursor self.call_location = existing.call_location diff --git a/stdlib/test/builtin/test_rebind.mojo b/stdlib/test/builtin/test_rebind.mojo index f23ae595e4..0d73aee2af 100644 --- a/stdlib/test/builtin/test_rebind.mojo +++ b/stdlib/test/builtin/test_rebind.mojo @@ -51,7 +51,7 @@ def test_rebind_register(): struct MyMemStruct[size: Int]: var value: Int - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): # Make sure no copy is made due to the rebind. print("Should not copy this!") self.value = existing.value diff --git a/stdlib/test/builtin/test_slice.mojo b/stdlib/test/builtin/test_slice.mojo index b552d13f0b..2208a5bf3a 100644 --- a/stdlib/test/builtin/test_slice.mojo +++ b/stdlib/test/builtin/test_slice.mojo @@ -38,7 +38,7 @@ struct BoringSlice: struct Sliceable: - fn __init__(inout self): + fn __init__(out self): pass fn __getitem__(self, a: FunnySlice) -> FunnySlice: @@ -63,7 +63,7 @@ def test_slicable(): struct SliceStringable: - fn __init__(inout self): + fn __init__(out self): pass fn __getitem__(self, a: Slice) -> String: diff --git a/stdlib/test/builtin/test_sort.mojo b/stdlib/test/builtin/test_sort.mojo index 987dbda3ec..7ff2834d46 100644 --- a/stdlib/test/builtin/test_sort.mojo +++ b/stdlib/test/builtin/test_sort.mojo @@ -497,7 +497,7 @@ fn test_sort_stress() raises: struct MyStruct(CollectionElement): var val: Int - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.val = other.val @@ -550,7 +550,7 @@ struct Person(ComparableCollectionElement): var name: String var age: Int - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.name = String(other=other.name) self.age = other.age diff --git a/stdlib/test/collections/test_dict.mojo b/stdlib/test/collections/test_dict.mojo index 44a7a04d5b..d9807ea83b 100644 --- a/stdlib/test/collections/test_dict.mojo +++ b/stdlib/test/collections/test_dict.mojo @@ -391,7 +391,7 @@ def test_dict_update_empty_new(): struct DummyKey(KeyElement): var value: Int - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self = other fn __hash__(self) -> UInt: diff --git a/stdlib/test/collections/test_list.mojo b/stdlib/test/collections/test_list.mojo index 35365af488..49bd72a1bb 100644 --- a/stdlib/test/collections/test_list.mojo +++ b/stdlib/test/collections/test_list.mojo @@ -551,11 +551,11 @@ struct CopyCountedStruct(CollectionElement): var counter: CopyCounter var value: String - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.counter = CopyCounter(other=other.counter) self.value = String(other=other.value) - fn __init__(inout self, value: String): + fn __init__(out self, value: String): self.counter = CopyCounter() self.value = value @@ -876,16 +876,16 @@ struct DtorCounter(CollectionElement): # NOTE: payload is required because List does not support zero sized structs. var payload: Int - fn __init__(inout self): + fn __init__(out self): self.payload = 0 - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.payload = other.payload - fn __copyinit__(inout self, existing: Self, /): + fn __copyinit__(out self, existing: Self, /): self.payload = existing.payload - fn __moveinit__(inout self, owned existing: Self, /): + fn __moveinit__(out self, owned existing: Self, /): self.payload = existing.payload existing.payload = 0 diff --git a/stdlib/test/hashlib/test_hasher.mojo b/stdlib/test/hashlib/test_hasher.mojo index 44bf5eed15..f41685b553 100644 --- a/stdlib/test/hashlib/test_hasher.mojo +++ b/stdlib/test/hashlib/test_hasher.mojo @@ -25,7 +25,7 @@ from utils import StringRef struct DummyHasher(_Hasher): var _dummy_value: UInt64 - fn __init__(inout self): + fn __init__(out self): self._dummy_value = 0 fn _update_with_bytes(inout self, data: UnsafePointer[UInt8], length: Int): diff --git a/stdlib/test/memory/test_unsafepointer.mojo b/stdlib/test/memory/test_unsafepointer.mojo index f7573c1941..657fc02b81 100644 --- a/stdlib/test/memory/test_unsafepointer.mojo +++ b/stdlib/test/memory/test_unsafepointer.mojo @@ -23,12 +23,12 @@ struct MoveOnlyType(Movable): var actions: UnsafePointer[List[String]] var value: Int - fn __init__(inout self, value: Int, actions: UnsafePointer[List[String]]): + fn __init__(out self, value: Int, actions: UnsafePointer[List[String]]): self.actions = actions self.value = value self.actions[0].append("__init__") - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): self.actions = existing.actions self.value = existing.value self.actions[0].append("__moveinit__") diff --git a/stdlib/test/os/path/test_expandvars.mojo b/stdlib/test/os/path/test_expandvars.mojo index 662558bbfb..d81746d88c 100644 --- a/stdlib/test/os/path/test_expandvars.mojo +++ b/stdlib/test/os/path/test_expandvars.mojo @@ -21,7 +21,7 @@ from testing import assert_equal struct EnvVar: var name: String - fn __init__(inout self, name: String, value: String) -> None: + fn __init__(out self, name: String, value: String) -> None: self.name = name _ = os.setenv(name, value) diff --git a/stdlib/test/test_utils/types.mojo b/stdlib/test/test_utils/types.mojo index ade9d8c809..b9dd9cd91a 100644 --- a/stdlib/test/test_utils/types.mojo +++ b/stdlib/test/test_utils/types.mojo @@ -27,7 +27,7 @@ struct MoveOnly[T: Movable](Movable): var data: T """Test data payload.""" - fn __init__(inout self, owned i: T): + fn __init__(out self, owned i: T): """Construct a MoveOnly providing the payload data. Args: @@ -35,7 +35,7 @@ struct MoveOnly[T: Movable](Movable): """ self.data = i^ - fn __moveinit__(inout self, owned other: Self): + fn __moveinit__(out self, owned other: Self): """Move construct a MoveOnly from an existing variable. Args: @@ -53,11 +53,11 @@ struct ExplicitCopyOnly(ExplicitlyCopyable): var value: Int var copy_count: Int - fn __init__(inout self, value: Int): + fn __init__(out self, value: Int): self.value = value self.copy_count = 0 - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.value = other.value self.copy_count = other.copy_count + 1 @@ -71,11 +71,11 @@ struct ImplicitCopyOnly(Copyable): var value: Int var copy_count: Int - fn __init__(inout self, value: Int): + fn __init__(out self, value: Int): self.value = value self.copy_count = 0 - fn __copyinit__(inout self, *, other: Self): + fn __copyinit__(out self, *, other: Self): self.value = other.value self.copy_count = other.copy_count + 1 @@ -90,16 +90,16 @@ struct CopyCounter(CollectionElement, ExplicitlyCopyable): var copy_count: Int - fn __init__(inout self): + fn __init__(out self): self.copy_count = 0 - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.copy_count = other.copy_count + 1 - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): self.copy_count = existing.copy_count - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): self.copy_count = existing.copy_count + 1 @@ -117,7 +117,7 @@ struct MoveCounter[T: CollectionElementNew]( var value: T var move_count: Int - fn __init__(inout self, owned value: T): + fn __init__(out self, owned value: T): """Construct a new instance of this type. This initial move is not counted. """ self.value = value^ @@ -125,7 +125,7 @@ struct MoveCounter[T: CollectionElementNew]( # TODO: This type should not be ExplicitlyCopyable, but has to be to satisfy # CollectionElementNew at the moment. - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): """Explicitly copy the provided value. Args: @@ -134,13 +134,13 @@ struct MoveCounter[T: CollectionElementNew]( self.value = T(other=other.value) self.move_count = other.move_count - fn __moveinit__(inout self, owned existing: Self): + fn __moveinit__(out self, owned existing: Self): self.value = existing.value^ self.move_count = existing.move_count + 1 # TODO: This type should not be Copyable, but has to be to satisfy # CollectionElement at the moment. - fn __copyinit__(inout self, existing: Self): + fn __copyinit__(out self, existing: Self): # print("ERROR: _MoveCounter copy constructor called unexpectedly!") self.value = T(other=existing.value) self.move_count = existing.move_count @@ -156,7 +156,7 @@ struct ValueDestructorRecorder(ExplicitlyCopyable): var value: Int var destructor_counter: UnsafePointer[List[Int]] - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self.value = other.value self.destructor_counter = other.destructor_counter @@ -173,7 +173,7 @@ struct ValueDestructorRecorder(ExplicitlyCopyable): struct ObservableDel(CollectionElement): var target: UnsafePointer[Bool] - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self = other fn __del__(owned self): diff --git a/stdlib/test/utils/test_variant.mojo b/stdlib/test/utils/test_variant.mojo index f517433183..bafac3221f 100644 --- a/stdlib/test/utils/test_variant.mojo +++ b/stdlib/test/utils/test_variant.mojo @@ -25,18 +25,18 @@ struct TestCounter(CollectionElement): var copied: Int var moved: Int - fn __init__(inout self): + fn __init__(out self): self.copied = 0 self.moved = 0 - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): self = other - fn __copyinit__(inout self, other: Self): + fn __copyinit__(out self, other: Self): self.copied = other.copied + 1 self.moved = other.moved - fn __moveinit__(inout self, owned other: Self): + fn __moveinit__(out self, owned other: Self): self.copied = other.copied self.moved = other.moved + 1 @@ -65,16 +65,16 @@ fn _destroy_poison(p: OpaquePointer): struct Poison(CollectionElement): - fn __init__(inout self): + fn __init__(out self): pass - fn __init__(inout self, *, other: Self): + fn __init__(out self, *, other: Self): _poison_ptr().init_pointee_move(True) - fn __copyinit__(inout self, other: Self): + fn __copyinit__(out self, other: Self): _poison_ptr().init_pointee_move(True) - fn __moveinit__(inout self, owned other: Self): + fn __moveinit__(out self, owned other: Self): _poison_ptr().init_pointee_move(True) fn __del__(owned self):