mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Move diagnostics into a namespace (#5173)
What this really does is avoids shadowing names, so that we can comfortable have things like `Check::DiagnosticEmitter` or `Check::DiagnosticLoc` without shadowing being a concern. Note, down this path I'm also thinking about: - Renaming misc DiagnosticConsumer/DiagnosticEmitter classes, possibly just to DiagnosticConsumer/DiagnosticEmitter (so `Check::DiagnosticEmitter` instead of `SemIRLocDiagnosticEmitter`). - Dropping `Diagnostic` from `Emitter::DiagnosticBuilder`. - But not for `Check::DiagnosticBuilder`, because `Check::Builder` would be ambiguous. - Renaming diagnostics/diagnostic_* to drop "diagnostic". [Discussion about SemIRLoc -> DiagnosticLoc](https://discord.com/channels/655572317891461132/655578254970716160/1353771570463768698) reminded me of this (in particular the older [Check::DiagnosticBuilder discussion](https://discord.com/channels/655572317891461132/655578254970716160/1344363562608627763)), but I'd only do that rename if there's matching consensus about a path forward where we keep SemIRLoc, and in a way that it's only ever used for diagnostics (the divergence from which is at the root of current LocId discussion). I'm trying to keep that separate from a namespace addition for clarity.
This commit is contained in:
@@ -187,7 +187,9 @@ class EvalContext {
|
||||
|
||||
auto sem_ir() -> SemIR::File& { return context().sem_ir(); }
|
||||
|
||||
auto emitter() -> DiagnosticEmitter<SemIRLoc>& { return context().emitter(); }
|
||||
auto emitter() -> Diagnostics::Emitter<SemIRLoc>& {
|
||||
return context().emitter();
|
||||
}
|
||||
|
||||
private:
|
||||
// The type-checking context in which we're performing evaluation.
|
||||
@@ -1036,7 +1038,7 @@ static auto PerformBuiltinIntShiftOp(Context& context, SemIRLoc loc,
|
||||
CARBON_DIAGNOSTIC(
|
||||
CompileTimeShiftOutOfRange, Error,
|
||||
"shift distance >= type width of {0} in `{1} {2:<<|>>} {3}`", unsigned,
|
||||
TypedInt, BoolAsSelect, TypedInt);
|
||||
TypedInt, Diagnostics::BoolAsSelect, TypedInt);
|
||||
context.emitter().Emit(
|
||||
loc, CompileTimeShiftOutOfRange, lhs_val.getBitWidth(),
|
||||
{.type = lhs.type_id, .value = lhs_val},
|
||||
@@ -1050,7 +1052,7 @@ static auto PerformBuiltinIntShiftOp(Context& context, SemIRLoc loc,
|
||||
context.sem_ir().types().IsSignedInt(rhs.type_id)) {
|
||||
CARBON_DIAGNOSTIC(CompileTimeShiftNegative, Error,
|
||||
"shift distance negative in `{0} {1:<<|>>} {2}`",
|
||||
TypedInt, BoolAsSelect, TypedInt);
|
||||
TypedInt, Diagnostics::BoolAsSelect, TypedInt);
|
||||
context.emitter().Emit(
|
||||
loc, CompileTimeShiftNegative, {.type = lhs.type_id, .value = lhs_val},
|
||||
builtin_kind == SemIR::BuiltinFunctionKind::IntLeftShift,
|
||||
@@ -1888,7 +1890,7 @@ auto TryEvalBlockForSpecific(Context& context, SemIRLoc loc,
|
||||
.values = result,
|
||||
});
|
||||
|
||||
DiagnosticAnnotationScope annotate_diagnostics(
|
||||
Diagnostics::AnnotationScope annotate_diagnostics(
|
||||
&context.emitter(), [&](auto& builder) {
|
||||
CARBON_DIAGNOSTIC(ResolvingSpecificHere, Note, "in {0} used here",
|
||||
InstIdAsType);
|
||||
|
||||
Reference in New Issue
Block a user