@@ -815,6 +815,22 @@ export abstract class BaseTypeGenerator<Type extends RustType> {
815815 }
816816 ` ;
817817
818+ /**
819+ * When an argument is an asterisk-based pointer, we usually simply create the
820+ * pointer-related handling like we do above, and nothing beyond that. However,
821+ * when the method taking that pointer is a constructor, it is likely that the
822+ * pointed-to argument will need to live well beyond the conclusion of the method
823+ * call. Specifically, it is likely a requirement of the instantiated object
824+ * that the argument is kept around for as long as necessary. We do that by
825+ * tethering the argument to the returned object. It's nothing but a reference
826+ * that will have Swift delay deallocation.
827+ *
828+ * If the reference is an elided type, such as an array, a nullable, or a tuple,
829+ * we, for the time being, just pretend that no anchoring is necessary. In reality,
830+ * we simply haven't encountered such a case yet, and until we do, it's a bit too
831+ * complicated to handle, because doing it blindly will probably only lead us to
832+ * introduce some new memory bugs.
833+ */
818834 if ( memoryContext && memoryContext . isConstructor && ( argument . type instanceof RustStruct || argument . type instanceof RustTaggedValueEnum || argument . type instanceof RustResult ) ) {
819835 preparedArgument . requiresAnchoring = true ;
820836 }
@@ -1298,7 +1314,11 @@ export interface PreparedArgument {
12981314 deferredCleanup : string
12991315
13001316 /**
1301- * If true (only applicable in constructors), add a `self.addAnchor` call after super.init()
1317+ * If true (only applicable in constructors), add a `self.addAnchor` call after super.init().
1318+ * For anchoring that doesn't immediately succeed object instantiation, or that can happen
1319+ * outside the initializer method, we have other mechanisms. This particular mechanism is,
1320+ * strictly speaking, somewhat of a workaround, but one that is necessary due to Swift's
1321+ * constraints surrounding when calls to `self` can be made.
13021322 */
13031323 requiresAnchoring : boolean
13041324}
0 commit comments