mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
This reverts commit afd679129d.
The commit introduced ASAN errors:
https://github.com/carbon-language/carbon-lang/actions/runs/27436787960/job/81100665405
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "toolchain/sem_ir/class.h"
|
||||
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "toolchain/base/value_store_impl.h"
|
||||
#include "toolchain/sem_ir/file.h"
|
||||
#include "toolchain/sem_ir/generic.h"
|
||||
@@ -52,80 +51,6 @@ auto Class::GetObjectRepr(const File& file, SpecificId specific_id) const
|
||||
.object_repr_type_inst_id);
|
||||
}
|
||||
|
||||
auto Class::GetStructTypeFields(const File& sem_ir) const
|
||||
-> llvm::ArrayRef<SemIR::StructTypeField> {
|
||||
if (adapt_id.has_value()) {
|
||||
// The representation of an adapter won't necessarily be a
|
||||
// struct. Return an empty array since adapters can't declare
|
||||
// fields.
|
||||
return {};
|
||||
}
|
||||
|
||||
auto object_repr_type_id = GetObjectRepr(sem_ir, SemIR::SpecificId::None);
|
||||
if (object_repr_type_id == SemIR::ErrorInst::TypeId) {
|
||||
return {};
|
||||
}
|
||||
auto struct_type =
|
||||
sem_ir.types().GetAs<SemIR::StructType>(object_repr_type_id);
|
||||
return sem_ir.struct_type_fields().Get(struct_type.fields_id);
|
||||
}
|
||||
|
||||
auto GetAsCarbonOwnedClass(const File& sem_ir, const clang::TagDecl* tag_decl)
|
||||
-> std::optional<std::pair<SemIR::TypeId, SemIR::ClassType>> {
|
||||
// Quickly check whether we could possibly own this class.
|
||||
// TODO: Once we multiplex with the ASTReader, handle
|
||||
// ASTReader::completeVisibleDeclsMap setting this to `false`.
|
||||
if (!tag_decl->hasExternalVisibleStorage()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto key = SemIR::ClangDeclKey::ForNonFunctionDecl(
|
||||
const_cast<clang::TagDecl*>(tag_decl->getFirstDecl()));
|
||||
auto clang_decl_id = sem_ir.clang_decls().LookupId(key);
|
||||
if (!clang_decl_id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto inst_id = sem_ir.clang_decls().Get(clang_decl_id).inst_id;
|
||||
auto const_id = sem_ir.constant_values().Get(inst_id);
|
||||
if (!const_id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto class_type =
|
||||
sem_ir.constant_values().TryGetInstAs<SemIR::ClassType>(const_id);
|
||||
if (!class_type) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Determine whether this class was imported from C++.
|
||||
// TODO: This currently can't happen, because only Carbon classes have
|
||||
// external lexical storage, but will happen once we support importing C++
|
||||
// classes from AST files. Add a test once that is supported.
|
||||
// TODO: Consider setting `extern_library_id` on classes imported from C++ to
|
||||
// indicate the current file does not own them.
|
||||
const auto& class_info = sem_ir.classes().Get(class_type->class_id);
|
||||
if (class_info.parent_scope_id.has_value() &&
|
||||
sem_ir.name_scopes().Get(class_info.parent_scope_id).is_cpp_scope()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto class_type_id = sem_ir.types().GetTypeIdForTypeConstantId(const_id);
|
||||
return std::make_pair(class_type_id, *class_type);
|
||||
}
|
||||
|
||||
auto LookupClassFieldByStructField(const File& sem_ir,
|
||||
const SemIR::NameScope& class_scope,
|
||||
const SemIR::StructTypeField& struct_field)
|
||||
-> std::optional<SemIR::InstStore::GetAsWithIdResult<SemIR::FieldDecl>> {
|
||||
if (auto entry_id = class_scope.Lookup(struct_field.name_id)) {
|
||||
auto field_inst_id =
|
||||
class_scope.GetEntry(*entry_id).result.target_inst_id();
|
||||
return sem_ir.insts().TryGetAsWithId<SemIR::FieldDecl>(field_inst_id);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace Carbon::SemIR
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
Reference in New Issue
Block a user