mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 19:51:09 +01:00
This allows us to capture the location at which a type literal was used, even in the cases where we don't otherwise need to create a new instruction to represent the type such as for `char` or `str`. The logic used to build the underlying type is now marked as desugaring. For cases such as `iN`, this causes the call to `Core.Int` to no longer be added as a dedicated IR instruction, and instead its constant value is used directly as the value of the `type_literal`. This results in this being on balance a reduction in the size of the IR. This also fixes a crash in C++ interop when using a `char` literal as a template argument. The crash was caused by the template argument not having an associated location when mapping to a C++ location. See changes to check/testdata/interop/cpp/template/type_param.carbon for an example that used to crash before this change. Update alias handling to allow an alias to point at any type literal, reinstating support for aliases for type literals such as `bool` and `i32` that had previously worked but stopped working when we transitioned those types to being defined in the prelude. See changes to toolchain/check/testdata/alias/builtins.carbon. All the test changes other than the two mentioned above are mechanical autoupdate changes switching to the new instruction.
205 lines
12 KiB
Plaintext
205 lines
12 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
|
|
//
|
|
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
|
|
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
|
|
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/fail_generic_redeclaration.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/fail_generic_redeclaration.carbon
|
|
|
|
interface NotGeneric;
|
|
// CHECK:STDERR: fail_generic_redeclaration.carbon:[[@LINE+7]]:1: error: redeclaration differs because of parameter list [RedeclParamListDiffers]
|
|
// CHECK:STDERR: interface NotGeneric(T:! type) {}
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR: fail_generic_redeclaration.carbon:[[@LINE-4]]:1: note: previously declared without parameter list [RedeclParamListPrevious]
|
|
// CHECK:STDERR: interface NotGeneric;
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
interface NotGeneric(T:! type) {}
|
|
|
|
interface Generic(T:! type);
|
|
// CHECK:STDERR: fail_generic_redeclaration.carbon:[[@LINE+7]]:1: error: redeclaration differs because of missing parameter list [RedeclParamListDiffers]
|
|
// CHECK:STDERR: interface Generic {}
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR: fail_generic_redeclaration.carbon:[[@LINE-4]]:1: note: previously declared with parameter list [RedeclParamListPrevious]
|
|
// CHECK:STDERR: interface Generic(T:! type);
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
interface Generic {}
|
|
|
|
interface DifferentParams(T:! type);
|
|
// CHECK:STDERR: fail_generic_redeclaration.carbon:[[@LINE+7]]:27: error: type `<pattern for ()>` of parameter 1 in redeclaration differs from previous parameter type `<pattern for type>` [RedeclParamDiffersType]
|
|
// CHECK:STDERR: interface DifferentParams(T:! ()) {}
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR: fail_generic_redeclaration.carbon:[[@LINE-4]]:27: note: previous declaration's corresponding parameter here [RedeclParamPrevious]
|
|
// CHECK:STDERR: interface DifferentParams(T:! type);
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
interface DifferentParams(T:! ()) {}
|
|
|
|
// CHECK:STDOUT: --- fail_generic_redeclaration.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %NotGeneric.type.a72: type = facet_type <@NotGeneric.loc15> [concrete]
|
|
// CHECK:STDOUT: %type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
|
|
// CHECK:STDOUT: %T.67d: type = symbolic_binding T, 0 [symbolic]
|
|
// CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
|
|
// CHECK:STDOUT: %NotGeneric.type.af7: type = generic_interface_type @NotGeneric.loc23 [concrete]
|
|
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
|
// CHECK:STDOUT: %NotGeneric.generic: %NotGeneric.type.af7 = struct_value () [concrete]
|
|
// CHECK:STDOUT: %NotGeneric.type.b27: type = facet_type <@NotGeneric.loc23, @NotGeneric.loc23(%T.67d)> [symbolic]
|
|
// CHECK:STDOUT: %Self.b1e: %NotGeneric.type.b27 = symbolic_binding Self, 1 [symbolic]
|
|
// CHECK:STDOUT: %Generic.type.835: type = generic_interface_type @Generic.loc25 [concrete]
|
|
// CHECK:STDOUT: %Generic.generic: %Generic.type.835 = struct_value () [concrete]
|
|
// CHECK:STDOUT: %Generic.type.aac: type = facet_type <@Generic.loc33> [concrete]
|
|
// CHECK:STDOUT: %Self.863: %Generic.type.aac = symbolic_binding Self, 0 [symbolic]
|
|
// CHECK:STDOUT: %DifferentParams.type.0d8654.1: type = generic_interface_type @DifferentParams.loc35 [concrete]
|
|
// CHECK:STDOUT: %DifferentParams.generic.de7f43.1: %DifferentParams.type.0d8654.1 = struct_value () [concrete]
|
|
// CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
|
|
// CHECK:STDOUT: %T.d5f: %empty_tuple.type = symbolic_binding T, 0 [symbolic]
|
|
// CHECK:STDOUT: %pattern_type.cb1: type = pattern_type %empty_tuple.type [concrete]
|
|
// CHECK:STDOUT: %DifferentParams.type.0d8654.2: type = generic_interface_type @DifferentParams.loc43 [concrete]
|
|
// CHECK:STDOUT: %DifferentParams.generic.de7f43.2: %DifferentParams.type.0d8654.2 = struct_value () [concrete]
|
|
// CHECK:STDOUT: %DifferentParams.type.7f1: type = facet_type <@DifferentParams.loc43, @DifferentParams.loc43(%T.d5f)> [symbolic]
|
|
// CHECK:STDOUT: %Self.afe: %DifferentParams.type.7f1 = symbolic_binding Self, 1 [symbolic]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .NotGeneric = %NotGeneric.decl.loc15
|
|
// CHECK:STDOUT: .Generic = %Generic.decl.loc25
|
|
// CHECK:STDOUT: .DifferentParams = %DifferentParams.decl.loc35
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %NotGeneric.decl.loc15: type = interface_decl @NotGeneric.loc15 [concrete = constants.%NotGeneric.type.a72] {} {}
|
|
// CHECK:STDOUT: %NotGeneric.decl.loc23: %NotGeneric.type.af7 = interface_decl @NotGeneric.loc23 [concrete = constants.%NotGeneric.generic] {
|
|
// CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc23_26.1: type = splice_block %.loc23_26.2 [concrete = type] {
|
|
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
|
|
// CHECK:STDOUT: %.loc23_26.2: type = type_literal type [concrete = type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %T.loc23_22.2: type = symbolic_binding T, 0 [symbolic = %T.loc23_22.1 (constants.%T.67d)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Generic.decl.loc25: %Generic.type.835 = interface_decl @Generic.loc25 [concrete = constants.%Generic.generic] {
|
|
// CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc25_23.1: type = splice_block %.loc25_23.2 [concrete = type] {
|
|
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
|
|
// CHECK:STDOUT: %.loc25_23.2: type = type_literal type [concrete = type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %T.loc25_19.2: type = symbolic_binding T, 0 [symbolic = %T.loc25_19.1 (constants.%T.67d)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Generic.decl.loc33: type = interface_decl @Generic.loc33 [concrete = constants.%Generic.type.aac] {} {}
|
|
// CHECK:STDOUT: %DifferentParams.decl.loc35: %DifferentParams.type.0d8654.1 = interface_decl @DifferentParams.loc35 [concrete = constants.%DifferentParams.generic.de7f43.1] {
|
|
// CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc35_31.1: type = splice_block %.loc35_31.2 [concrete = type] {
|
|
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
|
|
// CHECK:STDOUT: %.loc35_31.2: type = type_literal type [concrete = type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %T.loc35_27.2: type = symbolic_binding T, 0 [symbolic = %T.loc35_27.1 (constants.%T.67d)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %DifferentParams.decl.loc43: %DifferentParams.type.0d8654.2 = interface_decl @DifferentParams.loc43 [concrete = constants.%DifferentParams.generic.de7f43.2] {
|
|
// CHECK:STDOUT: %T.patt: %pattern_type.cb1 = symbolic_binding_pattern T, 0 [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc43_32.1: type = splice_block %.loc43_32.3 [concrete = constants.%empty_tuple.type] {
|
|
// CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
|
|
// CHECK:STDOUT: %.loc43_32.2: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
|
// CHECK:STDOUT: %.loc43_32.3: type = converted %.loc43_32.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %T.loc43_27.2: %empty_tuple.type = symbolic_binding T, 0 [symbolic = %T.loc43_27.1 (constants.%T.d5f)]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @NotGeneric.loc15;
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic interface @NotGeneric.loc23(%T.loc23_22.2: type) {
|
|
// CHECK:STDOUT: %T.loc23_22.1: type = symbolic_binding T, 0 [symbolic = %T.loc23_22.1 (constants.%T.67d)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %NotGeneric.type: type = facet_type <@NotGeneric.loc23, @NotGeneric.loc23(%T.loc23_22.1)> [symbolic = %NotGeneric.type (constants.%NotGeneric.type.b27)]
|
|
// CHECK:STDOUT: %Self.loc23_32.2: @NotGeneric.loc23.%NotGeneric.type (%NotGeneric.type.b27) = symbolic_binding Self, 1 [symbolic = %Self.loc23_32.2 (constants.%Self.b1e)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface {
|
|
// CHECK:STDOUT: %Self.loc23_32.1: @NotGeneric.loc23.%NotGeneric.type (%NotGeneric.type.b27) = symbolic_binding Self, 1 [symbolic = %Self.loc23_32.2 (constants.%Self.b1e)]
|
|
// CHECK:STDOUT: interface_with_self_decl @NotGeneric.loc23 [concrete]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self.loc23_32.1
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !requires:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic interface @Generic.loc25(%T.loc25_19.2: type) {
|
|
// CHECK:STDOUT: %T.loc25_19.1: type = symbolic_binding T, 0 [symbolic = %T.loc25_19.1 (constants.%T.67d)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface;
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @Generic.loc33 {
|
|
// CHECK:STDOUT: %Self: %Generic.type.aac = symbolic_binding Self, 0 [symbolic = constants.%Self.863]
|
|
// CHECK:STDOUT: interface_with_self_decl @Generic.loc33 [concrete]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !requires:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic interface @DifferentParams.loc35(%T.loc35_27.2: type) {
|
|
// CHECK:STDOUT: %T.loc35_27.1: type = symbolic_binding T, 0 [symbolic = %T.loc35_27.1 (constants.%T.67d)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface;
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic interface @DifferentParams.loc43(%T.loc43_27.2: %empty_tuple.type) {
|
|
// CHECK:STDOUT: %T.loc43_27.1: %empty_tuple.type = symbolic_binding T, 0 [symbolic = %T.loc43_27.1 (constants.%T.d5f)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %DifferentParams.type: type = facet_type <@DifferentParams.loc43, @DifferentParams.loc43(%T.loc43_27.1)> [symbolic = %DifferentParams.type (constants.%DifferentParams.type.7f1)]
|
|
// CHECK:STDOUT: %Self.loc43_35.2: @DifferentParams.loc43.%DifferentParams.type (%DifferentParams.type.7f1) = symbolic_binding Self, 1 [symbolic = %Self.loc43_35.2 (constants.%Self.afe)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface {
|
|
// CHECK:STDOUT: %Self.loc43_35.1: @DifferentParams.loc43.%DifferentParams.type (%DifferentParams.type.7f1) = symbolic_binding Self, 1 [symbolic = %Self.loc43_35.2 (constants.%Self.afe)]
|
|
// CHECK:STDOUT: interface_with_self_decl @DifferentParams.loc43 [concrete]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self.loc43_35.1
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !requires:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @NotGeneric.loc23(constants.%T.67d) {
|
|
// CHECK:STDOUT: %T.loc23_22.1 => constants.%T.67d
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @NotGeneric.loc23(constants.%T.67d, constants.%Self.b1e) {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Generic.loc25(constants.%T.67d) {
|
|
// CHECK:STDOUT: %T.loc25_19.1 => constants.%T.67d
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Generic.loc33(constants.%Self.863) {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @DifferentParams.loc35(constants.%T.67d) {
|
|
// CHECK:STDOUT: %T.loc35_27.1 => constants.%T.67d
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @DifferentParams.loc43(constants.%T.d5f) {
|
|
// CHECK:STDOUT: %T.loc43_27.1 => constants.%T.d5f
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @DifferentParams.loc43(constants.%T.d5f, constants.%Self.afe) {}
|
|
// CHECK:STDOUT:
|