Files
carbon-lang/toolchain/check/subst.h
T
Richard Smith e0b8728263 Allocate de Bruijn levels to symbolic bindings. (#3906)
Use a level comparison during substitution to determine whether we're
substituting a particular binding. Evaluate symbolic bindings with the
same name and the same level to the same symbolic constant, for example
across redeclarations of a generic function.
2024-04-23 16:15:47 +00:00

36 lines
1.3 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_CHECK_SUBST_H_
#define CARBON_TOOLCHAIN_CHECK_SUBST_H_
#include "toolchain/check/context.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::Check {
// A substitution that is being performed.
struct Substitution {
// The index of a `BindSymbolicName` instruction that is being replaced.
SemIR::CompileTimeBindIndex bind_id;
// The replacement constant value to substitute.
SemIR::ConstantId replacement_id;
};
using Substitutions = llvm::ArrayRef<Substitution>;
// Replaces the `BindSymbolicName` instruction `bind_id` with `replacement_id`
// throughout the constant `const_id`, and returns the substituted value.
auto SubstConstant(Context& context, SemIR::ConstantId const_id,
Substitutions substitutions) -> SemIR::ConstantId;
// Replaces the `BindSymbolicName` instruction `bind_id` with `replacement_id`
// throughout the type `type_id`, and returns the substituted value.
auto SubstType(Context& context, SemIR::TypeId type_id,
Substitutions substitutions) -> SemIR::TypeId;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_SUBST_H_