Skip to content

Conversation

@josesimoes
Copy link
Member

@josesimoes josesimoes commented Jul 4, 2025

Description

  • Now properly handling TypeSpecs for array types by dealing with Levels in CLR_RT_Assembly::DumpToken
  • Rename variables for clarity and consistency.
  • CLR_RT_TypeSystem::BuildTypeName now takes levels parameter to properly deal with TypeSpec arrays.
  • Fix wrong ouptut of generic notation.

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

    • Type names now accurately display array nesting levels, with brackets (e.g., []) indicating array dimensions.
  • Bug Fixes

    • Improved display of type names to correctly represent generic parameters and array or pointer levels in diagnostic outputs.

- Now properly handling TypeSpecs for array types by dealing with Levels in CLR_RT_Assembly::DumpToken
- Rename variables for clarity and consistency.
- CLR_RT_TypeSystem::BuildTypeName now takes levels parameter to properly deal with TypeSpec arrays.
- Fix wrong ouptut of generic notation.
@josesimoes josesimoes added the Area: Interpreter Everything related with the interpreter, execution engine and such label Jul 4, 2025
@nfbot nfbot added the Type: bug label Jul 4, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 4, 2025

Walkthrough

The changes update the BuildTypeName method in the type system to accept an additional parameter representing array nesting levels, and modify its implementation to append array brackets accordingly. All internal calls to this method are updated to supply the correct nesting level, ensuring type names accurately reflect array or pointer dimensionality.

Changes

File(s) Change Summary
src/CLR/Core/TypeSystem.cpp Modified BuildTypeName to accept a levels parameter and append array brackets to type names.
src/CLR/Include/nanoCLR_Runtime.h Updated the BuildTypeName method signature to include the new levels parameter.
src/CLR/Diagnostics/Info.cpp Updated calls to BuildTypeName to pass the correct array/pointer nesting level (elem.Levels).

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Internal Code (e.g., DumpToken)
    participant TypeSystem as CLR_RT_TypeSystem
    Note over Caller: Needs type name with array levels
    Caller->>TypeSystem: BuildTypeName(typeIndex, szBuffer, iBuffer, levels)
    TypeSystem->>TypeSystem: Construct type name
    alt Type is generic
        TypeSystem->>TypeSystem: Append generic argument delimiters
    end
    loop For each array nesting level
        TypeSystem->>TypeSystem: Append "[]"
    end
    TypeSystem-->>Caller: Type name with correct array brackets
Loading

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d93b7b8 and 7d24938.

📒 Files selected for processing (3)
  • src/CLR/Core/TypeSystem.cpp (3 hunks)
  • src/CLR/Diagnostics/Info.cpp (4 hunks)
  • src/CLR/Include/nanoCLR_Runtime.h (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: josesimoes
PR: nanoframework/nf-interpreter#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.
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.
src/CLR/Core/TypeSystem.cpp (6)

undefined

<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-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/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>

<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>

src/CLR/Diagnostics/Info.cpp (7)
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.
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#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.
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-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-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#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.
src/CLR/Include/nanoCLR_Runtime.h (6)

undefined

<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-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: #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>

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • 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 (10)
src/CLR/Include/nanoCLR_Runtime.h (1)

2003-2003: LGTM! API consistency improvement for array type handling.

The addition of the levels parameter to this BuildTypeName overload aligns well with the existing overload on lines 2004-2009 that already accepts this parameter. This change enables proper handling of array nesting levels for TypeSpec tokens, which is essential for correctly generating type names with the appropriate number of array brackets.

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

6247-6251: LGTM: Function signature correctly updated to handle array levels.

The addition of the CLR_UINT32 levels parameter to BuildTypeName is consistent with the PR objective to properly handle array type levels in TypeSpec tokens. This parameter represents the array nesting depth that needs to be appended as [] brackets.


6257-6258: LGTM: Boolean flag for proper generic signature management.

The introduction of closeGenericSignature flag is a good approach to ensure generic type delimiters < and > are only added when there are actual generic parameters, preventing incorrect output mentioned in the PR objectives.


6277-6282: LGTM: Conditional generic signature opening logic.

This logic correctly checks for the presence of generic parameters (parser.GenParamCount > 0) before adding the opening < delimiter and setting the flag to track that the signature needs to be closed. This prevents adding empty generic notation <> when there are no generic parameters.


6320-6328: LGTM: Proper generic signature closing and array bracket handling.

The implementation correctly:

  1. Conditionally closes the generic signature with > only if it was opened (closeGenericSignature is true)
  2. Appends the appropriate number of array brackets [] based on the levels parameter

This ensures that array dimensions are properly represented in the type name after the generic signature is closed, which aligns with the PR objective to correctly process TypeSpec arrays.

src/CLR/Diagnostics/Info.cpp (5)

455-455: LGTM! Correct levels parameter for field type name.

The addition of 0 for the levels parameter is appropriate here since this builds the generic owner type name for a field reference, which doesn't require array bracket notation.


557-557: LGTM! Preserves array levels for corrupt signatures.

Using elem.Levels ensures that any parsed array nesting information is preserved in the output even when the TypeSpec signature is corrupt, maintaining consistency in the diagnostic output format.


599-599: LGTM! Improved control flow clarity.

Changing from if to else if correctly clarifies that the SZARRAY handling is mutually exclusive with the preceding VAR/MVAR block, improving code readability and logical flow.


650-650: LGTM! Correct array levels for SZARRAY types.

Using elem.Levels here is essential for properly representing array dimensions in SZARRAY types, ensuring the output includes the correct number of bracket pairs (e.g., "Int32[]" vs "Int32[][]").


657-661: LGTM! Improved variable naming and array level handling.

The variable renaming (bufTypeName, pTypeName, cbType) improves code readability and consistency, while adding elem.Levels ensures proper array bracket notation in the default TypeSpec case.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 4, 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.

@josesimoes josesimoes merged commit 8fbcb09 into nanoframework:develop Jul 4, 2025
24 checks passed
@josesimoes josesimoes deleted the fix-dumptoken branch July 4, 2025 12:18
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants