1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//! Owned `ClassLayout` table representation.
//!
//! This module provides the [`crate::metadata::tables::classlayout::owned::ClassLayout`] struct
//! which contains fully resolved memory layout information for types with owned data and resolved
//! table references. This is the primary data structure for representing explicit class layout
//! information in a usable form after the dual variant resolution phase.
//!
//! # Architecture
//!
//! The owned representation stores fully resolved data from the `ClassLayout` metadata table,
//! including resolved references to type definitions. This eliminates the need for table
//! lookups during runtime access, providing immediate access to memory layout metadata.
//!
//! # Key Components
//!
//! - [`crate::metadata::tables::classlayout::owned::ClassLayout`] - Main owned layout structure
//! - [`crate::metadata::typesystem::CilTypeRc`] - Referenced type definition
//!
//! # Integration
//!
//! This module integrates with:
//! - [`crate::metadata::tables::classlayout::raw`] - Raw table representation
//! - [`crate::metadata::typesystem`] - Type system components
//! - [`crate::metadata::validation`] - Layout validation logic
//! - [`crate::metadata::token`] - Token-based metadata references
use crate::;
/// Represents explicit memory layout information for a .NET type
///
/// This structure contains the complete layout specification from the `ClassLayout`
/// metadata table (0x0F), with all table references resolved to owned type instances.
/// Unlike [`crate::metadata::tables::classlayout::raw::ClassLayoutRaw`], this provides
/// immediate access to the type data without requiring table lookups.
///
/// # Memory Layout Control
///
/// `ClassLayout` provides explicit control over type memory layout:
/// - **Field alignment**: `PackingSize` specifies byte boundary alignment for fields
/// - **Total size**: `ClassSize` can override automatic size calculation
/// - **Layout kind**: Works with Sequential and Explicit layout attributes
/// - **Interop support**: Enables precise control for native interoperability
///
/// # Usage Context
///
/// `ClassLayout` is primarily used for:
/// - **P/Invoke scenarios**: Matching native C/C++ struct layouts
/// - **Performance optimization**: Controlling cache alignment and padding
/// - **Binary compatibility**: Ensuring consistent layout across platforms
/// - **Custom marshalling**: Supporting specific serialization requirements
///
/// # Layout Validation
///
/// Layout parameters are validated during application to ensure:
/// - `PackingSize` is a power of 2 or 0 (for default)
/// - `ClassSize` is reasonable and not conflicting
/// - No duplicate layout specifications exist
///
/// # Thread Safety
///
/// This type is [`Send`] and [`Sync`]. All fields are read-only after construction and safe
/// for concurrent access. The `apply` method uses atomic operations when updating type
/// definition data.
///
/// # References
/// - [ECMA-335 II.22.8](https://ecma-international.org/wp-content/uploads/ECMA-335_6th_edition_june_2012.pdf) - `ClassLayout` table specification