| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- // 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
- // TIP: To test this file alone, run:
- // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/package_expr/syntax.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/package_expr/syntax.carbon
- // --- global.carbon
- package Global;
- var x: i32 = 0;
- var y: i32 = package.x;
- // --- inside_fn.carbon
- package InsideFn;
- var x: i32 = 0;
- fn Main() {
- var x: i32 = 1;
- var y: i32 = package.x;
- }
- // --- namespace.carbon
- package Namespace;
- namespace NS;
- class NS.C {
- fn Foo() {}
- };
- fn Main() {
- package.NS.C.Foo();
- }
- // CHECK:STDOUT: --- global.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
- // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
- // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [template]
- // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
- // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%import_ref.a5b), @impl.1(%int_32) [template]
- // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
- // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
- // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0.5c6, %Convert.956 [template]
- // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
- // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
- // CHECK:STDOUT: .Int = %import_ref.485
- // CHECK:STDOUT: .ImplicitAs = %import_ref.d44
- // CHECK:STDOUT: import Core//prelude
- // CHECK:STDOUT: import Core//prelude/...
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .x = %x
- // CHECK:STDOUT: .y = %y
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: name_binding_decl {
- // CHECK:STDOUT: %x.patt: %i32 = binding_pattern x
- // CHECK:STDOUT: %.loc4_1: %i32 = var_pattern %x.patt
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %x.var: ref %i32 = var x
- // CHECK:STDOUT: %.loc4_8: type = splice_block %i32.loc4 [template = constants.%i32] {
- // CHECK:STDOUT: %int_32.loc4: Core.IntLiteral = int_value 32 [template = constants.%int_32]
- // CHECK:STDOUT: %i32.loc4: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %x: ref %i32 = bind_name x, %x.var
- // CHECK:STDOUT: name_binding_decl {
- // CHECK:STDOUT: %y.patt: %i32 = binding_pattern y
- // CHECK:STDOUT: %.loc5_1: %i32 = var_pattern %y.patt
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %y.var: ref %i32 = var y
- // CHECK:STDOUT: %.loc5_8: type = splice_block %i32.loc5 [template = constants.%i32] {
- // CHECK:STDOUT: %int_32.loc5: Core.IntLiteral = int_value 32 [template = constants.%int_32]
- // CHECK:STDOUT: %i32.loc5: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %y: ref %i32 = bind_name y, %y.var
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @__global_init() {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0.5c6]
- // CHECK:STDOUT: %impl.elem0: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
- // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0, %impl.elem0 [template = constants.%Convert.bound]
- // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
- // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_0) [template = constants.%int_0.6a9]
- // CHECK:STDOUT: %.loc4: init %i32 = converted %int_0, %int.convert_checked [template = constants.%int_0.6a9]
- // CHECK:STDOUT: assign file.%x.var, %.loc4
- // CHECK:STDOUT: %package.ref: <namespace> = name_ref package, package [template = package]
- // CHECK:STDOUT: %x.ref: ref %i32 = name_ref x, file.%x
- // CHECK:STDOUT: %.loc5: %i32 = bind_value %x.ref
- // CHECK:STDOUT: assign file.%y.var, %.loc5
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- inside_fn.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
- // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
- // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [template]
- // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
- // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%import_ref.a5b), @impl.1(%int_32) [template]
- // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
- // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
- // CHECK:STDOUT: %Convert.bound.d04: <bound method> = bound_method %int_0.5c6, %Convert.956 [template]
- // CHECK:STDOUT: %Convert.specific_fn.d62: <specific function> = specific_function %Convert.bound.d04, @Convert.2(%int_32) [template]
- // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [template]
- // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
- // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
- // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [template]
- // CHECK:STDOUT: %Convert.bound.ab5: <bound method> = bound_method %int_1.5b8, %Convert.956 [template]
- // CHECK:STDOUT: %Convert.specific_fn.70c: <specific function> = specific_function %Convert.bound.ab5, @Convert.2(%int_32) [template]
- // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
- // CHECK:STDOUT: .Int = %import_ref.485
- // CHECK:STDOUT: .ImplicitAs = %import_ref.d44
- // CHECK:STDOUT: import Core//prelude
- // CHECK:STDOUT: import Core//prelude/...
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .x = %x
- // CHECK:STDOUT: .Main = %Main.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: name_binding_decl {
- // CHECK:STDOUT: %x.patt: %i32 = binding_pattern x
- // CHECK:STDOUT: %.loc4_1: %i32 = var_pattern %x.patt
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %x.var: ref %i32 = var x
- // CHECK:STDOUT: %.loc4_8: type = splice_block %i32 [template = constants.%i32] {
- // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
- // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %x: ref %i32 = bind_name x, %x.var
- // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {} {}
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Main() {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: name_binding_decl {
- // CHECK:STDOUT: %x.patt: %i32 = binding_pattern x
- // CHECK:STDOUT: %.loc7_3.1: %i32 = var_pattern %x.patt
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %x.var: ref %i32 = var x
- // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
- // CHECK:STDOUT: %impl.elem0: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
- // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_1, %impl.elem0 [template = constants.%Convert.bound.ab5]
- // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.70c]
- // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_1) [template = constants.%int_1.5d2]
- // CHECK:STDOUT: %.loc7_3.2: init %i32 = converted %int_1, %int.convert_checked [template = constants.%int_1.5d2]
- // CHECK:STDOUT: assign %x.var, %.loc7_3.2
- // CHECK:STDOUT: %.loc7_10: type = splice_block %i32.loc7 [template = constants.%i32] {
- // CHECK:STDOUT: %int_32.loc7: Core.IntLiteral = int_value 32 [template = constants.%int_32]
- // CHECK:STDOUT: %i32.loc7: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %x: ref %i32 = bind_name x, %x.var
- // CHECK:STDOUT: name_binding_decl {
- // CHECK:STDOUT: %y.patt: %i32 = binding_pattern y
- // CHECK:STDOUT: %.loc9_3: %i32 = var_pattern %y.patt
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %y.var: ref %i32 = var y
- // CHECK:STDOUT: %package.ref: <namespace> = name_ref package, package [template = package]
- // CHECK:STDOUT: %x.ref: ref %i32 = name_ref x, file.%x
- // CHECK:STDOUT: %.loc9_23: %i32 = bind_value %x.ref
- // CHECK:STDOUT: assign %y.var, %.loc9_23
- // CHECK:STDOUT: %.loc9_10: type = splice_block %i32.loc9 [template = constants.%i32] {
- // CHECK:STDOUT: %int_32.loc9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
- // CHECK:STDOUT: %i32.loc9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %y: ref %i32 = bind_name y, %y.var
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @__global_init() {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0.5c6]
- // CHECK:STDOUT: %impl.elem0: %Convert.type.1b6 = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
- // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0, %impl.elem0 [template = constants.%Convert.bound.d04]
- // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.d62]
- // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_0) [template = constants.%int_0.6a9]
- // CHECK:STDOUT: %.loc4: init %i32 = converted %int_0, %int.convert_checked [template = constants.%int_0.6a9]
- // CHECK:STDOUT: assign file.%x.var, %.loc4
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- namespace.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %C: type = class_type @C [template]
- // CHECK:STDOUT: %Foo.type: type = fn_type @Foo [template]
- // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
- // CHECK:STDOUT: %Foo: %Foo.type = struct_value () [template]
- // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
- // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
- // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
- // CHECK:STDOUT: import Core//prelude
- // CHECK:STDOUT: import Core//prelude/...
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .NS = %NS
- // CHECK:STDOUT: .Main = %Main.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: %NS: <namespace> = namespace [template] {
- // CHECK:STDOUT: .C = %C.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
- // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {} {}
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @C {
- // CHECK:STDOUT: %Foo.decl: %Foo.type = fn_decl @Foo [template = constants.%Foo] {} {}
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
- // CHECK:STDOUT: complete_type_witness = %complete_type
- // 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 [template = package]
- // CHECK:STDOUT: %NS.ref: <namespace> = name_ref NS, file.%NS [template = file.%NS]
- // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
- // CHECK:STDOUT: %Foo.ref: %Foo.type = name_ref Foo, @C.%Foo.decl [template = constants.%Foo]
- // CHECK:STDOUT: %Foo.call: init %empty_tuple.type = call %Foo.ref()
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|