Fix canonicalization and simplify default value patterns. (#7837)

Removes support for unspecified default values. Fixes canonicalization
of the `DefaultValuePattern` instruction by making them immutable after
they are issued, and by removing the `DefaultValueId` operand which
wasn't being canonicalized.
This commit is contained in:
Lucile Rose Nihlen
2026-09-25 22:59:55 +00:00
committed by GitHub
parent 3fad8b9eab
commit 1579d4ec7e
50 changed files with 3878 additions and 4325 deletions
+2 -16
View File
@@ -10,10 +10,8 @@
fn F(x: i32, y: i32 = 0);
fn G((x: i32, y: i32) = (1, 2));
fn H(unused x: i32 = 25);
fn H(unused x: i32 = _);
var b: auto = fn (x: i32 = 0) => x;
// Can be used in def to avoid repeating values defined in decl.
fn I(x: i32 = _);
// CHECK:STDOUT: - filename: default_values.carbon
// CHECK:STDOUT: ╭─FileStart ''
@@ -66,7 +64,7 @@ fn I(x: i32 = _);
// CHECK:STDOUT: │ │ │ ╭─LetBindingPattern ':'
// CHECK:STDOUT: │ │ │ ╭─UnusedPattern 'unused'
// CHECK:STDOUT: │ │ │ ├─DefaultValueExprStart '='
// CHECK:STDOUT: │ │ │ ├─IntLiteral '25'
// CHECK:STDOUT: │ │ │ ├─DefaultValueUnspecified '_'
// CHECK:STDOUT: │ │ ├─DefaultValuePattern '='
// CHECK:STDOUT: │ ├─ExplicitParamList ')'
// CHECK:STDOUT: ├─FunctionDecl ';'
@@ -91,17 +89,5 @@ fn I(x: i32 = _);
// CHECK:STDOUT: │ │ ├─IdentifierNameExpr 'x'
// CHECK:STDOUT: │ ├─Lambda 'fn'
// CHECK:STDOUT: ├─VariableDecl ';'
// CHECK:STDOUT: │ ╭─FunctionIntroducer 'fn'
// CHECK:STDOUT: │ ├─IdentifierNameMaybeBeforeSignature 'I'
// CHECK:STDOUT: │ │ ╭─ExplicitParamListStart '('
// CHECK:STDOUT: │ │ │ ╭─IdentifierNameNotBeforeSignature 'x'
// CHECK:STDOUT: │ │ │ ├─BindingPatternTypeStart ':'
// CHECK:STDOUT: │ │ │ ├─IntTypeLiteral 'i32'
// CHECK:STDOUT: │ │ │ ╭─LetBindingPattern ':'
// CHECK:STDOUT: │ │ │ ├─DefaultValueExprStart '='
// CHECK:STDOUT: │ │ │ ├─DefaultValueUnspecified '_'
// CHECK:STDOUT: │ │ ├─DefaultValuePattern '='
// CHECK:STDOUT: │ ├─ExplicitParamList ')'
// CHECK:STDOUT: ├─FunctionDecl ';'
// CHECK:STDOUT: ├─FileEnd ''
// CHECK:STDOUT: (root)