Skip to content

Merge generics support in mscorlib#245

Draft
josesimoes wants to merge 52 commits into
mainfrom
develop
Draft

Merge generics support in mscorlib#245
josesimoes wants to merge 52 commits into
mainfrom
develop

Conversation

@josesimoes
Copy link
Copy Markdown
Member

@josesimoes josesimoes commented Apr 29, 2025

Description

  • Merge with main.

Motivation and Context

  • Used for unit tests in interpreter.

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)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (add new Unit Test(s) or improved existing one(s), 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).
  • I have added new tests to cover my changes.

- Publish to nuget now happens on build from develop branch too.
- Temporary disable trigger for tags.

***NO_CI***
- Fix parameter name.
- Add branch to publish nugets from.

***NO_CI***
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2025

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR introduces Span<T> and ReadOnlySpan<T> ref struct implementations with comprehensive test coverage, adds generic collection interfaces (ICollection<T>), enhances Guid with equality operators and CompareTo overloads, adds MemoryExtensions.CopyTo() for array-to-span operations, updates CI pipeline configuration for conditional release handling based on branch names, and refactors test infrastructure.

Changes

Cohort / File(s) Summary
CI/Pipeline Configuration
azure-pipelines.yml, azure-pipelines-templates/check-nf-interpreter-to-test.yml
Removed tag-based trigger filtering, added DOTNET_NOLOGO variable, introduced nanoFramework interpreter version checking template, updated class-lib build/publish parameters (unitTestRunsettings, skipNuGetCache, usePreviewBuild, baseBranchName), modified GitHub release condition to gate on branch name (main/develop) with changelog generation enabled.
Version and Build Configuration
version.json, local_clr.runsettings
Updated base version to semantic format with preview tag and height-based build number; extended public release branch patterns. Added new test run settings file configuring MaxCpuCount, TestSessionTimeout, TargetFramework (net48), and local CLR instance path with verbose adapter logging.
Documentation
.github/copilot-instructions.md
Added comprehensive Copilot usage guidance covering repository purpose, architectural constraints, build variants, structure, conventions, and contribution rules for nanoFramework CoreLibrary development.
Core Span/Memory Types
nanoFramework.CoreLibrary/System/Span.cs, nanoFramework.CoreLibrary/System/ReadOnlySpan.cs, nanoFramework.CoreLibrary/System/MemoryExtensions.cs
Implemented Span<T> and ReadOnlySpan<T> readonly ref structs with constructors, indexers, slicing, ToArray(), CopyTo() (extern internal calls), enumerators, and equality operators. Added MemoryExtensions.CopyTo<T>() extension method wrapping nullable arrays to ReadOnlySpan<T>.
Guid Enhancements
nanoFramework.CoreLibrary/System/Guid.cs
Added CompareTo(Guid) overload, Equals(Guid) overload, equality operators (==, !=), renamed TryParseGuidWithDashes() to TryParse(), initialized backing _data field inline with null-coalescing guards.
Generic Collection Interfaces
nanoFramework.CoreLibrary/System/Collections/Generic/ICollection.cs, nanoFramework.CoreLibrary/System/Collections/Generic/ICollectionDebugView.cs
Added new ICollection<T> interface extending IEnumerable<T> with Count, IsReadOnly properties and manipulation methods. Added internal ICollectionDebugView<T> debug helper class.
Array and Unsafe Helpers
nanoFramework.CoreLibrary/System/Array.cs, nanoFramework.CoreLibrary/System/Runtime/CompilerServices/Unsafe.cs
Added conditional Array.Empty<T>() method and SZArrayHelper class for reflection-gated generic operations. Introduced Unsafe.As<T>() intrinsic for ref struct casting under NANOCLR_REFLECTION.
String Type Updates
nanoFramework.CoreLibrary/System/String.cs
Standardized to C# string keyword across APIs, added nullable-aware signatures under NANOCLR_REFLECTION, replaced managed Format with extern internal-call, expanded Trim* method variants, updated exception construction in PadLeft/PadRight.
Assembly and Project Configuration
nanoFramework.CoreLibrary/System/AssemblyInfo.cs, nanoFramework.CoreLibrary/CoreLibrary.nfproj, Tests/NFUnitTestSystemLib/NFUnitTestSystemLib.nfproj, Tests/NFUnitTestTypes/NFUnitTestTypes.nfproj, Tests/TestFramework/TestFramework.nfproj, nanoFramework.TestFramework
Updated AssemblyNativeVersion, set C# LangVersion to 13.0, added new compile items for span/collection/memory implementations, removed Assert.Obsolete.cs from test framework, updated subproject commit.
Comprehensive Unit Tests
Tests/NFUnitTestSystemLib/UnitTestMemoryExtensions.cs, Tests/NFUnitTestTypes/UnitTestGuid.cs, Tests/NFUnitTestTypes/UnitTestsReadOnlySpanByte.cs, Tests/NFUnitTestTypes/UnitTestsSpanByte.cs, Tests/NFUnitTestSystemLib/UnitTestInitLocalTests.cs, Tests/NFUnitTestArithmetic/UnitTestFormat.cs
Added extensive test coverage for Span<T> and ReadOnlySpan<byte> behavior (constructors, indexing, slicing, copying, equality), Guid operations (comparison, equality, parsing, hashing), MemoryExtensions.CopyTo(). Refactored SpanByte tests to use Span<byte>, enhanced SystemType1_GetType_Test() with progress logging, updated exception expectations in format tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Merge generics support in mscorlib' is concise, descriptive, and clearly summarizes the main objective of the changeset—adding generics support to the core library. It is well under 50 characters (34 characters) and does not end with a period.
Description check ✅ Passed The PR description, while minimal, provides relevant context including motivation (generics support for unit tests in interpreter) and acknowledges this is a merge with main. It is related to the substantial changeset that adds generics infrastructure, span/memory types, and supporting features.
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.


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.

