UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMNativeConstructorWrapper.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#if WITH_VERSE_VM || defined(__INTELLISENSE__)
5
6#include "VerseVM/VVMBitMap.h"
7#include "VerseVM/VVMCell.h"
10#include "VerseVM/VVMMap.h"
11
12namespace Verse
13{
14struct VUniqueString;
15struct VNativeStruct;
16
17/*
18 This is a wrapper around a native object for us to know what fields have been initialized or not in the object. Why?
19 - For pure-Verse objects, we rely on our emergent type to track field initialization and can directly store placeholders for uninitialized fields.
20 - Native objects don't have an emergent type and since the data lives in the `UObject` itself we can't directly store placeholders for uninitialized fields.
21
22 To handle this, we wrap native objects in a `VNativeConstructorWrapper` object uses its emergent types bitmap of the fields
23 created and placeholders for self/fields used before they are created. When we are done with archetype construction,
24 we unify any placeholders then unwrap the native object using a special opcode and return it as part of `NewObject`.
25 The wrapper object then gets GC'ed during the next collection.
26
27 By convention, non-native Verse objects are not wrapped; the unwrap opcode just no-ops and returns the
28 object itself when it encounters it (this is so we can avoid allocating an extra wrapper object in the common
29 non-native case).
30
31 Therefore, we always favour emitting the unwrap instruction where a native object needs to be unwrapped, since we
32 don't know during codegen whether the object in question is native or not (since we do the wrapping in `NewObject` at
33 runtime). Non-native objects can also be turned into native objects at any time (we test this as well using
34 `--uobject-probability` in our tests.)
35 */
37{
40 COREUOBJECT_API void AppendToStringImpl(FAllocationContext Context, FUtf8StringBuilderBase& Builder, EValueStringFormat Format, TSet<const void*>& VisitedObjects, uint32 RecursionDepth);
41
44
45 bool CreateFieldCached(FAllocationContext Context, FCreateFieldCacheCase Cache);
46 bool CreateField(FAllocationContext Context, VUniqueString& FieldName, FCreateFieldCacheCase* OutCacheCase = nullptr);
47
48 bool IsFieldCreated(uint32 FieldIndex)
49 {
50 return GetEmergentType()->IsFieldCreated(FieldIndex);
51 }
52
53 VValue UnifyFieldPlaceholder(FAllocationContext Context, VUniqueString& FieldName)
54 {
56 {
57 return VValue();
58 }
59 VValue Placeholder = FieldPlaceholders->Find(Context, VInt(GetFieldIndex(Context, FieldName)));
60 return Placeholder.Follow().IsPlaceholder() ? Placeholder : VValue();
61 }
62
63 // If `FieldName` is that of an uncreated field, returns an existing/new placeholder for it
64 VValue LoadFieldPlaceholder(FAllocationContext Context, VUniqueString& FieldName)
65 {
66 int32 FieldIndex = GetFieldIndex(Context, FieldName);
67 if (FieldIndex == -1 || IsFieldCreated(FieldIndex))
68 {
69 return VValue();
70 }
71
73 {
74 FieldPlaceholders.Set(Context, VMapBase::New<VMap>(Context, 1));
75 }
76
77 VValue Placeholder = FieldPlaceholders->Find(Context, VInt(FieldIndex));
78 if (!Placeholder)
79 {
80 Placeholder = VValue::Placeholder(VPlaceholder::New(Context, 0));
81 FieldPlaceholders->Add(Context, VInt(FieldIndex), Placeholder);
82 }
83 return Placeholder;
84 }
85
86 VValue WrappedObject() const;
87
90
91private:
92 // returns:
93 // the index of the field if its created
94 // -1 if its not a field
95 // -2 if its an uncreated field
96 int32 GetFieldIndex(FAllocationContext Context, VUniqueString& FieldName);
97
100
103
106
107 friend class FInterpreter;
108};
109
110} // namespace Verse
111#endif // WITH_VERSE_VM
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
T * New(FMemStackBase &Mem, int32 Count=1, int32 Align=DEFAULT_ALIGNMENT)
Definition MemStack.h:259
void ENGINE_API GetFieldIndex(const uint32 FieldType, int32 &FieldIndex, EFieldOutputType &FieldOutput)
Definition PhysicsFieldComponent.cpp:1099
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition StringBuilder.h:79
Definition Object.h:95
Definition Archive.h:36