From c45bfbb47ae746faf681b49ee41842c28e94b099 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Thu, 12 Jun 2025 20:46:22 -0700 Subject: [PATCH] Return retained objects from Value constructors. Summary: Mark them explicitly not using autorelease pool Reviewed By: cccclai Differential Revision: D76491605 --- .../ExecuTorch/Exported/ExecuTorchValue.h | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h index 20f13082d31..d4c6d7168d3 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchValue.h @@ -173,7 +173,9 @@ __attribute__((deprecated("This API is experimental."))) * @param value An ExecuTorchTensor instance. * @return A new ExecuTorchValue instance with a tag of ExecuTorchValueTagTensor. */ -+ (instancetype)valueWithTensor:(ExecuTorchTensor *)value NS_REFINED_FOR_SWIFT; ++ (instancetype)valueWithTensor:(ExecuTorchTensor *)value + NS_REFINED_FOR_SWIFT + NS_RETURNS_RETAINED; /** * Creates an instance encapsulating a string. @@ -182,7 +184,8 @@ __attribute__((deprecated("This API is experimental."))) * @return A new ExecuTorchValue instance with a tag of ExecuTorchValueTagString. */ + (instancetype)valueWithString:(ExecuTorchStringValue)value - NS_SWIFT_NAME(init(_:)); + NS_SWIFT_NAME(init(_:)) + NS_RETURNS_RETAINED; /** * Creates an instance encapsulating a boolean. @@ -191,7 +194,8 @@ __attribute__((deprecated("This API is experimental."))) * @return A new ExecuTorchValue instance with a tag of ExecuTorchValueTagBoolean. */ + (instancetype)valueWithBoolean:(ExecuTorchBooleanValue)value - NS_SWIFT_NAME(init(_:)); + NS_SWIFT_NAME(init(_:)) + NS_RETURNS_RETAINED; /** * Creates an instance encapsulating an integer. @@ -200,7 +204,8 @@ __attribute__((deprecated("This API is experimental."))) * @return A new ExecuTorchValue instance with a tag of ExecuTorchValueTagInteger. */ + (instancetype)valueWithInteger:(ExecuTorchIntegerValue)value - NS_SWIFT_NAME(init(_:)); + NS_SWIFT_NAME(init(_:)) + NS_RETURNS_RETAINED; /** * Creates an instance encapsulating a double value. @@ -209,7 +214,8 @@ __attribute__((deprecated("This API is experimental."))) * @return A new ExecuTorchValue instance with a tag of ExecuTorchValueTagDouble. */ + (instancetype)valueWithDouble:(ExecuTorchDoubleValue)value - NS_SWIFT_NAME(init(_:)); + NS_SWIFT_NAME(init(_:)) + NS_RETURNS_RETAINED; /** * Creates an instance encapsulating a float value. @@ -221,7 +227,8 @@ __attribute__((deprecated("This API is experimental."))) * @return A new ExecuTorchValue instance with a tag of ExecuTorchValueTagDouble. */ + (instancetype)valueWithFloat:(ExecuTorchFloatValue)value - NS_SWIFT_NAME(init(_:)); + NS_SWIFT_NAME(init(_:)) + NS_RETURNS_RETAINED; /** * Creates an instance encapsulating a scalar value. @@ -232,7 +239,8 @@ __attribute__((deprecated("This API is experimental."))) * @return A new ExecuTorchValue instance with the appropriate tag. */ + (instancetype)valueWithScalar:(ExecuTorchScalarValue)value - NS_SWIFT_NAME(init(_:)); + NS_SWIFT_NAME(init(_:)) + NS_RETURNS_RETAINED; /** * Returns a copy of the value.