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
//! Owned `GenericParamConstraint` structures for the `GenericParamConstraint` metadata table.
//!
//! This module provides the [`GenericParamConstraint`] struct which represents constraint
//! definitions with resolved references and owned data. Generic parameter constraints
//! specify base classes and interfaces that type arguments must satisfy.
//!
//! # Purpose
//! The `GenericParamConstraint` table enables constraint-based generic programming:
//! - **Base class constraints**: Inheritance requirements for type arguments
//! - **Interface constraints**: Implementation requirements for type arguments
//! - **Type safety**: Compile-time verification of constraint satisfaction
//! - **Code optimization**: Enabling specialized code generation for constrained types
//! - **Reflection metadata**: Runtime access to constraint information
//!
//! # Constraint Semantics
//! Constraints provide type safety guarantees:
//! - **Compile-time checking**: Verify type arguments satisfy all constraints
//! - **Method resolution**: Enable constraint-based method calls on parameters
//! - **Cast elimination**: Remove unnecessary runtime type checks
//! - **Performance optimization**: Generate specialized code for constrained types
//! - **API contracts**: Document type requirements for generic APIs
//!
//! # ECMA-335 Reference
//! See ECMA-335, Partition II, §22.21 for the `GenericParamConstraint` table specification.
use crate::;
/// Represents a generic parameter constraint definition with resolved references and owned data.
///
/// A generic parameter constraint specifies a type that serves as a constraint for a generic
/// parameter, requiring type arguments to satisfy inheritance or implementation relationships
/// with the constraint type.
///
/// # Constraint Types
/// Constraints can specify various requirements:
/// - **Base class constraints**: `where T : BaseClass` (inheritance requirement)
/// - **Interface constraints**: `where T : IInterface` (implementation requirement)
/// - **Multiple constraints**: Parameters can have multiple constraint entries
/// - **Circular constraints**: `where T : IComparable<T>` (self-referential constraints)
/// - **Nested generic constraints**: `where T : IList<U>` (constraints with generic arguments)
///
/// # Constraint Validation
/// Each constraint undergoes validation during application:
/// - **Compatibility checking**: Ensures constraint types are valid for the parameter
/// - **Accessibility verification**: Confirms constraint types are accessible
/// - **Circular dependency detection**: Prevents invalid constraint cycles
/// - **Attribute consistency**: Validates constraint compatibility with parameter attributes
///
/// # Type Safety Benefits
/// Constraints enable several type safety features:
/// ```text
/// ┌──────────────────────┬─────────────────────────────────────────┐
/// │ Benefit │ Description │
/// ├──────────────────────┼─────────────────────────────────────────┤
/// │ Compile-time Checking│ Verify type arguments satisfy constraints│
/// │ Method Resolution │ Enable calls to constraint methods │
/// │ Cast Elimination │ Remove unnecessary runtime type checks │
/// │ Code Specialization │ Generate optimized code for constraints │
/// │ API Documentation │ Document type requirements clearly │
/// └──────────────────────┴─────────────────────────────────────────┘
/// ```
///
/// # Constraint Application
/// When applied, constraints are:
/// - **Validated**: Checked for compatibility and accessibility
/// - **Associated**: Added to the parameter's constraint collection
/// - **Available**: Made available for type checking and code generation
/// - **Documented**: Accessible through reflection APIs
///
/// # ECMA-335 Reference
/// See ECMA-335, Partition II, §22.21 for the complete `GenericParamConstraint` table specification.