Represent integer literals as IntLiteral not as i32. (#4532)

When an `IntLiteral` appears as an operand of an `if` expression,
convert it to `i32` for now, so that we don't reject things like `if
cond then 1 else 2` due to having a non-constant value of type
`IntLiteral`.

For tuple indexing expressions such as `(a, b).0`, convert the index to
type `IntLiteral`, not to type `i32`. This isn't strictly necessary to
do in this PR, but avoids the need to provide an `IntLiteral` -> `i32`
implicit conversion for `no_prelude` tests using this syntax.
This commit is contained in:
Richard Smith
2024-11-15 23:24:15 +00:00
committed by GitHub
parent 980ce6b25a
commit bc395eb889
249 changed files with 19281 additions and 6668 deletions
+72 -48
View File
@@ -21,21 +21,26 @@ fn G() {
// CHECK:STDOUT: %G: %G.type = struct_value () [template]
// CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
// CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
// CHECK:STDOUT: %.1: i32 = int_value 3 [template]
// CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(Core.IntLiteral) [template]
// CHECK:STDOUT: %.1: Core.IntLiteral = int_value 3 [template]
// CHECK:STDOUT: %.2: type = array_type %.1, i32 [template]
// CHECK:STDOUT: %.4: Core.IntLiteral = int_value 1 [template]
// CHECK:STDOUT: %.5: Core.IntLiteral = int_value 2 [template]
// CHECK:STDOUT: %tuple.type.1: type = tuple_type (Core.IntLiteral, Core.IntLiteral, Core.IntLiteral) [template]
// CHECK:STDOUT: %.6: i32 = int_value 0 [template]
// CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(i32) [template]
// CHECK:STDOUT: %Convert.type.15: type = fn_type @Convert.11 [template]
// CHECK:STDOUT: %Convert.15: %Convert.type.15 = struct_value () [template]
// CHECK:STDOUT: %.25: <witness> = interface_witness (%Convert.15) [template]
// CHECK:STDOUT: %.26: <bound method> = bound_method %.1, %Convert.15 [template]
// CHECK:STDOUT: %.27: Core.IntLiteral = int_value 3 [template]
// CHECK:STDOUT: %.28: type = array_type %.27, i32 [template]
// CHECK:STDOUT: %.30: i32 = int_value 1 [template]
// CHECK:STDOUT: %.31: i32 = int_value 2 [template]
// CHECK:STDOUT: %tuple.type.1: type = tuple_type (i32, i32, i32) [template]
// CHECK:STDOUT: %.32: i32 = int_value 0 [template]
// CHECK:STDOUT: %array: %.28 = tuple_value (%.30, %.31, %.1) [template]
// CHECK:STDOUT: %.30: <witness> = interface_witness (%Convert.15) [template]
// CHECK:STDOUT: %.31: <bound method> = bound_method %.4, %Convert.15 [template]
// CHECK:STDOUT: %.32: i32 = int_value 1 [template]
// CHECK:STDOUT: %.33: <bound method> = bound_method %.5, %Convert.15 [template]
// CHECK:STDOUT: %.34: i32 = int_value 2 [template]
// CHECK:STDOUT: %.35: <bound method> = bound_method %.1, %Convert.15 [template]
// CHECK:STDOUT: %.36: i32 = int_value 3 [template]
// CHECK:STDOUT: %array: %.2 = tuple_value (%.32, %.34, %.36) [template]
// CHECK:STDOUT: %tuple.type.2: type = tuple_type (type, type, type) [template]
// CHECK:STDOUT: %tuple: %tuple.type.1 = tuple_value (%.30, %.31, %.1) [template]
// CHECK:STDOUT: %tuple.type.3: type = tuple_type (i32, i32, i32) [template]
// CHECK:STDOUT: %tuple: %tuple.type.3 = tuple_value (%.32, %.34, %.36) [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
@@ -59,32 +64,39 @@ fn G() {
// CHECK:STDOUT: fn @G() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
// CHECK:STDOUT: %.loc13_16.1: i32 = int_value 3 [template = constants.%.1]
// CHECK:STDOUT: %.loc13_16: Core.IntLiteral = int_value 3 [template = constants.%.1]
// CHECK:STDOUT: %.loc13_11.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
// CHECK:STDOUT: %.loc13_11.2: type = converted %int.make_type_32.loc13, %.loc13_11.1 [template = i32]
// CHECK:STDOUT: %.loc13_16.2: %Convert.type.2 = interface_witness_access constants.%.25, element0 [template = constants.%Convert.15]
// CHECK:STDOUT: %.loc13_16.3: <bound method> = bound_method %.loc13_16.1, %.loc13_16.2 [template = constants.%.26]
// CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %.loc13_16.3(%.loc13_16.1) [template = constants.%.27]
// CHECK:STDOUT: %.loc13_16.4: Core.IntLiteral = value_of_initializer %int.convert_checked [template = constants.%.27]
// CHECK:STDOUT: %.loc13_16.5: Core.IntLiteral = converted %.loc13_16.1, %.loc13_16.4 [template = constants.%.27]
// CHECK:STDOUT: %.loc13_17: type = array_type %.loc13_16.5, i32 [template = constants.%.28]
// CHECK:STDOUT: %a.var: ref %.28 = var a
// CHECK:STDOUT: %a: ref %.28 = bind_name a, %a.var
// CHECK:STDOUT: %.loc13_22: i32 = int_value 1 [template = constants.%.30]
// CHECK:STDOUT: %.loc13_25: i32 = int_value 2 [template = constants.%.31]
// CHECK:STDOUT: %.loc13_28: i32 = int_value 3 [template = constants.%.1]
// CHECK:STDOUT: %.loc13_17: type = array_type %.loc13_16, i32 [template = constants.%.2]
// CHECK:STDOUT: %a.var: ref %.2 = var a
// CHECK:STDOUT: %a: ref %.2 = bind_name a, %a.var
// CHECK:STDOUT: %.loc13_22: Core.IntLiteral = int_value 1 [template = constants.%.4]
// CHECK:STDOUT: %.loc13_25: Core.IntLiteral = int_value 2 [template = constants.%.5]
// CHECK:STDOUT: %.loc13_28: Core.IntLiteral = int_value 3 [template = constants.%.1]
// CHECK:STDOUT: %.loc13_29.1: %tuple.type.1 = tuple_literal (%.loc13_22, %.loc13_25, %.loc13_28)
// CHECK:STDOUT: %.loc13_29.2: i32 = int_value 0 [template = constants.%.32]
// CHECK:STDOUT: %.loc13_29.3: ref i32 = array_index %a.var, %.loc13_29.2
// CHECK:STDOUT: %.loc13_29.4: init i32 = initialize_from %.loc13_22 to %.loc13_29.3 [template = constants.%.30]
// CHECK:STDOUT: %.loc13_29.5: i32 = int_value 1 [template = constants.%.30]
// CHECK:STDOUT: %.loc13_29.2: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.15]
// CHECK:STDOUT: %.loc13_29.3: <bound method> = bound_method %.loc13_22, %.loc13_29.2 [template = constants.%.31]
// CHECK:STDOUT: %int.convert_checked.loc13_29.1: init i32 = call %.loc13_29.3(%.loc13_22) [template = constants.%.32]
// CHECK:STDOUT: %.loc13_29.4: init i32 = converted %.loc13_22, %int.convert_checked.loc13_29.1 [template = constants.%.32]
// CHECK:STDOUT: %.loc13_29.5: i32 = int_value 0 [template = constants.%.6]
// CHECK:STDOUT: %.loc13_29.6: ref i32 = array_index %a.var, %.loc13_29.5
// CHECK:STDOUT: %.loc13_29.7: init i32 = initialize_from %.loc13_25 to %.loc13_29.6 [template = constants.%.31]
// CHECK:STDOUT: %.loc13_29.8: i32 = int_value 2 [template = constants.%.31]
// CHECK:STDOUT: %.loc13_29.9: ref i32 = array_index %a.var, %.loc13_29.8
// CHECK:STDOUT: %.loc13_29.10: init i32 = initialize_from %.loc13_28 to %.loc13_29.9 [template = constants.%.1]
// CHECK:STDOUT: %.loc13_29.11: init %.28 = array_init (%.loc13_29.4, %.loc13_29.7, %.loc13_29.10) to %a.var [template = constants.%array]
// CHECK:STDOUT: %.loc13_30: init %.28 = converted %.loc13_29.1, %.loc13_29.11 [template = constants.%array]
// CHECK:STDOUT: %.loc13_29.7: init i32 = initialize_from %.loc13_29.4 to %.loc13_29.6 [template = constants.%.32]
// CHECK:STDOUT: %.loc13_29.8: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.15]
// CHECK:STDOUT: %.loc13_29.9: <bound method> = bound_method %.loc13_25, %.loc13_29.8 [template = constants.%.33]
// CHECK:STDOUT: %int.convert_checked.loc13_29.2: init i32 = call %.loc13_29.9(%.loc13_25) [template = constants.%.34]
// CHECK:STDOUT: %.loc13_29.10: init i32 = converted %.loc13_25, %int.convert_checked.loc13_29.2 [template = constants.%.34]
// CHECK:STDOUT: %.loc13_29.11: i32 = int_value 1 [template = constants.%.32]
// CHECK:STDOUT: %.loc13_29.12: ref i32 = array_index %a.var, %.loc13_29.11
// CHECK:STDOUT: %.loc13_29.13: init i32 = initialize_from %.loc13_29.10 to %.loc13_29.12 [template = constants.%.34]
// CHECK:STDOUT: %.loc13_29.14: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.15]
// CHECK:STDOUT: %.loc13_29.15: <bound method> = bound_method %.loc13_28, %.loc13_29.14 [template = constants.%.35]
// CHECK:STDOUT: %int.convert_checked.loc13_29.3: init i32 = call %.loc13_29.15(%.loc13_28) [template = constants.%.36]
// CHECK:STDOUT: %.loc13_29.16: init i32 = converted %.loc13_28, %int.convert_checked.loc13_29.3 [template = constants.%.36]
// CHECK:STDOUT: %.loc13_29.17: i32 = int_value 2 [template = constants.%.34]
// CHECK:STDOUT: %.loc13_29.18: ref i32 = array_index %a.var, %.loc13_29.17
// CHECK:STDOUT: %.loc13_29.19: init i32 = initialize_from %.loc13_29.16 to %.loc13_29.18 [template = constants.%.36]
// CHECK:STDOUT: %.loc13_29.20: init %.2 = array_init (%.loc13_29.7, %.loc13_29.13, %.loc13_29.19) to %a.var [template = constants.%array]
// CHECK:STDOUT: %.loc13_30: init %.2 = converted %.loc13_29.1, %.loc13_29.20 [template = constants.%array]
// CHECK:STDOUT: assign %a.var, %.loc13_30
// CHECK:STDOUT: %int.make_type_32.loc14_11: init type = call constants.%Int32() [template = i32]
// CHECK:STDOUT: %int.make_type_32.loc14_16: init type = call constants.%Int32() [template = i32]
@@ -96,21 +108,33 @@ fn G() {
// CHECK:STDOUT: %.loc14_24.5: type = converted %int.make_type_32.loc14_16, %.loc14_24.4 [template = i32]
// CHECK:STDOUT: %.loc14_24.6: type = value_of_initializer %int.make_type_32.loc14_21 [template = i32]
// CHECK:STDOUT: %.loc14_24.7: type = converted %int.make_type_32.loc14_21, %.loc14_24.6 [template = i32]
// CHECK:STDOUT: %.loc14_24.8: type = converted %.loc14_24.1, constants.%tuple.type.1 [template = constants.%tuple.type.1]
// CHECK:STDOUT: %b.var: ref %tuple.type.1 = var b
// CHECK:STDOUT: %b: ref %tuple.type.1 = bind_name b, %b.var
// CHECK:STDOUT: %.loc14_29: i32 = int_value 1 [template = constants.%.30]
// CHECK:STDOUT: %.loc14_32: i32 = int_value 2 [template = constants.%.31]
// CHECK:STDOUT: %.loc14_35: i32 = int_value 3 [template = constants.%.1]
// CHECK:STDOUT: %.loc14_24.8: type = converted %.loc14_24.1, constants.%tuple.type.3 [template = constants.%tuple.type.3]
// CHECK:STDOUT: %b.var: ref %tuple.type.3 = var b
// CHECK:STDOUT: %b: ref %tuple.type.3 = bind_name b, %b.var
// CHECK:STDOUT: %.loc14_29: Core.IntLiteral = int_value 1 [template = constants.%.4]
// CHECK:STDOUT: %.loc14_32: Core.IntLiteral = int_value 2 [template = constants.%.5]
// CHECK:STDOUT: %.loc14_35: Core.IntLiteral = int_value 3 [template = constants.%.1]
// CHECK:STDOUT: %.loc14_36.1: %tuple.type.1 = tuple_literal (%.loc14_29, %.loc14_32, %.loc14_35)
// CHECK:STDOUT: %.loc14_36.2: ref i32 = tuple_access %b.var, element0
// CHECK:STDOUT: %.loc14_36.3: init i32 = initialize_from %.loc14_29 to %.loc14_36.2 [template = constants.%.30]
// CHECK:STDOUT: %.loc14_36.4: ref i32 = tuple_access %b.var, element1
// CHECK:STDOUT: %.loc14_36.5: init i32 = initialize_from %.loc14_32 to %.loc14_36.4 [template = constants.%.31]
// CHECK:STDOUT: %.loc14_36.6: ref i32 = tuple_access %b.var, element2
// CHECK:STDOUT: %.loc14_36.7: init i32 = initialize_from %.loc14_35 to %.loc14_36.6 [template = constants.%.1]
// CHECK:STDOUT: %.loc14_36.8: init %tuple.type.1 = tuple_init (%.loc14_36.3, %.loc14_36.5, %.loc14_36.7) to %b.var [template = constants.%tuple]
// CHECK:STDOUT: %.loc14_37: init %tuple.type.1 = converted %.loc14_36.1, %.loc14_36.8 [template = constants.%tuple]
// CHECK:STDOUT: %.loc14_36.2: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.15]
// CHECK:STDOUT: %.loc14_36.3: <bound method> = bound_method %.loc14_29, %.loc14_36.2 [template = constants.%.31]
// CHECK:STDOUT: %int.convert_checked.loc14_36.1: init i32 = call %.loc14_36.3(%.loc14_29) [template = constants.%.32]
// CHECK:STDOUT: %.loc14_36.4: init i32 = converted %.loc14_29, %int.convert_checked.loc14_36.1 [template = constants.%.32]
// CHECK:STDOUT: %.loc14_36.5: ref i32 = tuple_access %b.var, element0
// CHECK:STDOUT: %.loc14_36.6: init i32 = initialize_from %.loc14_36.4 to %.loc14_36.5 [template = constants.%.32]
// CHECK:STDOUT: %.loc14_36.7: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.15]
// CHECK:STDOUT: %.loc14_36.8: <bound method> = bound_method %.loc14_32, %.loc14_36.7 [template = constants.%.33]
// CHECK:STDOUT: %int.convert_checked.loc14_36.2: init i32 = call %.loc14_36.8(%.loc14_32) [template = constants.%.34]
// CHECK:STDOUT: %.loc14_36.9: init i32 = converted %.loc14_32, %int.convert_checked.loc14_36.2 [template = constants.%.34]
// CHECK:STDOUT: %.loc14_36.10: ref i32 = tuple_access %b.var, element1
// CHECK:STDOUT: %.loc14_36.11: init i32 = initialize_from %.loc14_36.9 to %.loc14_36.10 [template = constants.%.34]
// CHECK:STDOUT: %.loc14_36.12: %Convert.type.2 = interface_witness_access constants.%.30, element0 [template = constants.%Convert.15]
// CHECK:STDOUT: %.loc14_36.13: <bound method> = bound_method %.loc14_35, %.loc14_36.12 [template = constants.%.35]
// CHECK:STDOUT: %int.convert_checked.loc14_36.3: init i32 = call %.loc14_36.13(%.loc14_35) [template = constants.%.36]
// CHECK:STDOUT: %.loc14_36.14: init i32 = converted %.loc14_35, %int.convert_checked.loc14_36.3 [template = constants.%.36]
// CHECK:STDOUT: %.loc14_36.15: ref i32 = tuple_access %b.var, element2
// CHECK:STDOUT: %.loc14_36.16: init i32 = initialize_from %.loc14_36.14 to %.loc14_36.15 [template = constants.%.36]
// CHECK:STDOUT: %.loc14_36.17: init %tuple.type.3 = tuple_init (%.loc14_36.6, %.loc14_36.11, %.loc14_36.16) to %b.var [template = constants.%tuple]
// CHECK:STDOUT: %.loc14_37: init %tuple.type.3 = converted %.loc14_36.1, %.loc14_36.17 [template = constants.%tuple]
// CHECK:STDOUT: assign %b.var, %.loc14_37
// CHECK:STDOUT: return
// CHECK:STDOUT: }