diff --git a/runtime/core/portable_type/optional.h b/runtime/core/portable_type/optional.h deleted file mode 100644 index 31ad06fd093..00000000000 --- a/runtime/core/portable_type/optional.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -namespace executorch { -namespace runtime { -namespace etensor { - -// NOLINTNEXTLINE(misc-unused-using-decls) -using std::nullopt; -// NOLINTNEXTLINE(misc-unused-using-decls) -using std::nullopt_t; -// NOLINTNEXTLINE(misc-unused-using-decls) -using std::optional; - -} // namespace etensor -} // namespace runtime -} // namespace executorch - -namespace torch { -namespace executor { -// TODO(T197294990): Remove these deprecated aliases once all users have moved -// to the new `::executorch` namespaces. -using ::executorch::runtime::etensor::nullopt; -using ::executorch::runtime::etensor::nullopt_t; -using ::executorch::runtime::etensor::optional; -} // namespace executor -} // namespace torch diff --git a/runtime/core/portable_type/targets.bzl b/runtime/core/portable_type/targets.bzl index 5b6e67fa213..3f5daa8eba2 100644 --- a/runtime/core/portable_type/targets.bzl +++ b/runtime/core/portable_type/targets.bzl @@ -14,7 +14,6 @@ def define_common_targets(): srcs = ["tensor_impl.cpp"], exported_headers = [ "tensor_options.h", - "optional.h", "scalar.h", "tensor.h", "tensor_impl.h", diff --git a/runtime/core/portable_type/test/optional_test.cpp b/runtime/core/portable_type/test/optional_test.cpp deleted file mode 100644 index 60d835d7439..00000000000 --- a/runtime/core/portable_type/test/optional_test.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include - -#include -#include - -#include -#include - -using namespace ::testing; -using executorch::runtime::etensor::nullopt; -using executorch::runtime::etensor::optional; - -// Test that optional::value_type matches the template parameter type. -static_assert( - std::is_same::value_type, int32_t>::value, - "Unexpected optional::value_type"); -static_assert( - std::is_same::value_type, std::string>::value, - "Unexpected optional::value_type"); - -TEST(TestOptional, DefaultHasNoValue) { - optional o; - EXPECT_FALSE(o.has_value()); -} - -TEST(TestOptional, NulloptHasNoValue) { - optional o(nullopt); - EXPECT_FALSE(o.has_value()); -} - -TEST(TestOptional, ValueOfEmptyOptionalShouldThrow) { - optional o; - EXPECT_FALSE(o.has_value()); - - EXPECT_THROW({ (void)o.value(); }, std::bad_optional_access); -} - -TEST(TestOptional, IntValue) { - optional o(15); - EXPECT_TRUE(o.has_value()); - EXPECT_EQ(o.value(), 15); -} - -TEST(TestOptional, NonTrivialValueType) { - optional o("hey"); - EXPECT_TRUE(o.has_value()); - EXPECT_EQ(o.value(), "hey"); -} - -TEST(TestOptional, ConstValue) { - const optional o("hey"); - auto s = o.value(); // If this compiles, we're good. - EXPECT_EQ(o.value(), "hey"); -} - -TEST(TestOptional, CopyCtorWithValue) { - optional o1(15); - optional o2(o1); - - EXPECT_TRUE(o2.has_value()); - EXPECT_EQ(o2.value(), 15); -} - -TEST(TestOptional, CopyCtorWithNoValue) { - optional o1; - optional o2(o1); - - EXPECT_FALSE(o2.has_value()); -} - -TEST(TestOptional, CopyAssignTrivial) { - optional o1(1); - optional o2(2); - o1 = o2; - - EXPECT_EQ(o1.value(), 2); -} - -TEST(TestOptional, CopyAssignNonTrivial) { - optional o1("abcde"); - optional o2("foo"); - o1 = o2; - - EXPECT_EQ(o1.value(), "foo"); -} - -TEST(TestOptional, CopyAssignNone) { - optional o1(2); - optional o2; - o1 = o2; - EXPECT_FALSE(o1.has_value()); -} - -TEST(TestOptional, MoveCtorWithNoValue) { - optional o1; - optional o2(std::move(o1)); - - EXPECT_FALSE(o2.has_value()); -} - -TEST(TestOptional, MoveCtorWithValue) { - optional o1(15); - optional o2(std::move(o1)); - - EXPECT_TRUE(o2.has_value()); - EXPECT_EQ(o2.value(), 15); -} - -TEST(TestOptional, MoveCtorNonTrivialType) { - optional o1("abc"); - optional o2(std::move(o1)); - - EXPECT_TRUE(o2.has_value()); - EXPECT_EQ(o2.value(), "abc"); -} - -optional function_returning_optional_of(int32_t value) { - return value; -} - -TEST(TestOptional, ImplicitReturnOfValue) { - auto o = function_returning_optional_of(21); - EXPECT_TRUE(o.has_value()); - EXPECT_EQ(o.value(), 21); -} - -optional function_returning_nullopt() { - return nullopt; -} - -TEST(TestOptional, ImplicitReturnOfNullopt) { - auto o = function_returning_nullopt(); - EXPECT_FALSE(o.has_value()); -}