Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/trunk' into whereck
Browse files Browse the repository at this point in the history
  • Loading branch information
josh11b committed Sep 19, 2024
2 parents 69448d3 + e7aebbe commit 9a54bb4
Show file tree
Hide file tree
Showing 690 changed files with 7,803 additions and 6,443 deletions.
4 changes: 2 additions & 2 deletions docs/design/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ represent that value.

Floating-point types in Carbon have IEEE-754 semantics, use the round-to-nearest
rounding mode, and do not set any floating-point exception state. They are named
with a _type literals_, consisting of `f` and the number of bits, which must be
a multiple of 8. These types will always be available:
using _type literals_, consisting of `f` and the number of bits, which must be a
multiple of 8. These types will always be available:
[`f16`](https://en.wikipedia.org/wiki/Half-precision_floating-point_format),
[`f32`](https://en.wikipedia.org/wiki/Single-precision_floating-point_format),
and
Expand Down
6 changes: 3 additions & 3 deletions toolchain/check/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static auto ResolveCalleeInCall(Context& context, SemIR::LocId loc_id,
"{0} argument(s) passed to {1} expecting "
"{2} argument(s).",
int, llvm::StringLiteral, int);
CARBON_DIAGNOSTIC(InCallToEntity, Note, "Calling {0} declared here.",
CARBON_DIAGNOSTIC(InCallToEntity, Note, "calling {0} declared here",
llvm::StringLiteral);
context.emitter()
.Build(loc_id, CallArgCountMismatch, arg_ids.size(),
Expand Down Expand Up @@ -128,7 +128,7 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id,
default: {
if (!callee_function.is_error) {
CARBON_DIAGNOSTIC(CallToNonCallable, Error,
"Value of type `{0}` is not callable.",
"value of type `{0}` is not callable",
SemIR::TypeId);
context.emitter().Emit(loc_id, CallToNonCallable,
context.insts().Get(callee_id).type_id());
Expand All @@ -154,7 +154,7 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id,
DiagnosticAnnotationScope annotate_diagnostics(
&context.emitter(), [&](auto& builder) {
CARBON_DIAGNOSTIC(IncompleteReturnTypeHere, Note,
"Return type declared here.");
"return type declared here");
builder.Note(callable.return_storage_id, IncompleteReturnTypeHere);
});
return CheckFunctionReturnType(context, callee_id, callable,
Expand Down
38 changes: 19 additions & 19 deletions toolchain/check/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ static auto DiagnoseMissingDefinitions(Context& context,
Context::DiagnosticEmitter& emitter)
-> void {
CARBON_DIAGNOSTIC(MissingDefinitionInImpl, Error,
"No definition found for declaration in impl file");
"no definition found for declaration in impl file");
for (SemIR::InstId decl_inst_id : context.definitions_required()) {
SemIR::Inst decl_inst = context.insts().Get(decl_inst_id);
CARBON_KIND_SWITCH(context.insts().Get(decl_inst_id)) {
Expand Down Expand Up @@ -983,8 +983,8 @@ static auto TrackImport(Map<ImportKey, UnitInfo*>& api_map,
explicit_import_map->Insert(import_key, import.node_id);
!insert_result.is_inserted()) {
CARBON_DIAGNOSTIC(RepeatedImport, Error,
"Library imported more than once.");
CARBON_DIAGNOSTIC(FirstImported, Note, "First import here.");
"library imported more than once");
CARBON_DIAGNOSTIC(FirstImported, Note, "first import here");
unit_info.emitter.Build(import.node_id, RepeatedImport)
.Note(insert_result.value(), FirstImported)
.Emit();
Expand Down Expand Up @@ -1014,9 +1014,9 @@ static auto TrackImport(Map<ImportKey, UnitInfo*>& api_map,
// `impl`.
if (is_same_library) {
CARBON_DIAGNOSTIC(ExplicitImportApi, Error,
"Explicit import of `api` from `impl` file is "
"redundant with implicit import.");
CARBON_DIAGNOSTIC(ImportSelf, Error, "File cannot import itself.");
"explicit import of `api` from `impl` file is "
"redundant with implicit import");
CARBON_DIAGNOSTIC(ImportSelf, Error, "file cannot import itself");
bool is_impl = !packaging || packaging->is_impl;
unit_info.emitter.Emit(import.node_id,
is_impl ? ExplicitImportApi : ImportSelf);
Expand All @@ -1028,7 +1028,7 @@ static auto TrackImport(Map<ImportKey, UnitInfo*>& api_map,
if (is_file_implicit_main && is_import_implicit_current_package &&
is_import_default_library) {
CARBON_DIAGNOSTIC(ImportMainDefaultLibrary, Error,
"Cannot import `Main//default`.");
"cannot import `Main//default`");
unit_info.emitter.Emit(import.node_id, ImportMainDefaultLibrary);

return;
Expand All @@ -1040,15 +1040,15 @@ static auto TrackImport(Map<ImportKey, UnitInfo*>& api_map,
if (is_same_package || (is_file_implicit_main && is_explicit_main)) {
CARBON_DIAGNOSTIC(
ImportCurrentPackageByName, Error,
"Imports from the current package must omit the package name.");
"imports from the current package must omit the package name");
unit_info.emitter.Emit(import.node_id, ImportCurrentPackageByName);
return;
}

// Diagnose explicit imports from `Main`.
if (is_explicit_main) {
CARBON_DIAGNOSTIC(ImportMainPackage, Error,
"Cannot import `Main` from other packages.");
"cannot import `Main` from other packages");
unit_info.emitter.Emit(import.node_id, ImportMainPackage);
return;
}
Expand Down Expand Up @@ -1088,8 +1088,8 @@ static auto TrackImport(Map<ImportKey, UnitInfo*>& api_map,
// The imported api is missing.
package_imports.has_load_error = true;
CARBON_DIAGNOSTIC(LibraryApiNotFound, Error,
"Corresponding API for '{0}' not found.", std::string);
CARBON_DIAGNOSTIC(ImportNotFound, Error, "Imported API '{0}' not found.",
"corresponding API for '{0}' not found", std::string);
CARBON_DIAGNOSTIC(ImportNotFound, Error, "imported API '{0}' not found",
std::string);
unit_info.emitter.Emit(
import.node_id,
Expand Down Expand Up @@ -1117,10 +1117,10 @@ static auto BuildApiMapAndDiagnosePackaging(
// APIs.
if (import_key.first == ExplicitMainName) {
CARBON_DIAGNOSTIC(ExplicitMainPackage, Error,
"`Main//default` must omit `package` declaration.");
"`Main//default` must omit `package` declaration");
CARBON_DIAGNOSTIC(
ExplicitMainLibrary, Error,
"Use `library` declaration in `Main` package libraries.");
"use `library` declaration in `Main` package libraries");
unit_info.emitter.Emit(packaging->names.node_id,
import_key.second.empty() ? ExplicitMainPackage
: ExplicitMainLibrary);
Expand All @@ -1140,13 +1140,13 @@ static auto BuildApiMapAndDiagnosePackaging(
insert_result.value()->unit->tokens->source().filename();
if (packaging) {
CARBON_DIAGNOSTIC(DuplicateLibraryApi, Error,
"Library's API previously provided by `{0}`.",
"library's API previously provided by `{0}`",
std::string);
unit_info.emitter.Emit(packaging->names.node_id, DuplicateLibraryApi,
prev_filename.str());
} else {
CARBON_DIAGNOSTIC(DuplicateMainApi, Error,
"Main//default previously provided by `{0}`.",
"`Main//default` previously provided by `{0}`",
std::string);
// Use the invalid node because there's no node to associate with.
unit_info.emitter.Emit(Parse::NodeId::Invalid, DuplicateMainApi,
Expand All @@ -1166,15 +1166,15 @@ static auto BuildApiMapAndDiagnosePackaging(
auto want_ext = is_impl ? ImplExt : ApiExt;
if (is_api_with_impl_ext || !filename.ends_with(want_ext)) {
CARBON_DIAGNOSTIC(IncorrectExtension, Error,
"File extension of `{0}` required for `{1}`.",
"file extension of `{0}` required for `{1}`",
llvm::StringLiteral, Lex::TokenKind);
auto diag = unit_info.emitter.Build(
packaging ? packaging->names.node_id : Parse::NodeId::Invalid,
IncorrectExtension, want_ext,
is_impl ? Lex::TokenKind::Impl : Lex::TokenKind::Api);
if (is_api_with_impl_ext) {
CARBON_DIAGNOSTIC(IncorrectExtensionImplNote, Note,
"File extension of `{0}` only allowed for `{1}`.",
"file extension of `{0}` only allowed for `{1}`",
llvm::StringLiteral, Lex::TokenKind);
diag.Note(Parse::NodeId::Invalid, IncorrectExtensionImplNote, ImplExt,
Lex::TokenKind::Impl);
Expand Down Expand Up @@ -1270,8 +1270,8 @@ auto CheckParseTrees(
} else {
// The import hasn't been checked, indicating a cycle.
CARBON_DIAGNOSTIC(ImportCycleDetected, Error,
"Import cannot be used due to a cycle. Cycle "
"must be fixed to import.");
"import cannot be used due to a cycle; cycle "
"must be fixed to import");
unit_info.emitter.Emit(import_it->names.node_id,
ImportCycleDetected);
// Make this look the same as an import which wasn't found.
Expand Down
46 changes: 24 additions & 22 deletions toolchain/check/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "toolchain/sem_ir/builtin_inst_kind.h"
#include "toolchain/sem_ir/file.h"
#include "toolchain/sem_ir/formatter.h"
#include "toolchain/sem_ir/generic.h"
#include "toolchain/sem_ir/ids.h"
#include "toolchain/sem_ir/import_ir.h"
#include "toolchain/sem_ir/inst.h"
Expand Down Expand Up @@ -69,8 +70,7 @@ Context::Context(const Lex::TokenizedBuffer& tokens, DiagnosticEmitter& emitter,
}

auto Context::TODO(SemIRLoc loc, std::string label) -> bool {
CARBON_DIAGNOSTIC(SemanticsTodo, Error, "Semantics TODO: `{0}`.",
std::string);
CARBON_DIAGNOSTIC(SemanticsTodo, Error, "semantics TODO: `{0}`", std::string);
emitter_->Emit(loc, SemanticsTodo, std::move(label));
return false;
}
Expand Down Expand Up @@ -201,18 +201,16 @@ auto Context::ReplaceInstBeforeConstantUse(SemIR::InstId inst_id,
auto Context::DiagnoseDuplicateName(SemIRLoc dup_def, SemIRLoc prev_def)
-> void {
CARBON_DIAGNOSTIC(NameDeclDuplicate, Error,
"Duplicate name being declared in the same scope.");
CARBON_DIAGNOSTIC(NameDeclPrevious, Note,
"Name is previously declared here.");
"duplicate name being declared in the same scope");
CARBON_DIAGNOSTIC(NameDeclPrevious, Note, "name is previously declared here");
emitter_->Build(dup_def, NameDeclDuplicate)
.Note(prev_def, NameDeclPrevious)
.Emit();
}

auto Context::DiagnoseNameNotFound(SemIRLoc loc, SemIR::NameId name_id)
-> void {
CARBON_DIAGNOSTIC(NameNotFound, Error, "Name `{0}` not found.",
SemIR::NameId);
CARBON_DIAGNOSTIC(NameNotFound, Error, "name `{0}` not found", SemIR::NameId);
emitter_->Emit(loc, NameNotFound, name_id);
}

Expand All @@ -222,11 +220,11 @@ auto Context::NoteIncompleteClass(SemIR::ClassId class_id,
CARBON_CHECK(!class_info.is_defined(), "Class is not incomplete");
if (class_info.definition_id.is_valid()) {
CARBON_DIAGNOSTIC(ClassIncompleteWithinDefinition, Note,
"Class is incomplete within its definition.");
"class is incomplete within its definition");
builder.Note(class_info.definition_id, ClassIncompleteWithinDefinition);
} else {
CARBON_DIAGNOSTIC(ClassForwardDeclaredHere, Note,
"Class was forward declared here.");
"class was forward declared here");
builder.Note(class_info.latest_decl_id(), ClassForwardDeclaredHere);
}
}
Expand All @@ -237,12 +235,12 @@ auto Context::NoteUndefinedInterface(SemIR::InterfaceId interface_id,
CARBON_CHECK(!interface_info.is_defined(), "Interface is not incomplete");
if (interface_info.is_being_defined()) {
CARBON_DIAGNOSTIC(InterfaceUndefinedWithinDefinition, Note,
"Interface is currently being defined.");
"interface is currently being defined");
builder.Note(interface_info.definition_id,
InterfaceUndefinedWithinDefinition);
} else {
CARBON_DIAGNOSTIC(InterfaceForwardDeclaredHere, Note,
"Interface was forward declared here.");
"interface was forward declared here");
builder.Note(interface_info.latest_decl_id(), InterfaceForwardDeclaredHere);
}
}
Expand Down Expand Up @@ -373,10 +371,10 @@ static auto DiagnoseInvalidQualifiedNameAccess(Context& context, SemIRLoc loc,
auto class_info = context.classes().Get(class_type->class_id);

CARBON_DIAGNOSTIC(ClassInvalidMemberAccess, Error,
"Cannot access {0} member `{1}` of type `{2}`.",
"cannot access {0} member `{1}` of type `{2}`",
SemIR::AccessKind, SemIR::NameId, SemIR::TypeId);
CARBON_DIAGNOSTIC(ClassMemberDefinition, Note,
"The {0} member `{1}` is defined here.", SemIR::AccessKind,
"the {0} member `{1}` is defined here", SemIR::AccessKind,
SemIR::NameId);

auto parent_type_id = class_info.self_type_id;
Expand Down Expand Up @@ -490,7 +488,7 @@ auto Context::LookupQualifiedName(SemIRLoc loc, SemIR::NameId name_id,
// Add test coverage once this is possible.
CARBON_DIAGNOSTIC(
NameAmbiguousDueToExtend, Error,
"Ambiguous use of name `{0}` found in multiple extended scopes.",
"ambiguous use of name `{0}` found in multiple extended scopes",
SemIR::NameId);
emitter_->Emit(loc, NameAmbiguousDueToExtend, name_id);
// TODO: Add notes pointing to the scopes.
Expand Down Expand Up @@ -553,9 +551,8 @@ static auto GetCorePackage(Context& context, SemIRLoc loc)
}
}

CARBON_DIAGNOSTIC(
CoreNotFound, Error,
"Package `Core` implicitly referenced here, but not found.");
CARBON_DIAGNOSTIC(CoreNotFound, Error,
"package `Core` implicitly referenced here, but not found");
context.emitter().Emit(loc, CoreNotFound);
return SemIR::NameScopeId::Invalid;
}
Expand All @@ -573,7 +570,7 @@ auto Context::LookupNameInCore(SemIRLoc loc, llvm::StringRef name)
if (!inst_id.is_valid()) {
CARBON_DIAGNOSTIC(
CoreNameNotFound, Error,
"Name `Core.{0}` implicitly referenced here, but not found.",
"name `Core.{0}` implicitly referenced here, but not found",
SemIR::NameId);
emitter_->Emit(loc, CoreNameNotFound, name_id);
return SemIR::InstId::BuiltinError;
Expand Down Expand Up @@ -873,7 +870,7 @@ class TypeCompleter {
if (inst.specific_id.is_valid()) {
ResolveSpecificDefinition(context_, inst.specific_id);
}
Push(class_info.object_repr_id);
Push(class_info.GetObjectRepr(context_.sem_ir(), inst.specific_id));
break;
}
case CARBON_KIND(SemIR::ConstType inst): {
Expand Down Expand Up @@ -1051,14 +1048,19 @@ class TypeCompleter {
// The value representation of an adapter is the value representation of
// its adapted type.
if (class_info.adapt_id.is_valid()) {
return GetNestedValueRepr(class_info.object_repr_id);
return GetNestedValueRepr(SemIR::GetTypeInSpecific(
context_.sem_ir(), inst.specific_id,
context_.insts()
.GetAs<SemIR::AdaptDecl>(class_info.adapt_id)
.adapted_type_id));
}
// Otherwise, the value representation for a class is a pointer to the
// object representation.
// TODO: Support customized value representations for classes.
// TODO: Pick a better value representation when possible.
return MakePointerValueRepr(class_info.object_repr_id,
SemIR::ValueRepr::ObjectAggregate);
return MakePointerValueRepr(
class_info.GetObjectRepr(context_.sem_ir(), inst.specific_id),
SemIR::ValueRepr::ObjectAggregate);
}

template <typename InstT>
Expand Down
Loading

0 comments on commit 9a54bb4

Please sign in to comment.