From a5bd7b1ac13716175d275f679bb79bdf586f3df2 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Mon, 12 Oct 2026 09:40:32 +0100 Subject: [PATCH] Delete abstract_structs_ --- cpp2rust/converter/converter.cpp | 4 +--- cpp2rust/converter/converter.h | 1 - cpp2rust/converter/converter_lib.cpp | 7 +++++++ cpp2rust/converter/converter_lib.h | 2 ++ cpp2rust/converter/models/converter_refcount.cpp | 6 +++--- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index dc59f0d05..426ab23f4 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -30,7 +30,6 @@ std::unordered_map Converter::inner_structs_; std::unordered_set Converter::decl_ids_; std::unordered_set Converter::globals_; std::vector Converter::global_inits_; -std::unordered_set Converter::abstract_structs_; Converter::RecordIndex Converter::record_decls_; std::map Converter::virtual_methods_; @@ -318,7 +317,7 @@ bool Converter::VisitPointerType(clang::PointerType *type) { auto pointee_type = type->getPointeeType(); StrCat(pointee_type.isConstQualified() ? "*const" : "*mut"); if (pointee_type->isRecordType() && - abstract_structs_.contains(GetID(pointee_type->getAsRecordDecl()))) { + IsAbstractUserClass(pointee_type->getAsRecordDecl())) { StrCat(keyword::kDyn); } return Convert(pointee_type); @@ -4629,7 +4628,6 @@ pub fn main() {{ } void Converter::ConvertAbstractClass(clang::CXXRecordDecl *decl) { - ENSURE(abstract_structs_.insert(GetID(decl)).second); auto trait_name = GetRecordName(decl); auto access_specifier_as_string = AccessSpecifierAsString(decl->getAccess()); auto signature = std::format("{} {} trait {}", access_specifier_as_string, diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 7d9e7b75d..bd3773230 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -952,7 +952,6 @@ class Converter : public clang::RecursiveASTVisitor { }; static std::unordered_set decl_ids_; - static std::unordered_set abstract_structs_; class RecordIndex { public: diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 8cbacc4eb..01ed8b0c2 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -301,6 +301,13 @@ bool IsUserDefinedDecl(const clang::Decl *decl) { !src_mgr.isInSystemMacro(src_loc); } +bool IsAbstractUserClass(const clang::RecordDecl *decl) { + auto cxx = llvm::dyn_cast(decl); + auto definition = cxx ? cxx->getDefinition() : nullptr; + return definition && IsUserDefinedDecl(definition) && + definition->isAbstract(); +} + bool RefersToUserDefinedDecl(const clang::Expr *expr) { expr = expr->IgnoreParenImpCasts(); const clang::Decl *decl = nullptr; diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index ccbbe8dc3..00405427a 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -66,6 +66,8 @@ bool IsCodeUnitStringLiteral(const clang::StringLiteral *expr); bool IsUserDefinedDecl(const clang::Decl *decl); +bool IsAbstractUserClass(const clang::RecordDecl *decl); + bool RefersToUserDefinedDecl(const clang::Expr *expr); bool IsUnsignedArithOp(const clang::BinaryOperator *expr); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index a9172bc13..3a47ff7ea 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -341,7 +341,7 @@ bool ConverterRefCount::VisitPointerType(clang::PointerType *type) { PushConversionKind push2(*this, ConversionKind::FullRefCount, pointee_is_array); if (pointee_type->isRecordType() && - abstract_structs_.contains(GetID(pointee_type->getAsRecordDecl()))) { + IsAbstractUserClass(pointee_type->getAsRecordDecl())) { StrCat("PtrDyn(expr->getType()); auto pointee_type = ptype->getPointeeType()->getAsCXXRecordDecl(); - if (pointee_type && abstract_structs_.contains(GetID(pointee_type))) { + if (pointee_type && IsAbstractUserClass(pointee_type)) { PushConversionKind push(*this, ConversionKind::Unboxed); StrCat(std::format("{}.to_dyn::<{}>(|w| w)", ToString(sub_expr->IgnoreCasts()), @@ -3222,7 +3222,7 @@ void ConverterRefCount::ConvertArrow(clang::Expr *expr) { auto pointee_type = expr->getType()->getPointeeType(); // Virtual methods, which take &mut self, are called through PtrDyn. if (auto *record = pointee_type->getAsRecordDecl(); - isLValue() && record && abstract_structs_.contains(GetID(record))) { + isLValue() && record && IsAbstractUserClass(record)) { StrCat(std::format("(*{}.upgrade().deref_mut())", ToString(expr))); SetValueFreshness(pointee_type); return;