Files
carbon-lang/toolchain/check/generic_region_stack.cpp
T
Richard Smith fa11050961 Track a list of dependent instructions created within a generic (#4092)
When checking a declaration or definition of a generic, track a list of
created instructions that depend on the generic's parameters in some
way, along with information on how they depend on the parameters. This
will eventually be used to determine what information we need to compute
when creating instances of the generic, but for now we're just building
the list.

Information is tracked separately for the declaration region and the
definition region of the generic, because in general these may be first
provided in separate declarations, and they should be substituted into
at different times.
2024-07-01 20:33:44 +00:00

33 lines
1.0 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
#include "toolchain/check/generic_region_stack.h"
namespace Carbon::Check {
auto GenericRegionStack::Push() -> void {
regions_.push_back(
{.first_dependent_inst = static_cast<int32_t>(dependent_insts_.size())});
}
auto GenericRegionStack::Pop() -> void {
auto region = regions_.pop_back_val();
dependent_insts_.truncate(region.first_dependent_inst);
}
auto GenericRegionStack::AddDependentInst(DependentInst inst) -> void {
CARBON_CHECK(!regions_.empty())
<< "Formed a dependent instruction while not in a generic region.";
CARBON_CHECK(inst.kind != DependencyKind::None);
dependent_insts_.push_back(inst);
}
auto GenericRegionStack::PeekDependentInsts() -> llvm::ArrayRef<DependentInst> {
CARBON_CHECK(!regions_.empty());
return llvm::ArrayRef(dependent_insts_)
.slice(regions_.back().first_dependent_inst);
}
} // namespace Carbon::Check