Add the .Self name for the type expression of a compile time binding (#5937)

We add a virtual node (`CompileTimeBindingPatternStart`) as the first
child of `CompileTimeBindingPattern` which holds the identifier
underneath it, so that it is checked just before the type expression of
the `CompileTimeBindingPattern`. When we reach this virtual node during
check, we add `.Self` as a name in the current scope, and when we reach
`CompileTimeBindingPattern` we remove it from scope, which ensures it's
present during only the checking of the type expression for the compile
time pattern.

At the moment the `.Self` has a different type (it's a `TypeType`) than
other `.Self` in the facet type (which are a single `FacetType`), but
the intention is to immediately substitute it out of the facet type
entirely, replacing it with a reference to the compile time binding (a
`BindSymbolicName`) itself. A TODO has been added for this.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Dana Jansens
2025-08-12 16:27:07 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 2e509e9103
commit 4b0e2b03b6
172 changed files with 2381 additions and 1034 deletions
+14 -11
View File
@@ -41,7 +41,8 @@ fn F() {
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'I'},
// CHECK:STDOUT: {kind: 'InterfaceDefinitionStart', text: '{', subtree_size: 3},
// CHECK:STDOUT: {kind: 'LetIntroducer', text: 'let'},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'T'},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'T'},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 2},
// CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'Foo'},
@@ -49,11 +50,12 @@ fn F() {
// CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Bar'},
// CHECK:STDOUT: {kind: 'RequirementImpls', text: 'impls', subtree_size: 4},
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 7},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 9},
// CHECK:STDOUT: {kind: 'LetDecl', text: ';', subtree_size: 11},
// CHECK:STDOUT: {kind: 'InterfaceDefinition', text: '}', subtree_size: 15},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 10},
// CHECK:STDOUT: {kind: 'LetDecl', text: ';', subtree_size: 12},
// CHECK:STDOUT: {kind: 'InterfaceDefinition', text: '}', subtree_size: 16},
// CHECK:STDOUT: {kind: 'LetIntroducer', text: 'let'},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'T'},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'T'},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 2},
// CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'U'},
@@ -62,15 +64,16 @@ fn F() {
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'RequirementEqual', text: '=', subtree_size: 5},
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 8},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 10},
// CHECK:STDOUT: {kind: 'LetDecl', text: ';', subtree_size: 12},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 11},
// CHECK:STDOUT: {kind: 'LetDecl', text: ';', subtree_size: 13},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'F'},
// CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
// CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
// CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 5},
// CHECK:STDOUT: {kind: 'LetIntroducer', text: 'let'},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'U'},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'U'},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 2},
// CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
// CHECK:STDOUT: {kind: 'WhereOperand', text: 'where', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'W'},
@@ -79,8 +82,8 @@ fn F() {
// CHECK:STDOUT: {kind: 'DesignatorExpr', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'RequirementEqualEqual', text: '==', subtree_size: 5},
// CHECK:STDOUT: {kind: 'WhereExpr', text: 'where', subtree_size: 8},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 10},
// CHECK:STDOUT: {kind: 'LetDecl', text: ';', subtree_size: 12},
// CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 18},
// CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 11},
// CHECK:STDOUT: {kind: 'LetDecl', text: ';', subtree_size: 13},
// CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 19},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]