mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-26 02:21:24 +00:00
Include the index rather than the name in the fingerprint of a symbolic binding. While both the index and the name contribute to the canonical identity, using either one of them in the fingerprint is sufficient to ensure that distinct entities get different fingerprints. Changing the name of a symbolic binding should ideally not result in fingerprint changes, so exclude the name from the fingerprint when we have an index. Use the canonical type and constraint when fingerprinting an impl, so that uses of names in `name_ref` instructions aren't considered, only the entity the name resolves to, and different ways of spelling the same type have the same fingerprint. This similarly allows compatible changes to be made to impls without changing the fingerprint. Exclude the declaration block when determining the fingerprint of a declaration. The declaration block contains the declarations of parameters of the declaration, which do affect whether two declarations are identical, but not whether they denote the same entity, because it would be invalid to have different declaration blocks for declarations with the same name in the same scope. Therefore changes to the declaration block are compatible, and it's useful for such changes to not affect the fingerprint. This is not easy to test in isolation with our current testing machinery. However, a follow-on PR will change the name of a parameter in the prelude, and with this in place, will not cause any changes to occur elsewhere in the toolchain tests.
190 lines
16 KiB
Plaintext
190 lines
16 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/basics/numeric_literals.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/basics/numeric_literals.carbon
|
|
|
|
fn F() {
|
|
// 8 and 9 trigger special behavior in APInt when mishandling signed versus
|
|
// unsigned, so we pay extra attention to those.
|
|
var ints: [i32; 6] = (
|
|
8,
|
|
9,
|
|
0x8,
|
|
0b1000,
|
|
2147483647,
|
|
0x7FFFFFFF,
|
|
);
|
|
var floats: [f64; 6] = (
|
|
0.9,
|
|
8.0,
|
|
80.0,
|
|
1.0e7,
|
|
1.0e8,
|
|
1.0e-8
|
|
);
|
|
}
|
|
|
|
// CHECK:STDOUT: --- numeric_literals.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [template]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [template]
|
|
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
|
|
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
|
|
// CHECK:STDOUT: %int_6: Core.IntLiteral = int_value 6 [template]
|
|
// CHECK:STDOUT: %array_type.d49: type = array_type %int_6, %i32 [template]
|
|
// CHECK:STDOUT: %int_8.b85: Core.IntLiteral = int_value 8 [template]
|
|
// CHECK:STDOUT: %int_9.988: Core.IntLiteral = int_value 9 [template]
|
|
// CHECK:STDOUT: %int_2147483647.d89: Core.IntLiteral = int_value 2147483647 [template]
|
|
// CHECK:STDOUT: %tuple.type.27c: type = tuple_type (Core.IntLiteral, Core.IntLiteral, Core.IntLiteral, Core.IntLiteral, Core.IntLiteral, Core.IntLiteral) [template]
|
|
// CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
|
|
// CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
|
|
// CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%import_ref.a5b), @impl.1(%int_32) [template]
|
|
// CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
|
|
// CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
|
|
// CHECK:STDOUT: %Convert.bound.e09: <bound method> = bound_method %int_8.b85, %Convert.956 [template]
|
|
// CHECK:STDOUT: %Convert.specific_fn.e0d: <specific function> = specific_function %Convert.bound.e09, @Convert.2(%int_32) [template]
|
|
// CHECK:STDOUT: %int_8.98c: %i32 = int_value 8 [template]
|
|
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
|
|
// CHECK:STDOUT: %Convert.bound.9e2: <bound method> = bound_method %int_9.988, %Convert.956 [template]
|
|
// CHECK:STDOUT: %Convert.specific_fn.b02: <specific function> = specific_function %Convert.bound.9e2, @Convert.2(%int_32) [template]
|
|
// CHECK:STDOUT: %int_9.f88: %i32 = int_value 9 [template]
|
|
// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template]
|
|
// CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template]
|
|
// CHECK:STDOUT: %int_4: Core.IntLiteral = int_value 4 [template]
|
|
// CHECK:STDOUT: %Convert.bound.f38: <bound method> = bound_method %int_2147483647.d89, %Convert.956 [template]
|
|
// CHECK:STDOUT: %Convert.specific_fn.221: <specific function> = specific_function %Convert.bound.f38, @Convert.2(%int_32) [template]
|
|
// CHECK:STDOUT: %int_2147483647.a74: %i32 = int_value 2147483647 [template]
|
|
// CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [template]
|
|
// CHECK:STDOUT: %array.ae2: %array_type.d49 = tuple_value (%int_8.98c, %int_9.f88, %int_8.98c, %int_8.98c, %int_2147483647.a74, %int_2147483647.a74) [template]
|
|
// CHECK:STDOUT: %array_type.72b: type = array_type %int_6, f64 [template]
|
|
// CHECK:STDOUT: %float.952: f64 = float_literal 0.90000000000000002 [template]
|
|
// CHECK:STDOUT: %float.298: f64 = float_literal 8 [template]
|
|
// CHECK:STDOUT: %float.dcb: f64 = float_literal 80 [template]
|
|
// CHECK:STDOUT: %float.1d0: f64 = float_literal 1.0E+7 [template]
|
|
// CHECK:STDOUT: %float.9f6: f64 = float_literal 1.0E+8 [template]
|
|
// CHECK:STDOUT: %float.401: f64 = float_literal 1.0E-8 [template]
|
|
// CHECK:STDOUT: %tuple.type.635: type = tuple_type (f64, f64, f64, f64, f64, f64) [template]
|
|
// CHECK:STDOUT: %array.a2f: %array_type.72b = tuple_value (%float.952, %float.298, %float.dcb, %float.1d0, %float.9f6, %float.401) [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
|
|
// CHECK:STDOUT: .Int = %import_ref.485
|
|
// CHECK:STDOUT: .ImplicitAs = %import_ref.d44
|
|
// CHECK:STDOUT: .Float = %import_ref.1d6
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .F = %F.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @F() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %ints.var: ref %array_type.d49 = var ints
|
|
// CHECK:STDOUT: %ints: ref %array_type.d49 = bind_name ints, %ints.var
|
|
// CHECK:STDOUT: %int_8.loc15: Core.IntLiteral = int_value 8 [template = constants.%int_8.b85]
|
|
// CHECK:STDOUT: %int_9: Core.IntLiteral = int_value 9 [template = constants.%int_9.988]
|
|
// CHECK:STDOUT: %int_8.loc17: Core.IntLiteral = int_value 8 [template = constants.%int_8.b85]
|
|
// CHECK:STDOUT: %int_8.loc18: Core.IntLiteral = int_value 8 [template = constants.%int_8.b85]
|
|
// CHECK:STDOUT: %int_2147483647.loc19: Core.IntLiteral = int_value 2147483647 [template = constants.%int_2147483647.d89]
|
|
// CHECK:STDOUT: %int_2147483647.loc20: Core.IntLiteral = int_value 2147483647 [template = constants.%int_2147483647.d89]
|
|
// CHECK:STDOUT: %.loc21_3.1: %tuple.type.27c = tuple_literal (%int_8.loc15, %int_9, %int_8.loc17, %int_8.loc18, %int_2147483647.loc19, %int_2147483647.loc20)
|
|
// CHECK:STDOUT: %impl.elem0.loc21_3.1: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
|
|
// CHECK:STDOUT: %Convert.bound.loc21_3.1: <bound method> = bound_method %int_8.loc15, %impl.elem0.loc21_3.1 [template = constants.%Convert.bound.e09]
|
|
// CHECK:STDOUT: %Convert.specific_fn.loc21_3.1: <specific function> = specific_function %Convert.bound.loc21_3.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.e0d]
|
|
// CHECK:STDOUT: %int.convert_checked.loc21_3.1: init %i32 = call %Convert.specific_fn.loc21_3.1(%int_8.loc15) [template = constants.%int_8.98c]
|
|
// CHECK:STDOUT: %.loc21_3.2: init %i32 = converted %int_8.loc15, %int.convert_checked.loc21_3.1 [template = constants.%int_8.98c]
|
|
// CHECK:STDOUT: %int_0.loc21: Core.IntLiteral = int_value 0 [template = constants.%int_0]
|
|
// CHECK:STDOUT: %.loc21_3.3: ref %i32 = array_index %ints.var, %int_0.loc21
|
|
// CHECK:STDOUT: %.loc21_3.4: init %i32 = initialize_from %.loc21_3.2 to %.loc21_3.3 [template = constants.%int_8.98c]
|
|
// CHECK:STDOUT: %impl.elem0.loc21_3.2: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
|
|
// CHECK:STDOUT: %Convert.bound.loc21_3.2: <bound method> = bound_method %int_9, %impl.elem0.loc21_3.2 [template = constants.%Convert.bound.9e2]
|
|
// CHECK:STDOUT: %Convert.specific_fn.loc21_3.2: <specific function> = specific_function %Convert.bound.loc21_3.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.b02]
|
|
// CHECK:STDOUT: %int.convert_checked.loc21_3.2: init %i32 = call %Convert.specific_fn.loc21_3.2(%int_9) [template = constants.%int_9.f88]
|
|
// CHECK:STDOUT: %.loc21_3.5: init %i32 = converted %int_9, %int.convert_checked.loc21_3.2 [template = constants.%int_9.f88]
|
|
// CHECK:STDOUT: %int_1.loc21: Core.IntLiteral = int_value 1 [template = constants.%int_1]
|
|
// CHECK:STDOUT: %.loc21_3.6: ref %i32 = array_index %ints.var, %int_1.loc21
|
|
// CHECK:STDOUT: %.loc21_3.7: init %i32 = initialize_from %.loc21_3.5 to %.loc21_3.6 [template = constants.%int_9.f88]
|
|
// CHECK:STDOUT: %impl.elem0.loc21_3.3: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
|
|
// CHECK:STDOUT: %Convert.bound.loc21_3.3: <bound method> = bound_method %int_8.loc17, %impl.elem0.loc21_3.3 [template = constants.%Convert.bound.e09]
|
|
// CHECK:STDOUT: %Convert.specific_fn.loc21_3.3: <specific function> = specific_function %Convert.bound.loc21_3.3, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.e0d]
|
|
// CHECK:STDOUT: %int.convert_checked.loc21_3.3: init %i32 = call %Convert.specific_fn.loc21_3.3(%int_8.loc17) [template = constants.%int_8.98c]
|
|
// CHECK:STDOUT: %.loc21_3.8: init %i32 = converted %int_8.loc17, %int.convert_checked.loc21_3.3 [template = constants.%int_8.98c]
|
|
// CHECK:STDOUT: %int_2.loc21: Core.IntLiteral = int_value 2 [template = constants.%int_2]
|
|
// CHECK:STDOUT: %.loc21_3.9: ref %i32 = array_index %ints.var, %int_2.loc21
|
|
// CHECK:STDOUT: %.loc21_3.10: init %i32 = initialize_from %.loc21_3.8 to %.loc21_3.9 [template = constants.%int_8.98c]
|
|
// CHECK:STDOUT: %impl.elem0.loc21_3.4: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
|
|
// CHECK:STDOUT: %Convert.bound.loc21_3.4: <bound method> = bound_method %int_8.loc18, %impl.elem0.loc21_3.4 [template = constants.%Convert.bound.e09]
|
|
// CHECK:STDOUT: %Convert.specific_fn.loc21_3.4: <specific function> = specific_function %Convert.bound.loc21_3.4, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.e0d]
|
|
// CHECK:STDOUT: %int.convert_checked.loc21_3.4: init %i32 = call %Convert.specific_fn.loc21_3.4(%int_8.loc18) [template = constants.%int_8.98c]
|
|
// CHECK:STDOUT: %.loc21_3.11: init %i32 = converted %int_8.loc18, %int.convert_checked.loc21_3.4 [template = constants.%int_8.98c]
|
|
// CHECK:STDOUT: %int_3.loc21: Core.IntLiteral = int_value 3 [template = constants.%int_3]
|
|
// CHECK:STDOUT: %.loc21_3.12: ref %i32 = array_index %ints.var, %int_3.loc21
|
|
// CHECK:STDOUT: %.loc21_3.13: init %i32 = initialize_from %.loc21_3.11 to %.loc21_3.12 [template = constants.%int_8.98c]
|
|
// CHECK:STDOUT: %impl.elem0.loc21_3.5: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
|
|
// CHECK:STDOUT: %Convert.bound.loc21_3.5: <bound method> = bound_method %int_2147483647.loc19, %impl.elem0.loc21_3.5 [template = constants.%Convert.bound.f38]
|
|
// CHECK:STDOUT: %Convert.specific_fn.loc21_3.5: <specific function> = specific_function %Convert.bound.loc21_3.5, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.221]
|
|
// CHECK:STDOUT: %int.convert_checked.loc21_3.5: init %i32 = call %Convert.specific_fn.loc21_3.5(%int_2147483647.loc19) [template = constants.%int_2147483647.a74]
|
|
// CHECK:STDOUT: %.loc21_3.14: init %i32 = converted %int_2147483647.loc19, %int.convert_checked.loc21_3.5 [template = constants.%int_2147483647.a74]
|
|
// CHECK:STDOUT: %int_4.loc21: Core.IntLiteral = int_value 4 [template = constants.%int_4]
|
|
// CHECK:STDOUT: %.loc21_3.15: ref %i32 = array_index %ints.var, %int_4.loc21
|
|
// CHECK:STDOUT: %.loc21_3.16: init %i32 = initialize_from %.loc21_3.14 to %.loc21_3.15 [template = constants.%int_2147483647.a74]
|
|
// CHECK:STDOUT: %impl.elem0.loc21_3.6: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
|
|
// CHECK:STDOUT: %Convert.bound.loc21_3.6: <bound method> = bound_method %int_2147483647.loc20, %impl.elem0.loc21_3.6 [template = constants.%Convert.bound.f38]
|
|
// CHECK:STDOUT: %Convert.specific_fn.loc21_3.6: <specific function> = specific_function %Convert.bound.loc21_3.6, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.221]
|
|
// CHECK:STDOUT: %int.convert_checked.loc21_3.6: init %i32 = call %Convert.specific_fn.loc21_3.6(%int_2147483647.loc20) [template = constants.%int_2147483647.a74]
|
|
// CHECK:STDOUT: %.loc21_3.17: init %i32 = converted %int_2147483647.loc20, %int.convert_checked.loc21_3.6 [template = constants.%int_2147483647.a74]
|
|
// CHECK:STDOUT: %int_5.loc21: Core.IntLiteral = int_value 5 [template = constants.%int_5]
|
|
// CHECK:STDOUT: %.loc21_3.18: ref %i32 = array_index %ints.var, %int_5.loc21
|
|
// CHECK:STDOUT: %.loc21_3.19: init %i32 = initialize_from %.loc21_3.17 to %.loc21_3.18 [template = constants.%int_2147483647.a74]
|
|
// CHECK:STDOUT: %.loc21_3.20: init %array_type.d49 = array_init (%.loc21_3.4, %.loc21_3.7, %.loc21_3.10, %.loc21_3.13, %.loc21_3.16, %.loc21_3.19) to %ints.var [template = constants.%array.ae2]
|
|
// CHECK:STDOUT: %.loc21_4: init %array_type.d49 = converted %.loc21_3.1, %.loc21_3.20 [template = constants.%array.ae2]
|
|
// CHECK:STDOUT: assign %ints.var, %.loc21_4
|
|
// CHECK:STDOUT: %floats.var: ref %array_type.72b = var floats
|
|
// CHECK:STDOUT: %floats: ref %array_type.72b = bind_name floats, %floats.var
|
|
// CHECK:STDOUT: %float.loc23: f64 = float_literal 0.90000000000000002 [template = constants.%float.952]
|
|
// CHECK:STDOUT: %float.loc24: f64 = float_literal 8 [template = constants.%float.298]
|
|
// CHECK:STDOUT: %float.loc25: f64 = float_literal 80 [template = constants.%float.dcb]
|
|
// CHECK:STDOUT: %float.loc26: f64 = float_literal 1.0E+7 [template = constants.%float.1d0]
|
|
// CHECK:STDOUT: %float.loc27: f64 = float_literal 1.0E+8 [template = constants.%float.9f6]
|
|
// CHECK:STDOUT: %float.loc28: f64 = float_literal 1.0E-8 [template = constants.%float.401]
|
|
// CHECK:STDOUT: %.loc29_3.1: %tuple.type.635 = tuple_literal (%float.loc23, %float.loc24, %float.loc25, %float.loc26, %float.loc27, %float.loc28)
|
|
// CHECK:STDOUT: %int_0.loc29: Core.IntLiteral = int_value 0 [template = constants.%int_0]
|
|
// CHECK:STDOUT: %.loc29_3.2: ref f64 = array_index %floats.var, %int_0.loc29
|
|
// CHECK:STDOUT: %.loc29_3.3: init f64 = initialize_from %float.loc23 to %.loc29_3.2 [template = constants.%float.952]
|
|
// CHECK:STDOUT: %int_1.loc29: Core.IntLiteral = int_value 1 [template = constants.%int_1]
|
|
// CHECK:STDOUT: %.loc29_3.4: ref f64 = array_index %floats.var, %int_1.loc29
|
|
// CHECK:STDOUT: %.loc29_3.5: init f64 = initialize_from %float.loc24 to %.loc29_3.4 [template = constants.%float.298]
|
|
// CHECK:STDOUT: %int_2.loc29: Core.IntLiteral = int_value 2 [template = constants.%int_2]
|
|
// CHECK:STDOUT: %.loc29_3.6: ref f64 = array_index %floats.var, %int_2.loc29
|
|
// CHECK:STDOUT: %.loc29_3.7: init f64 = initialize_from %float.loc25 to %.loc29_3.6 [template = constants.%float.dcb]
|
|
// CHECK:STDOUT: %int_3.loc29: Core.IntLiteral = int_value 3 [template = constants.%int_3]
|
|
// CHECK:STDOUT: %.loc29_3.8: ref f64 = array_index %floats.var, %int_3.loc29
|
|
// CHECK:STDOUT: %.loc29_3.9: init f64 = initialize_from %float.loc26 to %.loc29_3.8 [template = constants.%float.1d0]
|
|
// CHECK:STDOUT: %int_4.loc29: Core.IntLiteral = int_value 4 [template = constants.%int_4]
|
|
// CHECK:STDOUT: %.loc29_3.10: ref f64 = array_index %floats.var, %int_4.loc29
|
|
// CHECK:STDOUT: %.loc29_3.11: init f64 = initialize_from %float.loc27 to %.loc29_3.10 [template = constants.%float.9f6]
|
|
// CHECK:STDOUT: %int_5.loc29: Core.IntLiteral = int_value 5 [template = constants.%int_5]
|
|
// CHECK:STDOUT: %.loc29_3.12: ref f64 = array_index %floats.var, %int_5.loc29
|
|
// CHECK:STDOUT: %.loc29_3.13: init f64 = initialize_from %float.loc28 to %.loc29_3.12 [template = constants.%float.401]
|
|
// CHECK:STDOUT: %.loc29_3.14: init %array_type.72b = array_init (%.loc29_3.3, %.loc29_3.5, %.loc29_3.7, %.loc29_3.9, %.loc29_3.11, %.loc29_3.13) to %floats.var [template = constants.%array.a2f]
|
|
// CHECK:STDOUT: %.loc29_4: init %array_type.72b = converted %.loc29_3.1, %.loc29_3.14 [template = constants.%array.a2f]
|
|
// CHECK:STDOUT: assign %floats.var, %.loc29_4
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|