value.h 21 KB

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