value.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef EXECUTABLE_SEMANTICS_INTERPRETER_VALUE_H_
  5. #define EXECUTABLE_SEMANTICS_INTERPRETER_VALUE_H_
  6. #include <optional>
  7. #include <string>
  8. #include <variant>
  9. #include <vector>
  10. #include "common/ostream.h"
  11. #include "executable_semantics/ast/declaration.h"
  12. #include "executable_semantics/ast/statement.h"
  13. #include "executable_semantics/common/nonnull.h"
  14. #include "executable_semantics/interpreter/address.h"
  15. #include "executable_semantics/interpreter/field_path.h"
  16. #include "executable_semantics/interpreter/stack.h"
  17. #include "llvm/Support/Compiler.h"
  18. namespace Carbon {
  19. class Action;
  20. // Abstract base class of all AST nodes representing values.
  21. //
  22. // Value and its derived classes support LLVM-style RTTI, including
  23. // llvm::isa, llvm::cast, and llvm::dyn_cast. To support this, every
  24. // class derived from Value must provide a `classof` operation, and
  25. // every concrete derived class must have a corresponding enumerator
  26. // in `Kind`; see https://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html for
  27. // details.
  28. class Value {
  29. public:
  30. enum class Kind {
  31. IntValue,
  32. FunctionValue,
  33. BoundMethodValue,
  34. PointerValue,
  35. LValue,
  36. BoolValue,
  37. StructValue,
  38. NominalClassValue,
  39. AlternativeValue,
  40. TupleValue,
  41. Witness,
  42. IntType,
  43. BoolType,
  44. TypeType,
  45. FunctionType,
  46. PointerType,
  47. AutoType,
  48. StructType,
  49. NominalClassType,
  50. InterfaceType,
  51. ChoiceType,
  52. ContinuationType, // The type of a continuation.
  53. VariableType, // e.g., generic type parameters.
  54. BindingPlaceholderValue,
  55. AlternativeConstructorValue,
  56. ContinuationValue, // A first-class continuation value.
  57. StringType,
  58. StringValue,
  59. TypeOfClassType,
  60. TypeOfInterfaceType,
  61. TypeOfChoiceType,
  62. };
  63. Value(const Value&) = delete;
  64. auto operator=(const Value&) -> Value& = delete;
  65. void Print(llvm::raw_ostream& out) const;
  66. LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
  67. // Returns the sub-Value specified by `path`, which must be a valid field
  68. // path for *this.
  69. auto GetField(Nonnull<Arena*> arena, const FieldPath& path,
  70. SourceLocation source_loc) const
  71. -> ErrorOr<Nonnull<const Value*>>;
  72. // Returns a copy of *this, but with the sub-Value specified by `path`
  73. // set to `field_value`. `path` must be a valid field path for *this.
  74. auto SetField(Nonnull<Arena*> arena, const FieldPath& path,
  75. Nonnull<const Value*> field_value,
  76. SourceLocation source_loc) const
  77. -> ErrorOr<Nonnull<const Value*>>;
  78. // Returns the enumerator corresponding to the most-derived type of this
  79. // object.
  80. auto kind() const -> Kind { return kind_; }
  81. protected:
  82. // Constructs a Value. `kind` must be the enumerator corresponding to the
  83. // most-derived type being constructed.
  84. explicit Value(Kind kind) : kind_(kind) {}
  85. private:
  86. const Kind kind_;
  87. };
  88. // A NamedValue represents a value with a name, such as a single struct field.
  89. struct NamedValue {
  90. // The field name.
  91. std::string name;
  92. // The field's value.
  93. Nonnull<const Value*> value;
  94. };
  95. // An integer value.
  96. class IntValue : public Value {
  97. public:
  98. explicit IntValue(int value) : Value(Kind::IntValue), value_(value) {}
  99. static auto classof(const Value* value) -> bool {
  100. return value->kind() == Kind::IntValue;
  101. }
  102. auto value() const -> int { return value_; }
  103. private:
  104. int value_;
  105. };
  106. // A function value.
  107. class FunctionValue : public Value {
  108. public:
  109. explicit FunctionValue(Nonnull<const FunctionDeclaration*> declaration)
  110. : Value(Kind::FunctionValue), declaration_(declaration) {}
  111. static auto classof(const Value* value) -> bool {
  112. return value->kind() == Kind::FunctionValue;
  113. }
  114. auto declaration() const -> const FunctionDeclaration& {
  115. return *declaration_;
  116. }
  117. private:
  118. Nonnull<const FunctionDeclaration*> declaration_;
  119. };
  120. // A bound method value. It includes the receiver object.
  121. class BoundMethodValue : public Value {
  122. public:
  123. explicit BoundMethodValue(Nonnull<const FunctionDeclaration*> declaration,
  124. Nonnull<const Value*> receiver)
  125. : Value(Kind::BoundMethodValue),
  126. declaration_(declaration),
  127. receiver_(receiver) {}
  128. static auto classof(const Value* value) -> bool {
  129. return value->kind() == Kind::BoundMethodValue;
  130. }
  131. auto declaration() const -> const FunctionDeclaration& {
  132. return *declaration_;
  133. }
  134. auto receiver() const -> Nonnull<const Value*> { return receiver_; }
  135. private:
  136. Nonnull<const FunctionDeclaration*> declaration_;
  137. Nonnull<const Value*> receiver_;
  138. };
  139. // The value of a location in memory.
  140. class LValue : public Value {
  141. public:
  142. explicit LValue(Address value)
  143. : Value(Kind::LValue), value_(std::move(value)) {}
  144. static auto classof(const Value* value) -> bool {
  145. return value->kind() == Kind::LValue;
  146. }
  147. auto address() const -> const Address& { return value_; }
  148. private:
  149. Address value_;
  150. };
  151. // A pointer value
  152. class PointerValue : public Value {
  153. public:
  154. explicit PointerValue(Address value)
  155. : Value(Kind::PointerValue), value_(std::move(value)) {}
  156. static auto classof(const Value* value) -> bool {
  157. return value->kind() == Kind::PointerValue;
  158. }
  159. auto address() const -> const Address& { return value_; }
  160. private:
  161. Address value_;
  162. };
  163. // A bool value.
  164. class BoolValue : public Value {
  165. public:
  166. explicit BoolValue(bool value) : Value(Kind::BoolValue), value_(value) {}
  167. static auto classof(const Value* value) -> bool {
  168. return value->kind() == Kind::BoolValue;
  169. }
  170. auto value() const -> bool { return value_; }
  171. private:
  172. bool value_;
  173. };
  174. // A non-empty value of a struct type.
  175. //
  176. // It can't be empty because `{}` is a struct type as well as a value of that
  177. // type, so for consistency we always represent it as a StructType rather than
  178. // let it oscillate unpredictably between the two. However, this means code
  179. // that handles StructValue instances may also need to be able to handle
  180. // StructType instances.
  181. class StructValue : public Value {
  182. public:
  183. explicit StructValue(std::vector<NamedValue> elements)
  184. : Value(Kind::StructValue), elements_(std::move(elements)) {
  185. CHECK(!elements_.empty())
  186. << "`{}` is represented as a StructType, not a StructValue.";
  187. }
  188. static auto classof(const Value* value) -> bool {
  189. return value->kind() == Kind::StructValue;
  190. }
  191. auto elements() const -> llvm::ArrayRef<NamedValue> { return elements_; }
  192. // Returns the value of the field named `name` in this struct, or
  193. // nullopt if there is no such field.
  194. auto FindField(const std::string& name) const
  195. -> std::optional<Nonnull<const Value*>>;
  196. private:
  197. std::vector<NamedValue> elements_;
  198. };
  199. // A value of a nominal class type, i.e., an object.
  200. class NominalClassValue : public Value {
  201. public:
  202. NominalClassValue(Nonnull<const Value*> type, Nonnull<const Value*> inits)
  203. : Value(Kind::NominalClassValue), type_(type), inits_(inits) {}
  204. static auto classof(const Value* value) -> bool {
  205. return value->kind() == Kind::NominalClassValue;
  206. }
  207. auto type() const -> const Value& { return *type_; }
  208. auto inits() const -> const Value& { return *inits_; }
  209. private:
  210. Nonnull<const Value*> type_;
  211. Nonnull<const Value*> inits_; // The initializing StructValue.
  212. };
  213. // An alternative constructor value.
  214. class AlternativeConstructorValue : public Value {
  215. public:
  216. AlternativeConstructorValue(std::string alt_name, std::string choice_name)
  217. : Value(Kind::AlternativeConstructorValue),
  218. alt_name_(std::move(alt_name)),
  219. choice_name_(std::move(choice_name)) {}
  220. static auto classof(const Value* value) -> bool {
  221. return value->kind() == Kind::AlternativeConstructorValue;
  222. }
  223. auto alt_name() const -> const std::string& { return alt_name_; }
  224. auto choice_name() const -> const std::string& { return choice_name_; }
  225. private:
  226. std::string alt_name_;
  227. std::string choice_name_;
  228. };
  229. // An alternative value.
  230. class AlternativeValue : public Value {
  231. public:
  232. AlternativeValue(std::string alt_name, std::string choice_name,
  233. Nonnull<const Value*> argument)
  234. : Value(Kind::AlternativeValue),
  235. alt_name_(std::move(alt_name)),
  236. choice_name_(std::move(choice_name)),
  237. argument_(argument) {}
  238. static auto classof(const Value* value) -> bool {
  239. return value->kind() == Kind::AlternativeValue;
  240. }
  241. auto alt_name() const -> const std::string& { return alt_name_; }
  242. auto choice_name() const -> const std::string& { return choice_name_; }
  243. auto argument() const -> const Value& { return *argument_; }
  244. private:
  245. std::string alt_name_;
  246. std::string choice_name_;
  247. Nonnull<const Value*> argument_;
  248. };
  249. // A function value.
  250. class TupleValue : public Value {
  251. public:
  252. // An empty tuple, also known as the unit type.
  253. static auto Empty() -> Nonnull<const TupleValue*> {
  254. static const TupleValue empty =
  255. TupleValue(std::vector<Nonnull<const Value*>>());
  256. return Nonnull<const TupleValue*>(&empty);
  257. }
  258. explicit TupleValue(std::vector<Nonnull<const Value*>> elements)
  259. : Value(Kind::TupleValue), elements_(std::move(elements)) {}
  260. static auto classof(const Value* value) -> bool {
  261. return value->kind() == Kind::TupleValue;
  262. }
  263. auto elements() const -> llvm::ArrayRef<Nonnull<const Value*>> {
  264. return elements_;
  265. }
  266. private:
  267. std::vector<Nonnull<const Value*>> elements_;
  268. };
  269. // A binding placeholder value.
  270. class BindingPlaceholderValue : public Value {
  271. public:
  272. // Represents the `_` placeholder.
  273. explicit BindingPlaceholderValue() : Value(Kind::BindingPlaceholderValue) {}
  274. // Represents a named placeholder.
  275. explicit BindingPlaceholderValue(ValueNodeView value_node)
  276. : Value(Kind::BindingPlaceholderValue),
  277. value_node_(std::move(value_node)) {}
  278. static auto classof(const Value* value) -> bool {
  279. return value->kind() == Kind::BindingPlaceholderValue;
  280. }
  281. auto value_node() const -> const std::optional<ValueNodeView>& {
  282. return value_node_;
  283. }
  284. private:
  285. std::optional<ValueNodeView> value_node_;
  286. };
  287. // The int type.
  288. class IntType : public Value {
  289. public:
  290. IntType() : Value(Kind::IntType) {}
  291. static auto classof(const Value* value) -> bool {
  292. return value->kind() == Kind::IntType;
  293. }
  294. };
  295. // The bool type.
  296. class BoolType : public Value {
  297. public:
  298. BoolType() : Value(Kind::BoolType) {}
  299. static auto classof(const Value* value) -> bool {
  300. return value->kind() == Kind::BoolType;
  301. }
  302. };
  303. // A type type.
  304. class TypeType : public Value {
  305. public:
  306. TypeType() : Value(Kind::TypeType) {}
  307. static auto classof(const Value* value) -> bool {
  308. return value->kind() == Kind::TypeType;
  309. }
  310. };
  311. // A function type.
  312. class FunctionType : public Value {
  313. public:
  314. FunctionType(llvm::ArrayRef<Nonnull<const GenericBinding*>> deduced,
  315. Nonnull<const Value*> parameters,
  316. Nonnull<const Value*> return_type,
  317. llvm::ArrayRef<Nonnull<const ImplBinding*>> impl_bindings)
  318. : Value(Kind::FunctionType),
  319. deduced_(deduced),
  320. parameters_(parameters),
  321. return_type_(return_type),
  322. impl_bindings_(impl_bindings) {}
  323. static auto classof(const Value* value) -> bool {
  324. return value->kind() == Kind::FunctionType;
  325. }
  326. auto deduced() const -> llvm::ArrayRef<Nonnull<const GenericBinding*>> {
  327. return deduced_;
  328. }
  329. auto parameters() const -> const Value& { return *parameters_; }
  330. auto return_type() const -> const Value& { return *return_type_; }
  331. // The bindings for the witness tables (impls) required by the
  332. // bounds on the type parameters of the generic function.
  333. auto impl_bindings() const -> llvm::ArrayRef<Nonnull<const ImplBinding*>> {
  334. return impl_bindings_;
  335. }
  336. private:
  337. std::vector<Nonnull<const GenericBinding*>> deduced_;
  338. Nonnull<const Value*> parameters_;
  339. Nonnull<const Value*> return_type_;
  340. std::vector<Nonnull<const ImplBinding*>> impl_bindings_;
  341. };
  342. // A pointer type.
  343. class PointerType : public Value {
  344. public:
  345. explicit PointerType(Nonnull<const Value*> type)
  346. : Value(Kind::PointerType), type_(type) {}
  347. static auto classof(const Value* value) -> bool {
  348. return value->kind() == Kind::PointerType;
  349. }
  350. auto type() const -> const Value& { return *type_; }
  351. private:
  352. Nonnull<const Value*> type_;
  353. };
  354. // The `auto` type.
  355. class AutoType : public Value {
  356. public:
  357. AutoType() : Value(Kind::AutoType) {}
  358. static auto classof(const Value* value) -> bool {
  359. return value->kind() == Kind::AutoType;
  360. }
  361. };
  362. // A struct type.
  363. //
  364. // Code that handles this type may sometimes need to have special-case handling
  365. // for `{}`, which is a struct value in addition to being a struct type.
  366. class StructType : public Value {
  367. public:
  368. StructType() : StructType(std::vector<NamedValue>{}) {}
  369. explicit StructType(std::vector<NamedValue> fields)
  370. : Value(Kind::StructType), fields_(std::move(fields)) {}
  371. static auto classof(const Value* value) -> bool {
  372. return value->kind() == Kind::StructType;
  373. }
  374. auto fields() const -> llvm::ArrayRef<NamedValue> { return fields_; }
  375. private:
  376. std::vector<NamedValue> fields_;
  377. };
  378. // A class type.
  379. class NominalClassType : public Value {
  380. public:
  381. explicit NominalClassType(Nonnull<const ClassDeclaration*> declaration)
  382. : Value(Kind::NominalClassType), declaration_(declaration) {}
  383. static auto classof(const Value* value) -> bool {
  384. return value->kind() == Kind::NominalClassType;
  385. }
  386. auto declaration() const -> const ClassDeclaration& { return *declaration_; }
  387. // Returns the value of the function named `name` in this class, or
  388. // nullopt if there is no such function.
  389. auto FindFunction(const std::string& name) const
  390. -> std::optional<Nonnull<const FunctionValue*>>;
  391. private:
  392. Nonnull<const ClassDeclaration*> declaration_;
  393. };
  394. auto FieldTypes(const NominalClassType&) -> std::vector<NamedValue>;
  395. // Return the declaration of the member with the given name.
  396. auto FindMember(const std::string& name,
  397. llvm::ArrayRef<Nonnull<Declaration*>> members)
  398. -> std::optional<Nonnull<const Declaration*>>;
  399. // An interface type.
  400. class InterfaceType : public Value {
  401. public:
  402. explicit InterfaceType(Nonnull<const InterfaceDeclaration*> declaration)
  403. : Value(Kind::InterfaceType), declaration_(declaration) {}
  404. static auto classof(const Value* value) -> bool {
  405. return value->kind() == Kind::InterfaceType;
  406. }
  407. auto declaration() const -> const InterfaceDeclaration& {
  408. return *declaration_;
  409. }
  410. private:
  411. Nonnull<const InterfaceDeclaration*> declaration_;
  412. };
  413. // The witness table for an impl.
  414. class Witness : public Value {
  415. public:
  416. explicit Witness(Nonnull<const ImplDeclaration*> declaration)
  417. : Value(Kind::Witness), declaration_(declaration) {}
  418. static auto classof(const Value* value) -> bool {
  419. return value->kind() == Kind::Witness;
  420. }
  421. auto declaration() const -> const ImplDeclaration& { return *declaration_; }
  422. private:
  423. Nonnull<const ImplDeclaration*> declaration_;
  424. };
  425. auto FieldTypes(const NominalClassType&) -> std::vector<NamedValue>;
  426. // A choice type.
  427. class ChoiceType : public Value {
  428. public:
  429. ChoiceType(std::string name, std::vector<NamedValue> alternatives)
  430. : Value(Kind::ChoiceType),
  431. name_(std::move(name)),
  432. alternatives_(std::move(alternatives)) {}
  433. static auto classof(const Value* value) -> bool {
  434. return value->kind() == Kind::ChoiceType;
  435. }
  436. auto name() const -> const std::string& { return name_; }
  437. // Returns the parameter types of the alternative with the given name,
  438. // or nullopt if no such alternative is present.
  439. auto FindAlternative(std::string_view name) const
  440. -> std::optional<Nonnull<const Value*>>;
  441. private:
  442. std::string name_;
  443. std::vector<NamedValue> alternatives_;
  444. };
  445. // A continuation type.
  446. class ContinuationType : public Value {
  447. public:
  448. ContinuationType() : Value(Kind::ContinuationType) {}
  449. static auto classof(const Value* value) -> bool {
  450. return value->kind() == Kind::ContinuationType;
  451. }
  452. };
  453. // A variable type.
  454. class VariableType : public Value {
  455. public:
  456. explicit VariableType(Nonnull<const GenericBinding*> binding)
  457. : Value(Kind::VariableType), binding_(binding) {}
  458. static auto classof(const Value* value) -> bool {
  459. return value->kind() == Kind::VariableType;
  460. }
  461. auto binding() const -> const GenericBinding& { return *binding_; }
  462. private:
  463. Nonnull<const GenericBinding*> binding_;
  464. };
  465. // A first-class continuation representation of a fragment of the stack.
  466. // A continuation value behaves like a pointer to the underlying stack
  467. // fragment, which is exposed by `Stack()`.
  468. class ContinuationValue : public Value {
  469. public:
  470. class StackFragment {
  471. public:
  472. // Constructs an empty StackFragment.
  473. StackFragment() = default;
  474. // Requires *this to be empty, because by the time we're tearing down the
  475. // Arena, it's no longer safe to invoke ~Action.
  476. ~StackFragment();
  477. StackFragment(StackFragment&&) = delete;
  478. auto operator=(StackFragment&&) -> StackFragment& = delete;
  479. // Store the given partial todo stack in *this, which must currently be
  480. // empty. The stack is represented with the top of the stack at the
  481. // beginning of the vector, the reverse of the usual order.
  482. void StoreReversed(std::vector<std::unique_ptr<Action>> reversed_todo);
  483. // Restore the currently stored stack fragment to the top of `todo`,
  484. // leaving *this empty.
  485. void RestoreTo(Stack<std::unique_ptr<Action>>& todo);
  486. // Destroy the currently stored stack fragment.
  487. void Clear();
  488. void Print(llvm::raw_ostream& out) const;
  489. LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
  490. private:
  491. // The todo stack of a suspended continuation, starting with the top
  492. // Action.
  493. std::vector<std::unique_ptr<Action>> reversed_todo_;
  494. };
  495. explicit ContinuationValue(Nonnull<StackFragment*> stack)
  496. : Value(Kind::ContinuationValue), stack_(stack) {}
  497. static auto classof(const Value* value) -> bool {
  498. return value->kind() == Kind::ContinuationValue;
  499. }
  500. // The todo stack of the suspended continuation. Note that this provides
  501. // mutable access, even when *this is const, because of the reference-like
  502. // semantics of ContinuationValue.
  503. auto stack() const -> StackFragment& { return *stack_; }
  504. private:
  505. Nonnull<StackFragment*> stack_;
  506. };
  507. // The String type.
  508. class StringType : public Value {
  509. public:
  510. StringType() : Value(Kind::StringType) {}
  511. static auto classof(const Value* value) -> bool {
  512. return value->kind() == Kind::StringType;
  513. }
  514. };
  515. // A string value.
  516. class StringValue : public Value {
  517. public:
  518. explicit StringValue(std::string value)
  519. : Value(Kind::StringValue), value_(std::move(value)) {}
  520. static auto classof(const Value* value) -> bool {
  521. return value->kind() == Kind::StringValue;
  522. }
  523. auto value() const -> const std::string& { return value_; }
  524. private:
  525. std::string value_;
  526. };
  527. // The type of an expression whose value is a class type. Currently there is no
  528. // way to explicitly name such a type in Carbon code, but we are tentatively
  529. // using `typeof(ClassName)` as the debug-printing format, in anticipation of
  530. // something like that becoming valid Carbon syntax.
  531. class TypeOfClassType : public Value {
  532. public:
  533. explicit TypeOfClassType(Nonnull<const NominalClassType*> class_type)
  534. : Value(Kind::TypeOfClassType), class_type_(class_type) {}
  535. static auto classof(const Value* value) -> bool {
  536. return value->kind() == Kind::TypeOfClassType;
  537. }
  538. auto class_type() const -> const NominalClassType& { return *class_type_; }
  539. private:
  540. Nonnull<const NominalClassType*> class_type_;
  541. };
  542. class TypeOfInterfaceType : public Value {
  543. public:
  544. explicit TypeOfInterfaceType(Nonnull<const InterfaceType*> iface_type)
  545. : Value(Kind::TypeOfInterfaceType), iface_type_(iface_type) {}
  546. static auto classof(const Value* value) -> bool {
  547. return value->kind() == Kind::TypeOfInterfaceType;
  548. }
  549. auto interface_type() const -> const InterfaceType& { return *iface_type_; }
  550. private:
  551. Nonnull<const InterfaceType*> iface_type_;
  552. };
  553. // The type of an expression whose value is a choice type. Currently there is no
  554. // way to explicitly name such a type in Carbon code, but we are tentatively
  555. // using `typeof(ChoiceName)` as the debug-printing format, in anticipation of
  556. // something like that becoming valid Carbon syntax.
  557. class TypeOfChoiceType : public Value {
  558. public:
  559. explicit TypeOfChoiceType(Nonnull<const ChoiceType*> choice_type)
  560. : Value(Kind::TypeOfChoiceType), choice_type_(choice_type) {}
  561. static auto classof(const Value* value) -> bool {
  562. return value->kind() == Kind::TypeOfChoiceType;
  563. }
  564. auto choice_type() const -> const ChoiceType& { return *choice_type_; }
  565. private:
  566. Nonnull<const ChoiceType*> choice_type_;
  567. };
  568. auto TypeEqual(Nonnull<const Value*> t1, Nonnull<const Value*> t2) -> bool;
  569. auto ValueEqual(Nonnull<const Value*> v1, Nonnull<const Value*> v2) -> bool;
  570. } // namespace Carbon
  571. #endif // EXECUTABLE_SEMANTICS_INTERPRETER_VALUE_H_