mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 14:01:05 +01:00
This adds SemIR structs and implements building `observe` lists, as well as naming, formatting, and importing `observe` declarations. --------- Co-authored-by: Dana Jansens <danakj@orodu.net>
87 lines
4.0 KiB
Plaintext
87 lines
4.0 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/int.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/let/convert.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/convert.carbon
|
|
|
|
// --- convert.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn F() -> i32 {
|
|
var v: (i32, i32, i32) = (1, 2, 3);
|
|
// Convert from object representation to value representation.
|
|
//@dump-sem-ir-begin
|
|
let w: (i32, i32, i32) = v;
|
|
//@dump-sem-ir-end
|
|
return w.1;
|
|
}
|
|
|
|
// --- fail_let_bound_to_ref_not_mutable.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn G() {
|
|
var a: i32 = 0;
|
|
let unused n: i32 = a;
|
|
// CHECK:STDERR: fail_let_bound_to_ref_not_mutable.carbon:[[@LINE+11]]:3: error: expression is not assignable [AssignmentToNonAssignable]
|
|
// CHECK:STDERR: n = 1;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_let_bound_to_ref_not_mutable.carbon:[[@LINE-5]]:14: error: variable `n` marked `unused` but used [UnusedButUsed]
|
|
// CHECK:STDERR: let unused n: i32 = a;
|
|
// CHECK:STDERR: ^~~~~~
|
|
// CHECK:STDERR: fail_let_bound_to_ref_not_mutable.carbon:[[@LINE+4]]:3: note: usage here [UnusedButUsedHere]
|
|
// CHECK:STDERR: n = 1;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
n = 1;
|
|
}
|
|
|
|
// CHECK:STDOUT: --- convert.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: %tuple.type.ff9: type = tuple_type (type, type, type) [concrete]
|
|
// CHECK:STDOUT: %tuple.04d: %tuple.type.ff9 = tuple_value (%i32, %i32, %i32) [concrete]
|
|
// CHECK:STDOUT: %tuple.type.555: type = tuple_type (%i32, %i32, %i32) [concrete]
|
|
// CHECK:STDOUT: %pattern_type.777: type = pattern_type %tuple.type.555 [concrete]
|
|
// CHECK:STDOUT: %w.patt: %pattern_type.777 = value_binding_pattern w [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @F() -> out %return.param: %i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: %v.ref: ref %tuple.type.555 = name_ref v, %v
|
|
// CHECK:STDOUT: %tuple.elem0.loc8: ref %i32 = tuple_access %v.ref, element0
|
|
// CHECK:STDOUT: %.loc8_28.1: %i32 = acquire_value %tuple.elem0.loc8
|
|
// CHECK:STDOUT: %tuple.elem1.loc8: ref %i32 = tuple_access %v.ref, element1
|
|
// CHECK:STDOUT: %.loc8_28.2: %i32 = acquire_value %tuple.elem1.loc8
|
|
// CHECK:STDOUT: %tuple.elem2.loc8: ref %i32 = tuple_access %v.ref, element2
|
|
// CHECK:STDOUT: %.loc8_28.3: %i32 = acquire_value %tuple.elem2.loc8
|
|
// CHECK:STDOUT: %tuple: %tuple.type.555 = tuple_value (%.loc8_28.1, %.loc8_28.2, %.loc8_28.3)
|
|
// CHECK:STDOUT: %.loc8_28.4: %tuple.type.555 = converted %v.ref, %tuple
|
|
// CHECK:STDOUT: %.loc8_24.1: type = splice_block %.loc8_24.3 [concrete = constants.%tuple.type.555] {
|
|
// CHECK:STDOUT: %i32.loc8_11: type = type_literal constants.%i32 [concrete = constants.%i32]
|
|
// CHECK:STDOUT: %i32.loc8_16: type = type_literal constants.%i32 [concrete = constants.%i32]
|
|
// CHECK:STDOUT: %i32.loc8_21: type = type_literal constants.%i32 [concrete = constants.%i32]
|
|
// CHECK:STDOUT: %.loc8_24.2: %tuple.type.ff9 = tuple_literal (%i32.loc8_11, %i32.loc8_16, %i32.loc8_21) [concrete = constants.%tuple.04d]
|
|
// CHECK:STDOUT: %.loc8_24.3: type = converted %.loc8_24.2, constants.%tuple.type.555 [concrete = constants.%tuple.type.555]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %w: %tuple.type.555 = wrapper_binding w, %.loc8_28.4
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %w.patt: %pattern_type.777 = value_binding_pattern w [concrete = constants.%w.patt]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !observes:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|