Copy link
Copy Markdown

@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: 0

🧹 Nitpick comments (2)
azure-pipelines.yml (2)

59-60: Remove duplicate variable declaration & trailing spaces.

You’ve declared DOTNET_NOLOGO both globally (lines 36–37) and again under the Build_mscorlib job. This duplication is unnecessary and may lead to confusion. Also, YAMLlint flagged trailing spaces on line 60.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 60-60: trailing spaces

(trailing-spaces)


132-136: Consider adding the generics branch to release conditions.

You’ve broadened the GitHub release condition to run on main and develop. To stay consistent with the new publicReleaseRefSpec, you might also include generics here if you intend to create releases from that branch.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cca059e and e37e4b8.

⛔ Files ignored due to path filters (11)
  • .runsettings is excluded by none and included by none
  • Tests/NFUnitTestGC/TestGC.cs is excluded by none and included by none
  • Tests/NFUnitTestSystemLib/UnitTestGCTest.cs is excluded by none and included by none
  • Tests/NFUnitTestSystemLib/UnitTestInitLocalTests.cs is excluded by none and included by none
  • Tests/NFUnitTestSystemLib/UnitTestReflectionTypeTest.cs is excluded by none and included by none
  • Tests/UnitTestLauncher/UnitTestLauncher.nfproj is excluded by none and included by none
  • nanoFramework.CoreLibrary.nuspec is excluded by none and included by none
  • nanoFramework.CoreLibrary/System/AssemblyInfo.cs is excluded by none and included by none
  • nanoFramework.CoreLibrary/System/GC.cs is excluded by none and included by none
  • nanoFramework.CoreLibrary/System/Guid.cs is excluded by none and included by none
  • nanoFramework.TestFramework is excluded by none and included by none
