Skip to content

Fix box/unbox Nullable<T> types #3199

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

josesimoes
Copy link
Member

@josesimoes josesimoes commented Jul 7, 2025

Description

  • TypeDef_Instance ResolveToken now properly handles TypeSpec tokens for class and value types.
  • Add ResolveNullableType() to resolve T for Nullable types.
  • Add Nullable`1 to well known types array.
  • Add System_Nullable_1 to mscorlib class declaration.
  • Rework box/unbox handler code to properly deal with nullable types.

Motivation and Context

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

Summary by CodeRabbit

  • New Features

    • Added support for handling nullable types, including correct boxing and unboxing behavior in the interpreter.
    • Enhanced type resolution to recognize and process nullable value types.
  • Improvements

    • Expanded internal type tracking to include nullable types, improving compatibility with .NET code using System.Nullable.

@josesimoes josesimoes added the Area: Interpreter Everything related with the interpreter, execution engine and such label Jul 7, 2025
Copy link

coderabbitai bot commented Jul 7, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Support for System.Nullable<T> has been added to the type system and IL interpreter. This includes new struct definitions, updates to boxing and unboxing logic for nullable types, a new method for resolving nullable types from metadata tokens, and tracking of the nullable type in the well-known types list.

Changes

File(s) Change Summary
src/CLR/CorLib/corlib_native.h Added struct Library_corlib_native_System_Nullable_1 with static fields for hasValue and value.
src/CLR/Core/Interpreter.cpp Updated IL interpreter to handle boxing/unboxing of nullable types; added typedef for easier field access.
src/CLR/Core/TypeSystem.cpp Simplified type spec parsing; added ResolveNullableType method; registered "System.Nullable1"` as known.
src/CLR/Include/nanoCLR_Runtime.h Added Nullable to well-known types struct; declared ResolveNullableType method in type definition struct.

Sequence Diagram(s)

sequenceDiagram
    participant IL_Interpreter
    participant TypeSystem
    participant ObjectHeap

    IL_Interpreter->>TypeSystem: Is target type Nullable<T>?
    alt Boxing
        IL_Interpreter->>ObjectHeap: Check HasValue on Nullable<T>
        alt HasValue == false
            IL_Interpreter->>ObjectHeap: Box null reference
        else HasValue == true
            IL_Interpreter->>ObjectHeap: Box underlying value
        end
    else Unboxing
        IL_Interpreter->>ObjectHeap: Create Nullable<T> instance
        IL_Interpreter->>ObjectHeap: Set HasValue and assign value if present
    end
Loading
sequenceDiagram
    participant TypeDef_Instance
    participant Assembly
    participant SignatureParser

    TypeDef_Instance->>SignatureParser: Parse TypeSpec token
    alt Is Nullable<T> signature
        SignatureParser->>TypeDef_Instance: Advance to generic parameter
        alt Generic parameter is VAR/MVAR
            TypeDef_Instance->>TypeDef_Instance: Resolve via caller context
        else
            TypeDef_Instance->>Assembly: Resolve class/value type directly
        end
        TypeDef_Instance-->>Caller: Return resolved Nullable<T> type
    else
        TypeDef_Instance-->>Caller: Fail to resolve
    end
Loading

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@josesimoes
Copy link
Member Author

@coderabbitai review

Copy link

coderabbitai bot commented Jul 7, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
src/CLR/Core/Interpreter.cpp (2)

2877-2883: Simplify value assignment in unbox operation.

The temporary unboxedValue variable is unnecessary. After unboxing, evalPos[0] already contains the unboxed value.

                            else
                            {
                                // unbox the T value...
                                NANOCLR_CHECK_HRESULT(evalPos[0].PerformUnboxing(destinationType));

-                               CLR_RT_HeapBlock unboxedValue = {};
-                               unboxedValue.Assign(evalPos[0]);
-
                                // assign the copied unboxed value
-                               nullableObject.Dereference()[Sys_Nullable::FIELD__value].Assign(unboxedValue);
+                               nullableObject.Dereference()[Sys_Nullable::FIELD__value].Assign(evalPos[0]);

                                // set HasValue to true
                                nullableObject.Dereference()[Sys_Nullable::FIELD__hasValue].SetBoolean(true);
                            }

