mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Split evaluation up into one function per instruction kind (#5008)
Replace the large and growing `TryEvalInstInContext` function with one function per kind. While we still have special-case handling for a small number of instruction kinds, most instructions are now handled either fully automatically or use a common codepath that evaluates the instruction operands and then performs an eval-context-independent evaluation of the instruction. To support this, `InstConstantKind` is expanded to describe more fine-grained details about how each kind of instruction interacts with constant evaluation. Also, the operand kinds of instructions become slightly more fine-grained: we now distinguish between operands that describe the destination of an initializing expression (`DestInstId`) from other `InstId` operands, because `DestInstId` operands need different treatment during constant evaluation. In particular, an initializing expression can have a constant value even if its destination is non-constant or has not yet been set, because evaluation of an initializing expression doesn't include the store to the destination. Some minor test changes: - We now more consistently propagate errors into the results of constant evaluation, so more instructions that depend on errors have a constant value of `<error>`. - Diagnostic location for invalid array types now point at the whole array type rather than the array index expression, because `EvalConstantinst` doesn't have access to the original expression. - Diagnostic for failed `RequireCompleteType` doesn't print the original type any more because `EvalConstantInst` doesn't have access to the original expression. As a follow-up, some of this -- in particular, the `EvalConstantInst` overloads -- will be moved to a separate file, in an effort to split the overall constant evaluation machinery apart from the logic to evaluate each individual kind of instruction.
This commit is contained in:
@@ -41,7 +41,7 @@ fn F(n: i32, a: array(i32, n)*);
|
||||
// CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
|
||||
// CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, runtime_param0
|
||||
// CHECK:STDOUT: %a.patt: <error> = binding_pattern a
|
||||
// CHECK:STDOUT: %a.param_patt: <error> = value_param_pattern %a.patt, runtime_param1
|
||||
// CHECK:STDOUT: %a.param_patt: <error> = value_param_pattern %a.patt, runtime_param1 [concrete = <error>]
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: %n.param: %i32 = value_param runtime_param0
|
||||
// CHECK:STDOUT: %.loc15_9: type = splice_block %i32.loc15_9 [concrete = constants.%i32] {
|
||||
|
||||
Reference in New Issue
Block a user