diff --git a/src/Type.cc b/src/Type.cc index 397a27ebe8..82185faa77 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -18,6 +18,7 @@ #include "zeek/Traverse.h" #include "zeek/Val.h" #include "zeek/Var.h" +#include "zeek/ZVal.h" #include "zeek/module_util.h" #include "zeek/zeekygen/IdentifierInfo.h" #include "zeek/zeekygen/Manager.h" @@ -1105,6 +1106,7 @@ void RecordType::AddField(unsigned int field, const TypeDecl* td) { ASSERT(field == managed_fields.size()); managed_fields.push_back(ZVal::IsManagedType(td->type)); + field_properties.push_back({.is_managed = ZVal::IsManagedType(td->type), .type_tag = td->type->Tag()}); // We defer error-checking until here so that we can keep deferred_inits // and managed_fields correctly tracking the associated fields. @@ -1539,6 +1541,15 @@ bool RecordType::IsDeferrable() const { return std::ranges::all_of(creation_inits, is_deferrable); } +void RecordType::InitSlots(std::span slots) const { + int n = NumFields(); + if ( slots.size() != field_properties.size() ) + zeek::reporter->InternalError("wrong number of slots and slot properties"); + + for ( int i = 0; i < n; i++ ) + slots[i] = field_properties[i]; +} + FileType::FileType(TypePtr yield_type) : Type(TYPE_FILE), yield(std::move(yield_type)) {} FileType::~FileType() = default; diff --git a/src/Type.h b/src/Type.h index cc30238708..4a9ec8c101 100644 --- a/src/Type.h +++ b/src/Type.h @@ -21,6 +21,7 @@ namespace zeek { class Val; union ZVal; +class ZValSlot; class EnumVal; class RecordVal; class TableVal; @@ -635,6 +636,11 @@ private: using type_decl_list = PList; +struct RecordFieldProperties { + bool is_managed = false; + TypeTag type_tag = TYPE_VOID; +}; + class RecordType final : public Type { public: explicit RecordType(type_decl_list* types); @@ -692,7 +698,11 @@ public: // Returns flags corresponding to which fields in the record // have types requiring memory management (reference counting). - const std::vector& ManagedFields() const { return managed_fields; } + [[deprecated("Remove in v9.1: Unused and optimization related internal. Use FieldProperties() instead.")]] + const std::vector& ManagedFields() const { + return managed_fields; + } + const std::vector& FieldProperties() const { return field_properties; } int NumFields() const { return num_fields; } int NumOrigFields() const { return num_orig_fields; } @@ -771,10 +781,16 @@ private: const auto& DeferredInits() const { return deferred_inits; } const auto& CreationInits() const { return creation_inits; } + // Initialize the slots using slot_properties. + void InitSlots(std::span slots) const; + // If we were willing to bound the size of records, then we could // use std::bitset here instead. std::vector managed_fields; + // Field properties for ZvalSlot initialization + std::vector field_properties; + // Number of fields in the type. int num_fields = 0;