-
-
Notifications
You must be signed in to change notification settings - Fork 186
Add static fields for generic types #3218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add static fields for generic types #3218
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughImplements per-TypeSpec static field storage for closed generic types. Adds allocation, relocation, and access APIs for generic statics, integrates allocation into type-system resolution, and updates interpreter static field instructions to resolve and access per-generic static fields when a generic type context is present, falling back to non-generic statics otherwise. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor IL as IL Instruction
participant EE as ExecutionEngine
participant ASM as CLR_RT_Assembly
participant TS as TypeSpec (generic ctx)
IL->>EE: Execute static field op (e.g., ldsfld/stsfld)
EE->>TS: Check generic type context
alt Closed generic context
EE->>ASM: GetGenericStaticField(typeSpecIndex, fieldDefIndex)
ASM-->>EE: CLR_RT_HeapBlock* (per-TypeSpec static)
else No/invalid generic context
EE->>EE: AccessStaticField(field)
EE-->>EE: CLR_RT_HeapBlock* (non-generic static)
end
EE->>IL: Continue with field load/store using returned HeapBlock
sequenceDiagram
autonumber
participant TSYS as CLR_RT_TypeSystem::ResolveAll
participant ASM as CLR_RT_Assembly
participant TSX as TypeSpec CrossRefs
TSYS->>ASM: ResolveAllocateStaticFields()
TSYS->>ASM: ResolveAllocateGenericTypeStaticFields()
ASM->>TSX: Enumerate TypeSpecs
alt TypeSpec is closed generic
ASM->>TSX: Allocate genericStaticFields[] and genericStaticFieldDefs[]
ASM-->>TSYS: Map FieldDefs to per-TypeSpec static storage
else Not closed generic
ASM-->>TSYS: Skip allocation
end
note over ASM: Relocate() updated to relocate generic statics and mapping arrays
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9ad347a to
26314cb
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Nitpick comments (1)
src/CLR/Include/nanoCLR_Runtime.h (1)
2121-2122: Make IsClosedGenericType() constMethod does not mutate state. Mark it const for correctness and clarity.
- bool IsClosedGenericType(); + bool IsClosedGenericType() const;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/CLR/Core/Interpreter.cpp(3 hunks)src/CLR/Core/TypeSystem.cpp(7 hunks)src/CLR/Include/nanoCLR_Runtime.h(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
- GitHub Check: nf-interpreter (Build_Azure_RTOS_targets SL_STK3701A)
- GitHub Check: nf-interpreter (Build_WIN32_nanoCLR)
- GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_P4_UART)
- GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_ETHERNET_KIT_1.2)
- GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_S3_ALL)
- GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_H2_THREAD)
- GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_C6_THREAD)
- GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_C3)
- GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_BLE_REV0)
- GitHub Check: nf-interpreter (Build_STM32_targets ST_STM32F769I_DISCOVERY)
- GitHub Check: nf-interpreter (Build_NXP_targets NXP_MIMXRT1060_EVK)
- GitHub Check: nf-interpreter (Build_TI_SimpleLink_targets TI_CC1352R1_LAUNCHXL_915)
- GitHub Check: nf-interpreter (Build_ESP32_targets ESP32_PSRAM_REV0)
- GitHub Check: nf-interpreter (Build_STM32_targets ST_STM32F429I_DISCOVERY)
- GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALX)
- GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALTHREE)
- GitHub Check: nf-interpreter (Check_Code_Style)
- GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
- GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (6)
src/CLR/Include/nanoCLR_Runtime.h (1)
1433-1440: Clarify cctor semantics for generic statics accessorsDo GetGenericStaticField() / GetStaticFieldByFieldDef() ensure the declaring type’s static constructor is executed (per closed TypeSpec) before returning the storage, matching AccessStaticField()? If not, add that or gate here to preserve .NET semantics.
src/CLR/Core/TypeSystem.cpp (5)
707-724: Element init tweak looks fineUsing value-initialized Element and the follow-up logic is consistent with surrounding code.
2901-2904: Good: zeroing newly introduced TypeSpec cross-ref fieldsExplicitly initializing genericStaticFields/Defs/Count prevents stale pointers after load.
5059-5086: Prefer per-TypeSpec storage when available; ensure correct assembly contextThe lookup sequence is sound, but it relies on GetGenericStaticField using the TypeSpec-owning assembly (see fix above). After that change, this will correctly prefer per-closed-generic statics and fall back to non-generic static storage.
Also, please verify that InitializeReference with generic context is present and used consistently by all call sites that may initialize generic static storage (ctor paths, relocations). I can help scan/update those if needed.
5882-5897: Relocation for generic static storage looks correct
- Relocates heapblocks array with count.
- Relocates indices pointer.
- Guards for nulls.
LGTM.
6391-6391: Initialize per-TypeSpec statics in resolve flow (non-AppDomains)Good integration point. For AppDomains builds, there’s no symmetric allocation. If AppDomains are in scope, confirm whether generic statics should be per-AppDomain and wire allocation/relocation accordingly (e.g., alongside AppDomainAssembly::Resolve_AllocateStaticFields).
26314cb to
da5608a
Compare
- TypeSpec cross reference now stores instances of static fields and field defs. - Assembly now has GetGenericStaticField() and GetStaticFieldByFieldDef(). - TypeSpec instance now has a helper API IsClosedGenericType(). - Update handlers for stsfld, ldsfld and ldsflda to deal with static fields of closed generic types.
e3f3bea to
fe49631
Compare
fe49631 to
4a8f5c4
Compare
Description
Motivation and Context
How Has This Been Tested?
[build with MDP buildId 57148]
Screenshots
Types of changes
Checklist
Summary by CodeRabbit
New Features
Bug Fixes