📒 Files selected for processing (2)
  • azure-pipelines.yml (3 hunks)
  • version.json (2 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
azure-pipelines.yml

[error] 60-60: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: nanoframework.CoreLibrary (Build_mscorlib)
  • GitHub Check: nanoframework.CoreLibrary (Build_mscorlib)
🔇 Additional comments (4)
version.json (2)

3-3: Approve semantic version update.

Updating the base version to "2.0.0-preview.{height}" correctly switches to semantic versioning with a preview suffix. This aligns with the pipeline change enabling preview builds.


14-14: Approve new public release branch pattern.

Adding ^refs/heads/generics$ to publicReleaseRefSpec ensures the newly merged “generics” branch is considered for public releases.

azure-pipelines.yml (2)

79-79: Verify template supports usePreviewBuild.

You’ve enabled usePreviewBuild: true in the class-lib-build-only.yml invocation. Please confirm that the template accepts and correctly propagates this parameter to invoke preview-mode builds as expected.


122-125: Ensure publish step aligns with new branches.

The class-lib-publish.yml template is now called with baseBranchName: 'develop'. Given that version.json includes a generics branch for public releases, please verify whether baseBranchName should dynamically reflect generics (or accept a list of branches) to fully support that branch.

@sonarqubecloud
Copy link
Copy Markdown

- Add target for .NET Framework v4.7.2
Copy link
Copy Markdown

@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: 3

♻️ Duplicate comments (2)
nanoFramework.CoreLibrary/System/String.cs (2)

49-52: ⚠️ Potential issue | 🟡 Minor

Use an explicit local type here.

Line 51 still uses var; replace it with string to match the project style.

Proposed fix
-            var s = obj as string;
+            string s = obj as string;

As per coding guidelines, **/*.cs: Avoid using var keyword; use explicit types instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nanoFramework.CoreLibrary/System/String.cs` around lines 49 - 52, In the
System.String.Equals override, replace the implicit local declaration "var s =
obj as string;" with an explicit type by changing it to "string s = obj as
string;" so the Equals(object obj) method uses an explicit local type consistent
with project style; update the local variable declaration inside the Equals
method accordingly.

61-70: ⚠️ Potential issue | 🟡 Minor

Make Equals(string, string) nullable-aware in the reflection build.

NANOCLR_REFLECTION is active for the main CoreLibrary build, but Line 65 keeps non-nullable parameters while the XML docs and sibling == / != operators accept null.

Proposed fix
-        public static extern bool Equals(string a, string b);
+        public static extern bool Equals(string? a, string? b);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nanoFramework.CoreLibrary/System/String.cs` around lines 61 - 70, The
Equals(string a, string b) declaration inside the NANOCLR_REFLECTION block must
be made nullable-aware to match the XML docs and the sibling == / != operators:
change the parameter types to nullable (string? a, string? b) while keeping the
existing [MethodImpl(MethodImplOptions.InternalCall)] attribute and the
surrounding `#nullable` enable/#nullable restore directives so the reflection
build accepts null inputs consistently with the rest of the API.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@nanoFramework.CoreLibrary/System/String.cs`:
- Around line 217-228: The XML summaries are incorrect: change the Trim(params
char[]? trimChars) summary to say it removes all leading and trailing
occurrences of the specified characters (or whitespace if null/empty), correct
the parameter description to reference trimChars, and fix the parameterless
Trim() summary to describe trimming both ends; likewise update TrimStart() and
TrimEnd() summaries to state they remove only leading or only trailing
characters respectively (and that the parameterless overloads remove whitespace
when no chars parameter exists). Ensure the unique symbols Trim(params char[]?
trimChars), Trim(), TrimStart(), and TrimEnd() have accurate, concise XML docs
(also apply same corrections noted around the other occurrences referenced).
- Around line 222-253: The InternalCall declarations for Trim, Trim(params
char[]?), TrimStart, TrimStart(params char[]?), TrimEnd, and TrimEnd(params
char[]?) in String.cs lack matching native C++ implementations and registration;
add native functions that implement the exact .NET semantics (no-arg variants
trim Unicode white-space, params variants treat null/empty as white-space set,
return original string instance if nothing trimmed) and register them in the
runtime's internal-call table/registration macros so the CLR will resolve the
methods at runtime; implement the logic in the C++ string/native string helper
used by other String methods, name the native functions to match the
InternalCall mapping (corresponding to the C# method names) and run
Tests/NFUnitTestSystemLib/UnitTestStringTests.cs to verify all variants.

In `@Tests/NFUnitTestArithmetic/UnitTestFormat.cs`:
- Around line 46-48: Add an explicit test that exercises the params-array-null
path for String.Format: in UnitTestFormat (the test shown with nullFormat) add
an Assert.ThrowsException expecting ArgumentNullException that calls
string.Format with a valid format string but passes the params array as null
(e.g. string.Format("{0}", (object[])null)) so the args == null behavior is
covered and cannot regress.

---

Duplicate comments:
In `@nanoFramework.CoreLibrary/System/String.cs`:
- Around line 49-52: In the System.String.Equals override, replace the implicit
local declaration "var s = obj as string;" with an explicit type by changing it
to "string s = obj as string;" so the Equals(object obj) method uses an explicit
local type consistent with project style; update the local variable declaration
inside the Equals method accordingly.
- Around line 61-70: The Equals(string a, string b) declaration inside the
NANOCLR_REFLECTION block must be made nullable-aware to match the XML docs and
the sibling == / != operators: change the parameter types to nullable (string?
a, string? b) while keeping the existing
[MethodImpl(MethodImplOptions.InternalCall)] attribute and the surrounding
`#nullable` enable/#nullable restore directives so the reflection build accepts
null inputs consistently with the rest of the API.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: nanoframework/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 96a4aad0-5141-4f23-a902-86fb59b66a7f

📥 Commits

Reviewing files that changed from the base of the PR and between 7c5e825 and 2aa5d2a.

📒 Files selected for processing (2)
  • Tests/NFUnitTestArithmetic/UnitTestFormat.cs
  • nanoFramework.CoreLibrary/System/String.cs

Comment thread nanoFramework.CoreLibrary/System/String.cs Outdated
Comment thread nanoFramework.CoreLibrary/System/String.cs
Comment thread Tests/NFUnitTestArithmetic/UnitTestFormat.cs
@josesimoes josesimoes mentioned this pull request Apr 24, 2026
14 tasks
- Remove wrong space and update project entry.

***NO_CI***
@sonarqubecloud
Copy link
Copy Markdown

josesimoes added 2 commits May 6, 2026 22:07
- Fix logic to use build artifact in nf-interpreter pipeline when running unit tests.

***NO_CI***
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants