Skip to content

Commit

Permalink
Rename the builtin FloatType to LegacyFloatType, Error to ErrorInst (#…
Browse files Browse the repository at this point in the history
…4555)

This is for more clearly distinct names, and to make it a clearer
transition from `BuiltinInst` for name conflicts. `FloatType` is also an
instruction, and we have `Carbon::Error` (common/error.h). This avoids
affecting tests, although the name is embedded in the builtin test.

In `LegacyFloatType`, `Legacy` because I was having trouble coming up
with a more appropriate name. I'm not clear this is a `FloatLiteralType`
at present, it needs some work to mirror `IntLiteralType`.

In `ErrorInst`, the suffix `Inst` was discussed as good and similar to
`BuiltinInst` (although I'm trying to get rid of that).
  • Loading branch information
jonmeow authored Nov 19, 2024
1 parent e2ae5f2 commit 4a80d67
Show file tree
Hide file tree
Showing 35 changed files with 131 additions and 126 deletions.
8 changes: 4 additions & 4 deletions toolchain/check/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static auto PerformCallToGenericClass(Context& context, SemIR::LocId loc_id,
EntityKind::GenericClass, enclosing_specific_id,
/*self_id=*/SemIR::InstId::Invalid, arg_ids);
if (!callee_specific_id) {
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}
return context.GetOrAddInst<SemIR::ClassType>(
loc_id, {.type_id = SemIR::TypeId::TypeType,
Expand All @@ -114,7 +114,7 @@ static auto PerformCallToGenericInterface(
EntityKind::GenericInterface, enclosing_specific_id,
/*self_id=*/SemIR::InstId::Invalid, arg_ids);
if (!callee_specific_id) {
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}
return context.GetOrAddInst(loc_id, context.FacetTypeFromInterface(
interface_id, *callee_specific_id));
Expand Down Expand Up @@ -144,7 +144,7 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id,
"value of type {0} is not callable", TypeOfInstId);
context.emitter().Emit(loc_id, CallToNonCallable, callee_id);
}
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}
}
}
Expand All @@ -156,7 +156,7 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id,
EntityKind::Function, callee_function.enclosing_specific_id,
callee_function.self_id, arg_ids);
if (!callee_specific_id) {
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}
if (callee_specific_id->is_valid()) {
callee_id = context.GetOrAddInst(
Expand Down
16 changes: 8 additions & 8 deletions toolchain/check/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Context::Context(const Lex::TokenizedBuffer& tokens, DiagnosticEmitter& emitter,
// Map the builtin `<error>` and `type` type constants to their corresponding
// special `TypeId` values.
type_ids_for_type_constants_.Insert(
SemIR::ConstantId::ForTemplateConstant(SemIR::InstId::BuiltinError),
SemIR::ConstantId::ForTemplateConstant(SemIR::InstId::BuiltinErrorInst),
SemIR::TypeId::Error);
type_ids_for_type_constants_.Insert(
SemIR::ConstantId::ForTemplateConstant(SemIR::InstId::BuiltinTypeType),
Expand Down Expand Up @@ -345,7 +345,7 @@ auto Context::LookupUnqualifiedName(Parse::NodeId node_id,
}

return {.specific_id = SemIR::SpecificId::Invalid,
.inst_id = SemIR::InstId::BuiltinError};
.inst_id = SemIR::InstId::BuiltinErrorInst};
}

auto Context::LookupNameInExactScope(SemIRLoc loc, SemIR::NameId name_id,
Expand Down Expand Up @@ -571,7 +571,7 @@ auto Context::LookupQualifiedName(SemIRLoc loc, SemIR::NameId name_id,
emitter_->Emit(loc, NameAmbiguousDueToExtend, name_id);
// TODO: Add notes pointing to the scopes.
return {.specific_id = SemIR::SpecificId::Invalid,
.inst_id = SemIR::InstId::BuiltinError};
.inst_id = SemIR::InstId::BuiltinErrorInst};
}

result.inst_id = scope_result_id;
Expand All @@ -597,7 +597,7 @@ auto Context::LookupQualifiedName(SemIRLoc loc, SemIR::NameId name_id,
}

return {.specific_id = SemIR::SpecificId::Invalid,
.inst_id = SemIR::InstId::BuiltinError};
.inst_id = SemIR::InstId::BuiltinErrorInst};
}

