file.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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. #include "toolchain/sem_ir/file.h"
  5. #include "common/check.h"
  6. #include "llvm/ADT/STLExtras.h"
  7. #include "llvm/ADT/SmallVector.h"
  8. #include "toolchain/sem_ir/builtin_kind.h"
  9. #include "toolchain/sem_ir/node.h"
  10. #include "toolchain/sem_ir/node_kind.h"
  11. namespace Carbon::SemIR {
  12. File::File()
  13. // Builtins are always the first IR, even when self-referential.
  14. : cross_reference_irs_({this}),
  15. // Default entry for NodeBlockId::Empty.
  16. node_blocks_(1) {
  17. nodes_.reserve(BuiltinKind::ValidCount);
  18. // Error uses a self-referential type so that it's not accidentally treated as
  19. // a normal type. Every other builtin is a type, including the
  20. // self-referential TypeType.
  21. #define CARBON_SEMANTICS_BUILTIN_KIND(Name, ...) \
  22. nodes_.push_back(Node::Builtin::Make(BuiltinKind::Name, \
  23. BuiltinKind::Name == BuiltinKind::Error \
  24. ? TypeId::Error \
  25. : TypeId::TypeType));
  26. #include "toolchain/sem_ir/builtin_kind.def"
  27. CARBON_CHECK(nodes_.size() == BuiltinKind::ValidCount)
  28. << "Builtins should produce " << BuiltinKind::ValidCount
  29. << " nodes, actual: " << nodes_.size();
  30. }
  31. File::File(const File* builtins)
  32. // Builtins are always the first IR.
  33. : cross_reference_irs_({builtins}),
  34. // Default entry for NodeBlockId::Empty.
  35. node_blocks_(1) {
  36. CARBON_CHECK(builtins != nullptr);
  37. CARBON_CHECK(builtins->cross_reference_irs_[0] == builtins)
  38. << "Not called with builtins!";
  39. // Copy builtins over.
  40. nodes_.reserve(BuiltinKind::ValidCount);
  41. static constexpr auto BuiltinIR = CrossReferenceIRId(0);
  42. for (auto [i, node] : llvm::enumerate(builtins->nodes_)) {
  43. // We can reuse builtin type IDs because they're special-cased values.
  44. nodes_.push_back(Node::CrossReference::Make(node.type_id(), BuiltinIR,
  45. SemIR::NodeId(i)));
  46. }
  47. }
  48. auto File::Verify() const -> ErrorOr<Success> {
  49. // Invariants don't necessarily hold for invalid IR.
  50. if (has_errors_) {
  51. return Success();
  52. }
  53. // Check that every code block has a terminator sequence that appears at the
  54. // end of the block.
  55. for (const Function& function : functions_) {
  56. for (NodeBlockId block_id : function.body_block_ids) {
  57. TerminatorKind prior_kind = TerminatorKind::NotTerminator;
  58. for (NodeId node_id : GetNodeBlock(block_id)) {
  59. TerminatorKind node_kind = GetNode(node_id).kind().terminator_kind();
  60. if (prior_kind == TerminatorKind::Terminator) {
  61. return Error(llvm::formatv("Node {0} in block {1} follows terminator",
  62. node_id, block_id));
  63. }
  64. if (prior_kind > node_kind) {
  65. return Error(
  66. llvm::formatv("Non-terminator node {0} in block {1} follows "
  67. "terminator sequence",
  68. node_id, block_id));
  69. }
  70. prior_kind = node_kind;
  71. }
  72. if (prior_kind != TerminatorKind::Terminator) {
  73. return Error(llvm::formatv("No terminator in block {0}", block_id));
  74. }
  75. }
  76. }
  77. // TODO: Check that a node only references other nodes that are either global
  78. // or that dominate it.
  79. return Success();
  80. }
  81. static constexpr int Indent = 2;
  82. template <typename T>
  83. static auto PrintList(llvm::raw_ostream& out, llvm::StringLiteral name,
  84. const llvm::SmallVector<T>& list) {
  85. out << name << ": [\n";
  86. for (const auto& element : list) {
  87. out.indent(Indent);
  88. out << element << ",\n";
  89. }
  90. out << "]\n";
  91. }
  92. template <typename T>
  93. static auto PrintBlock(llvm::raw_ostream& out, llvm::StringLiteral block_name,
  94. const llvm::SmallVector<T>& blocks) {
  95. out << block_name << ": [\n";
  96. for (const auto& block : blocks) {
  97. out.indent(Indent);
  98. out << "[\n";
  99. for (const auto& node : block) {
  100. out.indent(2 * Indent);
  101. out << node << ",\n";
  102. }
  103. out.indent(Indent);
  104. out << "],\n";
  105. }
  106. out << "]\n";
  107. }
  108. auto File::Print(llvm::raw_ostream& out, bool include_builtins) const -> void {
  109. out << "cross_reference_irs_size: " << cross_reference_irs_.size() << "\n";
  110. PrintList(out, "functions", functions_);
  111. PrintList(out, "integer_literals", integer_literals_);
  112. PrintList(out, "real_literals", real_literals_);
  113. PrintList(out, "strings", strings_);
  114. PrintList(out, "types", types_);
  115. PrintBlock(out, "type_blocks", type_blocks_);
  116. out << "nodes: [\n";
  117. for (int i = include_builtins ? 0 : BuiltinKind::ValidCount;
  118. i < static_cast<int>(nodes_.size()); ++i) {
  119. const auto& element = nodes_[i];
  120. out.indent(Indent);
  121. out << element << ",\n";
  122. }
  123. out << "]\n";
  124. PrintBlock(out, "node_blocks", node_blocks_);
  125. }
  126. // Map a node kind representing a type into an integer describing the
  127. // precedence of that type's syntax. Higher numbers correspond to higher
  128. // precedence.
  129. static auto GetTypePrecedence(NodeKind kind) -> int {
  130. // clang warns on unhandled enum values; clang-tidy is incorrect here.
  131. // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
  132. switch (kind) {
  133. case NodeKind::ArrayType:
  134. case NodeKind::Builtin:
  135. case NodeKind::StructType:
  136. case NodeKind::TupleType:
  137. return 0;
  138. case NodeKind::ConstType:
  139. return -1;
  140. case NodeKind::PointerType:
  141. return -2;
  142. case NodeKind::CrossReference:
  143. // TODO: Once we support stringification of cross-references, we'll need
  144. // to determine the precedence of the target of the cross-reference. For
  145. // now, all cross-references refer to builtin types from the prelude.
  146. return 0;
  147. case NodeKind::AddressOf:
  148. case NodeKind::ArrayIndex:
  149. case NodeKind::ArrayValue:
  150. case NodeKind::Assign:
  151. case NodeKind::BinaryOperatorAdd:
  152. case NodeKind::BindValue:
  153. case NodeKind::BlockArg:
  154. case NodeKind::BoolLiteral:
  155. case NodeKind::Branch:
  156. case NodeKind::BranchIf:
  157. case NodeKind::BranchWithArg:
  158. case NodeKind::Call:
  159. case NodeKind::Dereference:
  160. case NodeKind::FunctionDeclaration:
  161. case NodeKind::IntegerLiteral:
  162. case NodeKind::Invalid:
  163. case NodeKind::Namespace:
  164. case NodeKind::NoOp:
  165. case NodeKind::Parameter:
  166. case NodeKind::RealLiteral:
  167. case NodeKind::Return:
  168. case NodeKind::ReturnExpression:
  169. case NodeKind::StringLiteral:
  170. case NodeKind::StructAccess:
  171. case NodeKind::StructTypeField:
  172. case NodeKind::StructValue:
  173. case NodeKind::StubReference:
  174. case NodeKind::Temporary:
  175. case NodeKind::TemporaryStorage:
  176. case NodeKind::TupleIndex:
  177. case NodeKind::TupleValue:
  178. case NodeKind::UnaryOperatorNot:
  179. case NodeKind::VarStorage:
  180. CARBON_FATAL() << "GetTypePrecedence for non-type node kind " << kind;
  181. }
  182. }
  183. auto File::StringifyType(TypeId type_id, bool in_type_context) const
  184. -> std::string {
  185. std::string str;
  186. llvm::raw_string_ostream out(str);
  187. struct Step {
  188. // The node to print.
  189. NodeId node_id;
  190. // The index into node_id to print. Not used by all types.
  191. int index = 0;
  192. auto Next() const -> Step {
  193. return {.node_id = node_id, .index = index + 1};
  194. }
  195. };
  196. auto outer_node_id = GetTypeAllowBuiltinTypes(type_id);
  197. llvm::SmallVector<Step> steps = {{.node_id = outer_node_id}};
  198. while (!steps.empty()) {
  199. auto step = steps.pop_back_val();
  200. // Invalid node IDs will use the default invalid printing.
  201. if (!step.node_id.is_valid()) {
  202. out << step.node_id;
  203. continue;
  204. }
  205. // Builtins have designated labels.
  206. if (step.node_id.index < BuiltinKind::ValidCount) {
  207. out << BuiltinKind::FromInt(step.node_id.index).label();
  208. continue;
  209. }
  210. auto node = GetNode(step.node_id);
  211. // clang warns on unhandled enum values; clang-tidy is incorrect here.
  212. // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
  213. switch (node.kind()) {
  214. case NodeKind::ArrayType: {
  215. auto [bound_id, type_id] = node.GetAsArrayType();
  216. if (step.index == 0) {
  217. out << "[";
  218. steps.push_back(step.Next());
  219. steps.push_back({.node_id = GetTypeAllowBuiltinTypes(type_id)});
  220. } else if (step.index == 1) {
  221. out << "; " << GetArrayBoundValue(bound_id) << "]";
  222. }
  223. break;
  224. }
  225. case NodeKind::ConstType: {
  226. if (step.index == 0) {
  227. out << "const ";
  228. // Add parentheses if required.
  229. auto inner_type_node_id =
  230. GetTypeAllowBuiltinTypes(node.GetAsConstType());
  231. if (GetTypePrecedence(GetNode(inner_type_node_id).kind()) <
  232. GetTypePrecedence(node.kind())) {
  233. out << "(";
  234. steps.push_back(step.Next());
  235. }
  236. steps.push_back({.node_id = inner_type_node_id});
  237. } else if (step.index == 1) {
  238. out << ")";
  239. }
  240. break;
  241. }
  242. case NodeKind::PointerType: {
  243. if (step.index == 0) {
  244. steps.push_back(step.Next());
  245. steps.push_back(
  246. {.node_id = GetTypeAllowBuiltinTypes(node.GetAsPointerType())});
  247. } else if (step.index == 1) {
  248. out << "*";
  249. }
  250. break;
  251. }
  252. case NodeKind::StructType: {
  253. auto refs = GetNodeBlock(node.GetAsStructType());
  254. if (refs.empty()) {
  255. out << "{}";
  256. break;
  257. } else if (step.index == 0) {
  258. out << "{";
  259. } else if (step.index < static_cast<int>(refs.size())) {
  260. out << ", ";
  261. } else {
  262. out << "}";
  263. break;
  264. }
  265. steps.push_back(step.Next());
  266. steps.push_back({.node_id = refs[step.index]});
  267. break;
  268. }
  269. case NodeKind::StructTypeField: {
  270. auto [name_id, type_id] = node.GetAsStructTypeField();
  271. out << "." << GetString(name_id) << ": ";
  272. steps.push_back({.node_id = GetTypeAllowBuiltinTypes(type_id)});
  273. break;
  274. }
  275. case NodeKind::TupleType: {
  276. auto refs = GetTypeBlock(node.GetAsTupleType());
  277. if (refs.empty()) {
  278. out << "()";
  279. break;
  280. } else if (step.index == 0) {
  281. out << "(";
  282. } else if (step.index < static_cast<int>(refs.size())) {
  283. out << ", ";
  284. } else {
  285. // A tuple of one element has a comma to disambiguate from an
  286. // expression.
  287. if (step.index == 1) {
  288. out << ",";
  289. }
  290. out << ")";
  291. break;
  292. }
  293. steps.push_back(step.Next());
  294. steps.push_back(
  295. {.node_id = GetTypeAllowBuiltinTypes(refs[step.index])});
  296. break;
  297. }
  298. case NodeKind::AddressOf:
  299. case NodeKind::ArrayIndex:
  300. case NodeKind::ArrayValue:
  301. case NodeKind::Assign:
  302. case NodeKind::BinaryOperatorAdd:
  303. case NodeKind::BindValue:
  304. case NodeKind::BlockArg:
  305. case NodeKind::BoolLiteral:
  306. case NodeKind::Branch:
  307. case NodeKind::BranchIf:
  308. case NodeKind::BranchWithArg:
  309. case NodeKind::Builtin:
  310. case NodeKind::Call:
  311. case NodeKind::CrossReference:
  312. case NodeKind::Dereference:
  313. case NodeKind::FunctionDeclaration:
  314. case NodeKind::IntegerLiteral:
  315. case NodeKind::Namespace:
  316. case NodeKind::NoOp:
  317. case NodeKind::Parameter:
  318. case NodeKind::RealLiteral:
  319. case NodeKind::Return:
  320. case NodeKind::ReturnExpression:
  321. case NodeKind::StringLiteral:
  322. case NodeKind::StructAccess:
  323. case NodeKind::StructValue:
  324. case NodeKind::StubReference:
  325. case NodeKind::Temporary:
  326. case NodeKind::TemporaryStorage:
  327. case NodeKind::TupleIndex:
  328. case NodeKind::TupleValue:
  329. case NodeKind::UnaryOperatorNot:
  330. case NodeKind::VarStorage:
  331. // We don't need to handle stringification for nodes that don't show up
  332. // in errors, but make it clear what's going on so that it's clearer
  333. // when stringification is needed.
  334. out << "<cannot stringify " << step.node_id << ">";
  335. break;
  336. case NodeKind::Invalid:
  337. llvm_unreachable("NodeKind::Invalid is never used.");
  338. }
  339. }
  340. // For `{}` or any tuple type, we've printed a non-type expression, so add a
  341. // conversion to type `type` if it's not implied by the context.
  342. if (!in_type_context) {
  343. auto outer_node = GetNode(outer_node_id);
  344. if (outer_node.kind() == NodeKind::TupleType ||
  345. (outer_node.kind() == NodeKind::StructType &&
  346. GetNodeBlock(outer_node.GetAsStructType()).empty())) {
  347. out << " as type";
  348. }
  349. }
  350. return str;
  351. }
  352. auto GetExpressionCategory(const File& file, NodeId node_id)
  353. -> ExpressionCategory {
  354. const File* ir = &file;
  355. while (true) {
  356. auto node = ir->GetNode(node_id);
  357. // clang warns on unhandled enum values; clang-tidy is incorrect here.
  358. // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
  359. switch (node.kind()) {
  360. case NodeKind::Invalid:
  361. case NodeKind::Assign:
  362. case NodeKind::Branch:
  363. case NodeKind::BranchIf:
  364. case NodeKind::BranchWithArg:
  365. case NodeKind::FunctionDeclaration:
  366. case NodeKind::Namespace:
  367. case NodeKind::NoOp:
  368. case NodeKind::Return:
  369. case NodeKind::ReturnExpression:
  370. case NodeKind::StructTypeField:
  371. return ExpressionCategory::NotExpression;
  372. case NodeKind::CrossReference: {
  373. auto [xref_id, xref_node_id] = node.GetAsCrossReference();
  374. ir = &ir->GetCrossReferenceIR(xref_id);
  375. node_id = xref_node_id;
  376. continue;
  377. }
  378. case NodeKind::AddressOf:
  379. case NodeKind::ArrayType:
  380. case NodeKind::BinaryOperatorAdd:
  381. case NodeKind::BindValue:
  382. case NodeKind::BlockArg:
  383. case NodeKind::BoolLiteral:
  384. case NodeKind::Builtin:
  385. case NodeKind::ConstType:
  386. case NodeKind::IntegerLiteral:
  387. case NodeKind::Parameter:
  388. case NodeKind::PointerType:
  389. case NodeKind::RealLiteral:
  390. case NodeKind::StringLiteral:
  391. case NodeKind::StructType:
  392. case NodeKind::TupleType:
  393. case NodeKind::UnaryOperatorNot:
  394. return ExpressionCategory::Value;
  395. case NodeKind::ArrayIndex: {
  396. auto [base_id, index_id] = node.GetAsArrayIndex();
  397. node_id = base_id;
  398. continue;
  399. }
  400. case NodeKind::StructAccess: {
  401. auto [base_id, member_index] = node.GetAsStructAccess();
  402. node_id = base_id;
  403. continue;
  404. }
  405. case NodeKind::TupleIndex: {
  406. auto [base_id, index_id] = node.GetAsTupleIndex();
  407. node_id = base_id;
  408. continue;
  409. }
  410. case NodeKind::StubReference: {
  411. node_id = node.GetAsStubReference();
  412. continue;
  413. }
  414. case NodeKind::ArrayValue:
  415. case NodeKind::StructValue:
  416. case NodeKind::TupleValue:
  417. // TODO: Eventually these will depend on the context in which the value
  418. // is used, and could be either Value or Initializing. We may want
  419. // different node kinds for a struct/tuple initializer versus a
  420. // struct/tuple value construction.
  421. return ExpressionCategory::Value;
  422. case NodeKind::Call:
  423. return ExpressionCategory::Initializing;
  424. case NodeKind::Dereference:
  425. case NodeKind::VarStorage:
  426. return ExpressionCategory::DurableReference;
  427. case NodeKind::Temporary:
  428. case NodeKind::TemporaryStorage:
  429. return ExpressionCategory::EphemeralReference;
  430. }
  431. }
  432. }
  433. auto GetValueRepresentation(const File& file, TypeId type_id)
  434. -> ValueRepresentation {
  435. const File* ir = &file;
  436. NodeId node_id = ir->GetTypeAllowBuiltinTypes(type_id);
  437. while (true) {
  438. auto node = ir->GetNode(node_id);
  439. // clang warns on unhandled enum values; clang-tidy is incorrect here.
  440. // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
  441. switch (node.kind()) {
  442. case NodeKind::AddressOf:
  443. case NodeKind::ArrayIndex:
  444. case NodeKind::ArrayValue:
  445. case NodeKind::Assign:
  446. case NodeKind::BinaryOperatorAdd:
  447. case NodeKind::BindValue:
  448. case NodeKind::BlockArg:
  449. case NodeKind::BoolLiteral:
  450. case NodeKind::Branch:
  451. case NodeKind::BranchIf:
  452. case NodeKind::BranchWithArg:
  453. case NodeKind::Call:
  454. case NodeKind::Dereference:
  455. case NodeKind::FunctionDeclaration:
  456. case NodeKind::IntegerLiteral:
  457. case NodeKind::Invalid:
  458. case NodeKind::Namespace:
  459. case NodeKind::NoOp:
  460. case NodeKind::Parameter:
  461. case NodeKind::RealLiteral:
  462. case NodeKind::Return:
  463. case NodeKind::ReturnExpression:
  464. case NodeKind::StringLiteral:
  465. case NodeKind::StructAccess:
  466. case NodeKind::StructTypeField:
  467. case NodeKind::StructValue:
  468. case NodeKind::Temporary:
  469. case NodeKind::TemporaryStorage:
  470. case NodeKind::TupleIndex:
  471. case NodeKind::TupleValue:
  472. case NodeKind::UnaryOperatorNot:
  473. case NodeKind::VarStorage:
  474. CARBON_FATAL() << "Type refers to non-type node " << node;
  475. case NodeKind::CrossReference: {
  476. auto [xref_id, xref_node_id] = node.GetAsCrossReference();
  477. ir = &ir->GetCrossReferenceIR(xref_id);
  478. node_id = xref_node_id;
  479. continue;
  480. }
  481. case NodeKind::StubReference: {
  482. node_id = node.GetAsStubReference();
  483. continue;
  484. }
  485. case NodeKind::ArrayType:
  486. // For arrays, it's convenient to always use a pointer representation,
  487. // even when the array has zero or one element, in order to support
  488. // indexing.
  489. return {.kind = ValueRepresentation::Pointer, .type = type_id};
  490. case NodeKind::StructType: {
  491. const auto& fields = ir->GetNodeBlock(node.GetAsStructType());
  492. if (fields.empty()) {
  493. // An empty struct has an empty representation.
  494. return {.kind = ValueRepresentation::None, .type = TypeId::Invalid};
  495. }
  496. if (fields.size() == 1) {
  497. // A struct with one field has the same representation as its field.
  498. auto [field_name_id, field_type_id] =
  499. ir->GetNode(fields.front()).GetAsStructTypeField();
  500. node_id = ir->GetTypeAllowBuiltinTypes(field_type_id);
  501. continue;
  502. }
  503. // For any other struct, use a pointer representation.
  504. return {.kind = ValueRepresentation::Pointer, .type = type_id};
  505. }
  506. case NodeKind::TupleType: {
  507. const auto& elements = ir->GetTypeBlock(node.GetAsTupleType());
  508. if (elements.empty()) {
  509. // An empty tuple has an empty representation.
  510. return {.kind = ValueRepresentation::None, .type = TypeId::Invalid};
  511. }
  512. if (elements.size() == 1) {
  513. // A one-tuple has the same representation as its sole element.
  514. node_id = ir->GetTypeAllowBuiltinTypes(elements.front());
  515. continue;
  516. }
  517. // For any other tuple, use a pointer representation.
  518. return {.kind = ValueRepresentation::Pointer, .type = type_id};
  519. }
  520. case NodeKind::Builtin:
  521. // clang warns on unhandled enum values; clang-tidy is incorrect here.
  522. // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
  523. switch (node.GetAsBuiltin()) {
  524. case BuiltinKind::TypeType:
  525. case BuiltinKind::Error:
  526. case BuiltinKind::Invalid:
  527. return {.kind = ValueRepresentation::None, .type = TypeId::Invalid};
  528. case BuiltinKind::BoolType:
  529. case BuiltinKind::IntegerType:
  530. case BuiltinKind::FloatingPointType:
  531. return {.kind = ValueRepresentation::Copy, .type = type_id};
  532. case BuiltinKind::StringType:
  533. // TODO: Decide on string value semantics. This should probably be a
  534. // custom value representation carrying a pointer and size or
  535. // similar.
  536. return {.kind = ValueRepresentation::Pointer, .type = type_id};
  537. }
  538. case NodeKind::PointerType:
  539. return {.kind = ValueRepresentation::Copy, .type = type_id};
  540. case NodeKind::ConstType:
  541. node_id = ir->GetTypeAllowBuiltinTypes(node.GetAsConstType());
  542. continue;
  543. }
  544. }
  545. }
  546. auto GetInitializingRepresentation(const File& file, TypeId type_id)
  547. -> InitializingRepresentation {
  548. auto value_rep = GetValueRepresentation(file, type_id);
  549. switch (value_rep.kind) {
  550. case ValueRepresentation::None:
  551. return {.kind = InitializingRepresentation::None};
  552. case ValueRepresentation::Copy:
  553. // TODO: Use in-place initialization for types that have non-trivial
  554. // destructive move.
  555. return {.kind = InitializingRepresentation::ByCopy};
  556. case ValueRepresentation::Pointer:
  557. case ValueRepresentation::Custom:
  558. return {.kind = InitializingRepresentation::InPlace};
  559. }
  560. }
  561. } // namespace Carbon::SemIR