mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:30:14 +01:00
This fake generic was used for two reasons: - The declaration name stack assumes that each declaration name is processed within a generic scope. This is important if the name might have generic parameters, which are always parsed even for declarations that disallow them in check. - Out-of-line redeclarations of generic entities produce instructions with symbolic constant values in non-generic scopes. The former case is addressed by pushing a generic each time we start a declaration name, even if we will reject generic parameters later. The latter case is worked around for now by not building a symbolic constant type or value for instructions that appear outside of any generic, and will be addressed more completely by #5310 and follow-ups.
37 lines
1.2 KiB
C++
37 lines
1.2 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 { dependent_insts_stack_.PushArray(); }
|
|
|
|
auto GenericRegionStack::Pop() -> void { dependent_insts_stack_.PopArray(); }
|
|
|
|
auto GenericRegionStack::AddDependentInst(DependentInst inst) -> void {
|
|
if (dependent_insts_stack_.empty()) {
|
|
// If we don't have a generic region here, leave the dependent instruction
|
|
// unattached. This happens for out-of-line redeclarations of members of
|
|
// dependent scopes:
|
|
//
|
|
// class A(T:! type) {
|
|
// fn F();
|
|
// }
|
|
// // Has generic type and constant value, but no generic region.
|
|
// fn A(T:! type).F() {}
|
|
//
|
|
// TODO: Use a different instruction kind for out-of-line definitions and
|
|
// CHECK this doesn't happen.
|
|
return;
|
|
}
|
|
dependent_insts_stack_.AppendToTop(inst);
|
|
}
|
|
|
|
auto GenericRegionStack::PeekDependentInsts() -> llvm::ArrayRef<DependentInst> {
|
|
return dependent_insts_stack_.PeekArray();
|
|
}
|
|
|
|
} // namespace Carbon::Check
|