deduce.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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/check/deduce.h"
  5. #include "llvm/ADT/SmallBitVector.h"
  6. #include "toolchain/base/kind_switch.h"
  7. #include "toolchain/check/context.h"
  8. #include "toolchain/check/convert.h"
  9. #include "toolchain/check/generic.h"
  10. #include "toolchain/check/subst.h"
  11. #include "toolchain/sem_ir/ids.h"
  12. #include "toolchain/sem_ir/impl.h"
  13. #include "toolchain/sem_ir/typed_insts.h"
  14. namespace Carbon::Check {
  15. namespace {
  16. // A list of pairs of (instruction from generic, corresponding instruction from
  17. // call to of generic) for which we still need to perform deduction, along with
  18. // methods to add and pop pending deductions from the list. Deductions are
  19. // popped in order from most- to least-recently pushed, with the intent that
  20. // they are visited in depth-first order, although the order is not expected to
  21. // matter except when it influences which error is diagnosed.
  22. class DeductionWorklist {
  23. public:
  24. explicit DeductionWorklist(Context& context) : context_(context) {}
  25. struct PendingDeduction {
  26. SemIR::InstId param;
  27. SemIR::InstId arg;
  28. bool needs_substitution;
  29. };
  30. // Adds a single (param, arg) deduction.
  31. auto Add(SemIR::InstId param, SemIR::InstId arg, bool needs_substitution)
  32. -> void {
  33. deductions_.push_back(
  34. {.param = param, .arg = arg, .needs_substitution = needs_substitution});
  35. }
  36. // Adds a single (param, arg) type deduction.
  37. auto Add(SemIR::TypeId param, SemIR::TypeId arg, bool needs_substitution)
  38. -> void {
  39. Add(context_.types().GetInstId(param), context_.types().GetInstId(arg),
  40. needs_substitution);
  41. }
  42. // Adds a single (param, arg) deduction of a specific.
  43. auto Add(SemIR::SpecificId param, SemIR::SpecificId arg,
  44. bool needs_substitution) -> void {
  45. if (!param.has_value() || !arg.has_value()) {
  46. return;
  47. }
  48. auto& param_specific = context_.specifics().Get(param);
  49. auto& arg_specific = context_.specifics().Get(arg);
  50. if (param_specific.generic_id != arg_specific.generic_id) {
  51. // TODO: Decide whether to error on this or just treat the specific as
  52. // non-deduced. For now we treat it as non-deduced.
  53. return;
  54. }
  55. AddAll(param_specific.args_id, arg_specific.args_id, needs_substitution);
  56. }
  57. // Adds a list of (param, arg) deductions. These are added in reverse order so
  58. // they are popped in forward order.
  59. template <typename ElementId>
  60. auto AddAll(llvm::ArrayRef<ElementId> params, llvm::ArrayRef<ElementId> args,
  61. bool needs_substitution) -> void {
  62. if (params.size() != args.size()) {
  63. // TODO: Decide whether to error on this or just treat the parameter list
  64. // as non-deduced. For now we treat it as non-deduced.
  65. return;
  66. }
  67. for (auto [param, arg] : llvm::reverse(llvm::zip_equal(params, args))) {
  68. Add(param, arg, needs_substitution);
  69. }
  70. }
  71. auto AddAll(SemIR::InstBlockId params, llvm::ArrayRef<SemIR::InstId> args,
  72. bool needs_substitution) -> void {
  73. AddAll(context_.inst_blocks().Get(params), args, needs_substitution);
  74. }
  75. auto AddAll(SemIR::StructTypeFieldsId params, SemIR::StructTypeFieldsId args,
  76. bool needs_substitution) -> void {
  77. const auto& param_fields = context_.struct_type_fields().Get(params);
  78. const auto& arg_fields = context_.struct_type_fields().Get(args);
  79. if (param_fields.size() != arg_fields.size()) {
  80. // TODO: Decide whether to error on this or just treat the parameter list
  81. // as non-deduced. For now we treat it as non-deduced.
  82. return;
  83. }
  84. // Don't do deduction unless the names match in order.
  85. // TODO: Support reordering of names.
  86. for (auto [param, arg] : llvm::zip_equal(param_fields, arg_fields)) {
  87. if (param.name_id != arg.name_id) {
  88. return;
  89. }
  90. }
  91. for (auto [param, arg] :
  92. llvm::reverse(llvm::zip_equal(param_fields, arg_fields))) {
  93. Add(param.type_id, arg.type_id, needs_substitution);
  94. }
  95. }
  96. auto AddAll(SemIR::InstBlockId params, SemIR::InstBlockId args,
  97. bool needs_substitution) -> void {
  98. AddAll(context_.inst_blocks().Get(params), context_.inst_blocks().Get(args),
  99. needs_substitution);
  100. }
  101. auto AddAll(SemIR::TypeBlockId params, SemIR::TypeBlockId args,
  102. bool needs_substitution) -> void {
  103. AddAll(context_.type_blocks().Get(params), context_.type_blocks().Get(args),
  104. needs_substitution);
  105. }
  106. auto AddAll(SemIR::FacetTypeId params, SemIR::FacetTypeId args,
  107. bool needs_substitution) -> void {
  108. const auto& param_impls =
  109. context_.facet_types().Get(params).impls_constraints;
  110. const auto& arg_impls = context_.facet_types().Get(args).impls_constraints;
  111. // TODO: Decide whether to error on these or just treat the parameter list
  112. // as non-deduced. For now we treat it as non-deduced.
  113. if (param_impls.size() != 1 || arg_impls.size() != 1) {
  114. return;
  115. }
  116. auto param = param_impls.front();
  117. auto arg = arg_impls.front();
  118. if (param.interface_id != arg.interface_id) {
  119. return;
  120. }
  121. Add(param.specific_id, arg.specific_id, needs_substitution);
  122. }
  123. // Adds a (param, arg) pair for an instruction argument, given its kind.
  124. auto AddInstArg(SemIR::IdKind kind, int32_t param, int32_t arg,
  125. bool needs_substitution) -> void {
  126. switch (kind) {
  127. case SemIR::IdKind::None:
  128. case SemIR::IdKind::For<SemIR::ClassId>:
  129. case SemIR::IdKind::For<SemIR::IntKind>:
  130. break;
  131. case SemIR::IdKind::For<SemIR::InstId>:
  132. Add(SemIR::InstId(param), SemIR::InstId(arg), needs_substitution);
  133. break;
  134. case SemIR::IdKind::For<SemIR::TypeId>:
  135. Add(SemIR::TypeId(param), SemIR::TypeId(arg), needs_substitution);
  136. break;
  137. case SemIR::IdKind::For<SemIR::StructTypeFieldsId>:
  138. AddAll(SemIR::StructTypeFieldsId(param), SemIR::StructTypeFieldsId(arg),
  139. needs_substitution);
  140. break;
  141. case SemIR::IdKind::For<SemIR::InstBlockId>:
  142. AddAll(SemIR::InstBlockId(param), SemIR::InstBlockId(arg),
  143. needs_substitution);
  144. break;
  145. case SemIR::IdKind::For<SemIR::TypeBlockId>:
  146. AddAll(SemIR::TypeBlockId(param), SemIR::TypeBlockId(arg),
  147. needs_substitution);
  148. break;
  149. case SemIR::IdKind::For<SemIR::SpecificId>:
  150. Add(SemIR::SpecificId(param), SemIR::SpecificId(arg),
  151. needs_substitution);
  152. break;
  153. case SemIR::IdKind::For<SemIR::FacetTypeId>:
  154. AddAll(SemIR::FacetTypeId(param), SemIR::FacetTypeId(arg),
  155. needs_substitution);
  156. break;
  157. default:
  158. CARBON_FATAL("unexpected argument kind");
  159. }
  160. }
  161. // Returns whether we have completed all deductions.
  162. auto Done() -> bool { return deductions_.empty(); }
  163. // Pops the next deduction. Requires `!Done()`.
  164. auto PopNext() -> PendingDeduction { return deductions_.pop_back_val(); }
  165. private:
  166. Context& context_;
  167. llvm::SmallVector<PendingDeduction> deductions_;
  168. };
  169. // State that is tracked throughout the deduction process.
  170. class DeductionContext {
  171. public:
  172. // Preparse to perform deduction. If an enclosing specific is provided, adds
  173. // the arguments from the given specific as known arguments that will not be
  174. // deduced.
  175. DeductionContext(Context& context, SemIR::LocId loc_id,
  176. SemIR::GenericId generic_id,
  177. SemIR::SpecificId enclosing_specific_id, bool diagnose);
  178. auto context() const -> Context& { return *context_; }
  179. // Adds a pending deduction of `param` from `arg`. `needs_substitution`
  180. // indicates whether we need to substitute known generic parameters into
  181. // `param`.
  182. template <typename ParamT, typename ArgT>
  183. auto Add(ParamT param, ArgT arg, bool needs_substitution) -> void {
  184. worklist_.Add(param, arg, needs_substitution);
  185. }
  186. // Same as `Add` but for an array or block of operands.
  187. template <typename ParamT, typename ArgT>
  188. auto AddAll(ParamT param, ArgT arg, bool needs_substitution) -> void {
  189. worklist_.AddAll(param, arg, needs_substitution);
  190. }
  191. // Performs all deductions in the deduction worklist. Returns whether
  192. // deduction succeeded.
  193. auto Deduce() -> bool;
  194. // Returns whether every generic parameter has a corresponding deduced generic
  195. // argument. If not, issues a suitable diagnostic.
  196. auto CheckDeductionIsComplete() -> bool;
  197. // Forms a specific corresponding to the deduced generic with the deduced
  198. // argument list. Must not be called before deduction is complete.
  199. auto MakeSpecific() -> SemIR::SpecificId;
  200. private:
  201. Context* context_;
  202. SemIR::LocId loc_id_;
  203. SemIR::GenericId generic_id_;
  204. bool diagnose_;
  205. DeductionWorklist worklist_;
  206. llvm::SmallVector<SemIR::InstId> result_arg_ids_;
  207. llvm::SmallVector<Substitution> substitutions_;
  208. SemIR::CompileTimeBindIndex first_deduced_index_;
  209. // Non-deduced indexes, indexed by parameter index - first_deduced_index_.
  210. llvm::SmallBitVector non_deduced_indexes_;
  211. };
  212. } // namespace
  213. static auto NoteGenericHere(Context& context, SemIR::GenericId generic_id,
  214. Context::DiagnosticBuilder& diag) -> void {
  215. CARBON_DIAGNOSTIC(DeductionGenericHere, Note,
  216. "while deducing parameters of generic declared here");
  217. diag.Note(context.generics().Get(generic_id).decl_id, DeductionGenericHere);
  218. }
  219. DeductionContext::DeductionContext(Context& context, SemIR::LocId loc_id,
  220. SemIR::GenericId generic_id,
  221. SemIR::SpecificId enclosing_specific_id,
  222. bool diagnose)
  223. : context_(&context),
  224. loc_id_(loc_id),
  225. generic_id_(generic_id),
  226. diagnose_(diagnose),
  227. worklist_(context),
  228. first_deduced_index_(0) {
  229. CARBON_CHECK(generic_id.has_value(),
  230. "Performing deduction for non-generic entity");
  231. // Initialize the deduced arguments to `None`.
  232. result_arg_ids_.resize(
  233. context.inst_blocks()
  234. .Get(context.generics().Get(generic_id_).bindings_id)
  235. .size(),
  236. SemIR::InstId::None);
  237. if (enclosing_specific_id.has_value()) {
  238. // Copy any outer generic arguments from the specified instance and prepare
  239. // to substitute them into the function declaration.
  240. auto args = context.inst_blocks().Get(
  241. context.specifics().Get(enclosing_specific_id).args_id);
  242. llvm::copy(args, result_arg_ids_.begin());
  243. // TODO: Subst is linear in the length of the substitutions list. Change
  244. // it so we can pass in an array mapping indexes to substitutions instead.
  245. substitutions_.reserve(args.size());
  246. for (auto [i, subst_inst_id] : llvm::enumerate(args)) {
  247. substitutions_.push_back(
  248. {.bind_id = SemIR::CompileTimeBindIndex(i),
  249. .replacement_id = context.constant_values().Get(subst_inst_id)});
  250. }
  251. first_deduced_index_ = SemIR::CompileTimeBindIndex(args.size());
  252. }
  253. non_deduced_indexes_.resize(result_arg_ids_.size() -
  254. first_deduced_index_.index);
  255. }
  256. auto DeductionContext::Deduce() -> bool {
  257. while (!worklist_.Done()) {
  258. auto [param_id, arg_id, needs_substitution] = worklist_.PopNext();
  259. auto note_initializing_param = [&](auto& builder) {
  260. if (auto param =
  261. context().insts().TryGetAs<SemIR::SymbolicBindingPattern>(
  262. param_id)) {
  263. CARBON_DIAGNOSTIC(InitializingGenericParam, Note,
  264. "initializing generic parameter `{0}` declared here",
  265. SemIR::NameId);
  266. builder.Note(
  267. param_id, InitializingGenericParam,
  268. context().entity_names().Get(param->entity_name_id).name_id);
  269. } else {
  270. NoteGenericHere(context(), generic_id_, builder);
  271. }
  272. };
  273. // TODO: Bail out if there's nothing to deduce: if we're not in a pattern
  274. // and the parameter doesn't have a symbolic constant value.
  275. // If the parameter has a symbolic type, deduce against that.
  276. auto param_type_id = context().insts().Get(param_id).type_id();
  277. if (param_type_id.AsConstantId().is_symbolic()) {
  278. Add(context().types().GetInstId(param_type_id),
  279. context().types().GetInstId(context().insts().Get(arg_id).type_id()),
  280. needs_substitution);
  281. } else {
  282. // The argument needs to have the same type as the parameter.
  283. // TODO: Suppress diagnostics here if diagnose_ is false.
  284. // TODO: Only do this when deducing against a symbolic pattern.
  285. DiagnosticAnnotationScope annotate_diagnostics(&context().emitter(),
  286. note_initializing_param);
  287. arg_id = ConvertToValueOfType(context(), loc_id_, arg_id, param_type_id);
  288. if (arg_id == SemIR::ErrorInst::SingletonInstId) {
  289. return false;
  290. }
  291. }
  292. // Attempt to match `param_inst` against `arg_id`. If the match succeeds,
  293. // this should `continue` the outer loop. On `break`, we will try to desugar
  294. // the parameter to continue looking for a match.
  295. auto param_inst = context().insts().Get(param_id);
  296. CARBON_KIND_SWITCH(param_inst) {
  297. // Deducing a symbolic binding pattern from an argument deduces the
  298. // binding as having that constant value. For example, deducing
  299. // `(T:! type)` against `(i32)` deduces `T` to be `i32`. This only arises
  300. // when initializing a generic parameter from an explicitly specified
  301. // argument, and in this case, the argument is required to be a
  302. // compile-time constant.
  303. case CARBON_KIND(SemIR::SymbolicBindingPattern bind): {
  304. auto& entity_name = context().entity_names().Get(bind.entity_name_id);
  305. auto index = entity_name.bind_index;
  306. if (!index.has_value()) {
  307. break;
  308. }
  309. CARBON_CHECK(
  310. index >= first_deduced_index_ &&
  311. static_cast<size_t>(index.index) < result_arg_ids_.size(),
  312. "Unexpected index {0} for symbolic binding pattern; "
  313. "expected to be in range [{1}, {2})",
  314. index.index, first_deduced_index_.index, result_arg_ids_.size());
  315. CARBON_CHECK(!result_arg_ids_[index.index].has_value(),
  316. "Deduced a value for parameter prior to its declaration");
  317. auto arg_const_inst_id =
  318. context().constant_values().GetConstantInstId(arg_id);
  319. if (!arg_const_inst_id.has_value()) {
  320. if (diagnose_) {
  321. CARBON_DIAGNOSTIC(CompTimeArgumentNotConstant, Error,
  322. "argument for generic parameter is not a "
  323. "compile-time constant");
  324. auto diag =
  325. context().emitter().Build(loc_id_, CompTimeArgumentNotConstant);
  326. note_initializing_param(diag);
  327. diag.Emit();
  328. }
  329. return false;
  330. }
  331. result_arg_ids_[index.index] = arg_const_inst_id;
  332. // This parameter index should not be deduced if it appears later.
  333. non_deduced_indexes_[index.index - first_deduced_index_.index] = true;
  334. continue;
  335. }
  336. // Deducing a symbolic binding appearing within an expression against a
  337. // constant value deduces the binding as having that value. For example,
  338. // deducing `[T:! type](x: T)` against `("foo")` deduces `T` as `String`.
  339. case CARBON_KIND(SemIR::BindSymbolicName bind): {
  340. auto& entity_name = context().entity_names().Get(bind.entity_name_id);
  341. auto index = entity_name.bind_index;
  342. if (!index.has_value() || index < first_deduced_index_ ||
  343. non_deduced_indexes_[index.index - first_deduced_index_.index]) {
  344. break;
  345. }
  346. CARBON_CHECK(static_cast<size_t>(index.index) < result_arg_ids_.size(),
  347. "Deduced value for unexpected index {0}; expected to "
  348. "deduce {1} arguments.",
  349. index, result_arg_ids_.size());
  350. auto arg_const_inst_id =
  351. context().constant_values().GetConstantInstId(arg_id);
  352. if (arg_const_inst_id.has_value()) {
  353. if (result_arg_ids_[index.index].has_value() &&
  354. result_arg_ids_[index.index] != arg_const_inst_id) {
  355. if (diagnose_) {
  356. // TODO: Include the two different deduced values.
  357. CARBON_DIAGNOSTIC(DeductionInconsistent, Error,
  358. "inconsistent deductions for value of generic "
  359. "parameter `{0}`",
  360. SemIR::NameId);
  361. auto diag = context().emitter().Build(
  362. loc_id_, DeductionInconsistent, entity_name.name_id);
  363. NoteGenericHere(context(), generic_id_, diag);
  364. diag.Emit();
  365. }
  366. return false;
  367. }
  368. result_arg_ids_[index.index] = arg_const_inst_id;
  369. }
  370. continue;
  371. }
  372. case CARBON_KIND(SemIR::ValueParamPattern pattern): {
  373. Add(pattern.subpattern_id, arg_id, needs_substitution);
  374. continue;
  375. }
  376. case SemIR::StructValue::Kind:
  377. // TODO: Match field name order between param and arg.
  378. break;
  379. // TODO: Handle more cases.
  380. default:
  381. if (param_inst.kind().deduce_through()) {
  382. // Various kinds of parameter should match an argument of the same
  383. // form, if the operands all match.
  384. auto arg_inst = context().insts().Get(arg_id);
  385. if (arg_inst.kind() != param_inst.kind()) {
  386. break;
  387. }
  388. auto [kind0, kind1] = param_inst.ArgKinds();
  389. worklist_.AddInstArg(kind0, param_inst.arg0(), arg_inst.arg0(),
  390. needs_substitution);
  391. worklist_.AddInstArg(kind1, param_inst.arg1(), arg_inst.arg1(),
  392. needs_substitution);
  393. continue;
  394. }
  395. break;
  396. }
  397. // We didn't manage to deduce against the syntactic form of the parameter.
  398. // Convert it to a canonical constant value and try deducing against that.
  399. auto param_const_id = context().constant_values().Get(param_id);
  400. if (!param_const_id.has_value() || !param_const_id.is_symbolic()) {
  401. // It's not a symbolic constant. There's nothing here to deduce.
  402. continue;
  403. }
  404. auto param_const_inst_id =
  405. context().constant_values().GetInstId(param_const_id);
  406. if (param_const_inst_id != param_id) {
  407. Add(param_const_inst_id, arg_id, needs_substitution);
  408. continue;
  409. }
  410. // If we've not yet substituted into the parameter, do so now and try again.
  411. if (needs_substitution) {
  412. param_const_id = SubstConstant(context(), param_const_id, substitutions_);
  413. if (!param_const_id.has_value() || !param_const_id.is_symbolic()) {
  414. continue;
  415. }
  416. Add(context().constant_values().GetInstId(param_const_id), arg_id,
  417. /*needs_substitution=*/false);
  418. }
  419. }
  420. return true;
  421. }
  422. auto DeductionContext::CheckDeductionIsComplete() -> bool {
  423. // Check we deduced an argument value for every parameter.
  424. for (auto [i, deduced_arg_id] :
  425. llvm::enumerate(llvm::ArrayRef(result_arg_ids_)
  426. .drop_front(first_deduced_index_.index))) {
  427. if (!deduced_arg_id.has_value()) {
  428. if (diagnose_) {
  429. auto binding_index = first_deduced_index_.index + i;
  430. auto binding_id = context().inst_blocks().Get(
  431. context().generics().Get(generic_id_).bindings_id)[binding_index];
  432. auto entity_name_id = context()
  433. .insts()
  434. .GetAs<SemIR::AnyBindName>(binding_id)
  435. .entity_name_id;
  436. CARBON_DIAGNOSTIC(DeductionIncomplete, Error,
  437. "cannot deduce value for generic parameter `{0}`",
  438. SemIR::NameId);
  439. auto diag = context().emitter().Build(
  440. loc_id_, DeductionIncomplete,
  441. context().entity_names().Get(entity_name_id).name_id);
  442. NoteGenericHere(context(), generic_id_, diag);
  443. diag.Emit();
  444. }
  445. return false;
  446. }
  447. }
  448. return true;
  449. }
  450. auto DeductionContext::MakeSpecific() -> SemIR::SpecificId {
  451. // TODO: Convert the deduced values to the types of the bindings.
  452. return Check::MakeSpecific(
  453. context(), loc_id_, generic_id_,
  454. context().inst_blocks().AddCanonical(result_arg_ids_));
  455. }
  456. auto DeduceGenericCallArguments(
  457. Context& context, SemIR::LocId loc_id, SemIR::GenericId generic_id,
  458. SemIR::SpecificId enclosing_specific_id,
  459. [[maybe_unused]] SemIR::InstBlockId implicit_params_id,
  460. SemIR::InstBlockId params_id, [[maybe_unused]] SemIR::InstId self_id,
  461. llvm::ArrayRef<SemIR::InstId> arg_ids) -> SemIR::SpecificId {
  462. DeductionContext deduction(context, loc_id, generic_id, enclosing_specific_id,
  463. /*diagnose=*/true);
  464. // Prepare to perform deduction of the explicit parameters against their
  465. // arguments.
  466. // TODO: Also perform deduction for type of self.
  467. deduction.AddAll(params_id, arg_ids, /*needs_substitution=*/true);
  468. if (!deduction.Deduce() || !deduction.CheckDeductionIsComplete()) {
  469. return SemIR::SpecificId::None;
  470. }
  471. return deduction.MakeSpecific();
  472. }
  473. // Deduces the impl arguments to use in a use of a parameterized impl. Returns
  474. // `None` if deduction fails.
  475. auto DeduceImplArguments(Context& context, SemIR::LocId loc_id,
  476. const SemIR::Impl& impl, SemIR::ConstantId self_id,
  477. SemIR::ConstantId constraint_id) -> SemIR::SpecificId {
  478. DeductionContext deduction(context, loc_id, impl.generic_id,
  479. /*enclosing_specific_id=*/SemIR::SpecificId::None,
  480. /*diagnose=*/false);
  481. // Prepare to perform deduction of the type and interface.
  482. deduction.Add(impl.self_id, context.constant_values().GetInstId(self_id),
  483. /*needs_substitution=*/false);
  484. deduction.Add(impl.constraint_id,
  485. context.constant_values().GetInstId(constraint_id),
  486. /*needs_substitution=*/false);
  487. if (!deduction.Deduce() || !deduction.CheckDeductionIsComplete()) {
  488. return SemIR::SpecificId::None;
  489. }
  490. return deduction.MakeSpecific();
  491. }
  492. } // namespace Carbon::Check