2912-2912: Address the TODO for nullable type support in CEE_UNBOX_ANY.

The TODO correctly identifies that CEE_UNBOX_ANY needs nullable type support for completeness.

Would you like me to help implement nullable type handling for CEE_UNBOX_ANY similar to what was done for CEE_UNBOX?

src/CLR/Core/TypeSystem.cpp (2)

1072-1173: Consider refactoring to reduce code duplication with ResolveToken.

The ResolveNullableType method contains logic very similar to parts of ResolveToken, particularly the generic parameter resolution sections (lines 1114-1158). This duplication could lead to maintenance issues.

Additionally, the method assumes the first element is DATATYPE_VALUETYPE but doesn't validate this assumption until after parsing begins, which could lead to confusing error states.

Consider extracting the common generic parameter resolution logic into a helper method:

+private:
+    bool ResolveGenericParameter(
+        CLR_RT_SignatureParser::Element& elem,
+        const CLR_RT_MethodDef_Instance* caller,
+        CLR_RT_TypeDef_Index& resolvedType);

 bool CLR_RT_TypeDef_Instance::ResolveNullableType(
     CLR_UINT32 tk,
     CLR_RT_Assembly *assm,
     const CLR_RT_MethodDef_Instance *caller)
 {
     // ... existing validation code ...
     
+    if (elem.DataType == DATATYPE_VAR || elem.DataType == DATATYPE_MVAR)
+    {
+        CLR_RT_TypeDef_Index resolvedType;
+        if (ResolveGenericParameter(elem, caller, resolvedType))
+        {
+            data = resolvedType.data;
+            assembly = g_CLR_RT_TypeSystem.m_assemblies[resolvedType.Assembly() - 1];
+            target = assembly->GetTypeDef(resolvedType.Type());
+            return true;
+        }
+        return false;
+    }

1101-1106: Early validation could improve error clarity.

The method checks if the first element is DATATYPE_VALUETYPE only after advancing the parser. Consider validating this constraint earlier to provide clearer error messaging.

 if (FAILED(parser.Advance(elem)))
 {
     return false;
 }

 if (elem.DataType != DATATYPE_VALUETYPE)
 {
-    // If it's not a value type, we can't resolve it as a nullable type
     ClearInstance();
     return false;
 }

Consider adding a more descriptive comment explaining why only value types are supported for nullable type resolution.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 406fa37 and ba1247b.

📒 Files selected for processing (4)
  • src/CLR/CorLib/corlib_native.h (1 hunks)
  • src/CLR/Core/Interpreter.cpp (3 hunks)
  • src/CLR/Core/TypeSystem.cpp (4 hunks)
  • src/CLR/Include/nanoCLR_Runtime.h (2 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: josesimoes
PR: nanoframework/nf-interpreter#3190
File: src/CLR/Core/TypeSystem.cpp:0-0
Timestamp: 2025-06-26T09:16:55.184Z
Learning: In nanoFramework's CLR attribute parsing (src/CLR/Core/TypeSystem.cpp), the sentinel value 0xFFFF in string tokens represents a null string. When encountered, this should result in a true null reference (using SetObjectReference(nullptr)) rather than an empty string instance, and the boxing operation should be skipped via early return.
Learnt from: josesimoes
PR: nanoframework/nf-interpreter#3062
File: src/System.Device.Spi/sys_dev_spi_native_System_Device_Spi_SpiDevice.cpp:77-93
Timestamp: 2025-01-09T13:10:31.388Z
Learning: In nanoFramework SPI transactions, NULL buffers are valid cases when there is no data to send or receive. The code should handle NULL buffers by setting corresponding sizes to 0 instead of throwing exceptions.
src/CLR/CorLib/corlib_native.h (5)
Learnt from: josesimoes
PR: nanoframework/nf-interpreter#3190
File: src/CLR/Core/TypeSystem.cpp:0-0
Timestamp: 2025-06-26T09:16:55.184Z
Learning: In nanoFramework's CLR attribute parsing (src/CLR/Core/TypeSystem.cpp), the sentinel value 0xFFFF in string tokens represents a null string. When encountered, this should result in a true null reference (using SetObjectReference(nullptr)) rather than an empty string instance, and the boxing operation should be skipped via early return.
Learnt from: josesimoes
PR: nanoframework/nf-interpreter#3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-10-08T15:52:09.445Z
Learning: In `nanoCLR_GetNativeAssemblyInformation`, there is no need to return the number of bytes written, as the memory buffer is zeroed, making the string buffer terminated.
Learnt from: josesimoes
PR: nanoframework/nf-interpreter#3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-09-25T11:28:38.536Z
Learning: In `nanoCLR_GetNativeAssemblyInformation`, there is no need to return the number of bytes written, as the memory buffer is zeroed, making the string buffer terminated.
Learnt from: josesimoes
PR: nanoframework/nf-interpreter#3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-09-25T11:28:38.536Z
Learning: When working with `nanoCLR_GetNativeAssemblyInformation`, fixed-size assembly names are required, so code that deals with variable-length names cannot be used.
Learnt from: josesimoes
PR: nanoframework/nf-interpreter#3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-10-12T19:00:39.000Z
Learning: When working with `nanoCLR_GetNativeAssemblyInformation`, fixed-size assembly names are required, so code that deals with variable-length names cannot be used.
src/CLR/Core/Interpreter.cpp (12)

undefined

<retrieved_learning>
Learnt from: josesimoes
PR: #3190
File: src/CLR/Core/TypeSystem.cpp:0-0
Timestamp: 2025-06-26T09:16:55.184Z
Learning: In nanoFramework's CLR attribute parsing (src/CLR/Core/TypeSystem.cpp), the sentinel value 0xFFFF in string tokens represents a null string. When encountered, this should result in a true null reference (using SetObjectReference(nullptr)) rather than an empty string instance, and the boxing operation should be skipped via early return.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-09-25T11:28:38.536Z
Learning: When working with nanoCLR_GetNativeAssemblyInformation, fixed-size assembly names are required, so code that deals with variable-length names cannot be used.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-10-12T19:00:39.000Z
Learning: When working with nanoCLR_GetNativeAssemblyInformation, fixed-size assembly names are required, so code that deals with variable-length names cannot be used.
</retrieved_learning>

<retrieved_learning>
Learnt from: frobijn
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR.Host/NativeAssemblyDetails.cs:0-0
Timestamp: 2024-10-08T15:52:09.445Z
Learning: In the context of NativeAssemblyDetails.Get(), exceptions from Interop.nanoCLR.nanoCLR_GetNativeAssemblyInformation are very unlikely, and additional exception handling may not be necessary.
</retrieved_learning>

<retrieved_learning>
Learnt from: frobijn
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR.Host/NativeAssemblyDetails.cs:0-0
Timestamp: 2024-09-23T19:44:42.051Z
Learning: In the context of NativeAssemblyDetails.Get(), exceptions from Interop.nanoCLR.nanoCLR_GetNativeAssemblyInformation are very unlikely, and additional exception handling may not be necessary.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3062
File: src/System.Device.Spi/sys_dev_spi_native_System_Device_Spi_SpiDevice.cpp:77-93
Timestamp: 2025-01-09T13:10:31.388Z
Learning: In nanoFramework SPI transactions, NULL buffers are valid cases when there is no data to send or receive. The code should handle NULL buffers by setting corresponding sizes to 0 instead of throwing exceptions.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3062
File: src/System.Device.Spi/sys_dev_spi_native_System_Device_Spi_SpiDevice.cpp:106-188
Timestamp: 2025-01-09T13:32:43.711Z
Learning: In nanoFramework, CLR_RT_HeapBlock_Array::Pin() method returns void and cannot fail. It should be called without error handling.
</retrieved_learning>

<retrieved_learning>
Learnt from: AdrianSoundy
PR: #3152
File: targets/ESP32/ESP32_P4/nanoCLR/nanoFramework.Graphics/Graphics_Memory.cpp:0-0
Timestamp: 2025-05-01T03:31:34.528Z
Learning: In the nanoFramework ESP32 codebase, assertions are preferred over graceful error handling for critical memory allocations (like graphics memory) where the system cannot function without the allocated resources.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-09-25T11:28:38.536Z
Learning: In nanoCLR_GetNativeAssemblyInformation, there is no need to return the number of bytes written, as the memory buffer is zeroed, making the string buffer terminated.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-10-08T15:52:09.445Z
Learning: In nanoCLR_GetNativeAssemblyInformation, there is no need to return the number of bytes written, as the memory buffer is zeroed, making the string buffer terminated.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3172
File: src/CLR/Core/TypeSystem.cpp:971-999
Timestamp: 2025-05-14T17:26:54.181Z
Learning: In the nanoFramework codebase, when handling HRESULT values from function calls like parser.Advance(elem), it's preferable to use if (parser.Advance(elem) != S_OK) for local error handling rather than using the NANOCLR_CHECK_HRESULT macro, which would immediately propagate errors up the call stack.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3074
File: src/CLR/Core/GarbageCollector_Info.cpp:107-167
Timestamp: 2025-01-22T03:38:57.394Z
Learning: In nanoFramework's memory management code, DataSize() validation is comprehensively handled through CLR_RT_HeapCluster::ValidateBlock() and other caller code. Additional size checks in ValidateCluster() are redundant as the validation is already performed at multiple levels.
</retrieved_learning>

src/CLR/Include/nanoCLR_Runtime.h (9)

undefined

<retrieved_learning>
Learnt from: josesimoes
PR: #3190
File: src/CLR/Core/TypeSystem.cpp:0-0
Timestamp: 2025-06-26T09:16:55.184Z
Learning: In nanoFramework's CLR attribute parsing (src/CLR/Core/TypeSystem.cpp), the sentinel value 0xFFFF in string tokens represents a null string. When encountered, this should result in a true null reference (using SetObjectReference(nullptr)) rather than an empty string instance, and the boxing operation should be skipped via early return.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-10-12T19:00:39.000Z
Learning: When working with nanoCLR_GetNativeAssemblyInformation, fixed-size assembly names are required, so code that deals with variable-length names cannot be used.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-09-25T11:28:38.536Z
Learning: When working with nanoCLR_GetNativeAssemblyInformation, fixed-size assembly names are required, so code that deals with variable-length names cannot be used.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3172
File: src/CLR/Core/CLR_RT_HeapBlock.cpp:899-900
Timestamp: 2025-05-14T16:27:02.573Z
Learning: The CLR_RT_TypeDescriptor type in nanoFramework doesn't have a GetElementType() API for extracting array element types.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-10-08T15:52:09.445Z
Learning: In nanoCLR_GetNativeAssemblyInformation, there is no need to return the number of bytes written, as the memory buffer is zeroed, making the string buffer terminated.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-09-25T11:28:38.536Z
Learning: In nanoCLR_GetNativeAssemblyInformation, there is no need to return the number of bytes written, as the memory buffer is zeroed, making the string buffer terminated.
</retrieved_learning>

<retrieved_learning>
Learnt from: frobijn
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR.Host/NativeAssemblyDetails.cs:0-0
Timestamp: 2024-09-23T19:44:42.051Z
Learning: In the context of NativeAssemblyDetails.Get(), exceptions from Interop.nanoCLR.nanoCLR_GetNativeAssemblyInformation are very unlikely, and additional exception handling may not be necessary.
</retrieved_learning>

<retrieved_learning>
Learnt from: frobijn
PR: #3023
File: targets/netcore/nanoFramework.nanoCLR.Host/NativeAssemblyDetails.cs:0-0
Timestamp: 2024-10-08T15:52:09.445Z
Learning: In the context of NativeAssemblyDetails.Get(), exceptions from Interop.nanoCLR.nanoCLR_GetNativeAssemblyInformation are very unlikely, and additional exception handling may not be necessary.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3074
File: src/CLR/Core/GarbageCollector_Info.cpp:107-167
Timestamp: 2025-01-22T03:38:57.394Z
Learning: In nanoFramework's memory management code, DataSize() validation is comprehensively handled through CLR_RT_HeapCluster::ValidateBlock() and other caller code. Additional size checks in ValidateCluster() are redundant as the validation is already performed at multiple levels.
</retrieved_learning>

src/CLR/Core/TypeSystem.cpp (2)

undefined

<retrieved_learning>
Learnt from: josesimoes
PR: #3190
File: src/CLR/Core/TypeSystem.cpp:0-0
Timestamp: 2025-06-26T09:16:55.184Z
Learning: In nanoFramework's CLR attribute parsing (src/CLR/Core/TypeSystem.cpp), the sentinel value 0xFFFF in string tokens represents a null string. When encountered, this should result in a true null reference (using SetObjectReference(nullptr)) rather than an empty string instance, and the boxing operation should be skipped via early return.
</retrieved_learning>

<retrieved_learning>
Learnt from: josesimoes
PR: #3172
File: src/CLR/Core/TypeSystem.cpp:4556-4589
Timestamp: 2025-05-14T17:33:51.546Z
Learning: When parsing TypeSpec signatures in nanoFramework, the first Advance() call consumes the VAR/MVAR token, followed by additional Advance() calls to walk to the specific generic parameter position.
</retrieved_learning>

⏰ 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). (18)
  • GitHub Check: nf-interpreter (Build_STM32_targets ST_STM32F769I_DISCOVERY)
  • GitHub Check: nf-interpreter (Build_WIN32_nanoCLR)
  • GitHub Check: nf-interpreter (Build_STM32_targets ST_STM32F429I_DISCOVERY)
  • GitHub Check: nf-interpreter (Build_Azure_RTOS_targets SL_STK3701A)
  • 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_ESP32_targets ESP32_PSRAM_REV0)
  • GitHub Check: nf-interpreter (Build_TI_SimpleLink_targets TI_CC1352R1_LAUNCHXL_915)
  • GitHub Check: nf-interpreter (Build_NXP_targets NXP_MIMXRT1060_EVK)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • 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 (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (6)
src/CLR/CorLib/corlib_native.h (1)

647-653: LGTM! Well-implemented native struct for Nullable support.

The struct correctly defines the field indices for System.Nullable<T> following the established patterns in the codebase. The field indices (1 for hasValue, 2 for value) match the expected internal layout and are consistent with other value type structures in this file.

src/CLR/Include/nanoCLR_Runtime.h (2)

1694-1694: LGTM! Well-positioned addition to well-known types.

Adding Nullable to the CLR_RT_WellKnownTypes struct is the correct approach for tracking System.Nullable<T> as a fundamental runtime type. The positioning after Enum and before exception types follows a logical grouping pattern.


2118-2118: LGTM! Appropriate method declaration for nullable type resolution.

The ResolveNullableType method declaration follows the established pattern of the ResolveToken method above it, with consistent parameter types and naming conventions. This specialized method for resolving nullable types is a sensible addition to complement the existing type resolution functionality.

src/CLR/Core/Interpreter.cpp (1)

8-8: Good use of typedef for readability.

The typedef alias improves code readability by shortening the long type name.

src/CLR/Core/TypeSystem.cpp (2)

387-387: LGTM: Well-known type addition looks correct.

The addition of System.Nullable1to the type index lookup follows the established pattern and correctly maps to theNullable` member in the well-known types structure.


979-996: Manual Verification Required: Confirm Array and ByRef Handling in TypeSpec Parsing

I wasn’t able to find any existing special‐case logic for DATATYPE_SZARRAY or DATATYPE_BYREF in the TypeSpec parsing code after the recent simplification. Because removing the explicit loop may silently drop handling for these tokens, please:

  • Review the TypeSystem.cpp signature‐parsing logic around the new parser.Advance(elem) call (lines 979–996)
  • Ensure that array (SZARRAY) and by‐ref (BYREF) annotations are still correctly consumed and resolved
  • Add or update unit tests to cover TypeSpec signatures containing arrays and by‐ref types

- TypeDef_Instance ResolveToken now properly handles TypeSpec tokens for class and value types.
- Add ResolveNullableType() to resolve T for Nullable<T> types.
- Add Nullable`1 to well known types array.
- Add System_Nullable_1 to mscorlib class declaration.
- Rework box/unbox handler code to properly deal with nullable types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Interpreter Everything related with the interpreter, execution engine and such Type: bug Type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants