Skip to content

Fix comparison in TaskHostParameters #12733

Merged
YuliiaKovalova merged 2 commits intomainfrom
dev/ykovalova/fix_comparison
Nov 10, 2025
Merged

Fix comparison in TaskHostParameters #12733
YuliiaKovalova merged 2 commits intomainfrom
dev/ykovalova/fix_comparison

Conversation

@YuliiaKovalova
Copy link
Member

@YuliiaKovalova YuliiaKovalova commented Nov 7, 2025

This change introduces a new read only struct that is used in Dictionary for caching in TaskRegistry
#12620

Without a proper equality check it spawns a new process due to mismatch.

Experimental insertion without extra allocation reported: https://devdiv.visualstudio.com/DevDiv/_git/VS/pullrequest/686770

Copilot AI review requested due to automatic review settings November 7, 2025 20:50
@YuliiaKovalova YuliiaKovalova changed the title fix comparison Fix comparison TaskHostParameters Nov 7, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements proper equality semantics for the TaskHostParameters struct by adding IEquatable<TaskHostParameters>, Equals, and GetHashCode implementations. The changes ensure that task host parameter comparisons correctly consider only the identity properties (Runtime, Architecture, and TaskHostFactoryExplicitlyRequested) and use case-insensitive string comparisons, while excluding path properties (DotnetHostPath and MSBuildAssemblyPath) from identity checks.

Key changes:

  • Adds IEquatable<TaskHostParameters> implementation with case-insensitive string comparison for Runtime and Architecture
  • Implements GetHashCode using a manual hash code calculation compatible with .NET Framework 4.7.2
  • Updates ToDictionary() to use StringComparer.OrdinalIgnoreCase for consistency
  • Refines IdentityParametersMatch in TaskRegistry.cs to explicitly exclude path properties from exact match comparisons

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Framework/TaskHostParameters.cs Implements IEquatable<TaskHostParameters>, adds Equals and GetHashCode methods, and updates ToDictionary to use case-insensitive string comparer
src/Build/Instance/TaskRegistry.cs Removes path property comparisons from exact match logic in IdentityParametersMatch to align with the new equality implementation
.mcp.json Adds MCP server configuration file (appears unrelated to the core PR purpose)
Comments suppressed due to low confidence (1)

src/Build/Instance/TaskRegistry.cs:914

  • With the new GetHashCode implementation in TaskHostParameters, this code could be simplified to call obj.TaskIdentityParameters.GetHashCode() directly instead of manually computing hash codes for Runtime and Architecture. This would ensure consistency and reduce code duplication.
                        int runtimeHash = obj.TaskIdentityParameters.Runtime == null ? 0 : StringComparer.OrdinalIgnoreCase.GetHashCode(obj.TaskIdentityParameters.Runtime);
                        int architectureHash = obj.TaskIdentityParameters.Architecture == null ? 0 : StringComparer.OrdinalIgnoreCase.GetHashCode(obj.TaskIdentityParameters.Architecture);

@YuliiaKovalova YuliiaKovalova force-pushed the dev/ykovalova/fix_comparison branch from d50ad2d to 4ee8cb0 Compare November 8, 2025 06:36
@YuliiaKovalova YuliiaKovalova changed the title Fix comparison TaskHostParameters Fix comparison in TaskHostParameters Nov 10, 2025
@YuliiaKovalova YuliiaKovalova enabled auto-merge (squash) November 10, 2025 07:31
@YuliiaKovalova YuliiaKovalova merged commit f4196fc into main Nov 10, 2025
10 checks passed
@YuliiaKovalova YuliiaKovalova deleted the dev/ykovalova/fix_comparison branch November 10, 2025 09:08
@YuliiaKovalova YuliiaKovalova self-assigned this Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants