Skip to content

Miscellaneous fixes related with generics#3347

Merged
josesimoes merged 12 commits into
nanoframework:developfrom
josesimoes:fixes-generics
May 8, 2026
Merged

Miscellaneous fixes related with generics#3347
josesimoes merged 12 commits into
nanoframework:developfrom
josesimoes:fixes-generics

Conversation

@josesimoes
Copy link
Copy Markdown
Member

@josesimoes josesimoes commented May 6, 2026

Description

  • Add ResolveMethodRef() TypeSpec fallback chain.
  • Runtime MethodRef TypeSpec handling to reuses the startup-resolved target.
  • InitializeReference() now has VAR fallback.
  • ResolveGenericTypeParameter() now returns failure to allow caller to handle it properly (otherwise it will go into an infinite loop).
  • Fix generic parameter check in DumpOpcode().
  • Fix DumpOpcodeDirect and BuildMethodName, now outputting correctly resolved generic types.
  • Fix generic interface dispatch and MVAR resolution.
  • Fix generic static field fallback.
  • Add NANOCLR_TRACE_GENERICS to output generics resolution. Needed to help debugging hard type resolutions.
  • Fix type resolution for nested generic 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).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

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.

⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: b83a1b8a-6665-4ba3-be84-cb9104643125

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR enhances generic type handling in the CLR runtime by introducing stricter parameter resolution, propagating generic context through IL interpretation (CALL, CALLVIRT, NEWOBJ, UNBOX.ANY), extending signature parsing for nested generics, and adding comprehensive diagnostic instrumentation to aid debugging.

Changes

Generic Type Resolution & Propagation

Layer / File(s) Summary
Core Resolution Guards
src/CLR/Core/Execution.cpp
ResolveGenericTypeParameter now fails on VAR/MVAR types to enable fallback handling; InitializeLocals drains all remaining generic-parameter tokens to prevent signature corruption during local initialization.
Context Propagation in Interpreter
src/CLR/Core/Interpreter.cpp
Passes stack→m_call.genericType into ResolveToken calls for CALL/CALLVIRT/NEWOBJ/UNBOX.ANY; introduces effectiveCallerGeneric and closed-generic checks; recovers from mismatches in generic constructors; adds extensive trace instrumentation for generic field operations (LDFLD, LDFLDA, LDSFLD).
Type System Enhancements
src/CLR/Core/TypeSystem.cpp
Adds pending GENERICINST state (m_pendingGenericInst) to CLR_RT_SignatureParser; expands ResolveToken to handle VAR/MVAR across assemblies and contexts; enhances virtual method dispatch with MatchSignatureForVirtualDispatch for explicit interface support; adds nested type resolution with '/' separator; introduces BuildMethodName overloads with parent-context support; extends on-demand allocation for generic static fields.
Diagnostics Infrastructure
src/CLR/Diagnostics/Diagnostics_stub.cpp, src/CLR/Diagnostics/Info.cpp
Extends DumpOpcodeDirect signature with parentCtx parameter; adds IsUserModePtr helper for safe pointer checking; implements frame walking to resolve open VAR parameters; adds new CLR_RT_DUMP::METHOD overload accepting parentCtx for context-aware method name printing.
Public API & Headers
src/CLR/Include/nanoCLR_Runtime.h, src/CLR/Include/nanoCLR_Checks.h
Introduces extern trace flag s_CLR_RT_fTrace_GenericFields; adds m_pendingGenericInst field to CLR_RT_SignatureParser; updates method signatures (DumpOpcodeDirect, BuildMethodName, FindVirtualMethod) to accept parentCtx and suffixMatchOnly parameters; disables generic tracing for RTM builds in nanoCLR_PlatformDef.h.
Debug Instrumentation
src/CLR/Core/Execution.cpp
Adds debug print blocks in NewGenericInstanceObject to log type name, field count, and field initialization state.

TI Platform Memory Layout Update

Layer / File(s) Summary
Block Storage Configuration
targets/TI_SimpleLink/TI_CC1352R1_LAUNCHXL/common/Device_BlockStorage.c
BlockRange1 adjusted to allocate 28 blocks (0–27) for nanoCLR code and 15 blocks (28–42) for deployment, shifting deployment start boundary from 27 to 28.
Linker Script
targets/TI_SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CC13x2_26x2_CLR.ld
FLASH memory LENGTH increased from 0x00036000 to 0x00038000 to accommodate expanded code footprint.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Suggested labels

Type: bug

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Miscellaneous fixes related with generics' clearly summarizes the main changes which extensively improve generics handling across the CLR interpreter, type system, and execution engine.
Description check ✅ Passed The description provides a detailed breakdown of specific changes addressing generics handling, including references to related issues and testing context, making it clearly related to the substantial changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@josesimoes
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

✅ 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
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

✅ 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 added the Area: Common libs Everything related with common libraries label May 6, 2026
@nfbot nfbot added the Type: bug label May 6, 2026
@josesimoes josesimoes mentioned this pull request May 7, 2026
13 tasks
josesimoes and others added 9 commits May 7, 2026 11:21
- Add ResolveMethodRef() TypeSpec fallback chain.
- Runtime MethodRef TypeSpec handling to reuses the startup-resolved target.
- InitializeReference() now has VAR fallback.
- ResolveGenericTypeParameter() now returns failure to allow caller to handle it properly (otherwise it will go into an infinite loop).
- Fix generic parameter check in DumpOpcode().
- Now outputting correctly resolved generic types.
- Relax _ASSERTE(DataSize == 1) to DataSize <= 1 in Assign/AssignId/AssignData/AssignAndPreserveType/AssignPreserveTypeCheckPinned.
Zero-initialized field blocks (DataSize == 0, default value of a field that was never written) are valid single-block copies; only DataSize > 1 should be forbidden (partial copy of an embedded value-type struct).

- When a valid genericType context is in scope but the per-TypeSpec field lookup still fails after
on-demand allocation, return nullptr instead of falling through to the   assembly-level fallback.  Generic static fields have no assembly-level slot (fdCross.offset == CLR_EmptyIndex), so reaching the fallback always fired _ASSERTE(fdCross.offset != CLR_EmptyIndex).

- Add NANOCLR_TRACE_GENERICS to output generics resolution. Needed to help debugging hard type resolutions.
- Relaxing the assert was wrong and was only a workaround.
Automated fixes for code style.
- Fixed conditions to publish dump files artifacts.
josesimoes and others added 2 commits May 8, 2026 10:47
- Runtime-inferred element types can now close open VAR and MVAR slots even when there is no normal TypeSpec or MethodSpec context.
- Also fixed array-element type handling for generic enumeration and ldelem.any, so element byrefs are validated as the element type rather than the enclosing array type.
Automated fixes for code style.
@nfbot
Copy link
Copy Markdown
Member

nfbot commented May 8, 2026

@josesimoes there are issues with the code style on the source files.
A PR was submitted with the code style fixes. Please click josesimoes#121, review the changes if you want and merge it.

Make sure to follow the project code style. Check the details here on how it works and the tools required to help you with that.

…70456-09ff-4288-a498-78245dd67462

Code style fixes for nanoframework/nf-interpreter PR#3347
@josesimoes josesimoes merged commit 5ca760b into nanoframework:develop May 8, 2026
23 checks passed
@josesimoes josesimoes deleted the fixes-generics branch May 8, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Common libs Everything related with common libraries Type: bug Type: enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants