mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Compute specific constant values. (#4128)
When forming a specific (previously called a generic instance), evaluate the eval block of the generic to determine the values of any constants used in that specific. The majority of the work here is updating eval.cpp so that it can use the results of prior evaluations in the same block when computing later values. Include the computed results in the formatted SemIR output. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
be94782eda
commit
efea072be3
+33
-9
@@ -73,13 +73,13 @@ var c_bad: C({.a = 3, .b = 4}) = F();
|
||||
// CHECK:STDOUT: %S: %.11 = bind_symbolic_name S 0 [symbolic]
|
||||
// CHECK:STDOUT: %C.type: type = generic_class_type @C [template]
|
||||
// CHECK:STDOUT: %C.1: %C.type = struct_value () [template]
|
||||
// CHECK:STDOUT: %C.2: type = class_type @C, (%S) [symbolic]
|
||||
// CHECK:STDOUT: %C.2: type = class_type @C, file.%C.decl(%S) [symbolic]
|
||||
// CHECK:STDOUT: %.12: type = struct_type {} [template]
|
||||
// CHECK:STDOUT: %.13: i32 = int_literal 1 [template]
|
||||
// CHECK:STDOUT: %.14: i32 = int_literal 2 [template]
|
||||
// CHECK:STDOUT: %.15: type = ptr_type %.11 [template]
|
||||
// CHECK:STDOUT: %struct.4: %.11 = struct_value (%.13, %.14) [template]
|
||||
// CHECK:STDOUT: %C.3: type = class_type @C, (%struct.4) [template]
|
||||
// CHECK:STDOUT: %C.3: type = class_type @C, file.%C.decl(%struct.4) [template]
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F [template]
|
||||
// CHECK:STDOUT: %F: %F.type = struct_value () [template]
|
||||
// CHECK:STDOUT: }
|
||||
@@ -189,6 +189,16 @@ var c_bad: C({.a = 3, .b = 4}) = F();
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific file.%C.decl(constants.%S) {
|
||||
// CHECK:STDOUT: declaration:
|
||||
// CHECK:STDOUT: file.%S.loc8_9.2 => constants.%S
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific file.%C.decl(constants.%struct.4) {
|
||||
// CHECK:STDOUT: declaration:
|
||||
// CHECK:STDOUT: file.%S.loc8_9.2 => constants.%struct.4
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- implicit.impl.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
@@ -208,12 +218,12 @@ var c_bad: C({.a = 3, .b = 4}) = F();
|
||||
// CHECK:STDOUT: %.10: type = struct_type {} [template]
|
||||
// CHECK:STDOUT: %.11: type = struct_type {.a: i32, .b: i32} [template]
|
||||
// CHECK:STDOUT: %S: %.11 = bind_symbolic_name S 0, <unexpected instref inst+103> [symbolic]
|
||||
// CHECK:STDOUT: %C.2: type = class_type @C, (%S) [symbolic]
|
||||
// CHECK:STDOUT: %C.2: type = class_type @C, <invalid>(%S) [symbolic]
|
||||
// CHECK:STDOUT: %.12: i32 = int_literal 1 [template]
|
||||
// CHECK:STDOUT: %.13: i32 = int_literal 2 [template]
|
||||
// CHECK:STDOUT: %.14: type = ptr_type %.11 [template]
|
||||
// CHECK:STDOUT: %struct: %.11 = struct_value (%.12, %.13) [template]
|
||||
// CHECK:STDOUT: %C.3: type = class_type @C, (%struct) [template]
|
||||
// CHECK:STDOUT: %C.3: type = class_type @C, <invalid>(%struct) [template]
|
||||
// CHECK:STDOUT: %.15: type = ptr_type %.10 [template]
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F [template]
|
||||
// CHECK:STDOUT: %F: %F.type = struct_value () [template]
|
||||
@@ -327,6 +337,10 @@ var c_bad: C({.a = 3, .b = 4}) = F();
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific <invalid>(constants.%S);
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific <invalid>(constants.%struct);
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- fail_bad_type.impl.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
@@ -336,13 +350,13 @@ var c_bad: C({.a = 3, .b = 4}) = F();
|
||||
// CHECK:STDOUT: %.2: type = struct_type {} [template]
|
||||
// CHECK:STDOUT: %.3: type = struct_type {.a: i32, .b: i32} [template]
|
||||
// CHECK:STDOUT: %S: %.3 = bind_symbolic_name S 0, <unexpected instref inst+21> [symbolic]
|
||||
// CHECK:STDOUT: %C.2: type = class_type @C, (%S) [symbolic]
|
||||
// CHECK:STDOUT: %C.2: type = class_type @C, <invalid>(%S) [symbolic]
|
||||
// CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
|
||||
// CHECK:STDOUT: %.5: i32 = int_literal 2 [template]
|
||||
// CHECK:STDOUT: %.6: type = struct_type {.c: i32, .d: i32} [template]
|
||||
// CHECK:STDOUT: %.7: type = ptr_type %.3 [template]
|
||||
// CHECK:STDOUT: %struct: %.3 = struct_value (%.4, %.5) [template]
|
||||
// CHECK:STDOUT: %C.3: type = class_type @C, (%struct) [template]
|
||||
// CHECK:STDOUT: %C.3: type = class_type @C, <invalid>(%struct) [template]
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F [template]
|
||||
// CHECK:STDOUT: %F: %F.type = struct_value () [template]
|
||||
// CHECK:STDOUT: %.8: type = ptr_type %.2 [template]
|
||||
@@ -396,6 +410,10 @@ var c_bad: C({.a = 3, .b = 4}) = F();
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific <invalid>(constants.%S);
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific <invalid>(constants.%struct);
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- fail_bad_value.impl.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
@@ -405,17 +423,17 @@ var c_bad: C({.a = 3, .b = 4}) = F();
|
||||
// CHECK:STDOUT: %.2: type = struct_type {} [template]
|
||||
// CHECK:STDOUT: %.3: type = struct_type {.a: i32, .b: i32} [template]
|
||||
// CHECK:STDOUT: %S: %.3 = bind_symbolic_name S 0, <unexpected instref inst+21> [symbolic]
|
||||
// CHECK:STDOUT: %C.2: type = class_type @C, (%S) [symbolic]
|
||||
// CHECK:STDOUT: %C.2: type = class_type @C, <invalid>(%S) [symbolic]
|
||||
// CHECK:STDOUT: %.4: i32 = int_literal 3 [template]
|
||||
// CHECK:STDOUT: %.5: i32 = int_literal 4 [template]
|
||||
// CHECK:STDOUT: %.6: type = ptr_type %.3 [template]
|
||||
// CHECK:STDOUT: %struct.1: %.3 = struct_value (%.4, %.5) [template]
|
||||
// CHECK:STDOUT: %C.3: type = class_type @C, (%struct.1) [template]
|
||||
// CHECK:STDOUT: %C.3: type = class_type @C, <invalid>(%struct.1) [template]
|
||||
// CHECK:STDOUT: %.7: type = ptr_type %.2 [template]
|
||||
// CHECK:STDOUT: %.8: i32 = int_literal 2 [template]
|
||||
// CHECK:STDOUT: %.9: i32 = int_literal 1 [template]
|
||||
// CHECK:STDOUT: %struct.2: %.3 = struct_value (%.9, %.8) [template]
|
||||
// CHECK:STDOUT: %C.4: type = class_type @C, (%struct.2) [template]
|
||||
// CHECK:STDOUT: %C.4: type = class_type @C, <invalid>(%struct.2) [template]
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F [template]
|
||||
// CHECK:STDOUT: %F: %F.type = struct_value () [template]
|
||||
// CHECK:STDOUT: }
|
||||
@@ -470,3 +488,9 @@ var c_bad: C({.a = 3, .b = 4}) = F();
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific <invalid>(constants.%S);
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific <invalid>(constants.%struct.1);
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific <invalid>(constants.%struct.2);
|
||||
// CHECK:STDOUT:
|
||||
|
||||
Reference in New Issue
Block a user