mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 18:48:12 +00:00
Diagnostic rendering was part of the data model: `Loc::FormatLocation` and `Loc::FormatSnippet` wrote plain text to a stream, so no capability, color, or terminal width could reach them. A diagnostic is now one message with labels, contexts, and location information attached, and `Diagnostics::Renderer` draws it into a `Terminal::Buffer`. The design is in `toolchain/docs/diagnostics_rendering.md` (#7668), authoring in `toolchain/docs/diagnostics.md`. Before: ``` example.carbon:6:3: error: 1 argument passed to function expecting 0 arguments Run0(1); ^~~~~~~ example.carbon:3:1: note: calling function declared here fn Run0() {} ^~~~~~~~~~~ ``` After: ``` error: 1 argument passed to function expecting 0 arguments ╭─┤ example.carbon:6:3 ┆ 3 │ fn Run0() {} · ─────┬───── · ╰──┤ calling function declared here ┆ -> 6 │ Run0(1); · ─────── ╰──────────── ``` `--no-diagnostic-snippets` gives a compact form, `example.carbon:6:3-9`. File tests use it; the rendering tests under `toolchain/diagnostics/testdata` ask for snippets. C++ interop diagnostics are data now rather than text Clang drew: `SemIR::ClangSourceLocId` names a `clang::SourceRange`, and a Clang location is marked as the point it names. `StreamConsumer` moves to a `:renderer` target that `:emitter` does not depend on, keeping `common/terminal` out of `consumer.h`. Capabilities come from the file behind the error stream, so tests get plain ASCII. `renderer_fuzzer` draws diagnostics built from fuzzer bytes with every capability combination, since a shape the renderer doesn't expect must never be why the compiler dies while reporting a problem. TODOs mark the follow-ups: line weights and crossing lines, wrapping that keeps a quoted type whole, and ordering diagnostics that share a byte offset. Also: `IncorrectExtension`'s hint moves into its message, since its note had no location of its own, and `strip_noise` in `check_diagnostics.py` blanks multi-line `#define`s instead of deleting them. Assisted-by: Claude Code
193 lines
12 KiB
Plaintext
193 lines
12 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
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/pointer/make_null.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/pointer/make_null.carbon
|
|
|
|
// --- call_exact.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {}
|
|
|
|
fn MakeUnformed(t: type) -> type = "maybe_unformed.make_type";
|
|
fn MakeNullEmptyStruct() -> MakeUnformed({}*) = "pointer.make_null";
|
|
fn MakeNullC() -> MakeUnformed(C*) = "pointer.make_null";
|
|
|
|
//@dump-sem-ir-begin
|
|
let s: MakeUnformed({}*) = MakeNullEmptyStruct();
|
|
let c: MakeUnformed(C*) = MakeNullC();
|
|
//@dump-sem-ir-end
|
|
|
|
// --- call_generic.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn MakeUnformed(t: type) -> type = "maybe_unformed.make_type";
|
|
fn MakeNull(generic T: type) -> MakeUnformed(T*) = "pointer.make_null";
|
|
|
|
class C {}
|
|
|
|
//@dump-sem-ir-begin
|
|
let s: MakeUnformed({}*) = MakeNull({});
|
|
let c: MakeUnformed(C*) = MakeNull(C);
|
|
//@dump-sem-ir-end
|
|
|
|
// --- fail_bad_decl.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn MakeUnformed(t: type) -> type = "maybe_unformed.make_type";
|
|
|
|
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+2]]:1-16: error: invalid signature for builtin function "pointer.make_null" [InvalidBuiltinSignature]
|
|
// CHECK:STDERR:
|
|
fn NoRetType() = "pointer.make_null";
|
|
|
|
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+2]]:1-24: error: invalid signature for builtin function "pointer.make_null" [InvalidBuiltinSignature]
|
|
// CHECK:STDERR:
|
|
fn NoUnformed() -> {}* = "pointer.make_null";
|
|
|
|
// CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+2]]:1-37: error: invalid signature for builtin function "pointer.make_null" [InvalidBuiltinSignature]
|
|
// CHECK:STDERR:
|
|
fn NotPointer() -> MakeUnformed({}) = "pointer.make_null";
|
|
|
|
// CHECK:STDOUT: --- call_exact.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
|
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
|
// CHECK:STDOUT: %MakeUnformed.type: type = fn_type @MakeUnformed [concrete]
|
|
// CHECK:STDOUT: %MakeUnformed: %MakeUnformed.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %ptr.c28: type = ptr_type %empty_struct_type [concrete]
|
|
// CHECK:STDOUT: %.b2d: type = maybe_unformed_type %ptr.c28 [concrete]
|
|
// CHECK:STDOUT: %pattern_type.b42: type = pattern_type %.b2d [concrete]
|
|
// CHECK:STDOUT: %MakeNullEmptyStruct.type: type = fn_type @MakeNullEmptyStruct [concrete]
|
|
// CHECK:STDOUT: %MakeNullEmptyStruct: %MakeNullEmptyStruct.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %ptr.6b6: type = ptr_type %C [concrete]
|
|
// CHECK:STDOUT: %.9e8: type = maybe_unformed_type %ptr.6b6 [concrete]
|
|
// CHECK:STDOUT: %pattern_type.e22: type = pattern_type %.9e8 [concrete]
|
|
// CHECK:STDOUT: %MakeNullC.type: type = fn_type @MakeNullC [concrete]
|
|
// CHECK:STDOUT: %MakeNullC: %MakeNullC.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %s.patt: %pattern_type.b42 = value_binding_pattern s [concrete]
|
|
// CHECK:STDOUT: %c.patt: %pattern_type.e22 = value_binding_pattern c [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %.loc11_48.1: %.b2d = value_of_initializer @__global_init.%MakeNullEmptyStruct.call
|
|
// CHECK:STDOUT: %.loc11_48.2: %.b2d = converted @__global_init.%MakeNullEmptyStruct.call, %.loc11_48.1
|
|
// CHECK:STDOUT: %.loc11_24.1: type = splice_block %.loc11_24.3 [concrete = constants.%.b2d] {
|
|
// CHECK:STDOUT: %MakeUnformed.ref.loc11: %MakeUnformed.type = name_ref MakeUnformed, %MakeUnformed.decl [concrete = constants.%MakeUnformed]
|
|
// CHECK:STDOUT: %.loc11_22: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
|
|
// CHECK:STDOUT: %.loc11_23: type = converted %.loc11_22, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
|
|
// CHECK:STDOUT: %ptr.loc11: type = ptr_type %.loc11_23 [concrete = constants.%ptr.c28]
|
|
// CHECK:STDOUT: %MakeUnformed.call.loc11: init type = call %MakeUnformed.ref.loc11(%ptr.loc11) [concrete = constants.%.b2d]
|
|
// CHECK:STDOUT: %.loc11_24.2: type = value_of_initializer %MakeUnformed.call.loc11 [concrete = constants.%.b2d]
|
|
// CHECK:STDOUT: %.loc11_24.3: type = converted %MakeUnformed.call.loc11, %.loc11_24.2 [concrete = constants.%.b2d]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %s: %.b2d = wrapper_binding s, %.loc11_48.2
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %s.patt: %pattern_type.b42 = value_binding_pattern s [concrete = constants.%s.patt]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %.loc12_37.1: %.9e8 = value_of_initializer @__global_init.%MakeNullC.call
|
|
// CHECK:STDOUT: %.loc12_37.2: %.9e8 = converted @__global_init.%MakeNullC.call, %.loc12_37.1
|
|
// CHECK:STDOUT: %.loc12_23.1: type = splice_block %.loc12_23.3 [concrete = constants.%.9e8] {
|
|
// CHECK:STDOUT: %MakeUnformed.ref.loc12: %MakeUnformed.type = name_ref MakeUnformed, %MakeUnformed.decl [concrete = constants.%MakeUnformed]
|
|
// CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: %ptr.loc12: type = ptr_type %C.ref [concrete = constants.%ptr.6b6]
|
|
// CHECK:STDOUT: %MakeUnformed.call.loc12: init type = call %MakeUnformed.ref.loc12(%ptr.loc12) [concrete = constants.%.9e8]
|
|
// CHECK:STDOUT: %.loc12_23.2: type = value_of_initializer %MakeUnformed.call.loc12 [concrete = constants.%.9e8]
|
|
// CHECK:STDOUT: %.loc12_23.3: type = converted %MakeUnformed.call.loc12, %.loc12_23.2 [concrete = constants.%.9e8]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %c: %.9e8 = wrapper_binding c, %.loc12_37.2
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %c.patt: %pattern_type.e22 = value_binding_pattern c [concrete = constants.%c.patt]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @__global_init() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %MakeNullEmptyStruct.ref: %MakeNullEmptyStruct.type = name_ref MakeNullEmptyStruct, file.%MakeNullEmptyStruct.decl [concrete = constants.%MakeNullEmptyStruct]
|
|
// CHECK:STDOUT: %MakeNullEmptyStruct.call: init %.b2d = call %MakeNullEmptyStruct.ref()
|
|
// CHECK:STDOUT: %MakeNullC.ref: %MakeNullC.type = name_ref MakeNullC, file.%MakeNullC.decl [concrete = constants.%MakeNullC]
|
|
// CHECK:STDOUT: %MakeNullC.call: init %.9e8 = call %MakeNullC.ref()
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- call_generic.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %MakeUnformed.type: type = fn_type @MakeUnformed [concrete]
|
|
// CHECK:STDOUT: %MakeUnformed: %MakeUnformed.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %MakeNull.type: type = fn_type @MakeNull [concrete]
|
|
// CHECK:STDOUT: %MakeNull: %MakeNull.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
|
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
|
// CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %ptr.c28: type = ptr_type %empty_struct_type [concrete]
|
|
// CHECK:STDOUT: %.b2d: type = maybe_unformed_type %ptr.c28 [concrete]
|
|
// CHECK:STDOUT: %pattern_type.b42: type = pattern_type %.b2d [concrete]
|
|
// CHECK:STDOUT: %s.patt: %pattern_type.b42 = value_binding_pattern s [concrete]
|
|
// CHECK:STDOUT: %MakeNull.specific_fn.3e4: <specific function> = specific_function %MakeNull, @MakeNull(%empty_struct_type) [concrete]
|
|
// CHECK:STDOUT: %ptr.6b6: type = ptr_type %C [concrete]
|
|
// CHECK:STDOUT: %.9e8: type = maybe_unformed_type %ptr.6b6 [concrete]
|
|
// CHECK:STDOUT: %pattern_type.e22: type = pattern_type %.9e8 [concrete]
|
|
// CHECK:STDOUT: %c.patt: %pattern_type.e22 = value_binding_pattern c [concrete]
|
|
// CHECK:STDOUT: %MakeNull.specific_fn.e96: <specific function> = specific_function %MakeNull, @MakeNull(%C) [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %.loc10_39.1: %.b2d = value_of_initializer @__global_init.%MakeNull.call.loc10
|
|
// CHECK:STDOUT: %.loc10_39.2: %.b2d = converted @__global_init.%MakeNull.call.loc10, %.loc10_39.1
|
|
// CHECK:STDOUT: %.loc10_24.1: type = splice_block %.loc10_24.3 [concrete = constants.%.b2d] {
|
|
// CHECK:STDOUT: %MakeUnformed.ref.loc10: %MakeUnformed.type = name_ref MakeUnformed, %MakeUnformed.decl [concrete = constants.%MakeUnformed]
|
|
// CHECK:STDOUT: %.loc10_22: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
|
|
// CHECK:STDOUT: %.loc10_23: type = converted %.loc10_22, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
|
|
// CHECK:STDOUT: %ptr.loc10: type = ptr_type %.loc10_23 [concrete = constants.%ptr.c28]
|
|
// CHECK:STDOUT: %MakeUnformed.call.loc10: init type = call %MakeUnformed.ref.loc10(%ptr.loc10) [concrete = constants.%.b2d]
|
|
// CHECK:STDOUT: %.loc10_24.2: type = value_of_initializer %MakeUnformed.call.loc10 [concrete = constants.%.b2d]
|
|
// CHECK:STDOUT: %.loc10_24.3: type = converted %MakeUnformed.call.loc10, %.loc10_24.2 [concrete = constants.%.b2d]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %s: %.b2d = wrapper_binding s, %.loc10_39.2
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %s.patt: %pattern_type.b42 = value_binding_pattern s [concrete = constants.%s.patt]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %.loc11_37.1: %.9e8 = value_of_initializer @__global_init.%MakeNull.call.loc11
|
|
// CHECK:STDOUT: %.loc11_37.2: %.9e8 = converted @__global_init.%MakeNull.call.loc11, %.loc11_37.1
|
|
// CHECK:STDOUT: %.loc11_23.1: type = splice_block %.loc11_23.3 [concrete = constants.%.9e8] {
|
|
// CHECK:STDOUT: %MakeUnformed.ref.loc11: %MakeUnformed.type = name_ref MakeUnformed, %MakeUnformed.decl [concrete = constants.%MakeUnformed]
|
|
// CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: %ptr.loc11: type = ptr_type %C.ref [concrete = constants.%ptr.6b6]
|
|
// CHECK:STDOUT: %MakeUnformed.call.loc11: init type = call %MakeUnformed.ref.loc11(%ptr.loc11) [concrete = constants.%.9e8]
|
|
// CHECK:STDOUT: %.loc11_23.2: type = value_of_initializer %MakeUnformed.call.loc11 [concrete = constants.%.9e8]
|
|
// CHECK:STDOUT: %.loc11_23.3: type = converted %MakeUnformed.call.loc11, %.loc11_23.2 [concrete = constants.%.9e8]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %c: %.9e8 = wrapper_binding c, %.loc11_37.2
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %c.patt: %pattern_type.e22 = value_binding_pattern c [concrete = constants.%c.patt]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @__global_init() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %MakeNull.ref.loc10: %MakeNull.type = name_ref MakeNull, file.%MakeNull.decl [concrete = constants.%MakeNull]
|
|
// CHECK:STDOUT: %.loc10_38: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
|
|
// CHECK:STDOUT: %.loc10_39: type = converted %.loc10_38, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
|
|
// CHECK:STDOUT: %MakeNull.specific_fn.loc10: <specific function> = specific_function %MakeNull.ref.loc10, @MakeNull(constants.%empty_struct_type) [concrete = constants.%MakeNull.specific_fn.3e4]
|
|
// CHECK:STDOUT: %MakeNull.call.loc10: init %.b2d = call %MakeNull.specific_fn.loc10()
|
|
// CHECK:STDOUT: %MakeNull.ref.loc11: %MakeNull.type = name_ref MakeNull, file.%MakeNull.decl [concrete = constants.%MakeNull]
|
|
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: %MakeNull.specific_fn.loc11: <specific function> = specific_function %MakeNull.ref.loc11, @MakeNull(constants.%C) [concrete = constants.%MakeNull.specific_fn.e96]
|
|
// CHECK:STDOUT: %MakeNull.call.loc11: init %.9e8 = call %MakeNull.specific_fn.loc11()
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|