ソースを参照

Remove the indirect_value library (#5312)

This was used by explorer, and no longer has uses.
Jon Ross-Perkins 1 年間 前
コミット
72cfaad1c7
3 ファイル変更0 行追加255 行削除
  1. 0 16
      common/BUILD
  2. 0 109
      common/indirect_value.h
  3. 0 130
      common/indirect_value_test.cpp

+ 0 - 16
common/BUILD

@@ -230,22 +230,6 @@ cc_test(
     ],
 )
 
-cc_library(
-    name = "indirect_value",
-    hdrs = ["indirect_value.h"],
-)
-
-cc_test(
-    name = "indirect_value_test",
-    size = "small",
-    srcs = ["indirect_value_test.cpp"],
-    deps = [
-        ":indirect_value",
-        "//testing/base:gtest_main",
-        "@googletest//:gtest",
-    ],
-)
-
 cc_library(
     name = "init_llvm",
     srcs = ["init_llvm.cpp"],

+ 0 - 109
common/indirect_value.h

@@ -1,109 +0,0 @@
-// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
-// Exceptions. See /LICENSE for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#ifndef CARBON_COMMON_INDIRECT_VALUE_H_
-#define CARBON_COMMON_INDIRECT_VALUE_H_
-
-#include <memory>
-#include <type_traits>
-#include <utility>
-
-namespace Carbon {
-
-template <typename T>
-class IndirectValue;
-
-// Creates and returns an IndirectValue that holds the value returned by
-// `callable()`.
-template <typename Callable>
-auto MakeIndirectValue(Callable callable)
-    -> IndirectValue<std::decay_t<decltype(callable())>>;
-
-// An IndirectValue<T> object stores a T value, using a layer of indirection
-// that allows us to name the IndirectValue<T> type, and even access the
-// underlying T value, in a context where T is not a complete type. This makes
-// it useful for things like defining recursive types. T must be an object type.
-//
-// The underlying value is accessed using the * and -> operators, but
-// IndirectValue does not otherwise behave like a pointer: it has no null state,
-// and separate IndirectValue objects are never aliases for the same T object.
-// Instead, an IndirectValue object behaves as much as possible like a T object:
-// the default constructor, copy operations, and move operations all delegate to
-// the corresponding operations on T, and a const IndirectValue object provides
-// only const access to the underlying T object. The address of the underlying T
-// object remains the same throughout the lifetime of the IndirectValue.
-//
-// IndirectValue is inspired by the indirect_value library proposed in
-// http://wg21.link/P1950R1, but makes some different design choices (notably,
-// not having an empty state) in order to provide a more value-like API.
-template <typename T>
-class IndirectValue {
- public:
-  // TODO(geoffromer): consider using enable_if to disable constructors and
-  // assignment operators when they wouldn't compile, so that traits like
-  // std::is_constructible give correct answers.
-
-  // Initializes the underlying T object as if by `T()`.
-  IndirectValue() : value_(std::make_unique<T>()) {}
-
-  // Initializes the underlying T object as if by `T(std::move(value))`.
-  // NOLINTNEXTLINE(google-explicit-constructor): Implicit constructor.
-  IndirectValue(T value) : value_(std::make_unique<T>(std::move(value))) {}
-
-  // TODO(geoffromer): consider defining implicit conversions from
-  // U and IndirectValue<U>, when U is implicitly convertible to T.
-
-  IndirectValue(const IndirectValue& other)
-      : value_(std::make_unique<T>(*other)) {}
-
-  IndirectValue(IndirectValue&& other) noexcept
-      : value_(std::make_unique<T>(std::move(*other))) {}
-
-  auto operator=(const IndirectValue& other) -> IndirectValue& {
-    *value_ = *other.value_;
-    return *this;
-  }
-
-  auto operator=(IndirectValue&& other) noexcept -> IndirectValue& {
-    *value_ = std::move(*other.value_);
-    return *this;
-  }
-
-  auto operator*() -> T& { return *value_; }
-  auto operator*() const -> const T& { return *value_; }
-
-  auto operator->() -> T* { return value_.get(); }
-  auto operator->() const -> const T* { return value_.get(); }
-
-  // Returns the address of the stored value.
-  //
-  // TODO(geoffromer): Consider eliminating this method, which is not
-  // present in comparable types like indirect_value<T> or optional<T>,
-  // once our APIs are less pointer-centric.
-  auto GetPointer() -> T* { return value_.get(); }
-  auto GetPointer() const -> const T* { return value_.get(); }
-
- private:
-  static_assert(std::is_object_v<T>, "T must be an object type");
-
-  template <typename Callable>
-  friend auto MakeIndirectValue(Callable callable)
-      -> IndirectValue<std::decay_t<decltype(callable())>>;
-
-  template <typename... Args>
-  explicit IndirectValue(std::unique_ptr<T> value) : value_(std::move(value)) {}
-
-  const std::unique_ptr<T> value_;
-};
-
-template <typename Callable>
-auto MakeIndirectValue(Callable callable)
-    -> IndirectValue<std::decay_t<decltype(callable())>> {
-  using T = std::decay_t<decltype(callable())>;
-  return IndirectValue<T>(std::unique_ptr<T>(new T(callable())));
-}
-
-}  // namespace Carbon
-
-#endif  // CARBON_COMMON_INDIRECT_VALUE_H_

+ 0 - 130
common/indirect_value_test.cpp

@@ -1,130 +0,0 @@
-// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
-// Exceptions. See /LICENSE for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include "common/indirect_value.h"
-
-#include <gtest/gtest.h>
-
-#include <string>
-
-namespace Carbon {
-namespace {
-
-TEST(IndirectValueTest, ConstAccess) {
-  const IndirectValue<int> v = 42;
-  EXPECT_EQ(*v, 42);
-  EXPECT_EQ(v.GetPointer(), &*v);
-}
-
-TEST(IndirectValueTest, MutableAccess) {
-  IndirectValue<int> v = 42;
-  EXPECT_EQ(*v, 42);
-  EXPECT_EQ(v.GetPointer(), &*v);
-  *v = 0;
-  EXPECT_EQ(*v, 0);
-}
-
-struct NonMovable {
-  explicit NonMovable(int i) : i(i) {}
-  NonMovable(NonMovable&&) = delete;
-  auto operator=(NonMovable&&) -> NonMovable& = delete;
-
-  int i;
-};
-
-TEST(IndirectValueTest, Create) {
-  IndirectValue<NonMovable> v =
-      MakeIndirectValue([] { return NonMovable(42); });
-  EXPECT_EQ(v->i, 42);
-}
-
-auto GetIntReference() -> const int& {
-  static int i = 42;
-  return i;
-}
-
-TEST(IndirectValueTest, CreateWithDecay) {
-  auto v = MakeIndirectValue(GetIntReference);
-  EXPECT_TRUE((std::is_same_v<decltype(v), IndirectValue<int>>));
-  EXPECT_EQ(*v, 42);
-}
-
-// Test double which presents a value-like interface, but tracks which special
-// member function (if any) caused it to reach its present value.
-struct TestValue {
-  TestValue() : state("default constructed") {}
-  TestValue(const TestValue& /*rhs*/) : state("copy constructed") {}
-  TestValue(TestValue&& other) noexcept : state("move constructed") {
-    other.state = "move constructed from";
-  }
-  auto operator=(const TestValue& /*unused*/) noexcept -> TestValue& {
-    state = "copy assigned";
-    return *this;
-  }
-  auto operator=(TestValue&& other) noexcept -> TestValue& {
-    state = "move assigned";
-    other.state = "move assigned from";
-    return *this;
-  }
-
-  std::string state;
-};
-
-TEST(IndirectValueTest, ConstArrow) {
-  const IndirectValue<TestValue> v;
-  EXPECT_EQ(v->state, "default constructed");
-}
-
-TEST(IndirectValueTest, MutableArrow) {
-  IndirectValue<TestValue> v;
-  EXPECT_EQ(v->state, "default constructed");
-  v->state = "explicitly set";
-  EXPECT_EQ(v->state, "explicitly set");
-}
-
-TEST(IndirectValueTest, CopyConstruct) {
-  IndirectValue<TestValue> v1;
-  // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
-  auto v2 = v1;
-  EXPECT_EQ(v1->state, "default constructed");
-  EXPECT_EQ(v2->state, "copy constructed");
-}
-
-TEST(IndirectValueTest, CopyAssign) {
-  IndirectValue<TestValue> v1;
-  IndirectValue<TestValue> v2;
-  v2 = v1;
-  EXPECT_EQ(v1->state, "default constructed");
-  EXPECT_EQ(v2->state, "copy assigned");
-}
-
-TEST(IndirectValueTest, MoveConstruct) {
-  IndirectValue<TestValue> v1;
-  auto v2 = std::move(v1);
-  // While not entirely safe, the `v1->state` access tests move behavior.
-  // NOLINTNEXTLINE(bugprone-use-after-move)
-  EXPECT_EQ(v1->state, "move constructed from");
-  EXPECT_EQ(v2->state, "move constructed");
-}
-
-TEST(IndirectValueTest, MoveAssign) {
-  IndirectValue<TestValue> v1;
-  IndirectValue<TestValue> v2;
-  v2 = std::move(v1);
-  // While not entirely safe, the `v1->state` access tests move behavior.
-  // NOLINTNEXTLINE(bugprone-use-after-move)
-  EXPECT_EQ(v1->state, "move assigned from");
-  EXPECT_EQ(v2->state, "move assigned");
-}
-
-TEST(IndirectValueTest, IncompleteType) {
-  struct S {
-    std::optional<IndirectValue<S>> v;
-  };
-
-  S s = {.v = S{}};
-}
-
-}  // namespace
-}  // namespace Carbon