mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 14:48:10 +00:00
Shorthand names are intended to be used in the textual format of references to instructions in another IR (which can't happen now, but will be possible in a forthcoming PR). The shorthand name uses the file name (minus the `.carbon` suffix) as a base, and if that base name is ambiguous within the compilation, it is given a numerical suffix `.N`, just like other textual IR names. Shorthand names are prefixed with `$` in the textual format, to distinguish them from inst and scope names. For example, a file `foo/bar.carbon` has the shorthand name `$bar`, and an instruction `@baz.%qux` in that file can be referenced from another file as `$bar.@baz.%qux`. This PR adds `toolchain/check/testdata/basics/file_name.carbon` to test this behavior. All other test changes are just applying this change to the existing textual SemIR dumps. --------- Co-authored-by: Dana Jansens <danakj@orodu.net>
266 lines
11 KiB
Plaintext
266 lines
11 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/none.carbon
|
|
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
|
|
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/declaration/extern.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/declaration/extern.carbon
|
|
|
|
// --- basic.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
extern fn F();
|
|
|
|
// --- basic_use.carbon
|
|
|
|
import library "basic";
|
|
|
|
var x: () = F();
|
|
|
|
// --- fail_redecl.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
extern fn F();
|
|
// CHECK:STDERR: ╭─┤ fail_redecl.carbon:[[@LINE+10]]:1
|
|
// CHECK:STDERR: │ extern fn F();
|
|
// CHECK:STDERR: · ───────┬──────
|
|
// CHECK:STDERR: · ╰──┤ previously declared here [RedeclPrevDecl]
|
|
// CHECK:STDERR: ┆
|
|
// CHECK:STDERR: -> │ extern fn F();
|
|
// CHECK:STDERR: · ━━━━━━━┳━━━━━━
|
|
// CHECK:STDERR: · ┗━━┫ error: redeclaration of `fn F` is redundant [RedeclRedundant]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
extern fn F();
|
|
|
|
// --- fail_redecl_extern.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
extern fn F();
|
|
// CHECK:STDERR: ╭─┤ fail_redecl_extern.carbon:[[@LINE+10]]:1
|
|
// CHECK:STDERR: │ extern fn F();
|
|
// CHECK:STDERR: · ───────┬──────
|
|
// CHECK:STDERR: · ╰──┤ previously declared here [RedeclPrevDecl]
|
|
// CHECK:STDERR: ┆
|
|
// CHECK:STDERR: -> │ fn F();
|
|
// CHECK:STDERR: · ━━━┳━━━
|
|
// CHECK:STDERR: · ┗━━┫ error: redeclaration of `fn F` is redundant [RedeclRedundant]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
fn F();
|
|
|
|
// --- fail_member_extern.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
// CHECK:STDERR: ╭─┤ fail_member_extern.carbon:[[@LINE+7]]:3
|
|
// CHECK:STDERR: -> │ extern fn F();
|
|
// CHECK:STDERR: · ━━━┳━━
|
|
// CHECK:STDERR: · ┗━━┫ error: `extern` not allowed; requires file or namespace scope
|
|
// CHECK:STDERR: · ┃ [ModifierExternNotAllowed]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
extern fn F();
|
|
// CHECK:STDERR: ╭─┤ fail_member_extern.carbon:[[@LINE+7]]:3
|
|
// CHECK:STDERR: -> │ extern fn G(self);
|
|
// CHECK:STDERR: · ━━━┳━━
|
|
// CHECK:STDERR: · ┗━━┫ error: `extern` not allowed; requires file or namespace scope
|
|
// CHECK:STDERR: · ┃ [ModifierExternNotAllowed]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
extern fn G(self);
|
|
}
|
|
|
|
// --- fail_extern_library_in_importer.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import library "basic";
|
|
|
|
// CHECK:STDERR: ╭─┤ fail_extern_library_in_importer.carbon:[[@LINE+12]]:1
|
|
// CHECK:STDERR: -> │ extern library "basic" fn F();
|
|
// CHECK:STDERR: · ━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━
|
|
// CHECK:STDERR: · ┗━━┫ error: cannot declare imported `fn F` as `extern library`
|
|
// CHECK:STDERR: · ┃ [ExternLibraryInImporter]
|
|
// CHECK:STDERR: ┆
|
|
// CHECK:STDERR: ├─┤ basic.carbon
|
|
// CHECK:STDERR: │ extern fn F();
|
|
// CHECK:STDERR: · ───────┬──────
|
|
// CHECK:STDERR: · ╰──┤ previously declared here [RedeclPrevDecl]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
extern library "basic" fn F();
|
|
|
|
// CHECK:STDOUT: --- basic.carbon = $basic
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .F = %F.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: extern fn @F();
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- basic_use.carbon = $basic_use
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
|
// CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
|
|
// CHECK:STDOUT: %pattern_type: type = pattern_type %empty_tuple.type [concrete]
|
|
// CHECK:STDOUT: %x.patt: %pattern_type = ref_binding_pattern x [concrete]
|
|
// CHECK:STDOUT: %x.var_patt: %pattern_type = var_pattern %x.patt [concrete]
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Main.F: %F.type = import_ref Main//basic, F, loaded [concrete = constants.%F]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .F = imports.%Main.F
|
|
// CHECK:STDOUT: .x = %x
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %default.import = import <none>
|
|
// CHECK:STDOUT: %x.var: ref %empty_tuple.type = var_storage %x.var_patt [concrete]
|
|
// CHECK:STDOUT: %.loc4_9.1: type = splice_block %.loc4_9.3 [concrete = constants.%empty_tuple.type] {
|
|
// CHECK:STDOUT: %.loc4_9.2: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
|
|
// CHECK:STDOUT: %.loc4_9.3: type = converted %.loc4_9.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %x: ref %empty_tuple.type = wrapper_binding x, %x.var [concrete = %x.var]
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %x.patt: %pattern_type = ref_binding_pattern x [concrete = constants.%x.patt]
|
|
// CHECK:STDOUT: %x.var_patt: %pattern_type = var_pattern %x.patt [concrete = constants.%x.var_patt]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: extern fn @F [from "basic.carbon"];
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @__global_init() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %F.ref: %F.type = name_ref F, imports.%Main.F [concrete = constants.%F]
|
|
// CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
|
|
// CHECK:STDOUT: assign file.%x.var, %F.call
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_redecl.carbon = $fail_redecl
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .F = %F.decl.loc4
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %F.decl.loc4: %F.type = fn_decl @F [concrete = constants.%F] {} {}
|
|
// CHECK:STDOUT: %F.decl.loc15: %F.type = fn_decl @F [concrete = constants.%F] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: extern fn @F();
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_redecl_extern.carbon = $fail_redecl_extern
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .F = %F.decl.loc4
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %F.decl.loc4: %F.type = fn_decl @F [concrete = constants.%F] {} {}
|
|
// CHECK:STDOUT: %F.decl.loc15: %F.type = fn_decl @F [concrete = constants.%F] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: extern fn @F();
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_member_extern.carbon = $fail_member_extern
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
|
// CHECK:STDOUT: %C.F.type: type = fn_type @C.F [concrete]
|
|
// CHECK:STDOUT: %C.F: %C.F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %pattern_type: type = pattern_type %C [concrete]
|
|
// CHECK:STDOUT: %self.param_patt: %pattern_type = value_param_pattern [concrete]
|
|
// CHECK:STDOUT: %self.patt: %pattern_type = wrapper_binding_pattern self, %self.param_patt [concrete]
|
|
// CHECK:STDOUT: %C.G.type: type = fn_type @C.G [concrete]
|
|
// CHECK:STDOUT: %C.G: %C.G.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .C = %C.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @C {
|
|
// CHECK:STDOUT: %C.F.decl: %C.F.type = fn_decl @C.F [concrete = constants.%C.F] {} {}
|
|
// CHECK:STDOUT: %C.G.decl: %C.G.type = fn_decl @C.G [concrete = constants.%C.G] {
|
|
// CHECK:STDOUT: %self.param_patt: %pattern_type = value_param_pattern [concrete = constants.%self.param_patt]
|
|
// CHECK:STDOUT: %self.patt: %pattern_type = wrapper_binding_pattern self, %self.param_patt [concrete = constants.%self.patt]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %self.param: %C = value_param call_param0
|
|
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
|
|
// CHECK:STDOUT: %self: %C = wrapper_binding self, %self.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
|
|
// CHECK:STDOUT: complete_type_witness = %complete_type
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%C
|
|
// CHECK:STDOUT: .F = %C.F.decl
|
|
// CHECK:STDOUT: .G = %C.G.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @C.F();
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @C.G(%self.param: %C);
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_extern_library_in_importer.carbon = $fail_extern_library_in_importer
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .F = invalid
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %default.import = import <none>
|
|
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: extern fn @F [from "basic.carbon"];
|
|
// CHECK:STDOUT:
|