mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:30:12 +01:00
This implements initializing expression semantics for structs and tuples, following #2006 and discussions since. Tuple and (and analogously, struct) literals are treated as having a mixed expression category that is later resolved based on how the literal is used, as either a tuple initializer or a tuple value, at which point we create a `TupleInit` or `TupleValue` that represents the formation of the tuple initializer or tuple value from the tuple literal. There's quite a lot of TODOs here, and the SemIR representation is still not quite right, but this seems like a good place to checkpoint some incremental progress.
55 lines
3.1 KiB
Plaintext
55 lines
3.1 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
|
|
|
|
fn Run() {
|
|
var a: [i32; 1] = (1,);
|
|
var b: [f64; 2] = (11.1, 2.2,);
|
|
var c: [(); 5] = ((), (), (), (), (),);
|
|
var d: (i32, i32, i32) = (1, 2, 3);
|
|
var e: [i32; 3] = d;
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ModuleID = 'base.carbon'
|
|
// CHECK:STDOUT: source_filename = "base.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define void @Run() {
|
|
// CHECK:STDOUT: %a = alloca [1 x i32], align 4
|
|
// CHECK:STDOUT: %array.index = getelementptr inbounds [1 x i32], ptr %a, i32 0, i32 0
|
|
// CHECK:STDOUT: store i32 1, ptr %array.index, align 4
|
|
// CHECK:STDOUT: %b = alloca [2 x double], align 8
|
|
// CHECK:STDOUT: %array.index1 = getelementptr inbounds [2 x double], ptr %b, i32 0, i32 0
|
|
// CHECK:STDOUT: store double 0x4026333333333334, ptr %array.index1, align 8
|
|
// CHECK:STDOUT: %array.index2 = getelementptr inbounds [2 x double], ptr %b, i32 0, i32 1
|
|
// CHECK:STDOUT: store double 2.200000e+00, ptr %array.index2, align 8
|
|
// CHECK:STDOUT: %c = alloca [5 x {}], align 8
|
|
// CHECK:STDOUT: %array.index3 = getelementptr inbounds [5 x {}], ptr %c, i32 0, i32 0
|
|
// CHECK:STDOUT: %array.index4 = getelementptr inbounds [5 x {}], ptr %c, i32 0, i32 1
|
|
// CHECK:STDOUT: %array.index5 = getelementptr inbounds [5 x {}], ptr %c, i32 0, i32 2
|
|
// CHECK:STDOUT: %array.index6 = getelementptr inbounds [5 x {}], ptr %c, i32 0, i32 3
|
|
// CHECK:STDOUT: %array.index7 = getelementptr inbounds [5 x {}], ptr %c, i32 0, i32 4
|
|
// CHECK:STDOUT: %d = alloca { i32, i32, i32 }, align 8
|
|
// CHECK:STDOUT: %tuple.index = getelementptr inbounds { i32, i32, i32 }, ptr %d, i32 0, i32 0
|
|
// CHECK:STDOUT: store i32 1, ptr %tuple.index, align 4
|
|
// CHECK:STDOUT: %tuple.index8 = getelementptr inbounds { i32, i32, i32 }, ptr %d, i32 0, i32 1
|
|
// CHECK:STDOUT: store i32 2, ptr %tuple.index8, align 4
|
|
// CHECK:STDOUT: %tuple.index9 = getelementptr inbounds { i32, i32, i32 }, ptr %d, i32 0, i32 2
|
|
// CHECK:STDOUT: store i32 3, ptr %tuple.index9, align 4
|
|
// CHECK:STDOUT: %e = alloca [3 x i32], align 4
|
|
// CHECK:STDOUT: %array.index10 = getelementptr inbounds [3 x i32], ptr %e, i32 0, i32 0
|
|
// CHECK:STDOUT: %tuple.index11 = getelementptr inbounds { i32, i32, i32 }, ptr %d, i32 0, i32 0
|
|
// CHECK:STDOUT: %1 = load i32, ptr %tuple.index11, align 4
|
|
// CHECK:STDOUT: store i32 %1, ptr %array.index10, align 4
|
|
// CHECK:STDOUT: %array.index12 = getelementptr inbounds [3 x i32], ptr %e, i32 0, i32 1
|
|
// CHECK:STDOUT: %tuple.index13 = getelementptr inbounds { i32, i32, i32 }, ptr %d, i32 0, i32 1
|
|
// CHECK:STDOUT: %2 = load i32, ptr %tuple.index13, align 4
|
|
// CHECK:STDOUT: store i32 %2, ptr %array.index12, align 4
|
|
// CHECK:STDOUT: %array.index14 = getelementptr inbounds [3 x i32], ptr %e, i32 0, i32 2
|
|
// CHECK:STDOUT: %tuple.index15 = getelementptr inbounds { i32, i32, i32 }, ptr %d, i32 0, i32 2
|
|
// CHECK:STDOUT: %3 = load i32, ptr %tuple.index15, align 4
|
|
// CHECK:STDOUT: store i32 %3, ptr %array.index14, align 4
|
|
// CHECK:STDOUT: ret void
|
|
// CHECK:STDOUT: }
|