return result;
Expand Down Expand Up @@ -639,7 +639,7 @@ auto Context::LookupNameInCore(SemIRLoc loc, llvm::StringRef name)
-> SemIR::InstId {
auto core_package_id = GetCorePackage(*this, loc);
if (!core_package_id.is_valid()) {
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

auto name_id = SemIR::NameId::ForIdentifier(identifiers().Add(name));
Expand All @@ -651,7 +651,7 @@ auto Context::LookupNameInCore(SemIRLoc loc, llvm::StringRef name)
"name `Core.{0}` implicitly referenced here, but not found",
SemIR::NameId);
emitter_->Emit(loc, CoreNameNotFound, name_id);
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

// Look through import_refs and aliases.
Expand Down Expand Up @@ -1006,11 +1006,11 @@ class TypeCompleter {
switch (builtin.builtin_inst_kind) {
case SemIR::BuiltinInstKind::TypeType:
case SemIR::BuiltinInstKind::AutoType:
case SemIR::BuiltinInstKind::Error:
case SemIR::BuiltinInstKind::ErrorInst:
case SemIR::BuiltinInstKind::Invalid:
case SemIR::BuiltinInstKind::BoolType:
case SemIR::BuiltinInstKind::IntLiteralType:
case SemIR::BuiltinInstKind::FloatType:
case SemIR::BuiltinInstKind::LegacyFloatType:
case SemIR::BuiltinInstKind::NamespaceType:
case SemIR::BuiltinInstKind::BoundMethodType:
case SemIR::BuiltinInstKind::WitnessType:
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class Context {
-> LookupResult;

// Returns the instruction corresponding to a name in the core package, or
// BuiltinError if not found.
// BuiltinErrorInst if not found.
auto LookupNameInCore(SemIRLoc loc, llvm::StringRef name) -> SemIR::InstId;

// Prints a diagnostic for a duplicate name.
Expand Down
46 changes: 23 additions & 23 deletions toolchain/check/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
? ArrayInitFromExprArgCountMismatch
: ArrayInitFromLiteralArgCountMismatch,
array_bound, tuple_elem_types.size());
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

PendingBlock target_block_storage(context);
Expand Down Expand Up @@ -276,8 +276,8 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
context, value_loc_id, value_id, src_type_id, literal_elems,
ConversionTarget::FullInitializer, return_slot_id,
array_type.element_type_id, target_block, i);
if (init_id == SemIR::InstId::BuiltinError) {
return SemIR::InstId::BuiltinError;
if (init_id == SemIR::InstId::BuiltinErrorInst) {
return SemIR::InstId::BuiltinErrorInst;
}
inits.push_back(init_id);
}
Expand Down Expand Up @@ -325,7 +325,7 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
IntAsSelect, IntAsSelect);
context.emitter().Emit(value_loc_id, TupleInitElementCountMismatch,
dest_elem_types.size(), src_elem_types.size());
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

// If we're forming an initializer, then we want an initializer for each
Expand Down Expand Up @@ -357,8 +357,8 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
ConvertAggregateElement<SemIR::TupleAccess, SemIR::TupleAccess>(
context, value_loc_id, value_id, src_type_id, literal_elems,
inner_kind, target.init_id, dest_type_id, target.init_block, i);
if (init_id == SemIR::InstId::BuiltinError) {
return SemIR::InstId::BuiltinError;
if (init_id == SemIR::InstId::BuiltinErrorInst) {
return SemIR::InstId::BuiltinErrorInst;
}
new_block.Set(i, init_id);
}
Expand Down Expand Up @@ -423,7 +423,7 @@ static auto ConvertStructToStructOrClass(Context& context,
context.emitter().Emit(value_loc_id, StructInitElementCountMismatch,
ToClass, dest_elem_fields_size,
src_elem_fields.size());
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

// Prepare to look up fields in the source by index.
Expand Down Expand Up @@ -459,7 +459,7 @@ static auto ConvertStructToStructOrClass(Context& context,
for (auto [i, dest_field] : llvm::enumerate(dest_elem_fields)) {
if (dest_field.name_id == SemIR::NameId::Vptr) {
// TODO: Initialize the vptr to point to a vtable.
new_block.Set(i, SemIR::InstId::BuiltinError);
new_block.Set(i, SemIR::InstId::BuiltinErrorInst);
continue;
}

Expand All @@ -485,7 +485,7 @@ static auto ConvertStructToStructOrClass(Context& context,
StructInitMissingFieldInConversion, value_id,
target.type_id, dest_field.name_id);
}
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}
}
auto src_field = src_elem_fields[src_field_index];
Expand All @@ -497,8 +497,8 @@ static auto ConvertStructToStructOrClass(Context& context,
context, value_loc_id, value_id, src_field.type_id, literal_elems,
inner_kind, target.init_id, dest_field.type_id, target.init_block,
src_field_index);
if (init_id == SemIR::InstId::BuiltinError) {
return SemIR::InstId::BuiltinError;
if (init_id == SemIR::InstId::BuiltinErrorInst) {
return SemIR::InstId::BuiltinErrorInst;
}
new_block.Set(i, init_id);
}
Expand Down Expand Up @@ -548,7 +548,7 @@ static auto ConvertStructToClass(Context& context, SemIR::StructType src_type,
auto object_repr_id =
dest_class_info.GetObjectRepr(context.sem_ir(), dest_type.specific_id);
if (object_repr_id == SemIR::TypeId::Error) {
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}
auto dest_struct_type =
context.types().GetAs<SemIR::StructType>(object_repr_id);
Expand Down Expand Up @@ -911,7 +911,7 @@ static auto PerformCopy(Context& context, SemIR::InstId expr_id)
auto expr = context.insts().Get(expr_id);
auto type_id = expr.type_id();
if (type_id == SemIR::TypeId::Error) {
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

// TODO: Directly track on the value representation whether it's a copy of
Expand All @@ -930,7 +930,7 @@ static auto PerformCopy(Context& context, SemIR::InstId expr_id)
CARBON_DIAGNOSTIC(CopyOfUncopyableType, Error,
"cannot copy value of type {0}", TypeOfInstId);
context.emitter().Emit(expr_id, CopyOfUncopyableType, expr_id);
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
Expand All @@ -942,7 +942,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
// result is invalid and we shouldn't error.
if (sem_ir.insts().Get(expr_id).type_id() == SemIR::TypeId::Error ||
target.type_id == SemIR::TypeId::Error) {
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

if (SemIR::GetExprCategory(sem_ir, expr_id) == SemIR::ExprCategory::NotExpr) {
Expand All @@ -952,7 +952,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
CARBON_DIAGNOSTIC(UseOfNonExprAsValue, Error,
"expression cannot be used as a value");
context.emitter().Emit(expr_id, UseOfNonExprAsValue);
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

// We can only perform initialization for complete types.
Expand Down Expand Up @@ -985,12 +985,12 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
return context.emitter().Build(loc_id, AbstractTypeInInit,
target.type_id);
})) {
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

// Check whether any builtin conversion applies.
expr_id = PerformBuiltinConversion(context, loc_id, expr_id, target);
if (expr_id == SemIR::InstId::BuiltinError) {
if (expr_id == SemIR::InstId::BuiltinErrorInst) {
return expr_id;
}

Expand Down Expand Up @@ -1020,7 +1020,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
});

// Pull a value directly out of the initializer if possible and wanted.
if (expr_id != SemIR::InstId::BuiltinError &&
if (expr_id != SemIR::InstId::BuiltinErrorInst &&
CanUseValueOfInitializer(sem_ir, target.type_id, target.kind)) {
expr_id = context.AddInst<SemIR::ValueOfInitializer>(
loc_id, {.type_id = target.type_id, .init_id = expr_id});
Expand Down Expand Up @@ -1049,7 +1049,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
sem_ir.insts().Get(expr_id));

case SemIR::ExprCategory::Error:
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;

case SemIR::ExprCategory::Initializing:
if (target.is_initializer()) {
Expand Down Expand Up @@ -1202,7 +1202,7 @@ auto ConvertCallArgs(Context& context, SemIR::LocId call_loc_id,
.Build(call_loc_id, MissingObjectInMethodCall)
.Note(callee_decl_id, InCallToFunction)
.Emit();
self_id = SemIR::InstId::BuiltinError;
self_id = SemIR::InstId::BuiltinErrorInst;
}

return CallerPatternMatch(context, callee_specific_id, self_param_id,
Expand All @@ -1214,7 +1214,7 @@ auto ExprAsType(Context& context, SemIR::LocId loc_id, SemIR::InstId value_id)
-> TypeExpr {
auto type_inst_id =
ConvertToValueOfType(context, loc_id, value_id, SemIR::TypeId::TypeType);
if (type_inst_id == SemIR::InstId::BuiltinError) {
if (type_inst_id == SemIR::InstId::BuiltinErrorInst) {
return {.inst_id = type_inst_id, .type_id = SemIR::TypeId::Error};
}

Expand All @@ -1223,7 +1223,7 @@ auto ExprAsType(Context& context, SemIR::LocId loc_id, SemIR::InstId value_id)
CARBON_DIAGNOSTIC(TypeExprEvaluationFailure, Error,
"cannot evaluate type expression");
context.emitter().Emit(loc_id, TypeExprEvaluationFailure);
return {.inst_id = SemIR::InstId::BuiltinError,
return {.inst_id = SemIR::InstId::BuiltinErrorInst,
.type_id = SemIR::TypeId::Error};
}

Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ auto ConvertCallArgs(Context& context, SemIR::LocId call_loc_id,

// A type that has been converted for use as a type expression.
struct TypeExpr {
// The converted expression of type `type`, or `InstId::BuiltinError`.
// The converted expression of type `type`, or `InstId::BuiltinErrorInst`.
SemIR::InstId inst_id;
// The corresponding type, or `TypeId::Error`.
SemIR::TypeId type_id;
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/deduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ auto DeductionContext::Deduce() -> bool {
DiagnosticAnnotationScope annotate_diagnostics(&context().emitter(),
note_initializing_param);
arg_id = ConvertToValueOfType(context(), loc_id_, arg_id, param_type_id);
if (arg_id == SemIR::InstId::BuiltinError) {
if (arg_id == SemIR::InstId::BuiltinErrorInst) {
return false;
}
}
Expand Down
6 changes: 4 additions & 2 deletions toolchain/check/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,8 @@ static auto MakeConstantForBuiltinCall(Context& context, SemIRLoc loc,
if (!ValidateFloatBitWidth(context, loc, arg_ids[0])) {
return SemIR::ConstantId::Error;
}
return context.constant_values().Get(SemIR::InstId::BuiltinFloatType);
return context.constant_values().Get(
SemIR::InstId::BuiltinLegacyFloatType);
}

case SemIR::BuiltinFunctionKind::BoolMakeType: {
Expand Down Expand Up @@ -1716,7 +1717,8 @@ auto TryEvalBlockForSpecific(Context& context, SemIR::SpecificId specific_id,
result[i] = context.constant_values().GetInstId(const_id);

// TODO: If this becomes possible through monomorphization failure, produce
// a diagnostic and put `SemIR::InstId::BuiltinError` in the table entry.
// a diagnostic and put `SemIR::InstId::BuiltinErrorInst` in the table
// entry.
CARBON_CHECK(result[i].is_valid());
}

Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/handle_alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ auto HandleParseNode(Context& context, Parse::AliasId /*node_id*/) -> bool {
"alias initializer must be a name reference");
context.emitter().Emit(expr_node, AliasRequiresNameRef);
alias_type_id = SemIR::TypeId::Error;
alias_value_id = SemIR::InstId::BuiltinError;
alias_value_id = SemIR::InstId::BuiltinErrorInst;
}
auto alias_id = context.AddInst<SemIR::BindAlias>(
name_context.loc_id, {.type_id = alias_type_id,
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/handle_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ auto HandleParseNode(Context& context, Parse::ArrayExprId node_id) -> bool {
if (!context.constant_values().Get(bound_inst_id).is_constant()) {
CARBON_DIAGNOSTIC(InvalidArrayExpr, Error, "array bound is not a constant");
context.emitter().Emit(bound_inst_id, InvalidArrayExpr);
context.node_stack().Push(node_id, SemIR::InstId::BuiltinError);
context.node_stack().Push(node_id, SemIR::InstId::BuiltinErrorInst);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions toolchain/check/handle_binding_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
break;
}
if (had_error) {
context.AddNameToLookup(name_id, SemIR::InstId::BuiltinError);
context.AddNameToLookup(name_id, SemIR::InstId::BuiltinErrorInst);
// Replace the parameter with an invalid instruction so that we don't
// try constructing a generic based on it.
param_pattern_id = SemIR::InstId::BuiltinError;
param_pattern_id = SemIR::InstId::BuiltinErrorInst;
} else {
auto bind_id = context.AddInstInNoBlock(
make_bind_name(cast_type_id, SemIR::InstId::Invalid));
Expand Down
6 changes: 3 additions & 3 deletions toolchain/check/handle_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ static auto CheckCompleteAdapterClassType(Context& context,
.Build(class_info.adapt_id, AdaptWithBase)
.Note(class_info.base_id, AdaptWithBaseHere)
.Emit();
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

if (auto fields = context.struct_type_fields().Get(fields_id);
Expand All @@ -584,7 +584,7 @@ static auto CheckCompleteAdapterClassType(Context& context,
.Build(class_info.adapt_id, AdaptWithFields)
.Note(first_field_inst_id, AdaptWithFieldHere)
.Emit();
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}

for (auto inst_id : context.inst_block_stack().PeekCurrentBlockContents()) {
Expand All @@ -601,7 +601,7 @@ static auto CheckCompleteAdapterClassType(Context& context,
.Build(class_info.adapt_id, AdaptWithVirtual)
.Note(inst_id, AdaptWithVirtualHere)
.Emit();
return SemIR::InstId::BuiltinError;
return SemIR::InstId::BuiltinErrorInst;
}
}
}
Expand Down
Loading

0 comments on commit 4a80d67

Please sign in to comment.