Files
carbon-lang/toolchain/check/testdata/package_expr/syntax.carbon
T
Richard Smith 7553d864e1 Very basic support for constant evaluation of expressions. (#3581)
Form a side table with constant values for each instruction. Evaluation
is only supported for a few very simple kinds of instruction for now.
This is not observable outside of the SemIR output, because nothing
depends on expressions having a constant value phase yet.
2024-01-11 23:12:58 +00:00

144 lines
4.4 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
// --- global.carbon
package Global api;
var x: i32 = 0;
fn Main() {
var x: i32 = 1;
var y: i32 = package.x;
}
// --- inside_fn.carbon
package InsideFn api;
var x: i32 = 0;
fn Main() {
var x: i32 = 1;
var y: i32 = package.x;
}
// --- namespace.carbon
package Namespace api;
namespace NS;
class NS.C {
fn Foo() {}
};
fn Main() {
package.NS.C.Foo();
}
// CHECK:STDOUT: --- global.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.loc4: i32 = int_literal 0, const
// CHECK:STDOUT: %.loc7: i32 = int_literal 1, const
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace package, {.x = %x, .Main = %Main}
// CHECK:STDOUT: %x.var: ref i32 = var x
// CHECK:STDOUT: %x: ref i32 = bind_name x, %x.var
// CHECK:STDOUT: %.loc4: i32 = int_literal 0, const = constants.%.loc4
// CHECK:STDOUT: assign %x.var, %.loc4
// CHECK:STDOUT: %Main: <function> = fn_decl @Main, const
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Main() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %x.var: ref i32 = var x
// CHECK:STDOUT: %x: ref i32 = bind_name x, %x.var
// CHECK:STDOUT: %.loc7: i32 = int_literal 1, const = constants.%.loc7
// CHECK:STDOUT: assign %x.var, %.loc7
// CHECK:STDOUT: %y.var: ref i32 = var y
// CHECK:STDOUT: %y: ref i32 = bind_name y, %y.var
// CHECK:STDOUT: %package.ref: <namespace> = name_ref package, package
// CHECK:STDOUT: %x.ref: ref i32 = name_ref x, file.%x
// CHECK:STDOUT: %.loc9: i32 = bind_value %x.ref
// CHECK:STDOUT: assign %y.var, %.loc9
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- inside_fn.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.loc4: i32 = int_literal 0, const
// CHECK:STDOUT: %.loc7: i32 = int_literal 1, const
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace package, {.x = %x, .Main = %Main}
// CHECK:STDOUT: %x.var: ref i32 = var x
// CHECK:STDOUT: %x: ref i32 = bind_name x, %x.var
// CHECK:STDOUT: %.loc4: i32 = int_literal 0, const = constants.%.loc4
// CHECK:STDOUT: assign %x.var, %.loc4
// CHECK:STDOUT: %Main: <function> = fn_decl @Main, const
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Main() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %x.var: ref i32 = var x
// CHECK:STDOUT: %x: ref i32 = bind_name x, %x.var
// CHECK:STDOUT: %.loc7: i32 = int_literal 1, const = constants.%.loc7
// CHECK:STDOUT: assign %x.var, %.loc7
// CHECK:STDOUT: %y.var: ref i32 = var y
// CHECK:STDOUT: %y: ref i32 = bind_name y, %y.var
// CHECK:STDOUT: %package.ref: <namespace> = name_ref package, package
// CHECK:STDOUT: %x.ref: ref i32 = name_ref x, file.%x
// CHECK:STDOUT: %.loc9: i32 = bind_value %x.ref
// CHECK:STDOUT: assign %y.var, %.loc9
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- namespace.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.loc8: type = struct_type {}, const
// CHECK:STDOUT: %.loc11: type = tuple_type (), const
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace package, {.NS = %.loc4, .Main = %Main}
// CHECK:STDOUT: %.loc4: <namespace> = namespace NS, {.C = %C.decl}
// CHECK:STDOUT: %C.decl = class_decl @C, ()
// CHECK:STDOUT: %C: type = class_type @C, const
// CHECK:STDOUT: %Main: <function> = fn_decl @Main, const
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @C {
// CHECK:STDOUT: %Foo: <function> = fn_decl @Foo, const
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Foo = %Foo
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Foo() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Main() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %package.ref: <namespace> = name_ref package, package
// CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, file.%.loc4
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C, const = file.%C
// CHECK:STDOUT: %Foo.ref: <function> = name_ref Foo, @C.%Foo, const = @C.%Foo
// CHECK:STDOUT: %.loc11: init () = call %Foo.ref()
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: