Remove SemIR:: from most sem_ir files (#5358)

This is just cleanup, at least some from LocId replacements.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-Perkins
2025-04-25 16:06:10 +00:00
committed by GitHub
co-authored by Richard Smith
parent d2826ae841
commit 949cc21ccc
32 changed files with 176 additions and 194 deletions
+13 -13
View File
@@ -23,10 +23,10 @@ static auto FollowImportRef(
auto import_loc_id = cursor_ir->insts().GetLocId(import_ir.decl_id);
switch (import_loc_id.kind()) {
case SemIR::LocId::Kind::None:
case LocId::Kind::None:
break;
case SemIR::LocId::Kind::ImportIRInstId: {
case LocId::Kind::ImportIRInstId: {
// For implicit imports, we need to unravel the location a little
// further.
auto implicit_import_ir_inst =
@@ -35,7 +35,7 @@ static auto FollowImportRef(
cursor_ir->import_irs().Get(implicit_import_ir_inst.ir_id());
auto implicit_loc_id = implicit_ir.sem_ir->insts().GetLocId(
implicit_import_ir_inst.inst_id());
CARBON_CHECK(implicit_loc_id.kind() == SemIR::LocId::Kind::NodeId,
CARBON_CHECK(implicit_loc_id.kind() == LocId::Kind::NodeId,
"Should only be one layer of implicit imports");
absolute_node_ids.push_back(
{.check_ir_id = implicit_ir.sem_ir->check_ir_id(),
@@ -43,10 +43,10 @@ static auto FollowImportRef(
break;
}
case SemIR::LocId::Kind::InstId:
case LocId::Kind::InstId:
CARBON_FATAL("Unexpected LocId: {0}", import_loc_id);
case SemIR::LocId::Kind::NodeId: {
case LocId::Kind::NodeId: {
// For imports in the current file, the location is simple.
absolute_node_ids.push_back({.check_ir_id = cursor_ir->check_ir_id(),
.node_id = import_loc_id.node_id()});
@@ -64,21 +64,21 @@ static auto HandleLocId(llvm::SmallVector<AbsoluteNodeId>& absolute_node_ids,
const File*& cursor_ir, InstId& cursor_inst_id,
LocId loc_id) -> bool {
switch (loc_id.kind()) {
case SemIR::LocId::Kind::ImportIRInstId: {
case LocId::Kind::ImportIRInstId: {
FollowImportRef(absolute_node_ids, cursor_ir, cursor_inst_id,
loc_id.import_ir_inst_id());
return false;
}
case SemIR::LocId::Kind::NodeId: {
case LocId::Kind::NodeId: {
// Parse nodes always refer to the current IR.
absolute_node_ids.push_back({.check_ir_id = cursor_ir->check_ir_id(),
.node_id = loc_id.node_id()});
return true;
}
case SemIR::LocId::Kind::None:
case SemIR::LocId::Kind::InstId:
case LocId::Kind::None:
case LocId::Kind::InstId:
CARBON_FATAL("Unexpected LocId: {0}", loc_id);
}
}
@@ -123,17 +123,17 @@ auto GetAbsoluteNodeId(const File* sem_ir, LocId loc_id)
-> llvm::SmallVector<AbsoluteNodeId> {
llvm::SmallVector<AbsoluteNodeId> absolute_node_ids;
switch (loc_id.kind()) {
case SemIR::LocId::Kind::None:
case LocId::Kind::None:
absolute_node_ids.push_back({.check_ir_id = sem_ir->check_ir_id(),
.node_id = Parse::NodeId::None});
break;
case SemIR::LocId::Kind::InstId:
case LocId::Kind::InstId:
GetAbsoluteNodeIdImpl(absolute_node_ids, sem_ir, loc_id.inst_id());
break;
case SemIR::LocId::Kind::ImportIRInstId:
case SemIR::LocId::Kind::NodeId: {
case LocId::Kind::ImportIRInstId:
case LocId::Kind::NodeId: {
const File* cursor_ir = sem_ir;
InstId cursor_inst_id = InstId::None;
if (HandleLocId(absolute_node_ids, cursor_ir, cursor_inst_id, loc_id)) {
+5 -6
View File
@@ -72,11 +72,10 @@ template <typename PointeeT>
struct PointerTo {
static auto Check(const File& sem_ir, ValidateState& state, TypeId type_id)
-> bool {
if (!sem_ir.types().Is<SemIR::PointerType>(type_id)) {
if (!sem_ir.types().Is<PointerType>(type_id)) {
return false;
}
return SemIR::Check<PointeeT>(sem_ir, state,
sem_ir.GetPointeeType(type_id));
return Check<PointeeT>(sem_ir, state, sem_ir.GetPointeeType(type_id));
}
};
@@ -85,7 +84,7 @@ struct PointerTo {
struct NoReturn {
static auto Check(const File& sem_ir, ValidateState& /*state*/,
TypeId type_id) -> bool {
auto tuple = sem_ir.types().TryGetAs<SemIR::TupleType>(type_id);
auto tuple = sem_ir.types().TryGetAs<TupleType>(type_id);
if (!tuple) {
return false;
}
@@ -575,11 +574,11 @@ auto BuiltinFunctionKind::IsValidType(const File& sem_ir,
static auto AnyIntLiteralTypes(const File& sem_ir,
llvm::ArrayRef<InstId> arg_ids,
TypeId return_type_id) -> bool {
if (sem_ir.types().Is<SemIR::IntLiteralType>(return_type_id)) {
if (sem_ir.types().Is<IntLiteralType>(return_type_id)) {
return true;
}
for (auto arg_id : arg_ids) {
if (sem_ir.types().Is<SemIR::IntLiteralType>(
if (sem_ir.types().Is<IntLiteralType>(
sem_ir.insts().Get(arg_id).type_id())) {
return true;
}
+1 -1
View File
@@ -16,7 +16,7 @@ static auto GetFoundationType(const File& file, SpecificId specific_id,
if (!inst_id.has_value()) {
return TypeId::None;
}
if (inst_id == SemIR::ErrorInst::InstId) {
if (inst_id == ErrorInst::InstId) {
return ErrorInst::TypeId;
}
return TypeId::ForTypeConstant(GetConstantValueInSpecific(
+1 -1
View File
@@ -14,7 +14,7 @@ auto ConstantStore::GetOrAdd(Inst inst, ConstantDependence dependence)
auto inst_id = sem_ir_->insts().AddInNoBlock(LocIdAndInst::NoLoc(inst));
ConstantId const_id = ConstantId::None;
if (dependence == ConstantDependence::None) {
const_id = SemIR::ConstantId::ForConcreteConstant(inst_id);
const_id = ConstantId::ForConcreteConstant(inst_id);
} else {
// The instruction in the constants store is an abstract symbolic
// constant, not associated with any particular generic.
+4 -4
View File
@@ -19,7 +19,7 @@ namespace Carbon::SemIR {
//
// This is intended to avoid an unnecessary block allocation in the case where
// the new block ends up being exactly the same as the original block.
template <typename BlockIdType, auto (SemIR::File::*ValueStore)()>
template <typename BlockIdType, auto (File::*ValueStore)()>
class CopyOnWriteBlock {
public:
struct UninitializedBlock {
@@ -28,12 +28,12 @@ class CopyOnWriteBlock {
// Constructs the block. `source_id` is used as the initial value of the
// block. `file` must not be null.
explicit CopyOnWriteBlock(SemIR::File* file, BlockIdType source_id)
explicit CopyOnWriteBlock(File* file, BlockIdType source_id)
: file_(file), source_id_(source_id) {}
// Constructs the block, treating the original block as an uninitialized block
// with `size` elements. `file` must not be null.
explicit CopyOnWriteBlock(SemIR::File* file, UninitializedBlock uninit)
explicit CopyOnWriteBlock(File* file, UninitializedBlock uninit)
: file_(file),
source_id_(BlockIdType::None),
id_((file_->*ValueStore)().AddUninitialized(uninit.size)) {}
@@ -62,7 +62,7 @@ class CopyOnWriteBlock {
}
private:
SemIR::File* file_;
File* file_;
BlockIdType source_id_;
BlockIdType id_ = source_id_;
};
+3 -3
View File
@@ -57,7 +57,7 @@ struct EntityWithParamsBase {
}
// Returns the instruction for the first declaration.
auto first_decl_id() const -> SemIR::InstId {
auto first_decl_id() const -> InstId {
if (non_owning_decl_id.has_value()) {
return non_owning_decl_id;
}
@@ -66,7 +66,7 @@ struct EntityWithParamsBase {
}
// Returns the instruction for the latest declaration.
auto latest_decl_id() const -> SemIR::InstId {
auto latest_decl_id() const -> InstId {
if (has_definition_started()) {
return definition_id;
}
@@ -115,7 +115,7 @@ struct EntityWithParamsBase {
bool is_extern;
// For an `extern library` declaration, the library name.
SemIR::LibraryNameId extern_library_id;
LibraryNameId extern_library_id;
// The non-owning declaration of the entity, if present. This will be a
// <entity>Decl.
+1 -2
View File
@@ -10,8 +10,7 @@ namespace Carbon::SemIR {
static constexpr llvm::StringLiteral EntryPointFunction = "Run";
auto IsEntryPoint(const SemIR::File& file, SemIR::FunctionId function_id)
-> bool {
auto IsEntryPoint(const File& file, FunctionId function_id) -> bool {
// TODO: Check if `file` is in the `Main` package.
const auto& function = file.functions().Get(function_id);
// TODO: Check if `function` is in a namespace.
+1 -2
View File
@@ -11,8 +11,7 @@ namespace Carbon::SemIR {
// Returns whether the specified function is the entry point function for the
// program, `Main.Run`.
auto IsEntryPoint(const SemIR::File& file, SemIR::FunctionId function_id)
-> bool;
auto IsEntryPoint(const File& file, FunctionId function_id) -> bool;
} // namespace Carbon::SemIR
+1 -1
View File
@@ -49,7 +49,7 @@ auto GetExprCategory(const File& file, InstId inst_id) -> ExprCategory {
case ImportRefUnloaded::Kind:
case ImportRefLoaded::Kind: {
auto import_ir_inst = ir->import_ir_insts().Get(
untyped_inst.As<SemIR::AnyImportRef>().import_ir_inst_id);
untyped_inst.As<AnyImportRef>().import_ir_inst_id);
ir = ir->import_irs().Get(import_ir_inst.ir_id()).sem_ir;
inst_id = import_ir_inst.inst_id();
continue;
+3 -3
View File
@@ -59,7 +59,7 @@ struct ExprRegion {
class File : public Printable<File> {
public:
using IdentifiedFacetTypeStore =
RelationalValueStore<SemIR::FacetTypeId, SemIR::IdentifiedFacetTypeId>;
RelationalValueStore<FacetTypeId, IdentifiedFacetTypeId>;
// Starts a new file for Check::CheckParseTree.
explicit File(const Parse::Tree* parse_tree, CheckIRId check_ir_id,
@@ -103,12 +103,12 @@ class File : public Printable<File> {
// Returns true if this file is an `impl`.
auto is_impl() -> bool {
return import_irs().Get(SemIR::ImportIRId::ApiForImpl).sem_ir != nullptr;
return import_irs().Get(ImportIRId::ApiForImpl).sem_ir != nullptr;
}
auto check_ir_id() const -> CheckIRId { return check_ir_id_; }
auto package_id() const -> PackageNameId { return package_id_; }
auto library_id() const -> SemIR::LibraryNameId { return library_id_; }
auto library_id() const -> LibraryNameId { return library_id_; }
// Directly expose SharedValueStores members.
auto identifiers() -> SharedValueStores::IdentifierStore& {
+10 -10
View File
@@ -190,7 +190,7 @@ class FormatterImpl {
// Determines whether the specified entity should be included in the formatted
// output.
auto ShouldFormatEntity(SemIR::InstId decl_id) -> bool {
auto ShouldFormatEntity(InstId decl_id) -> bool {
if (!decl_id.has_value()) {
return true;
}
@@ -564,7 +564,7 @@ class FormatterImpl {
// that IR in the output before the `{` or `;`.
if (first_owning_decl_id.has_value()) {
auto loc_id = sem_ir_->insts().GetLocId(first_owning_decl_id);
if (loc_id.kind() == SemIR::LocId::Kind::ImportIRInstId) {
if (loc_id.kind() == LocId::Kind::ImportIRInstId) {
auto import_ir_id =
sem_ir_->import_ir_insts().Get(loc_id.import_ir_inst_id()).ir_id();
const auto* import_file =
@@ -691,12 +691,12 @@ class FormatterImpl {
out_ << ".";
FormatName(name_id);
switch (result.access_kind()) {
case SemIR::AccessKind::Public:
case AccessKind::Public:
break;
case SemIR::AccessKind::Protected:
case AccessKind::Protected:
out_ << " [protected]";
break;
case SemIR::AccessKind::Private:
case AccessKind::Private:
out_ << " [private]";
break;
}
@@ -914,7 +914,7 @@ class FormatterImpl {
// don't include it in the argument list if there is no corresponding
// specific, that is, when we're not in a generic context.
if constexpr (std::is_same_v<typename Info::template ArgType<1>,
SemIR::SpecificId>) {
SpecificId>) {
if (!Info::template Get<1>(inst).has_value()) {
FormatArgs(Info::template Get<0>(inst));
return;
@@ -1161,17 +1161,17 @@ class FormatterImpl {
auto loc_id =
import_ir.sem_ir->insts().GetLocId(import_ir_inst.inst_id());
switch (loc_id.kind()) {
case SemIR::LocId::Kind::None: {
case LocId::Kind::None: {
out_ << import_ir_inst.inst_id() << " [no loc]";
break;
}
case SemIR::LocId::Kind::ImportIRInstId: {
case LocId::Kind::ImportIRInstId: {
// TODO: Probably don't want to format each indirection, but maybe
// reuse GetCanonicalImportIRInst?
out_ << import_ir_inst.inst_id() << " [indirect]";
break;
}
case SemIR::LocId::Kind::NodeId: {
case LocId::Kind::NodeId: {
// Formats a NodeId from the import.
const auto& tree = import_ir.sem_ir->parse_tree();
auto token = tree.node_token(loc_id.node_id());
@@ -1179,7 +1179,7 @@ class FormatterImpl {
<< tree.tokens().GetColumnNumber(token);
break;
}
case SemIR::LocId::Kind::InstId:
case LocId::Kind::InstId:
CARBON_FATAL("Unexpected LocId: {0}", loc_id);
}
}
+3 -3
View File
@@ -55,7 +55,7 @@ auto GetCalleeFunction(const File& sem_ir, InstId callee_id,
auto fn_type = fn_type_inst.TryAs<FunctionType>();
if (!fn_type) {
result.is_error = fn_type_inst.Is<SemIR::ErrorInst>();
result.is_error = fn_type_inst.Is<ErrorInst>();
return result;
}
@@ -70,12 +70,12 @@ auto Function::GetParamPatternInfoFromPatternId(const File& sem_ir,
auto inst_id = pattern_id;
auto inst = sem_ir.insts().Get(inst_id);
if (auto addr_pattern = inst.TryAs<SemIR::AddrPattern>()) {
if (auto addr_pattern = inst.TryAs<AddrPattern>()) {
inst_id = addr_pattern->inner_id;
inst = sem_ir.insts().Get(inst_id);
}
auto param_pattern_inst = inst.TryAs<SemIR::AnyParamPattern>();
auto param_pattern_inst = inst.TryAs<AnyParamPattern>();
if (!param_pattern_inst) {
return std::nullopt;
}
+6 -6
View File
@@ -50,7 +50,7 @@ struct FunctionFields {
// The implicit self parameter, if any, in implicit_param_patterns_id from
// EntityWithParamsBase.
InstId self_param_id = SemIR::InstId::None;
InstId self_param_id = InstId::None;
// The following member is set on the first call to the function, or at the
// point where the function is defined.
@@ -126,16 +126,16 @@ class File;
struct CalleeFunction {
// The function. `None` if not a function.
SemIR::FunctionId function_id;
FunctionId function_id;
// The specific that contains the function.
SemIR::SpecificId enclosing_specific_id;
SpecificId enclosing_specific_id;
// The specific for the callee itself, in a resolved call.
SemIR::SpecificId resolved_specific_id;
SpecificId resolved_specific_id;
// The bound `Self` type or facet value. `None` if not a bound interface
// member.
SemIR::InstId self_type_id;
InstId self_type_id;
// The bound `self` parameter. `None` if not a method.
SemIR::InstId self_id;
InstId self_id;
// True if an error instruction was found.
bool is_error;
};
+2 -2
View File
@@ -135,8 +135,8 @@ class TypeEnum : public Printable<TypeEnum<Types...>> {
//
// As instruction operands, the types listed here can appear as fields of typed
// instructions (`toolchain/sem_ir/typed_insts.h`) and must implement the
// `FromRaw` and `ToRaw` protocol in `SemIR::Inst`. In most cases this is done
// by inheriting from `IdBase` or `IndexBase`.
// `FromRaw` and `ToRaw` protocol in `Inst`. In most cases this is done by
// inheriting from `IdBase` or `IndexBase`.
//
// clang-format off: We want one per line.
using IdKind = TypeEnum<
+5 -5
View File
@@ -635,11 +635,11 @@ constexpr InstBlockId InstBlockId::Unreachable = InstBlockId(NoneIndex - 1);
class InstBlockIdOrError {
public:
// NOLINTNEXTLINE(google-explicit-constructor)
InstBlockIdOrError(SemIR::InstBlockId inst_block_id)
InstBlockIdOrError(InstBlockId inst_block_id)
: InstBlockIdOrError(inst_block_id, false) {}
static auto MakeError() -> InstBlockIdOrError {
return {SemIR::InstBlockId::None, true};
return {InstBlockId::None, true};
}
// Returns whether this class contains either an InstBlockId (other than
@@ -659,16 +659,16 @@ class InstBlockIdOrError {
// false.
//
// Only valid to call if `has_error_value()` is false.
auto inst_block_id() const -> SemIR::InstBlockId {
auto inst_block_id() const -> InstBlockId {
CARBON_CHECK(!has_error_value());
return inst_block_id_;
}
private:
InstBlockIdOrError(SemIR::InstBlockId inst_block_id, bool error)
InstBlockIdOrError(InstBlockId inst_block_id, bool error)
: inst_block_id_(inst_block_id), error_(error) {}
SemIR::InstBlockId inst_block_id_;
InstBlockId inst_block_id_;
bool error_;
};
+4 -4
View File
@@ -82,7 +82,7 @@ INSTANTIATE_TEST_SUITE_P(
TEST_P(LocIdAsNoneTestWithParam, Test) {
auto [_, loc_id] = BuildIdAndLocId<Parse::NodeId>();
EXPECT_FALSE(loc_id.has_value());
EXPECT_THAT(loc_id.kind(), Eq(SemIR::LocId::Kind::None));
EXPECT_THAT(loc_id.kind(), Eq(LocId::Kind::None));
EXPECT_FALSE(loc_id.is_implicit());
EXPECT_THAT(loc_id.import_ir_inst_id(), Eq(ImportIRInstId::None));
EXPECT_THAT(loc_id.inst_id(), Eq(InstId::None));
@@ -99,7 +99,7 @@ INSTANTIATE_TEST_SUITE_P(Test, LocIdAsImportIRInstIdTest,
TEST_P(LocIdAsImportIRInstIdTest, Test) {
auto [import_ir_inst_id, loc_id] = BuildIdAndLocId<ImportIRInstId>();
EXPECT_TRUE(loc_id.has_value());
ASSERT_THAT(loc_id.kind(), Eq(SemIR::LocId::Kind::ImportIRInstId));
ASSERT_THAT(loc_id.kind(), Eq(LocId::Kind::ImportIRInstId));
EXPECT_THAT(loc_id.import_ir_inst_id(), import_ir_inst_id);
EXPECT_FALSE(loc_id.is_implicit());
EXPECT_THAT(loc_id.is_token_only(), Eq(is_token_only()));
@@ -115,7 +115,7 @@ INSTANTIATE_TEST_SUITE_P(
TEST_P(LocIdAsInstIdTest, Test) {
auto [inst_id, loc_id] = BuildIdAndLocId<InstId>();
EXPECT_TRUE(loc_id.has_value());
ASSERT_THAT(loc_id.kind(), Eq(SemIR::LocId::Kind::InstId));
ASSERT_THAT(loc_id.kind(), Eq(LocId::Kind::InstId));
EXPECT_THAT(loc_id.inst_id(), inst_id);
// Note that `is_implicit` and `is_token_only` are invalid to use with
// `InstId`.
@@ -129,7 +129,7 @@ INSTANTIATE_TEST_SUITE_P(Test, LocIdAsNodeIdTest,
TEST_P(LocIdAsNodeIdTest, Test) {
auto [node_id, loc_id] = BuildIdAndLocId<Parse::NodeId>();
EXPECT_TRUE(loc_id.has_value());
ASSERT_THAT(loc_id.kind(), Eq(SemIR::LocId::Kind::NodeId));
ASSERT_THAT(loc_id.kind(), Eq(LocId::Kind::NodeId));
EXPECT_THAT(loc_id.node_id(), node_id);
EXPECT_THAT(loc_id.is_implicit(), Eq(is_implicit()));
EXPECT_THAT(loc_id.is_token_only(), Eq(is_token_only()));
+2 -3
View File
@@ -14,9 +14,8 @@ auto ImplStore::GetOrAddLookupBucket(const Impl& impl) -> LookupBucketRef {
SpecificId specific_id = SpecificId::None;
auto facet_type_id = TypeId::ForTypeConstant(
sem_ir_.constant_values().Get(impl.constraint_id));
if (auto facet_type =
sem_ir_.types().TryGetAs<SemIR::FacetType>(facet_type_id)) {
const SemIR::FacetTypeInfo& facet_type_info =
if (auto facet_type = sem_ir_.types().TryGetAs<FacetType>(facet_type_id)) {
const FacetTypeInfo& facet_type_info =
sem_ir_.facet_types().Get(facet_type->facet_type_id);
if (auto interface_type = facet_type_info.TryAsSingleInterface()) {
interface_id = interface_type->interface_id;
+1 -1
View File
@@ -24,7 +24,7 @@ struct ImplFields {
// The single interface to implement from `constraint_id`.
// The members are `None` if `constraint_id` isn't complete or doesn't
// correspond to a single interface.
SemIR::SpecificInterface interface;
SpecificInterface interface;
// The witness for the impl. This can be `BuiltinErrorInst` or an import
// reference. Note that the entries in the witness are updated at the end of
+1 -2
View File
@@ -40,8 +40,7 @@ class ImportIRInst : public Printable<ImportIRInst> {
// Constructor for a `Cpp` import.
explicit ImportIRInst(ClangSourceLocId clang_source_loc_id)
: ir_id_(SemIR::ImportIRId::Cpp),
clang_source_loc_id_(clang_source_loc_id) {}
: ir_id_(ImportIRId::Cpp), clang_source_loc_id_(clang_source_loc_id) {}
auto Print(llvm::raw_ostream& out) const -> void {
out << "{ir_id: " << ir_id() << ", ";
+4 -4
View File
@@ -136,14 +136,14 @@ class Inst : public Printable<Inst> {
// Converts to `IdT`, validating the `kind` matches.
template <typename IdT>
auto As() const -> IdT {
CARBON_DCHECK(kind_ == SemIR::IdKind::For<IdT>);
CARBON_DCHECK(kind_ == IdKind::For<IdT>);
return IdT(value_);
}
// Converts to `IdT`, returning nullopt if the kind is incorrect.
template <typename IdT>
auto TryAs() const -> std::optional<IdT> {
if (kind_ != SemIR::IdKind::For<IdT>) {
if (kind_ != IdKind::For<IdT>) {
return std::nullopt;
}
return IdT(value_);
@@ -369,7 +369,7 @@ struct LocIdAndInst {
// node.
template <typename InstT>
requires(Internal::HasUntypedNodeId<InstT>)
LocIdAndInst(SemIR::LocId loc_id, InstT inst) : loc_id(loc_id), inst(inst) {}
LocIdAndInst(LocId loc_id, InstT inst) : loc_id(loc_id), inst(inst) {}
LocId loc_id;
Inst inst;
@@ -504,7 +504,7 @@ class InstBlockStore : public BlockValueStore<InstBlockId> {
// Sets the contents of a placeholder block to the given content.
auto ReplacePlaceholder(InstBlockId block_id, llvm::ArrayRef<InstId> content)
-> void {
CARBON_CHECK(block_id != SemIR::InstBlockId::Empty);
CARBON_CHECK(block_id != InstBlockId::Empty);
CARBON_CHECK(Get(block_id).empty(),
"inst block content set more than once");
values().Get(block_id) = AllocateCopy(content);
+7 -7
View File
@@ -320,19 +320,19 @@ struct Worklist {
// null IdKind as a parameter in order to get the type pack.
template <typename... Types>
static constexpr auto MakeAddTable(TypeEnum<Types...>* /*id_kind*/)
-> std::array<AddFnT*, SemIR::IdKind::NumValues> {
std::array<AddFnT*, SemIR::IdKind::NumValues> table = {};
((table[SemIR::IdKind::template For<Types>.ToIndex()] =
-> std::array<AddFnT*, IdKind::NumValues> {
std::array<AddFnT*, IdKind::NumValues> table = {};
((table[IdKind::template For<Types>.ToIndex()] =
[](Worklist& worklist, int32_t arg) {
worklist.Add(Inst::FromRaw<Types>(arg));
}),
...);
table[SemIR::IdKind::Invalid.ToIndex()] = [](Worklist& /*worklist*/,
int32_t /*arg*/) {
table[IdKind::Invalid.ToIndex()] = [](Worklist& /*worklist*/,
int32_t /*arg*/) {
CARBON_FATAL("Unexpected invalid argument kind");
};
table[SemIR::IdKind::None.ToIndex()] = [](Worklist& /*worklist*/,
int32_t /*arg*/) {};
table[IdKind::None.ToIndex()] = [](Worklist& /*worklist*/,
int32_t /*arg*/) {};
return table;
}
+18 -21
View File
@@ -40,8 +40,8 @@ InstNamer::InstNamer(const File* sem_ir) : sem_ir_(sem_ir) {
CollectNamesInBlock(ScopeId::Constants, sem_ir->constants().array_ref());
// Build the ImportRef scope.
CollectNamesInBlock(ScopeId::ImportRefs, sem_ir->inst_blocks().Get(
SemIR::InstBlockId::ImportRefs));
CollectNamesInBlock(ScopeId::ImportRefs,
sem_ir->inst_blocks().Get(InstBlockId::ImportRefs));
// Build the file scope.
CollectNamesInBlock(ScopeId::File, sem_ir->top_inst_block_id());
@@ -157,7 +157,7 @@ auto InstNamer::GetNameFor(ScopeId scope_id, InstId inst_id) const
}
// Check for a builtin.
if (SemIR::IsSingletonInstId(inst_id)) {
if (IsSingletonInstId(inst_id)) {
return sem_ir_->insts().Get(inst_id).kind().ir_name().str();
}
@@ -172,7 +172,7 @@ auto InstNamer::GetNameFor(ScopeId scope_id, InstId inst_id) const
out << "<unexpected>." << inst_id;
auto loc_id = sem_ir_->insts().GetLocId(inst_id);
// TODO: Consider handling other kinds.
if (loc_id.kind() == SemIR::LocId::Kind::NodeId) {
if (loc_id.kind() == LocId::Kind::NodeId) {
const auto& tree = sem_ir_->parse_tree();
auto token = tree.node_token(loc_id.node_id());
out << ".loc" << tree.tokens().GetLineNumber(token) << "_"
@@ -226,8 +226,8 @@ auto InstNamer::Namespace::Name::str() const -> llvm::StringRef {
auto InstNamer::Namespace::AllocateName(
const InstNamer& inst_namer,
std::variant<SemIR::LocId, uint64_t> loc_id_or_fingerprint,
std::string name) -> Name {
std::variant<LocId, uint64_t> loc_id_or_fingerprint, std::string name)
-> Name {
// The best (shortest) name for this instruction so far, and the current
// name for it.
Name best;
@@ -264,7 +264,7 @@ auto InstNamer::Namespace::AllocateName(
// Append location information to try to disambiguate.
if (auto* loc_id = std::get_if<LocId>(&loc_id_or_fingerprint)) {
// TODO: Consider handling other kinds.
if (loc_id->kind() == SemIR::LocId::Kind::NodeId) {
if (loc_id->kind() == LocId::Kind::NodeId) {
const auto& tree = inst_namer.sem_ir_->parse_tree();
auto token = tree.node_token(loc_id->node_id());
llvm::raw_string_ostream(name)
@@ -303,7 +303,7 @@ auto InstNamer::Namespace::AllocateName(
auto InstNamer::AddBlockLabel(
ScopeId scope_id, InstBlockId block_id, std::string name,
std::variant<SemIR::LocId, uint64_t> loc_id_or_fingerprint) -> void {
std::variant<LocId, uint64_t> loc_id_or_fingerprint) -> void {
if (!block_id.has_value() || labels_[block_id.index].second) {
return;
}
@@ -323,8 +323,8 @@ auto InstNamer::AddBlockLabel(
// Finds and adds a suitable block label for the given SemIR instruction that
// represents some kind of branch.
auto InstNamer::AddBlockLabel(ScopeId scope_id, SemIR::LocId loc_id,
AnyBranch branch) -> void {
auto InstNamer::AddBlockLabel(ScopeId scope_id, LocId loc_id, AnyBranch branch)
-> void {
if (!loc_id.node_id().has_value()) {
AddBlockLabel(scope_id, branch.target_id, "", loc_id);
return;
@@ -414,7 +414,7 @@ auto InstNamer::CollectNamesInBlock(ScopeId top_scope_id,
auto queue_block_insts = [&](ScopeId scope_id,
llvm::ArrayRef<InstId> inst_ids) {
for (auto inst_id : llvm::reverse(inst_ids)) {
if (inst_id.has_value() && !SemIR::IsSingletonInstId(inst_id)) {
if (inst_id.has_value() && !IsSingletonInstId(inst_id)) {
insts.push_back(std::make_pair(scope_id, inst_id));
}
}
@@ -437,8 +437,7 @@ auto InstNamer::CollectNamesInBlock(ScopeId top_scope_id,
auto add_inst_name = [&](std::string name) {
ScopeId old_scope_id = insts_[inst_id.index].first;
if (old_scope_id == ScopeId::None) {
std::variant<SemIR::LocId, uint64_t> loc_id_or_fingerprint =
SemIR::LocId::None;
std::variant<LocId, uint64_t> loc_id_or_fingerprint = LocId::None;
if (scope_id == ScopeId::Constants || scope_id == ScopeId::ImportRefs) {
loc_id_or_fingerprint = fingerprinter_.GetOrCompute(sem_ir_, inst_id);
} else {
@@ -457,7 +456,7 @@ auto InstNamer::CollectNamesInBlock(ScopeId top_scope_id,
(sem_ir_->names().GetIRBaseName(name_id).str() + suffix).str());
};
auto add_int_or_float_type_name = [&](char type_literal_prefix,
SemIR::InstId bit_width_id,
InstId bit_width_id,
llvm::StringRef suffix = "") {
RawStringOstream out;
out << type_literal_prefix;
@@ -471,8 +470,8 @@ auto InstNamer::CollectNamesInBlock(ScopeId top_scope_id,
};
auto add_witness_table_name = [&](InstId witness_table_inst_id,
std::string name) {
auto witness_table = sem_ir_->insts().GetAs<SemIR::ImplWitnessTable>(
witness_table_inst_id);
auto witness_table =
sem_ir_->insts().GetAs<ImplWitnessTable>(witness_table_inst_id);
if (!witness_table.impl_id.has_value()) {
// TODO: The witness comes from a facet value. Can we get the
// interface names from it? Store the facet value instruction in the
@@ -567,16 +566,14 @@ auto InstNamer::CollectNamesInBlock(ScopeId top_scope_id,
continue;
}
case CARBON_KIND(Call inst): {
auto callee_function =
SemIR::GetCalleeFunction(*sem_ir_, inst.callee_id);
auto callee_function = GetCalleeFunction(*sem_ir_, inst.callee_id);
if (!callee_function.function_id.has_value()) {
break;
}
const auto& function =
sem_ir_->functions().Get(callee_function.function_id);
// Name the call's result based on the callee.
if (function.builtin_function_kind !=
SemIR::BuiltinFunctionKind::None) {
if (function.builtin_function_kind != BuiltinFunctionKind::None) {
// For a builtin, use the builtin name. Otherwise, we'd typically pick
// the name `Op` below, which is probably not very useful.
add_inst_name(function.builtin_function_kind.name().str());
@@ -819,7 +816,7 @@ auto InstNamer::CollectNamesInBlock(ScopeId top_scope_id,
case OutParamPattern::Kind:
case RefParamPattern::Kind:
case ValueParamPattern::Kind: {
add_inst_name_id(SemIR::GetPrettyNameFromPatternId(*sem_ir_, inst_id),
add_inst_name_id(GetPrettyNameFromPatternId(*sem_ir_, inst_id),
".param_patt");
continue;
}
+8 -10
View File
@@ -136,10 +136,9 @@ class InstNamer {
return Name(allocated.insert({name, NameResult()}).first);
}
auto AllocateName(
const InstNamer& inst_namer,
std::variant<SemIR::LocId, uint64_t> loc_id_or_fingerprint,
std::string name) -> Name;
auto AllocateName(const InstNamer& inst_namer,
std::variant<LocId, uint64_t> loc_id_or_fingerprint,
std::string name) -> Name;
};
// A named scope that contains named entities.
@@ -157,15 +156,14 @@ class InstNamer {
return scopes_[static_cast<int>(scope_id)];
}
auto AddBlockLabel(ScopeId scope_id, InstBlockId block_id,
std::string name = "",
std::variant<SemIR::LocId, uint64_t>
loc_id_or_fingerprint = SemIR::LocId::None) -> void;
auto AddBlockLabel(
ScopeId scope_id, InstBlockId block_id, std::string name = "",
std::variant<LocId, uint64_t> loc_id_or_fingerprint = LocId::None)
-> void;
// Finds and adds a suitable block label for the given SemIR instruction that
// represents some kind of branch.
auto AddBlockLabel(ScopeId scope_id, SemIR::LocId loc_id, AnyBranch branch)
-> void;
auto AddBlockLabel(ScopeId scope_id, LocId loc_id, AnyBranch branch) -> void;
auto CollectNamesInBlock(ScopeId scope_id, InstBlockId block_id) -> void;
+2 -2
View File
@@ -18,8 +18,8 @@ namespace Carbon::SemIR {
// as `NameId`s with the same non-negative index as the `IdentifierId` of the
// identifier. Special names are represented as `NameId`s with a negative index.
//
// `SemIR::NameId` values should be obtained by using `NameId::ForIdentifier`
// or the named constants such as `NameId::SelfValue`.
// `NameId` values should be obtained by using `NameId::ForIdentifier` or the
// named constants such as `NameId::SelfValue`.
//
// As we do not require any additional explicit storage for names, this is
// currently a wrapper around an identifier store that has no state of its own.
+1 -1
View File
@@ -23,7 +23,7 @@ auto IsSelfPattern(const File& sem_ir, InstId pattern_id) -> bool;
// This should only be used for decorative purposes such as SemIR
// pretty-printing or LLVM parameter naming.
auto GetPrettyNameFromPatternId(const File& sem_ir, InstId pattern_id)
-> SemIR::NameId;
-> NameId;
} // namespace Carbon::SemIR
+56 -64
View File
@@ -64,7 +64,7 @@ class StepStack {
// Starts a new stack, which always contains the first instruction to
// stringify.
explicit StepStack(const SemIR::File* file) : sem_ir_(file) {}
explicit StepStack(const File* file) : sem_ir_(file) {}
// These push basic entries onto the stack.
auto PushInstId(InstId inst_id) -> void { steps_.push_back(inst_id); }
@@ -185,7 +185,7 @@ class StepStack {
PushString("(");
}
const SemIR::File* sem_ir_;
const File* sem_ir_;
// Remaining steps to take.
llvm::SmallVector<Step> steps_;
};
@@ -193,13 +193,13 @@ class StepStack {
// Provides `StringifyInst` overloads for each instruction.
class Stringifier {
public:
explicit Stringifier(const SemIR::File* sem_ir, StepStack* step_stack,
explicit Stringifier(const File* sem_ir, StepStack* step_stack,
llvm::raw_ostream* out)
: sem_ir_(sem_ir), step_stack_(step_stack), out_(out) {}
// By default try to print a constant, but otherwise may fail to
// stringify.
auto StringifyInstDefault(SemIR::InstId inst_id, Inst inst) -> void {
auto StringifyInstDefault(InstId inst_id, Inst inst) -> void {
// We don't know how to print this instruction, but it might have a
// constant value that we can print.
auto const_inst_id = sem_ir_->constant_values().GetConstantInstId(inst_id);
@@ -215,7 +215,7 @@ class Stringifier {
}
template <typename InstT>
auto StringifyInst(SemIR::InstId inst_id, InstT inst) -> void {
auto StringifyInst(InstId inst_id, InstT inst) -> void {
// This doesn't use requires so that more specific overloads are chosen when
// provided.
static_assert(InstT::Kind.is_type() != InstIsType::Always ||
@@ -229,32 +229,30 @@ class Stringifier {
// Singleton instructions use their IR name as a label.
template <typename InstT>
requires(IsSingletonInstKind(InstT::Kind))
auto StringifyInst(SemIR::InstId /*inst_id*/, InstT /*inst*/) -> void {
auto StringifyInst(InstId /*inst_id*/, InstT /*inst*/) -> void {
*out_ << InstT::Kind.ir_name();
}
auto StringifyInst(SemIR::InstId /*inst_id*/, ArrayType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, ArrayType inst) -> void {
*out_ << "array(";
step_stack_->Push(inst.element_type_inst_id, ", ", inst.bound_id, ")");
}
auto StringifyInst(SemIR::InstId /*inst_id*/, AssociatedConstantDecl inst)
-> void {
auto StringifyInst(InstId /*inst_id*/, AssociatedConstantDecl inst) -> void {
const auto& assoc_const =
sem_ir_->associated_constants().Get(inst.assoc_const_id);
step_stack_->PushQualifiedName(assoc_const.parent_scope_id,
assoc_const.name_id);
}
auto StringifyInst(SemIR::InstId /*inst_id*/, AssociatedEntityType inst)
-> void {
auto StringifyInst(InstId /*inst_id*/, AssociatedEntityType inst) -> void {
*out_ << "<associated entity in ";
step_stack_->Push(">");
step_stack_->PushSpecificInterface(
SpecificInterface{inst.interface_id, inst.interface_specific_id});
}
auto StringifyInst(SemIR::InstId /*inst_id*/, BoolLiteral inst) -> void {
auto StringifyInst(InstId /*inst_id*/, BoolLiteral inst) -> void {
step_stack_->Push(inst.value.ToBool() ? "true" : "false");
}
@@ -262,11 +260,11 @@ class Stringifier {
requires(std::same_as<InstT, BindAlias> ||
std::same_as<InstT, BindSymbolicName> ||
std::same_as<InstT, ExportDecl>)
auto StringifyInst(SemIR::InstId /*inst_id*/, InstT inst) -> void {
auto StringifyInst(InstId /*inst_id*/, InstT inst) -> void {
step_stack_->PushEntityNameId(inst.entity_name_id);
}
auto StringifyInst(SemIR::InstId /*inst_id*/, ClassType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, ClassType inst) -> void {
const auto& class_info = sem_ir_->classes().Get(inst.class_id);
if (auto literal_info = NumericTypeLiteralInfo::ForType(*sem_ir_, inst);
literal_info.is_valid()) {
@@ -276,12 +274,12 @@ class Stringifier {
step_stack_->PushEntityName(class_info, inst.specific_id);
}
auto StringifyInst(SemIR::InstId /*inst_id*/, ConstType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, ConstType inst) -> void {
*out_ << "const ";
// Add parentheses if required.
if (GetPrecedence(sem_ir_->insts().Get(inst.inner_id).kind()) <
GetPrecedence(SemIR::ConstType::Kind)) {
GetPrecedence(ConstType::Kind)) {
*out_ << "(";
// Note the `inst.inner_id` ends up here.
step_stack_->PushString(")");
@@ -290,12 +288,12 @@ class Stringifier {
step_stack_->PushInstId(inst.inner_id);
}
auto StringifyInst(SemIR::InstId /*inst_id*/, FacetAccessType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, FacetAccessType inst) -> void {
// Given `T:! I`, print `T as type` as simply `T`.
step_stack_->PushInstId(inst.facet_value_inst_id);
}
auto StringifyInst(SemIR::InstId /*inst_id*/, FacetType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, FacetType inst) -> void {
const FacetTypeInfo& facet_type_info =
sem_ir_->facet_types().Get(inst.facet_type_id);
// Output `where` restrictions.
@@ -338,12 +336,12 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId /*inst_id*/, FacetValue inst) -> void {
auto StringifyInst(InstId /*inst_id*/, FacetValue inst) -> void {
// No need to output the witness.
step_stack_->Push(inst.type_inst_id, " as ", inst.type_id);
}
auto StringifyInst(SemIR::InstId /*inst_id*/, FloatType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, FloatType inst) -> void {
// TODO: Is this okay?
if (auto width_value =
sem_ir_->insts().TryGetAs<IntValue>(inst.bit_width_id)) {
@@ -355,16 +353,16 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId /*inst_id*/, FunctionType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, FunctionType inst) -> void {
const auto& fn = sem_ir_->functions().Get(inst.function_id);
*out_ << "<type of ";
step_stack_->Push(
StepStack::QualifiedNameItem{fn.parent_scope_id, fn.name_id}, ">");
}
auto StringifyInst(SemIR::InstId /*inst_id*/, FunctionTypeWithSelfType inst)
auto StringifyInst(InstId /*inst_id*/, FunctionTypeWithSelfType inst)
-> void {
StepStack::PushItem fn_name = SemIR::InstId::None;
StepStack::PushItem fn_name = InstId::None;
if (auto fn_inst = sem_ir_->insts().TryGetAs<FunctionType>(
inst.interface_function_type_id)) {
const auto& fn = sem_ir_->functions().Get(fn_inst->function_id);
@@ -377,7 +375,7 @@ class Stringifier {
step_stack_->Push(fn_name, " in ", inst.self_id, ">");
}
auto StringifyInst(SemIR::InstId /*inst_id*/, GenericClassType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, GenericClassType inst) -> void {
const auto& class_info = sem_ir_->classes().Get(inst.class_id);
*out_ << "<type of ";
step_stack_->Push(StepStack::QualifiedNameItem{class_info.parent_scope_id,
@@ -385,8 +383,7 @@ class Stringifier {
">");
}
auto StringifyInst(SemIR::InstId /*inst_id*/, GenericInterfaceType inst)
-> void {
auto StringifyInst(InstId /*inst_id*/, GenericInterfaceType inst) -> void {
const auto& interface = sem_ir_->interfaces().Get(inst.interface_id);
*out_ << "<type of ";
step_stack_->Push(StepStack::QualifiedNameItem{interface.parent_scope_id,
@@ -397,10 +394,10 @@ class Stringifier {
// Determine the specific interface that an impl witness instruction provides
// an implementation of.
// TODO: Should we track this in the type?
auto TryGetSpecificInterfaceForImplWitness(SemIR::InstId impl_witness_id)
auto TryGetSpecificInterfaceForImplWitness(InstId impl_witness_id)
-> std::optional<SpecificInterface> {
if (auto lookup = sem_ir_->insts().TryGetAs<SemIR::LookupImplWitness>(
impl_witness_id)) {
if (auto lookup =
sem_ir_->insts().TryGetAs<LookupImplWitness>(impl_witness_id)) {
return sem_ir_->specific_interfaces().Get(
lookup->query_specific_interface_id);
}
@@ -409,8 +406,7 @@ class Stringifier {
return std::nullopt;
}
auto StringifyInst(SemIR::InstId /*inst_id*/, ImplWitnessAccess inst)
-> void {
auto StringifyInst(InstId /*inst_id*/, ImplWitnessAccess inst) -> void {
auto witness_inst_id =
sem_ir_->constant_values().GetConstantInstId(inst.witness_id);
if (auto specific_interface =
@@ -453,7 +449,7 @@ class Stringifier {
lookup->query_self_inst_id)) {
auto name_id =
sem_ir_->entity_names().Get(sym_name->entity_name_id).name_id;
period_self = (name_id == SemIR::NameId::PeriodSelf);
period_self = (name_id == NameId::PeriodSelf);
}
if (!period_self) {
step_stack_->PushInstId(lookup->query_self_inst_id);
@@ -464,8 +460,7 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId /*inst_id*/, ImportRefUnloaded inst)
-> void {
auto StringifyInst(InstId /*inst_id*/, ImportRefUnloaded inst) -> void {
if (inst.entity_name_id.has_value()) {
step_stack_->PushEntityNameId(inst.entity_name_id);
} else {
@@ -473,7 +468,7 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId /*inst_id*/, IntType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, IntType inst) -> void {
*out_ << "<builtin ";
step_stack_->PushString(">");
if (auto width_value =
@@ -486,33 +481,32 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId /*inst_id*/, IntValue inst) -> void {
auto StringifyInst(InstId /*inst_id*/, IntValue inst) -> void {
sem_ir_->ints().Get(inst.int_id).print(*out_, /*isSigned=*/true);
}
auto StringifyInst(SemIR::InstId /*inst_id*/, LookupImplWitness inst)
-> void {
auto StringifyInst(InstId /*inst_id*/, LookupImplWitness inst) -> void {
step_stack_->Push(
inst.query_self_inst_id, " as ",
sem_ir_->specific_interfaces().Get(inst.query_specific_interface_id));
}
auto StringifyInst(SemIR::InstId /*inst_id*/, NameRef inst) -> void {
auto StringifyInst(InstId /*inst_id*/, NameRef inst) -> void {
*out_ << sem_ir_->names().GetFormatted(inst.name_id);
}
auto StringifyInst(SemIR::InstId /*inst_id*/, Namespace inst) -> void {
auto StringifyInst(InstId /*inst_id*/, Namespace inst) -> void {
const auto& name_scope = sem_ir_->name_scopes().Get(inst.name_scope_id);
step_stack_->PushQualifiedName(name_scope.parent_scope_id(),
name_scope.name_id());
}
auto StringifyInst(SemIR::InstId /*inst_id*/, PointerType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, PointerType inst) -> void {
step_stack_->Push(inst.pointee_id, "*");
}
auto StringifyInst(SemIR::InstId /*inst_id*/, SpecificFunction inst) -> void {
auto callee = SemIR::GetCalleeFunction(*sem_ir_, inst.callee_id);
auto StringifyInst(InstId /*inst_id*/, SpecificFunction inst) -> void {
auto callee = GetCalleeFunction(*sem_ir_, inst.callee_id);
if (callee.function_id.has_value()) {
step_stack_->PushEntityName(sem_ir_->functions().Get(callee.function_id),
inst.specific_id);
@@ -521,9 +515,8 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId /*inst_id*/, SpecificImplFunction inst)
-> void {
auto callee = SemIR::GetCalleeFunction(*sem_ir_, inst.callee_id);
auto StringifyInst(InstId /*inst_id*/, SpecificImplFunction inst) -> void {
auto callee = GetCalleeFunction(*sem_ir_, inst.callee_id);
if (callee.function_id.has_value()) {
// TODO: The specific_id here is for the interface member, but the
// entity we're passing is the impl member. This might result in
@@ -535,7 +528,7 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId /*inst_id*/, StructType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, StructType inst) -> void {
auto fields = sem_ir_->struct_type_fields().Get(inst.fields_id);
if (fields.empty()) {
*out_ << "{}";
@@ -549,7 +542,7 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId /*inst_id*/, StructValue inst) -> void {
auto StringifyInst(InstId /*inst_id*/, StructValue inst) -> void {
auto field_values = sem_ir_->inst_blocks().Get(inst.elements_id);
if (field_values.empty()) {
*out_ << "{}";
@@ -571,7 +564,7 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId /*inst_id*/, TupleType inst) -> void {
auto StringifyInst(InstId /*inst_id*/, TupleType inst) -> void {
auto refs = sem_ir_->inst_blocks().Get(inst.type_elements_id);
if (refs.empty()) {
*out_ << "()";
@@ -590,7 +583,7 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId /*inst_id*/, TupleValue inst) -> void {
auto StringifyInst(InstId /*inst_id*/, TupleValue inst) -> void {
auto refs = sem_ir_->inst_blocks().Get(inst.elements_id);
if (refs.empty()) {
*out_ << "()";
@@ -609,7 +602,7 @@ class Stringifier {
}
}
auto StringifyInst(SemIR::InstId inst_id, TypeOfInst /*inst*/) -> void {
auto StringifyInst(InstId inst_id, TypeOfInst /*inst*/) -> void {
// Print the constant value if we've already computed the inst.
auto const_inst_id = sem_ir_->constant_values().GetConstantInstId(inst_id);
if (const_inst_id.has_value() && const_inst_id != inst_id) {
@@ -619,25 +612,24 @@ class Stringifier {
*out_ << "<dependent type>";
}
auto StringifyInst(SemIR::InstId /*inst_id*/, UnboundElementType inst)
-> void {
auto StringifyInst(InstId /*inst_id*/, UnboundElementType inst) -> void {
*out_ << "<unbound element of class ";
step_stack_->Push(inst.class_type_inst_id, ">");
}
auto StringifyInst(SemIR::InstId /*inst_id*/, VtablePtr /*inst*/) -> void {
auto StringifyInst(InstId /*inst_id*/, VtablePtr /*inst*/) -> void {
*out_ << "<vtable ptr>";
}
private:
const SemIR::File* sem_ir_;
const File* sem_ir_;
StepStack* step_stack_;
llvm::raw_ostream* out_;
};
} // namespace
static auto Stringify(const SemIR::File& sem_ir, StepStack& step_stack)
static auto Stringify(const File& sem_ir, StepStack& step_stack)
-> std::string {
RawStringOstream out;
@@ -671,7 +663,7 @@ static auto Stringify(const SemIR::File& sem_ir, StepStack& step_stack)
return out.TakeStr();
}
auto StringifyConstantInst(const SemIR::File& sem_ir, InstId outer_inst_id)
auto StringifyConstantInst(const File& sem_ir, InstId outer_inst_id)
-> std::string {
StepStack step_stack(&sem_ir);
step_stack.PushInstId(outer_inst_id);
@@ -686,14 +678,14 @@ auto StringifySpecific(const File& sem_ir, SpecificId specific_id)
const auto& generic = sem_ir.generics().Get(specific.generic_id);
auto decl = sem_ir.insts().Get(generic.decl_id);
CARBON_KIND_SWITCH(decl) {
case CARBON_KIND(SemIR::ClassDecl class_decl): {
case CARBON_KIND(ClassDecl class_decl): {
// Print `Core.Int(N)` as `iN`.
// TODO: This duplicates work done in StringifyInst for ClassType.
const auto& class_info = sem_ir.classes().Get(class_decl.class_id);
if (auto literal_info = NumericTypeLiteralInfo::ForType(
sem_ir, SemIR::ClassType{.type_id = SemIR::TypeType::TypeId,
.class_id = class_decl.class_id,
.specific_id = specific_id});
sem_ir, ClassType{.type_id = TypeType::TypeId,
.class_id = class_decl.class_id,
.specific_id = specific_id});
literal_info.is_valid()) {
RawStringOstream out;
literal_info.PrintLiteral(sem_ir, out);
@@ -702,17 +694,17 @@ auto StringifySpecific(const File& sem_ir, SpecificId specific_id)
step_stack.PushEntityName(class_info, specific_id);
break;
}
case CARBON_KIND(SemIR::FunctionDecl function_decl): {
case CARBON_KIND(FunctionDecl function_decl): {
step_stack.PushEntityName(
sem_ir.functions().Get(function_decl.function_id), specific_id);
break;
}
case CARBON_KIND(SemIR::ImplDecl impl_decl): {
case CARBON_KIND(ImplDecl impl_decl): {
step_stack.PushEntityName(sem_ir.impls().Get(impl_decl.impl_id),
specific_id);
break;
}
case CARBON_KIND(SemIR::InterfaceDecl interface_decl): {
case CARBON_KIND(InterfaceDecl interface_decl): {
step_stack.PushEntityName(
sem_ir.interfaces().Get(interface_decl.interface_id), specific_id);
break;
+1 -1
View File
@@ -21,7 +21,7 @@ auto StringifyConstantInst(const File& sem_ir, InstId outer_inst_id)
// Produces a string version of the name of a specific. Generally, this should
// not be called directly. To format a string into a diagnostic, use a
// diagnostic parameter of type `SemIR::SpecificId`.
// diagnostic parameter of type `SpecificId`.
auto StringifySpecific(const File& sem_ir, SpecificId specific_id)
-> std::string;
+4 -4
View File
@@ -68,7 +68,7 @@ class TypeStore : public Yaml::Printable<TypeStore> {
// GetAsTypeInstId().
auto GetBlockAsTypeInstIds(llvm::ArrayRef<InstId> array
[[clang::lifetimebound]]) const -> auto {
return llvm::map_range(array, [&](SemIR::InstId type_inst_id) {
return llvm::map_range(array, [&](InstId type_inst_id) {
return GetAsTypeInstId(type_inst_id);
});
}
@@ -77,7 +77,7 @@ class TypeStore : public Yaml::Printable<TypeStore> {
// GetTypeIdForTypeInstId().
auto GetBlockAsTypeIds(llvm::ArrayRef<InstId> array
[[clang::lifetimebound]]) const -> auto {
return llvm::map_range(array, [&](SemIR::InstId type_inst_id) {
return llvm::map_range(array, [&](InstId type_inst_id) {
return GetTypeIdForTypeInstId(type_inst_id);
});
}
@@ -166,8 +166,8 @@ class TypeStore : public Yaml::Printable<TypeStore> {
auto GetIntTypeInfo(TypeId int_type_id) const -> IntTypeInfo;
// Returns whether `type_id` represents a facet type.
auto IsFacetType(SemIR::TypeId type_id) const -> bool {
return type_id == SemIR::TypeType::TypeId || Is<SemIR::FacetType>(type_id);
auto IsFacetType(TypeId type_id) const -> bool {
return type_id == TypeType::TypeId || Is<FacetType>(type_id);
}
// Returns a list of types that were completed in this file, in the order in
+2 -2
View File
@@ -45,8 +45,8 @@ auto ValueRepr::IsCopyOfObjectRepr(const File& file, TypeId orig_type_id) const
-> bool {
// If aggregate_kind is ValueAggregate, then the representations are known to
// be different in some way even, if they're represented by the same type.
return (kind == SemIR::ValueRepr::Copy || kind == SemIR::ValueRepr::None) &&
aggregate_kind != SemIR::ValueRepr::ValueAggregate &&
return (kind == ValueRepr::Copy || kind == ValueRepr::None) &&
aggregate_kind != ValueRepr::ValueAggregate &&
type_id == file.types().GetObjectRepr(orig_type_id);
}
+1 -1
View File
@@ -80,7 +80,7 @@ struct CompleteTypeInfo : public Printable<CompleteTypeInfo> {
ValueRepr value_repr = ValueRepr();
// If this type is abstract, this is id of an abstract class it uses.
SemIR::ClassId abstract_class_id = SemIR::ClassId::None;
ClassId abstract_class_id = ClassId::None;
};
// The initializing representation to use when returning by value.
+4 -4
View File
@@ -24,12 +24,12 @@
// value. This includes instructions that produce an abstract value, such as a
// `Namespace`, for which a placeholder type should be used.
// - Up to two members describing the contents of the struct. These are types
// listed in the `SemIR::IdKind` type-enum, typically derived from `IdBase`.
// listed in the `IdKind` type-enum, typically derived from `IdBase`.
//
// The field names here matter -- the fields must have the names specified
// above, when present. When converting to a `SemIR::Inst`, the `kind` and
// `type_id` fields will become the kind and type associated with the
// type-erased instruction.
// above, when present. When converting to a `Inst`, the `kind` and `type_id`
// fields will become the kind and type associated with the type-erased
// instruction.
//
// Each type that describes a single kind of instructions provides a constant
// `Kind` that associates the type with a particular member of the `InstKind`
+1 -1
View File
@@ -11,7 +11,7 @@
namespace Carbon::SemIR {
// A friend of `SemIR::Inst` that is used to pierce the abstraction.
// A friend of `Inst` that is used to pierce the abstraction.
class InstTestHelper {
public:
static auto MakeInst(InstKind inst_kind, TypeId type_id, int32_t arg0,