mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 16:11:06 +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.
86 lines
2.9 KiB
Plaintext
86 lines
2.9 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/primitives.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/alias/builtins.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/alias/builtins.carbon
|
|
|
|
// --- i32.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
//@dump-sem-ir-begin
|
|
alias a = i32;
|
|
//@dump-sem-ir-end
|
|
|
|
// --- bool.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
//@dump-sem-ir-begin
|
|
alias b = bool;
|
|
//@dump-sem-ir-end
|
|
|
|
// --- fail_bool_value.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
//@dump-sem-ir-begin
|
|
// CHECK:STDERR: fail_bool_value.carbon:[[@LINE+4]]:11: error: alias initializer must be a name reference [AliasRequiresNameRef]
|
|
// CHECK:STDERR: alias a = false;
|
|
// CHECK:STDERR: ^~~~~
|
|
// CHECK:STDERR:
|
|
alias a = false;
|
|
|
|
// This fails silently due to the above diagnostic.
|
|
let a_test: bool = a;
|
|
//@dump-sem-ir-end
|
|
|
|
// CHECK:STDOUT: --- i32.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
|
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %i32: type = type_literal constants.%i32 [concrete = constants.%i32]
|
|
// CHECK:STDOUT: %a: type = alias_binding a, constants.%i32 [concrete = constants.%i32]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- bool.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %.loc5: type = type_literal bool [concrete = bool]
|
|
// CHECK:STDOUT: %b: type = alias_binding b, bool [concrete = bool]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_bool_value.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %false: bool = bool_literal false [concrete]
|
|
// CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %false: bool = bool_literal false [concrete = constants.%false]
|
|
// CHECK:STDOUT: %a: <error> = alias_binding a, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %a_test.patt: %pattern_type.831 = value_binding_pattern a_test [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %.loc12: type = type_literal bool [concrete = bool]
|
|
// CHECK:STDOUT: %a_test: bool = value_binding a_test, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @__global_init() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %a.ref: <error> = name_ref a, file.%a [concrete = <error>]
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|