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.
This commit is contained in:
Richard Smith
2024-04-23 16:15:47 +00:00
committed by GitHub
parent 76a5cf5f50
commit e0b8728263
106 changed files with 1240 additions and 706 deletions
+7 -1
View File
@@ -5,6 +5,7 @@
#include "toolchain/check/context.h"
#include "toolchain/check/convert.h"
#include "toolchain/check/return.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::Check {
@@ -25,7 +26,12 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
// scopes, but right now we don't support qualified names here.
auto bind_name_id = context.bind_names().Add(
{.name_id = name_id,
.enclosing_scope_id = context.scope_stack().PeekNameScopeId()});
.enclosing_scope_id = context.scope_stack().PeekNameScopeId(),
// TODO: Don't allocate a compile-time binding index for an associated
// constant declaration.
.bind_index = is_generic
? context.scope_stack().AddCompileTimeBinding()
: SemIR::CompileTimeBindIndex::Invalid});
if (is_generic) {
// TODO: Create a `BindTemplateName` instead inside a `template` pattern.
return {name_node,