mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 16:20:30 +00:00
Historically, we disabled the rendered form in tests outside of `toolchain/diagnostics`. The idea was to keep tests shorter and avoid very long chains of autoupdate before stabilizing due to all the line numbers and other artifacts in the rendered form. This PR adds `--diagnostic-line-numbers=[all|first]` and defaults to `first` in tests. This keeps the rendered form so that we can easily code review that form and the visual cues it does or doesn't provide. But it removes all but the first location's line numbers to provide significantly more stability in tests. By default, tests get the full unicode line-drawing form of diagnostics so we can ensure all of the artifacts there make sense with the specific case being diagnosed, but we do retain some focused ASCII-rendering tests to ensure that fallback remains usable. There are some issues here that will be fixed in subsequent PRs. Notably, we try to keep the frame together in the check lines, and so force some parts to use the first location. This largely works, but fails in some edge cases, causing the entire frame to be located incorrectly. There is a TODO about this that we need to fix, and it only occurs 6 times across the test suite, so it didn't seem worth front-loading a fix for here. Assisted-by: Claude Code
247 lines
14 KiB
Plaintext
247 lines
14 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/destroy.carbon
|
|
// 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/interop/cpp/var/import/global.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/var/import/global.carbon
|
|
|
|
// ============================================================================
|
|
// Global scope
|
|
// ============================================================================
|
|
|
|
// --- global_scope.h
|
|
|
|
class C {};
|
|
C global;
|
|
C* _Nonnull global_ptr = &global;
|
|
C& global_ref = global;
|
|
|
|
|
|
// --- import_global_scope.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp library "global_scope.h";
|
|
|
|
fn MyF() {
|
|
let unused local: Cpp.C = Cpp.global;
|
|
let unused local_ptr: Cpp.C* = Cpp.global_ptr;
|
|
let unused local_ref: Cpp.C* = Cpp.global_ref;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Unsupported global type
|
|
// ============================================================================
|
|
|
|
// --- unsupported_type.h
|
|
|
|
// CHECK:STDERR: ╷ ╭── included from: fail_import_unsupported_type.carbon [InCppInclude]
|
|
// CHECK:STDERR: ├─┤ ./unsupported_type.h:[[@LINE+14]]:7
|
|
// CHECK:STDERR: -> │ using UnusupportedType = _BitInt(23);
|
|
// CHECK:STDERR: · ┳
|
|
// CHECK:STDERR: · ┗━━┫ error: semantics TODO:
|
|
// CHECK:STDERR: · ┃ `Unsupported: Type declaration: UnusupportedType`
|
|
// CHECK:STDERR: · ┃ [SemanticsTodo]
|
|
// CHECK:STDERR: ┆
|
|
// CHECK:STDERR: ├─┤ fail_import_unsupported_type.carbon
|
|
// CHECK:STDERR: │ let unused local: Cpp.UnusupportedType = Cpp.unsupported_global;
|
|
// CHECK:STDERR: · ──────────┬─────────
|
|
// CHECK:STDERR: · ╰──┤ in `Cpp` name lookup for `UnusupportedType`
|
|
// CHECK:STDERR: · │ [InCppNameLookup]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
using UnusupportedType = _BitInt(23);
|
|
UnusupportedType unsupported_global;
|
|
|
|
// --- fail_import_unsupported_type.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp library "unsupported_type.h";
|
|
|
|
fn MyF() {
|
|
// CHECK:STDERR: ╭─┤ fail_import_unsupported_type.carbon:[[@LINE+11]]:44
|
|
// CHECK:STDERR: -> │ let unused local: Cpp.UnusupportedType = Cpp.unsupported_global;
|
|
// CHECK:STDERR: · ┳━━━━━━━━━━━━━━━━━━━━━
|
|
// CHECK:STDERR: · ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
// CHECK:STDERR: · ┃ error: semantics TODO: `Unsupported: var type: UnusupportedType`
|
|
// CHECK:STDERR: · ┃ [SemanticsTodo]
|
|
// CHECK:STDERR: · ╰──┤ in `Cpp` name lookup for
|
|
// CHECK:STDERR: · │ `unsupported_global`
|
|
// CHECK:STDERR: · │ [InCppNameLookup]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
let unused local: Cpp.UnusupportedType = Cpp.unsupported_global;
|
|
}
|
|
|
|
// CHECK:STDOUT: --- import_global_scope.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %MyF.type: type = fn_type @MyF [concrete]
|
|
// CHECK:STDOUT: %MyF: %MyF.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
|
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
|
|
// CHECK:STDOUT: %pattern_type.bbc: type = pattern_type %C [concrete]
|
|
// CHECK:STDOUT: %local.patt: %pattern_type.bbc = value_binding_pattern local [concrete]
|
|
// CHECK:STDOUT: %global.patt: %pattern_type.bbc = ref_binding_pattern global [concrete]
|
|
// CHECK:STDOUT: %global.var_patt: %pattern_type.bbc = var_pattern %global.patt [concrete]
|
|
// CHECK:STDOUT: %ptr.0a2: type = ptr_type %C [concrete]
|
|
// CHECK:STDOUT: %pattern_type.8fa: type = pattern_type %ptr.0a2 [concrete]
|
|
// CHECK:STDOUT: %local_ptr.patt: %pattern_type.8fa = value_binding_pattern local_ptr [concrete]
|
|
// CHECK:STDOUT: %global_ptr.patt: %pattern_type.8fa = ref_binding_pattern global_ptr [concrete]
|
|
// CHECK:STDOUT: %global_ptr.var_patt: %pattern_type.8fa = var_pattern %global_ptr.patt [concrete]
|
|
// CHECK:STDOUT: %local_ref.patt: %pattern_type.8fa = value_binding_pattern local_ref [concrete]
|
|
// CHECK:STDOUT: %const: type = const_type %ptr.0a2 [concrete]
|
|
// CHECK:STDOUT: %pattern_type.635: type = pattern_type %const [concrete]
|
|
// CHECK:STDOUT: %global_ref.patt: %pattern_type.635 = ref_binding_pattern global_ref [concrete]
|
|
// CHECK:STDOUT: %global_ref.var_patt: %pattern_type.635 = var_pattern %global_ref.patt [concrete]
|
|
// CHECK:STDOUT: %global_ref.var: ref %ptr.0a2 = var_storage imports.%global_ref.var_patt [concrete]
|
|
// CHECK:STDOUT: %addr: %ptr.0a2 = addr_of imports.%global.var [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
|
|
// CHECK:STDOUT: .C = %C.decl
|
|
// CHECK:STDOUT: .global = %global.var
|
|
// CHECK:STDOUT: .global_ptr = %global_ptr.var
|
|
// CHECK:STDOUT: .global_ref = %global_ref.var
|
|
// CHECK:STDOUT: import Cpp//...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
|
|
// CHECK:STDOUT: %global.patt: %pattern_type.bbc = ref_binding_pattern global [concrete = constants.%global.patt]
|
|
// CHECK:STDOUT: %global.var_patt: %pattern_type.bbc = var_pattern %global.patt [concrete = constants.%global.var_patt]
|
|
// CHECK:STDOUT: %global.var: ref %C = var_storage %global.var_patt [concrete]
|
|
// CHECK:STDOUT: %global_ptr.patt: %pattern_type.8fa = ref_binding_pattern global_ptr [concrete = constants.%global_ptr.patt]
|
|
// CHECK:STDOUT: %global_ptr.var_patt: %pattern_type.8fa = var_pattern %global_ptr.patt [concrete = constants.%global_ptr.var_patt]
|
|
// CHECK:STDOUT: %global_ptr.var: ref %ptr.0a2 = var_storage %global_ptr.var_patt [concrete]
|
|
// CHECK:STDOUT: %global_ref.patt: %pattern_type.635 = ref_binding_pattern global_ref [concrete = constants.%global_ref.patt]
|
|
// CHECK:STDOUT: %global_ref.var_patt: %pattern_type.635 = var_pattern %global_ref.patt [concrete = constants.%global_ref.var_patt]
|
|
// CHECK:STDOUT: %global_ref.var: ref %const = var_storage %global_ref.var_patt [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .Cpp = imports.%Cpp
|
|
// CHECK:STDOUT: .MyF = %MyF.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
|
// CHECK:STDOUT: import Cpp "global_scope.h"
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @C {
|
|
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
|
|
// CHECK:STDOUT: complete_type_witness = %complete_type
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: import Cpp//...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @MyF() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %Cpp.ref.loc7_29: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
|
// CHECK:STDOUT: %global.ref: ref %C = name_ref global, imports.%global.var [concrete = imports.%global.var]
|
|
// CHECK:STDOUT: %.loc7_32: %C = acquire_value %global.ref
|
|
// CHECK:STDOUT: %.loc7_24: type = splice_block %C.ref.loc7 [concrete = constants.%C] {
|
|
// CHECK:STDOUT: %Cpp.ref.loc7_21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
|
// CHECK:STDOUT: %C.ref.loc7: type = name_ref C, imports.%C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %local: %C = wrapper_binding local, %.loc7_32
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %local.patt: %pattern_type.bbc = value_binding_pattern local [concrete = constants.%local.patt]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Cpp.ref.loc8_34: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
|
// CHECK:STDOUT: %global_ptr.ref: ref %ptr.0a2 = name_ref global_ptr, imports.%global_ptr.var [concrete = imports.%global_ptr.var]
|
|
// CHECK:STDOUT: %.loc8_37: %ptr.0a2 = acquire_value %global_ptr.ref
|
|
// CHECK:STDOUT: %.loc8_30: type = splice_block %ptr.loc8 [concrete = constants.%ptr.0a2] {
|
|
// CHECK:STDOUT: %Cpp.ref.loc8_25: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
|
// CHECK:STDOUT: %C.ref.loc8: type = name_ref C, imports.%C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: %ptr.loc8: type = ptr_type %C.ref.loc8 [concrete = constants.%ptr.0a2]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %local_ptr: %ptr.0a2 = wrapper_binding local_ptr, %.loc8_37
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %local_ptr.patt: %pattern_type.8fa = value_binding_pattern local_ptr [concrete = constants.%local_ptr.patt]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Cpp.ref.loc9_34: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
|
// CHECK:STDOUT: %global_ref.ref: ref %const = name_ref global_ref, imports.%global_ref.var [concrete = imports.%global_ref.var]
|
|
// CHECK:STDOUT: %.loc9_37.1: ref %ptr.0a2 = as_compatible %global_ref.ref [concrete = constants.%global_ref.var]
|
|
// CHECK:STDOUT: %.loc9_37.2: ref %ptr.0a2 = converted %global_ref.ref, %.loc9_37.1 [concrete = constants.%global_ref.var]
|
|
// CHECK:STDOUT: %addr: %ptr.0a2 = addr_of imports.%global.var [concrete = constants.%addr]
|
|
// CHECK:STDOUT: %.loc9_37.3: %ptr.0a2 = acquire_value %.loc9_37.2 [concrete = constants.%addr]
|
|
// CHECK:STDOUT: %.loc9_30: type = splice_block %ptr.loc9 [concrete = constants.%ptr.0a2] {
|
|
// CHECK:STDOUT: %Cpp.ref.loc9_25: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
|
// CHECK:STDOUT: %C.ref.loc9: type = name_ref C, imports.%C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: %ptr.loc9: type = ptr_type %C.ref.loc9 [concrete = constants.%ptr.0a2]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %local_ref: %ptr.0a2 = wrapper_binding local_ref, %.loc9_37.3
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %local_ref.patt: %pattern_type.8fa = value_binding_pattern local_ref [concrete = constants.%local_ref.patt]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_import_unsupported_type.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %MyF.type: type = fn_type @MyF [concrete]
|
|
// CHECK:STDOUT: %MyF: %MyF.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
|
|
// CHECK:STDOUT: .UnusupportedType = <error>
|
|
// CHECK:STDOUT: .unsupported_global = <error>
|
|
// CHECK:STDOUT: import Cpp//...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .Cpp = imports.%Cpp
|
|
// CHECK:STDOUT: .MyF = %MyF.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
|
|
// CHECK:STDOUT: import Cpp "unsupported_type.h"
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @MyF() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %Cpp.ref.loc18_44: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
|
// CHECK:STDOUT: %unsupported_global.ref: <error> = name_ref unsupported_global, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: %.1: <error> = splice_block <error> [concrete = <error>] {
|
|
// CHECK:STDOUT: %Cpp.ref.loc18_21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
|
|
// CHECK:STDOUT: %UnusupportedType.ref: <error> = name_ref UnusupportedType, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %local: <error> = wrapper_binding local, <error> [concrete = <error>]
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %local.patt: <error> = value_binding_pattern local [concrete = <error>]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|