mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Create an array stack type for a shared use-case (#4100)
Based on discussion around the region handling in generic_region_stack, create a generic structure for the stack-of-vectors support. I also want to add this to InstBlockStack, but that's a little more complex due to GlobalInit, so cutting a PR here to check with review. My work here is how I noticed #4099; I want to be sure that I'm correct about the issue, but it's the difference between being able to use PeekArray or not. Note in scope_stack.h, I believe we could remove next_compile_time_index and make it just based on elements_size(). However, I want to verify with you before I make further changes there. --------- Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
co-authored by
Chandler Carruth
parent
e71e6ca07f
commit
d437e4bffe
@@ -6,27 +6,16 @@
|
||||
|
||||
namespace Carbon::Check {
|
||||
|
||||
auto GenericRegionStack::Push() -> void {
|
||||
regions_.push_back(
|
||||
{.first_dependent_inst = static_cast<int32_t>(dependent_insts_.size())});
|
||||
}
|
||||
auto GenericRegionStack::Push() -> void { dependent_insts_stack_.PushArray(); }
|
||||
|
||||
auto GenericRegionStack::Pop() -> void {
|
||||
auto region = regions_.pop_back_val();
|
||||
dependent_insts_.truncate(region.first_dependent_inst);
|
||||
}
|
||||
auto GenericRegionStack::Pop() -> void { dependent_insts_stack_.PopArray(); }
|
||||
|
||||
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);
|
||||
dependent_insts_stack_.AppendToTop(inst);
|
||||
}
|
||||
|
||||
auto GenericRegionStack::PeekDependentInsts() -> llvm::ArrayRef<DependentInst> {
|
||||
CARBON_CHECK(!regions_.empty());
|
||||
return llvm::ArrayRef(dependent_insts_)
|
||||
.slice(regions_.back().first_dependent_inst);
|
||||
return dependent_insts_stack_.PeekArray();
|
||||
}
|
||||
|
||||
} // namespace Carbon::Check
|
||||
|
||||
Reference in New Issue
Block a user