Replace :! binding syntax with phase keywords and contextual defaults (#7479)

Implement the toolchain side of proposal #7254, removing the `:!`
binding
syntax for generic and template parameters in favor of the keywords
`generic`,
`template`, and `runtime` plus contextual defaults for phase.

For valid programs this is semantics-preserving: each binding resolves
to the
same phase, and produces the same SemIR, as it did under `:!`/`:`. The
parser
derives a binding's phase from its syntactic context plus any explicit
phase
keyword; new diagnostics and error recovery for misused keywords are
described
below.

Implementation details for each component:

- Lexer: remove the `:!` (`ColonExclaim`) token, move its virtual
parse-node
  budget onto `:`, and add the `generic` and `runtime` keywords.
- Parser: thread a `BindingContext` (`ExplicitParam`, `DeducedParam`, or
`CompileTimeEntityParam`) from declaration introducers down through
parameter
lists to each binding pattern, using a one-token lookahead to
distinguish a
name-qualifier parameter list from a declaration's own final list.
Parameters
of a compile-time entity (`class`, `interface`, `constraint`, `choice`,
`alias`, `export`, `namespace`) and deduced `[]` parameters default to
checked
generic; explicit function parameters and local bindings default to
runtime.
`HandleBindingPattern` resolves the phase from that context plus the
keyword: a
`generic` keyword needs no node of its own (the phase is carried by the
  binding's node kind), while a `runtime` keyword is preserved as a
`RuntimeBindingName` node so `check` can name it in a diagnostic. A
phase
keyword that is merely redundant with the contextual default is
diagnosed
  here, without invalidating the parse tree.
- Check: a phase keyword that is invalid for its context (for example
`runtime`
on a checked-generic parameter) is diagnosed here, and recovers by
building an
error binding that still introduces the name so that later uses of it do
not
  produce cascading errors.

The removed `:!` syntax is now rejected as an ordinary parse error.

The `form`/`:?`/`->?` ("extended types") portion of proposal #7254 is
left for a
separate change.

Assisted-by: Claude Code
This commit is contained in:
Chandler Carruth
2026-07-11 01:22:44 +00:00
committed by GitHub
parent bf106c3b4b
commit 8be274cf60
482 changed files with 16917 additions and 16226 deletions
+20 -20
View File
@@ -16,7 +16,7 @@
library "[[@TEST_NAME]]";
interface HasF(T:! type) {
interface HasF(T: type) {
fn F() -> T;
}
@@ -41,11 +41,11 @@ fn G(c: C) {
library "[[@TEST_NAME]]";
interface I(T:! type) {
interface I(T: type) {
fn F(self, t: T);
}
class X(U:! type) {
class X(U: type) {
extend impl as I(U) {
fn F(unused self, unused t: U) { }
}
@@ -183,9 +183,9 @@ class X(U:! type) {
// CHECK:STDOUT: %HasF.decl: %HasF.type.c96 = interface_decl @HasF [concrete = constants.%HasF.generic] {
// CHECK:STDOUT: %T.patt.loc4_17.1: %pattern_type.98f = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_17.2 (constants.%T.patt.d47)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc4_20.1: type = splice_block %.loc4_20.2 [concrete = type] {
// CHECK:STDOUT: %.loc4_19.1: type = splice_block %.loc4_19.2 [concrete = type] {
// CHECK:STDOUT: %.Self.frozen: %type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
// CHECK:STDOUT: %.loc4_20.2: type = type_literal type [concrete = type]
// CHECK:STDOUT: %.loc4_19.2: type = type_literal type [concrete = type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %T.loc4_17.2: type = symbolic_binding T, 0 [symbolic = %T.loc4_17.1 (constants.%T.67d)]
// CHECK:STDOUT: }
@@ -207,10 +207,10 @@ class X(U:! type) {
// CHECK:STDOUT:
// CHECK:STDOUT: !definition:
// CHECK:STDOUT: %HasF.type: type = facet_type <@HasF, @HasF(%T.loc4_17.1)> [symbolic = %HasF.type (constants.%HasF.type.daf)]
// CHECK:STDOUT: %Self.loc4_26.2: @HasF.%HasF.type (%HasF.type.daf) = symbolic_binding Self, 1 [symbolic = %Self.loc4_26.2 (constants.%Self.822)]
// CHECK:STDOUT: %Self.loc4_25.2: @HasF.%HasF.type (%HasF.type.daf) = symbolic_binding Self, 1 [symbolic = %Self.loc4_25.2 (constants.%Self.822)]
// CHECK:STDOUT:
// CHECK:STDOUT: interface {
// CHECK:STDOUT: %Self.loc4_26.1: @HasF.%HasF.type (%HasF.type.daf) = symbolic_binding Self, 1 [symbolic = %Self.loc4_26.2 (constants.%Self.822)]
// CHECK:STDOUT: %Self.loc4_25.1: @HasF.%HasF.type (%HasF.type.daf) = symbolic_binding Self, 1 [symbolic = %Self.loc4_25.2 (constants.%Self.822)]
// CHECK:STDOUT: %HasF.WithSelf.decl = interface_with_self_decl @HasF [concrete]
// CHECK:STDOUT:
// CHECK:STDOUT: !with Self:
@@ -226,7 +226,7 @@ class X(U:! type) {
// CHECK:STDOUT: %assoc0.loc5_14.1: @HasF.WithSelf.%HasF.assoc_type (%HasF.assoc_type.ddf) = assoc_entity element0, %HasF.WithSelf.F.decl [symbolic = %assoc0.loc5_14.2 (constants.%assoc0.e9a)]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = %Self.loc4_26.1
// CHECK:STDOUT: .Self = %Self.loc4_25.1
// CHECK:STDOUT: .T = <poisoned>
// CHECK:STDOUT: .T = <poisoned>
// CHECK:STDOUT: .F = @HasF.WithSelf.%assoc0.loc5_14.1
@@ -287,7 +287,7 @@ class X(U:! type) {
// CHECK:STDOUT: extend @C.as.HasF.impl.%HasF.type
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: generic fn @HasF.WithSelf.F(@HasF.%T.loc4_17.2: type, @HasF.%Self.loc4_26.1: @HasF.%HasF.type (%HasF.type.daf)) {
// CHECK:STDOUT: generic fn @HasF.WithSelf.F(@HasF.%T.loc4_17.2: type, @HasF.%Self.loc4_25.1: @HasF.%HasF.type (%HasF.type.daf)) {
// CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic = %T (constants.%T.67d)]
// CHECK:STDOUT: %.loc5_13.1: Core.Form = init_form %T [symbolic = %.loc5_13.1 (constants.%.184347.1)]
// CHECK:STDOUT: %pattern_type: type = pattern_type %T [symbolic = %pattern_type (constants.%pattern_type.51d1c4.1)]
@@ -411,7 +411,7 @@ class X(U:! type) {
// CHECK:STDOUT:
// CHECK:STDOUT: !definition:
// CHECK:STDOUT: %HasF.type => constants.%HasF.type.9e1
// CHECK:STDOUT: %Self.loc4_26.2 => constants.%Self.ef3
// CHECK:STDOUT: %Self.loc4_25.2 => constants.%Self.ef3
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @HasF.WithSelf(constants.%Param, constants.%Self.822) {
@@ -525,18 +525,18 @@ class X(U:! type) {
// CHECK:STDOUT: %I.decl: %I.type.335 = interface_decl @I [concrete = constants.%I.generic] {
// CHECK:STDOUT: %T.patt.loc4_14.1: %pattern_type.98f = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc4_14.2 (constants.%T.patt)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc4_17.1: type = splice_block %.loc4_17.2 [concrete = type] {
// CHECK:STDOUT: %.loc4_16.1: type = splice_block %.loc4_16.2 [concrete = type] {
// CHECK:STDOUT: %.Self.frozen: %type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
// CHECK:STDOUT: %.loc4_17.2: type = type_literal type [concrete = type]
// CHECK:STDOUT: %.loc4_16.2: type = type_literal type [concrete = type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %T.loc4_14.2: type = symbolic_binding T, 0 [symbolic = %T.loc4_14.1 (constants.%T)]
// CHECK:STDOUT: }
// CHECK:STDOUT: %X.decl: %X.type = class_decl @X [concrete = constants.%X.generic] {
// CHECK:STDOUT: %U.patt.loc8_10.1: %pattern_type.98f = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc8_10.2 (constants.%U.patt)]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %.loc8_13.1: type = splice_block %.loc8_13.2 [concrete = type] {
// CHECK:STDOUT: %.loc8_12.1: type = splice_block %.loc8_12.2 [concrete = type] {
// CHECK:STDOUT: %.Self.frozen: %type = symbolic_binding .Self [symbolic_self = constants.%.Self.frozen]
// CHECK:STDOUT: %.loc8_13.2: type = type_literal type [concrete = type]
// CHECK:STDOUT: %.loc8_12.2: type = type_literal type [concrete = type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %U.loc8_10.2: type = symbolic_binding U, 0 [symbolic = %U.loc8_10.1 (constants.%U)]
// CHECK:STDOUT: }
@@ -548,10 +548,10 @@ class X(U:! type) {
// CHECK:STDOUT:
// CHECK:STDOUT: !definition:
// CHECK:STDOUT: %I.type: type = facet_type <@I, @I(%T.loc4_14.1)> [symbolic = %I.type (constants.%I.type.3fe556.1)]
// CHECK:STDOUT: %Self.loc4_23.2: @I.%I.type (%I.type.3fe556.1) = symbolic_binding Self, 1 [symbolic = %Self.loc4_23.2 (constants.%Self.1916c4.1)]
// CHECK:STDOUT: %Self.loc4_22.2: @I.%I.type (%I.type.3fe556.1) = symbolic_binding Self, 1 [symbolic = %Self.loc4_22.2 (constants.%Self.1916c4.1)]
// CHECK:STDOUT:
// CHECK:STDOUT: interface {
// CHECK:STDOUT: %Self.loc4_23.1: @I.%I.type (%I.type.3fe556.1) = symbolic_binding Self, 1 [symbolic = %Self.loc4_23.2 (constants.%Self.1916c4.1)]
// CHECK:STDOUT: %Self.loc4_22.1: @I.%I.type (%I.type.3fe556.1) = symbolic_binding Self, 1 [symbolic = %Self.loc4_22.2 (constants.%Self.1916c4.1)]
// CHECK:STDOUT: %I.WithSelf.decl = interface_with_self_decl @I [concrete]
// CHECK:STDOUT:
// CHECK:STDOUT: !with Self:
@@ -563,7 +563,7 @@ class X(U:! type) {
// CHECK:STDOUT: } {
// CHECK:STDOUT: %self.param: @I.WithSelf.F.%Self.as_type.loc5_8.1 (%Self.as_type) = value_param call_param0
// CHECK:STDOUT: %.loc5_8.1: type = splice_block %.loc5_8.3 [symbolic = %Self.as_type.loc5_8.1 (constants.%Self.as_type)] {
// CHECK:STDOUT: %.loc5_8.2: @I.WithSelf.F.%I.type (%I.type.3fe556.1) = specific_constant @I.%Self.loc4_23.1, @I(constants.%T) [symbolic = %Self (constants.%Self.1916c4.1)]
// CHECK:STDOUT: %.loc5_8.2: @I.WithSelf.F.%I.type (%I.type.3fe556.1) = specific_constant @I.%Self.loc4_22.1, @I(constants.%T) [symbolic = %Self (constants.%Self.1916c4.1)]
// CHECK:STDOUT: %Self.ref: @I.WithSelf.F.%I.type (%I.type.3fe556.1) = name_ref Self, %.loc5_8.2 [symbolic = %Self (constants.%Self.1916c4.1)]
// CHECK:STDOUT: %Self.as_type.loc5_8.2: type = facet_access_type %Self.ref [symbolic = %Self.as_type.loc5_8.1 (constants.%Self.as_type)]
// CHECK:STDOUT: %.loc5_8.3: type = converted %Self.ref, %Self.as_type.loc5_8.2 [symbolic = %Self.as_type.loc5_8.1 (constants.%Self.as_type)]
@@ -576,7 +576,7 @@ class X(U:! type) {
// CHECK:STDOUT: %assoc0.loc5_19.1: @I.WithSelf.%I.assoc_type (%I.assoc_type.b71f2b.1) = assoc_entity element0, %I.WithSelf.F.decl [symbolic = %assoc0.loc5_19.2 (constants.%assoc0.13b5f8.1)]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = %Self.loc4_23.1
// CHECK:STDOUT: .Self = %Self.loc4_22.1
// CHECK:STDOUT: .T = <poisoned>
// CHECK:STDOUT: .T = <poisoned>
// CHECK:STDOUT: .F = @I.WithSelf.%assoc0.loc5_19.1
@@ -655,7 +655,7 @@ class X(U:! type) {
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: generic fn @I.WithSelf.F(@I.%T.loc4_14.2: type, @I.%Self.loc4_23.1: @I.%I.type (%I.type.3fe556.1)) {
// CHECK:STDOUT: generic fn @I.WithSelf.F(@I.%T.loc4_14.2: type, @I.%Self.loc4_22.1: @I.%I.type (%I.type.3fe556.1)) {
// CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic = %T (constants.%T)]
// CHECK:STDOUT: %I.type: type = facet_type <@I, @I(%T)> [symbolic = %I.type (constants.%I.type.3fe556.1)]
// CHECK:STDOUT: %Self: @I.WithSelf.F.%I.type (%I.type.3fe556.1) = symbolic_binding Self, 1 [symbolic = %Self (constants.%Self.1916c4.1)]
@@ -727,7 +727,7 @@ class X(U:! type) {
// CHECK:STDOUT:
// CHECK:STDOUT: !definition:
// CHECK:STDOUT: %I.type => constants.%I.type.3fe556.2
// CHECK:STDOUT: %Self.loc4_23.2 => constants.%Self.1916c4.2
// CHECK:STDOUT: %Self.loc4_22.2 => constants.%Self.1916c4.2
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: specific @X.as.I.impl(constants.%U) {