diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index a380bc7a96d12e..a75171aeda1b04 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -15,7 +15,7 @@ ] }, "microsoft.dotnet.xharness.cli": { - "version": "9.0.0-prerelease.24420.3", + "version": "9.0.0-prerelease.24452.1", "commands": [ "xharness" ] diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 3527b7f79945c6..77c06d86deee33 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -316,17 +316,17 @@ https://github.com/dotnet/runtime 7cb32e193a55a95c74fc3bd56501b951b48b700f - + https://github.com/dotnet/xharness - 69f15217657bc3a7f0102911aa967525529fdfdb + c2215b88cdac5390888de3e6ad301c113f40ed6c - + https://github.com/dotnet/xharness - 69f15217657bc3a7f0102911aa967525529fdfdb + c2215b88cdac5390888de3e6ad301c113f40ed6c - + https://github.com/dotnet/xharness - 69f15217657bc3a7f0102911aa967525529fdfdb + c2215b88cdac5390888de3e6ad301c113f40ed6c https://github.com/dotnet/arcade diff --git a/eng/Versions.props b/eng/Versions.props index de50ced3759ace..a6407d4ed6c891 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -180,9 +180,9 @@ 1.4.0 17.4.0-preview-20220707-01 - 9.0.0-prerelease.24420.3 - 9.0.0-prerelease.24420.3 - 9.0.0-prerelease.24420.3 + 9.0.0-prerelease.24452.1 + 9.0.0-prerelease.24452.1 + 9.0.0-prerelease.24452.1 9.0.0-alpha.0.24419.1 3.12.0 4.5.0 diff --git a/eng/pipelines/common/templates/runtimes/build-runtime-tests-and-send-to-helix.yml b/eng/pipelines/common/templates/runtimes/build-runtime-tests-and-send-to-helix.yml index b0a2043bbd5710..cd249357a9c6d5 100644 --- a/eng/pipelines/common/templates/runtimes/build-runtime-tests-and-send-to-helix.yml +++ b/eng/pipelines/common/templates/runtimes/build-runtime-tests-and-send-to-helix.yml @@ -68,7 +68,7 @@ steps: displayName: "AOT compile CoreCLR tests" target: ${{ coalesce(parameters.llvmAotStepContainer, parameters.container) }} - ${{ if in(parameters.runtimeVariant, 'llvmfullaot', 'minifullaot') }}: - - script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) $(logRootNameArg)MonoAot mono_fullaot ${{ parameters.buildConfig }} ${{ parameters.archType }} /p:RuntimeVariant=${{ parameters.runtimeVariant }} -maxcpucount:1 + - script: $(Build.SourcesDirectory)/src/tests/build$(scriptExt) $(logRootNameArg)MonoAot mono_fullaot ${{ parameters.buildConfig }} ${{ parameters.archType }} /p:RuntimeVariant=${{ parameters.runtimeVariant }} -maxcpucount:2 displayName: "AOT compile CoreCLR tests" target: ${{ coalesce(parameters.llvmAotStepContainer, parameters.container) }} - ${{ if eq(parameters.archType, 'arm64') }}: diff --git a/eng/pipelines/coreclr/templates/run-performance-job.yml b/eng/pipelines/coreclr/templates/run-performance-job.yml index 7560912bf5f09d..1feb524a2deba4 100644 --- a/eng/pipelines/coreclr/templates/run-performance-job.yml +++ b/eng/pipelines/coreclr/templates/run-performance-job.yml @@ -78,6 +78,7 @@ jobs: export NODE_MAJOR=18 && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list && sudo apt-get update && + sudo apt autoremove -y && sudo apt-get install nodejs -y && test -n "$(V8Version)" && npm install --prefix $HELIX_WORKITEM_PAYLOAD jsvu -g && diff --git a/eng/pipelines/libraries/stress/http.yml b/eng/pipelines/libraries/stress/http.yml index ee772d0da0e95c..13bff1454fe2b2 100644 --- a/eng/pipelines/libraries/stress/http.yml +++ b/eng/pipelines/libraries/stress/http.yml @@ -99,7 +99,10 @@ extends: displayName: Docker NanoServer timeoutInMinutes: 150 variables: - DUMPS_SHARE_MOUNT_ROOT: "C:/dumps-share" + # This will get assigned to the DUMPS_SHARE_MOUNT_ROOT environment + # variable in the stress test script. We need to keep the + # DUMPS_SHARE_MOUNT_ROOT variable empty during the build step. + DUMPS_SHARE_MOUNT_ROOT_PATH: "C:/dumps-share" # The 1es-windows-2022-open image has an issue where the Chocolatey-installed V1 docker-compose takes precendence over the # V2 docker-compose required by the stress tests, see: https://github.com/actions/runner-images/issues/7080 @@ -140,6 +143,7 @@ extends: - powershell: | cd '$(httpStressProject)' + $env:DUMPS_SHARE_MOUNT_ROOT = $env:DUMPS_SHARE_MOUNT_ROOT_PATH $env:CLIENT_DUMPS_SHARE="$(Build.ArtifactStagingDirectory)/dumps/client/3.0" $env:SERVER_DUMPS_SHARE="$(Build.ArtifactStagingDirectory)/dumps/server/3.0" New-Item -Force $env:CLIENT_DUMPS_SHARE -ItemType Directory @@ -152,6 +156,7 @@ extends: - powershell: | cd '$(httpStressProject)' + $env:DUMPS_SHARE_MOUNT_ROOT = $env:DUMPS_SHARE_MOUNT_ROOT_PATH $env:CLIENT_DUMPS_SHARE="$(Build.ArtifactStagingDirectory)/dumps/client/2.0" $env:SERVER_DUMPS_SHARE="$(Build.ArtifactStagingDirectory)/dumps/server/2.0" New-Item -Force $env:CLIENT_DUMPS_SHARE -ItemType Directory @@ -164,6 +169,7 @@ extends: - powershell: | cd '$(httpStressProject)' + $env:DUMPS_SHARE_MOUNT_ROOT = $env:DUMPS_SHARE_MOUNT_ROOT_PATH $env:CLIENT_DUMPS_SHARE="$(Build.ArtifactStagingDirectory)/dumps/client/1.1" $env:SERVER_DUMPS_SHARE="$(Build.ArtifactStagingDirectory)/dumps/server/1.1" New-Item -Force $env:CLIENT_DUMPS_SHARE -ItemType Directory diff --git a/eng/pipelines/runtime-llvm.yml b/eng/pipelines/runtime-llvm.yml index 5be2a5b063aaaa..16c337b406d072 100644 --- a/eng/pipelines/runtime-llvm.yml +++ b/eng/pipelines/runtime-llvm.yml @@ -144,7 +144,7 @@ extends: nameSuffix: AllSubsets_Mono_LLVMFULLAOT_RuntimeTests runtimeVariant: llvmfullaot buildArgs: -s mono+libs+clr.hosts+clr.iltools -c $(_BuildConfig) /p:MonoEnableLLVM=true - timeoutInMinutes: 360 + timeoutInMinutes: 400 condition: >- or( eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true), @@ -191,7 +191,7 @@ extends: nameSuffix: AllSubsets_Mono_LLVMFULLAOT_RuntimeIntrinsicsTests runtimeVariant: llvmfullaot buildArgs: -s mono+libs+clr.hosts+clr.iltools -c $(_BuildConfig) /p:MonoEnableLLVM=true - timeoutInMinutes: 360 + timeoutInMinutes: 400 condition: >- or( eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true), diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 881e10841bd387..94e8a3887a55f9 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -16,6 +16,43 @@ // allocation helpers in gcscan.cpp // +#include "common.h" +#include "gcenv.h" + +#include "gc.h" +#include "gcscan.h" +#include "gcdesc.h" +#include "softwarewritewatch.h" +#include "handletable.h" +#include "handletable.inl" +#include "gcenv.inl" +#include "gceventstatus.h" + +#ifdef __INTELLISENSE__ +#if defined(FEATURE_SVR_GC) + +#define SERVER_GC 1 + +#else // defined(FEATURE_SVR_GC) + +#ifdef SERVER_GC +#undef SERVER_GC +#endif + +#endif // defined(FEATURE_SVR_GC) +#endif // __INTELLISENSE__ + +#ifdef TARGET_AMD64 +#include "vxsort/do_vxsort.h" +#endif + +#ifdef SERVER_GC +namespace SVR { +#else // SERVER_GC +namespace WKS { +#endif // SERVER_GC + +#include "gcimpl.h" #include "gcpriv.h" #ifdef TARGET_AMD64 @@ -53401,3 +53438,5 @@ size_t gc_heap::get_mark_array_size (heap_segment* seg) return 0; } #endif //USE_REGIONS + +} diff --git a/src/coreclr/gc/gcee.cpp b/src/coreclr/gc/gcee.cpp index b48632cf06923f..283c9055d6bc3f 100644 --- a/src/coreclr/gc/gcee.cpp +++ b/src/coreclr/gc/gcee.cpp @@ -7,6 +7,35 @@ // sets up vars for GC +#include "common.h" +#include "gcenv.h" + +#include "gc.h" +#include "gcscan.h" +#include "gchandletableimpl.h" +#include "gceventstatus.h" + +#ifdef __INTELLISENSE__ +#if defined(FEATURE_SVR_GC) + +#define SERVER_GC 1 + +#else // defined(FEATURE_SVR_GC) + +#ifdef SERVER_GC +#undef SERVER_GC +#endif + +#endif // defined(FEATURE_SVR_GC) +#endif // __INTELLISENSE__ + +#ifdef SERVER_GC +namespace SVR { +#else // SERVER_GC +namespace WKS { +#endif // SERVER_GC + +#include "gcimpl.h" #include "gcpriv.h" #ifndef DACCESS_COMPILE @@ -540,4 +569,4 @@ uint64_t GCHeap::GetGenerationBudget(int generation) #endif // !DACCESS_COMPILE - +} diff --git a/src/coreclr/gc/gceesvr.cpp b/src/coreclr/gc/gceesvr.cpp index be7c129cc3fc74..9b37a77b0ae697 100644 --- a/src/coreclr/gc/gceesvr.cpp +++ b/src/coreclr/gc/gceesvr.cpp @@ -1,25 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. - - -#include "common.h" - #if defined(FEATURE_SVR_GC) - -#include "gcenv.h" - -#include "gc.h" -#include "gcscan.h" -#include "gchandletableimpl.h" -#include "gceventstatus.h" - #define SERVER_GC 1 - - -namespace SVR { -#include "gcimpl.h" #include "gcee.cpp" -} - #endif // FEATURE_SVR_GC diff --git a/src/coreclr/gc/gceewks.cpp b/src/coreclr/gc/gceewks.cpp index 203464ab6b5369..d0e275be2bb7ba 100644 --- a/src/coreclr/gc/gceewks.cpp +++ b/src/coreclr/gc/gceewks.cpp @@ -1,23 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. - - -#include "common.h" - -#include "gcenv.h" - -#include "gc.h" -#include "gcscan.h" -#include "gchandletableimpl.h" -#include "gceventstatus.h" - #ifdef SERVER_GC #undef SERVER_GC #endif -namespace WKS { -#include "gcimpl.h" #include "gcee.cpp" -} - diff --git a/src/coreclr/gc/gcsvr.cpp b/src/coreclr/gc/gcsvr.cpp index 5dc848f40c3f7f..4d54ca2db58aa2 100644 --- a/src/coreclr/gc/gcsvr.cpp +++ b/src/coreclr/gc/gcsvr.cpp @@ -1,32 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. - - -#include "common.h" - -#if defined(FEATURE_SVR_GC) - -#include "gcenv.h" - -#include "gc.h" -#include "gcscan.h" -#include "gcdesc.h" -#include "softwarewritewatch.h" -#include "handletable.h" -#include "handletable.inl" -#include "gcenv.inl" -#include "gceventstatus.h" - +#ifdef FEATURE_SVR_GC #define SERVER_GC 1 - -#ifdef TARGET_AMD64 -#include "vxsort/do_vxsort.h" -#endif - -namespace SVR { -#include "gcimpl.h" #include "gc.cpp" -} - -#endif // defined(FEATURE_SVR_GC) +#endif // FEATURE_SVR_GC diff --git a/src/coreclr/gc/gcwks.cpp b/src/coreclr/gc/gcwks.cpp index 6b4cfe1681463b..886e199a29efb4 100644 --- a/src/coreclr/gc/gcwks.cpp +++ b/src/coreclr/gc/gcwks.cpp @@ -1,31 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. - - -#include "common.h" - -#include "gcenv.h" - -#include "gc.h" -#include "gcscan.h" -#include "gcdesc.h" -#include "softwarewritewatch.h" -#include "handletable.h" -#include "handletable.inl" -#include "gcenv.inl" -#include "gceventstatus.h" - #ifdef SERVER_GC #undef SERVER_GC #endif -#ifdef TARGET_AMD64 -#include "vxsort/do_vxsort.h" -#endif - -namespace WKS { -#include "gcimpl.h" #include "gc.cpp" -} - diff --git a/src/coreclr/jit/emitarm64.cpp b/src/coreclr/jit/emitarm64.cpp index 784cb603ca0b69..4153f4ec5080c2 100644 --- a/src/coreclr/jit/emitarm64.cpp +++ b/src/coreclr/jit/emitarm64.cpp @@ -12248,7 +12248,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) } else { - assert(id->idReg3() == REG_SP); + assert(encodingZRtoSP(id->idReg3()) == REG_SP); } assert(varNum2 != -1); #endif // DEBUG @@ -17082,7 +17082,7 @@ emitter::RegisterOrder emitter::IsOptimizableLdrStrWithPair( } regNumber prevReg1 = emitLastIns->idReg1(); - regNumber prevReg2 = emitLastIns->idReg2(); + regNumber prevReg2 = encodingZRtoSP(emitLastIns->idReg2()); insFormat lastInsFmt = emitLastIns->idInsFmt(); emitAttr prevSize = emitLastIns->idOpSize(); ssize_t prevImm = emitGetInsSC(emitLastIns); diff --git a/src/coreclr/jit/hwintrinsic.h b/src/coreclr/jit/hwintrinsic.h index cbc88369cb03a6..139f2fbddeabd3 100644 --- a/src/coreclr/jit/hwintrinsic.h +++ b/src/coreclr/jit/hwintrinsic.h @@ -229,6 +229,9 @@ enum HWIntrinsicFlag : unsigned int // (HW_Flag_BaseTypeFrom{First, Second}Arg must also be set to denote the position of the ValueTuple) HW_Flag_BaseTypeFromValueTupleArg = 0x1000000, + // The intrinsic is a reduce operation. + HW_Flag_ReduceOperation = 0x2000000, + #else #error Unsupported platform #endif @@ -998,6 +1001,12 @@ struct HWIntrinsicInfo return (flags & HW_Flag_BaseTypeFromValueTupleArg) != 0; } + static bool IsReduceOperation(NamedIntrinsic id) + { + const HWIntrinsicFlag flags = lookupFlags(id); + return (flags & HW_Flag_ReduceOperation) != 0; + } + static NamedIntrinsic GetScalarInputVariant(NamedIntrinsic id) { assert(HasScalarInputVariant(id)); diff --git a/src/coreclr/jit/hwintrinsiclistarm64sve.h b/src/coreclr/jit/hwintrinsiclistarm64sve.h index ed238ba0fca56c..922b116fa25a23 100644 --- a/src/coreclr/jit/hwintrinsiclistarm64sve.h +++ b/src/coreclr/jit/hwintrinsiclistarm64sve.h @@ -23,12 +23,12 @@ HARDWARE_INTRINSIC(Sve, AbsoluteCompareLessThan, HARDWARE_INTRINSIC(Sve, AbsoluteCompareLessThanOrEqual, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_facle, INS_sve_facle}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ReturnsPerElementMask|HW_Flag_ZeroingMaskedOperation) HARDWARE_INTRINSIC(Sve, AbsoluteDifference, -1, -1, {INS_sve_sabd, INS_sve_uabd, INS_sve_sabd, INS_sve_uabd, INS_sve_sabd, INS_sve_uabd, INS_sve_sabd, INS_sve_uabd, INS_sve_fabd, INS_sve_fabd}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) HARDWARE_INTRINSIC(Sve, Add, -1, -1, {INS_sve_add, INS_sve_add, INS_sve_add, INS_sve_add, INS_sve_add, INS_sve_add, INS_sve_add, INS_sve_add, INS_sve_fadd, INS_sve_fadd}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_OptionalEmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) -HARDWARE_INTRINSIC(Sve, AddAcross, -1, 1, {INS_sve_saddv, INS_sve_uaddv, INS_sve_saddv, INS_sve_uaddv, INS_sve_saddv, INS_sve_uaddv, INS_sve_uaddv, INS_sve_uaddv, INS_sve_faddv, INS_sve_faddv}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_BaseTypeFromFirstArg|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) +HARDWARE_INTRINSIC(Sve, AddAcross, -1, 1, {INS_sve_saddv, INS_sve_uaddv, INS_sve_saddv, INS_sve_uaddv, INS_sve_saddv, INS_sve_uaddv, INS_sve_uaddv, INS_sve_uaddv, INS_sve_faddv, INS_sve_faddv}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_BaseTypeFromFirstArg|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ReduceOperation) HARDWARE_INTRINSIC(Sve, AddRotateComplex, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_fcadd, INS_sve_fcadd}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_HasImmediateOperand) HARDWARE_INTRINSIC(Sve, AddSaturate, -1, 2, {INS_sve_sqadd, INS_sve_uqadd, INS_sve_sqadd, INS_sve_uqadd, INS_sve_sqadd, INS_sve_uqadd, INS_sve_sqadd, INS_sve_uqadd, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) -HARDWARE_INTRINSIC(Sve, AddSequentialAcross, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_fadda, INS_sve_fadda}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_HasRMWSemantics) +HARDWARE_INTRINSIC(Sve, AddSequentialAcross, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_fadda, INS_sve_fadda}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_ReduceOperation) HARDWARE_INTRINSIC(Sve, And, -1, -1, {INS_sve_and, INS_sve_and, INS_sve_and, INS_sve_and, INS_sve_and, INS_sve_and, INS_sve_and, INS_sve_and, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_OptionalEmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) -HARDWARE_INTRINSIC(Sve, AndAcross, -1, -1, {INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) +HARDWARE_INTRINSIC(Sve, AndAcross, -1, -1, {INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_sve_andv, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ReduceOperation) HARDWARE_INTRINSIC(Sve, BitwiseClear, -1, -1, {INS_sve_bic, INS_sve_bic, INS_sve_bic, INS_sve_bic, INS_sve_bic, INS_sve_bic, INS_sve_bic, INS_sve_bic, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_OptionalEmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) HARDWARE_INTRINSIC(Sve, BooleanNot, -1, -1, {INS_sve_cnot, INS_sve_cnot, INS_sve_cnot, INS_sve_cnot, INS_sve_cnot, INS_sve_cnot, INS_sve_cnot, INS_sve_cnot, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) HARDWARE_INTRINSIC(Sve, Compact, -1, 2, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_compact, INS_sve_compact, INS_sve_compact, INS_sve_compact, INS_sve_compact, INS_sve_compact}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_ExplicitMaskedOperation|HW_Flag_LowMaskedOperation) @@ -208,13 +208,13 @@ HARDWARE_INTRINSIC(Sve, LoadVectorUInt32ZeroExtendFirstFaulting, HARDWARE_INTRINSIC(Sve, LoadVectorUInt32ZeroExtendToInt64, -1, 2, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_ld1w, INS_invalid, INS_invalid, INS_invalid}, HW_Category_MemoryLoad, HW_Flag_Scalable|HW_Flag_ExplicitMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ZeroingMaskedOperation) HARDWARE_INTRINSIC(Sve, LoadVectorUInt32ZeroExtendToUInt64, -1, 2, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_ld1w, INS_invalid, INS_invalid}, HW_Category_MemoryLoad, HW_Flag_Scalable|HW_Flag_ExplicitMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ZeroingMaskedOperation) HARDWARE_INTRINSIC(Sve, Max, -1, -1, {INS_sve_smax, INS_sve_umax, INS_sve_smax, INS_sve_umax, INS_sve_smax, INS_sve_umax, INS_sve_smax, INS_sve_umax, INS_sve_fmax, INS_sve_fmax}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) -HARDWARE_INTRINSIC(Sve, MaxAcross, -1, -1, {INS_sve_smaxv, INS_sve_umaxv, INS_sve_smaxv, INS_sve_umaxv, INS_sve_smaxv, INS_sve_umaxv, INS_sve_smaxv, INS_sve_umaxv, INS_sve_fmaxv, INS_sve_fmaxv}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) +HARDWARE_INTRINSIC(Sve, MaxAcross, -1, -1, {INS_sve_smaxv, INS_sve_umaxv, INS_sve_smaxv, INS_sve_umaxv, INS_sve_smaxv, INS_sve_umaxv, INS_sve_smaxv, INS_sve_umaxv, INS_sve_fmaxv, INS_sve_fmaxv}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ReduceOperation) HARDWARE_INTRINSIC(Sve, MaxNumber, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_fmaxnm, INS_sve_fmaxnm}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) -HARDWARE_INTRINSIC(Sve, MaxNumberAcross, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_fmaxnmv, INS_sve_fmaxnmv}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) +HARDWARE_INTRINSIC(Sve, MaxNumberAcross, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_fmaxnmv, INS_sve_fmaxnmv}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ReduceOperation) HARDWARE_INTRINSIC(Sve, Min, -1, -1, {INS_sve_smin, INS_sve_umin, INS_sve_smin, INS_sve_umin, INS_sve_smin, INS_sve_umin, INS_sve_smin, INS_sve_umin, INS_sve_fmin, INS_sve_fmin}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) -HARDWARE_INTRINSIC(Sve, MinAcross, -1, -1, {INS_sve_sminv, INS_sve_uminv, INS_sve_sminv, INS_sve_uminv, INS_sve_sminv, INS_sve_uminv, INS_sve_sminv, INS_sve_uminv, INS_sve_fminv, INS_sve_fminv}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) +HARDWARE_INTRINSIC(Sve, MinAcross, -1, -1, {INS_sve_sminv, INS_sve_uminv, INS_sve_sminv, INS_sve_uminv, INS_sve_sminv, INS_sve_uminv, INS_sve_sminv, INS_sve_uminv, INS_sve_fminv, INS_sve_fminv}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ReduceOperation) HARDWARE_INTRINSIC(Sve, MinNumber, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_fminnm, INS_sve_fminnm}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) -HARDWARE_INTRINSIC(Sve, MinNumberAcross, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_fminnmv, INS_sve_fminnmv}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) +HARDWARE_INTRINSIC(Sve, MinNumberAcross, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_fminnmv, INS_sve_fminnmv}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ReduceOperation) HARDWARE_INTRINSIC(Sve, Multiply, -1, 2, {INS_sve_mul, INS_sve_mul, INS_sve_mul, INS_sve_mul, INS_sve_mul, INS_sve_mul, INS_sve_mul, INS_sve_mul, INS_sve_fmul, INS_sve_fmul}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) HARDWARE_INTRINSIC(Sve, MultiplyAdd, -1, -1, {INS_sve_mla, INS_sve_mla, INS_sve_mla, INS_sve_mla, INS_sve_mla, INS_sve_mla, INS_sve_mla, INS_sve_mla, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation|HW_Flag_FmaIntrinsic|HW_Flag_SpecialCodeGen) HARDWARE_INTRINSIC(Sve, MultiplyAddRotateComplex, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_fcmla, INS_sve_fcmla}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_HasImmediateOperand) @@ -225,7 +225,7 @@ HARDWARE_INTRINSIC(Sve, MultiplySubtract, HARDWARE_INTRINSIC(Sve, Negate, -1, -1, {INS_sve_neg, INS_invalid, INS_sve_neg, INS_invalid, INS_sve_neg, INS_invalid, INS_sve_neg, INS_invalid, INS_sve_fneg, INS_sve_fneg}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) HARDWARE_INTRINSIC(Sve, Not, -1, -1, {INS_sve_not, INS_sve_not, INS_sve_not, INS_sve_not, INS_sve_not, INS_sve_not, INS_sve_not, INS_sve_not, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation) HARDWARE_INTRINSIC(Sve, Or, -1, -1, {INS_sve_orr, INS_sve_orr, INS_sve_orr, INS_sve_orr, INS_sve_orr, INS_sve_orr, INS_sve_orr, INS_sve_orr, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_OptionalEmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) -HARDWARE_INTRINSIC(Sve, OrAcross, -1, -1, {INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) +HARDWARE_INTRINSIC(Sve, OrAcross, -1, -1, {INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_sve_orv, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ReduceOperation) HARDWARE_INTRINSIC(Sve, PopCount, -1, -1, {INS_sve_cnt, INS_sve_cnt, INS_sve_cnt, INS_sve_cnt, INS_sve_cnt, INS_sve_cnt, INS_sve_cnt, INS_sve_cnt, INS_sve_cnt, INS_sve_cnt}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_BaseTypeFromFirstArg|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) HARDWARE_INTRINSIC(Sve, PrefetchBytes, -1, 3, {INS_invalid, INS_sve_prfb, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_Special, HW_Flag_Scalable|HW_Flag_SpecialCodeGen|HW_Flag_ExplicitMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_BaseTypeFromFirstArg|HW_Flag_HasImmediateOperand|HW_Flag_SpecialSideEffect_Other) HARDWARE_INTRINSIC(Sve, PrefetchInt16, -1, 3, {INS_invalid, INS_invalid, INS_invalid, INS_sve_prfh, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_Special, HW_Flag_Scalable|HW_Flag_SpecialCodeGen|HW_Flag_ExplicitMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_BaseTypeFromFirstArg|HW_Flag_HasImmediateOperand|HW_Flag_SpecialSideEffect_Other) @@ -293,7 +293,7 @@ HARDWARE_INTRINSIC(Sve, UnzipEven, HARDWARE_INTRINSIC(Sve, UnzipOdd, -1, 2, {INS_sve_uzp2, INS_sve_uzp2, INS_sve_uzp2, INS_sve_uzp2, INS_sve_uzp2, INS_sve_uzp2, INS_sve_uzp2, INS_sve_uzp2, INS_sve_uzp2, INS_sve_uzp2}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_SpecialCodeGen) HARDWARE_INTRINSIC(Sve, VectorTableLookup, -1, 2, {INS_sve_tbl, INS_sve_tbl, INS_sve_tbl, INS_sve_tbl, INS_sve_tbl, INS_sve_tbl, INS_sve_tbl, INS_sve_tbl, INS_sve_tbl, INS_sve_tbl}, HW_Category_SIMD, HW_Flag_Scalable) HARDWARE_INTRINSIC(Sve, Xor, -1, -1, {INS_sve_eor, INS_sve_eor, INS_sve_eor, INS_sve_eor, INS_sve_eor, INS_sve_eor, INS_sve_eor, INS_sve_eor, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_OptionalEmbeddedMaskedOperation|HW_Flag_HasRMWSemantics|HW_Flag_LowMaskedOperation) -HARDWARE_INTRINSIC(Sve, XorAcross, -1, -1, {INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) +HARDWARE_INTRINSIC(Sve, XorAcross, -1, -1, {INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_sve_eorv, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation|HW_Flag_ReduceOperation) HARDWARE_INTRINSIC(Sve, ZeroExtend16, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_uxth, INS_invalid, INS_sve_uxth, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) HARDWARE_INTRINSIC(Sve, ZeroExtend32, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_sve_uxtw, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) HARDWARE_INTRINSIC(Sve, ZeroExtend8, -1, -1, {INS_invalid, INS_invalid, INS_invalid, INS_sve_uxtb, INS_invalid, INS_sve_uxtb, INS_invalid, INS_sve_uxtb, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_Scalable|HW_Flag_EmbeddedMaskedOperation|HW_Flag_LowMaskedOperation) diff --git a/src/coreclr/jit/lowerarmarch.cpp b/src/coreclr/jit/lowerarmarch.cpp index 978c066be998a5..a74bb3651c88f9 100644 --- a/src/coreclr/jit/lowerarmarch.cpp +++ b/src/coreclr/jit/lowerarmarch.cpp @@ -4055,9 +4055,10 @@ GenTree* Lowering::LowerHWIntrinsicCndSel(GenTreeHWIntrinsic* cndSelNode) NamedIntrinsic nestedOp2Id = nestedOp2->AsHWIntrinsic()->GetHWIntrinsicId(); // If the nested op uses Pg/Z, then inactive lanes will result in zeros, so can only transform if - // op3 is all zeros. + // op3 is all zeros. Such a Csel operation is absorbed into the instruction when emitted. Skip this optimisation + // when the nestedOp is a reduce operation. - if (nestedOp1->IsMaskAllBitsSet() && + if (nestedOp1->IsMaskAllBitsSet() && !HWIntrinsicInfo::IsReduceOperation(nestedOp2Id) && (!HWIntrinsicInfo::IsZeroingMaskedOperation(nestedOp2Id) || op3->IsVectorZero())) { GenTree* nestedOp2 = nestedCndSel->Op(2); diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 622ae2b6757ca7..aaf9c05f121d87 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -90,9 +90,6 @@ SPTR_IMPL(SystemDomain, SystemDomain, m_pSystemDomain); #ifndef DACCESS_COMPILE -// Base Domain Statics -CrstStatic BaseDomain::m_MethodTableExposedClassObjectCrst; - // System Domain Statics GlobalStringLiteralMap* SystemDomain::m_pGlobalStringLiteralMap = NULL; FrozenObjectHeapManager* SystemDomain::m_FrozenObjectHeapManager = NULL; @@ -104,7 +101,7 @@ CrstStatic SystemDomain::m_SystemDomainCrst; CrstStatic SystemDomain::m_DelayedUnloadCrst; // Constructor for the PinnedHeapHandleBucket class. -PinnedHeapHandleBucket::PinnedHeapHandleBucket(PinnedHeapHandleBucket *pNext, PTRARRAYREF pinnedHandleArrayObj, DWORD size, BaseDomain *pDomain) +PinnedHeapHandleBucket::PinnedHeapHandleBucket(PinnedHeapHandleBucket *pNext, PTRARRAYREF pinnedHandleArrayObj, DWORD size) : m_pNext(pNext) , m_ArraySize(size) , m_CurrentPos(0) @@ -115,7 +112,6 @@ PinnedHeapHandleBucket::PinnedHeapHandleBucket(PinnedHeapHandleBucket *pNext, PT THROWS; GC_NOTRIGGER; MODE_COOPERATIVE; - PRECONDITION(CheckPointer(pDomain)); INJECT_FAULT(COMPlusThrowOM();); } CONTRACTL_END; @@ -125,7 +121,7 @@ PinnedHeapHandleBucket::PinnedHeapHandleBucket(PinnedHeapHandleBucket *pNext, PT m_pArrayDataPtr = (OBJECTREF *)pinnedHandleArrayObj->GetDataPtr(); // Store the array in a strong handle to keep it alive. - m_hndHandleArray = pDomain->CreateStrongHandle((OBJECTREF)pinnedHandleArrayObj); + m_hndHandleArray = AppDomain::GetCurrentDomain()->CreateStrongHandle((OBJECTREF)pinnedHandleArrayObj); } @@ -215,9 +211,8 @@ void PinnedHeapHandleBucket::EnumStaticGCRefs(promote_func* fn, ScanContext* sc) #define MAX_BUCKETSIZE (16384 - 4) // Constructor for the PinnedHeapHandleTable class. -PinnedHeapHandleTable::PinnedHeapHandleTable(BaseDomain *pDomain, DWORD InitialBucketSize) +PinnedHeapHandleTable::PinnedHeapHandleTable(DWORD InitialBucketSize) : m_pHead(NULL) -, m_pDomain(pDomain) , m_NextBucketSize(InitialBucketSize) , m_pFreeSearchHint(NULL) , m_cEmbeddedFree(0) @@ -227,7 +222,6 @@ PinnedHeapHandleTable::PinnedHeapHandleTable(BaseDomain *pDomain, DWORD InitialB THROWS; GC_TRIGGERS; MODE_COOPERATIVE; - PRECONDITION(CheckPointer(pDomain)); INJECT_FAULT(COMPlusThrowOM();); } CONTRACTL_END; @@ -359,7 +353,7 @@ OBJECTREF* PinnedHeapHandleTable::AllocateHandles(DWORD nRequested) m_pHead->ConsumeRemaining(); } - m_pHead = new PinnedHeapHandleBucket(m_pHead, pinnedHandleArrayObj, newBucketSize, m_pDomain); + m_pHead = new PinnedHeapHandleBucket(m_pHead, pinnedHandleArrayObj, newBucketSize); // we already computed nextBucketSize to be double the previous size above, but it is possible that // other threads increased m_NextBucketSize while the lock was unheld. We want to ensure @@ -439,10 +433,6 @@ void PinnedHeapHandleTable::EnumStaticGCRefs(promote_func* fn, ScanContext* sc) //***************************************************************************** // BaseDomain //***************************************************************************** -void BaseDomain::Attach() -{ - m_MethodTableExposedClassObjectCrst.Init(CrstMethodTableExposedObject); -} BaseDomain::BaseDomain() { @@ -459,29 +449,8 @@ BaseDomain::BaseDomain() // Make sure the container is set to NULL so that it gets loaded when it is used. m_pPinnedHeapHandleTable = NULL; - - // Note that m_handleStore is overridden by app domains - m_handleStore = GCHandleUtilities::GetGCHandleManager()->GetGlobalHandleStore(); } //BaseDomain::BaseDomain -//***************************************************************************** -void BaseDomain::Init() -{ - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACTL_END; - - // - // Initialize the domain locks - // - m_crstLoaderAllocatorReferences.Init(CrstLoaderAllocatorReferences); -} - #undef LOADERHEAP_PROFILE_COUNTER void AppDomain::ClearBinderContext() @@ -733,7 +702,7 @@ void BaseDomain::InitPinnedHeapHandleTable() } CONTRACTL_END; - PinnedHeapHandleTable* pTable = new PinnedHeapHandleTable(this, STATIC_OBJECT_TABLE_BUCKET_SIZE); + PinnedHeapHandleTable* pTable = new PinnedHeapHandleTable(STATIC_OBJECT_TABLE_BUCKET_SIZE); if(InterlockedCompareExchangeT(&m_pPinnedHeapHandleTable, pTable, NULL) != NULL) { // another thread beat us to initializing the field, delete our copy @@ -797,9 +766,6 @@ void SystemDomain::Attach() "Created system domain at %p\n", m_pSystemDomain)); - // We need to initialize the memory pools etc. for the system domain. - m_pSystemDomain->BaseDomain::Init(); // Setup the memory heaps - // Create the one and only app domain AppDomain::Create(); @@ -869,7 +835,7 @@ void SystemDomain::PreallocateSpecialObjects() _ASSERTE(g_pPreallocatedSentinelObject == NULL); OBJECTREF pPreallocatedSentinelObject = AllocateObject(g_pObjectClass); - g_pPreallocatedSentinelObject = CreatePinningHandle( pPreallocatedSentinelObject ); + g_pPreallocatedSentinelObject = AppDomain::GetCurrentDomain()->CreatePinningHandle( pPreallocatedSentinelObject ); } void SystemDomain::CreatePreallocatedExceptions() @@ -887,27 +853,30 @@ void SystemDomain::CreatePreallocatedExceptions() pOutOfMemory->SetHResult(COR_E_OUTOFMEMORY); pOutOfMemory->SetXCode(EXCEPTION_COMPLUS); _ASSERTE(g_pPreallocatedOutOfMemoryException == NULL); - g_pPreallocatedOutOfMemoryException = CreateHandle(pOutOfMemory); + g_pPreallocatedOutOfMemoryException = AppDomain::GetCurrentDomain()->CreateHandle(pOutOfMemory); EXCEPTIONREF pStackOverflow = (EXCEPTIONREF)AllocateObject(g_pStackOverflowExceptionClass); pStackOverflow->SetHResult(COR_E_STACKOVERFLOW); pStackOverflow->SetXCode(EXCEPTION_COMPLUS); _ASSERTE(g_pPreallocatedStackOverflowException == NULL); - g_pPreallocatedStackOverflowException = CreateHandle(pStackOverflow); + g_pPreallocatedStackOverflowException = AppDomain::GetCurrentDomain()->CreateHandle(pStackOverflow); EXCEPTIONREF pExecutionEngine = (EXCEPTIONREF)AllocateObject(g_pExecutionEngineExceptionClass); pExecutionEngine->SetHResult(COR_E_EXECUTIONENGINE); pExecutionEngine->SetXCode(EXCEPTION_COMPLUS); _ASSERTE(g_pPreallocatedExecutionEngineException == NULL); - g_pPreallocatedExecutionEngineException = CreateHandle(pExecutionEngine); + g_pPreallocatedExecutionEngineException = AppDomain::GetCurrentDomain()->CreateHandle(pExecutionEngine); } void SystemDomain::Init() { STANDARD_VM_CONTRACT; + // The AppDomain should have already been created + _ASSERTE(AppDomain::GetCurrentDomain() != NULL); + HRESULT hr = S_OK; #ifdef _DEBUG @@ -927,10 +896,6 @@ void SystemDomain::Init() )); #endif // _DEBUG - // The base domain is initialized in SystemDomain::Attach() - // to allow stub caches to use the memory pool. Do not - // initialize it here! - m_pSystemPEAssembly = NULL; m_pSystemAssembly = NULL; @@ -1537,16 +1502,14 @@ void AppDomain::Create() { STANDARD_VM_CONTRACT; - AppDomainRefHolder pDomain(new AppDomain()); + _ASSERTE(m_pTheAppDomain == NULL); + AppDomainRefHolder pDomain(new AppDomain()); pDomain->Init(); - pDomain->SetStage(AppDomain::STAGE_OPEN); pDomain->CreateDefaultBinder(); - pDomain.SuppressRelease(); - - m_pTheAppDomain = pDomain; + m_pTheAppDomain = pDomain.Extract(); LOG((LF_CLASSLOADER | LF_CORDB, LL_INFO10, @@ -1760,17 +1723,15 @@ void AppDomain::Init() m_crstAssemblyList.Init(CrstAssemblyList, CrstFlags( CRST_GC_NOTRIGGER_WHEN_TAKEN | CRST_DEBUGGER_THREAD | CRST_TAKEN_DURING_SHUTDOWN)); - BaseDomain::Init(); + m_crstLoaderAllocatorReferences.Init(CrstLoaderAllocatorReferences); + m_MethodTableExposedClassObjectCrst.Init(CrstMethodTableExposedObject); // Set up the binding caches m_AssemblyCache.Init(&m_DomainCacheCrst, GetHighFrequencyHeap()); m_MemoryPressure = 0; - - // Default domain reuses the handletablemap that was created during EEStartup m_handleStore = GCHandleUtilities::GetGCHandleManager()->GetGlobalHandleStore(); - if (!m_handleStore) { COMPlusThrowOM(); diff --git a/src/coreclr/vm/appdomain.hpp b/src/coreclr/vm/appdomain.hpp index 7fa872674fef68..b2fcc9d58696ca 100644 --- a/src/coreclr/vm/appdomain.hpp +++ b/src/coreclr/vm/appdomain.hpp @@ -68,7 +68,7 @@ class PinnedHeapHandleBucket { public: // Constructor and desctructor. - PinnedHeapHandleBucket(PinnedHeapHandleBucket *pNext, PTRARRAYREF pinnedHandleArrayObj, DWORD size, BaseDomain *pDomain); + PinnedHeapHandleBucket(PinnedHeapHandleBucket *pNext, PTRARRAYREF pinnedHandleArrayObj, DWORD size); ~PinnedHeapHandleBucket(); // This returns the next bucket. @@ -123,7 +123,7 @@ class PinnedHeapHandleTable { public: // Constructor and desctructor. - PinnedHeapHandleTable(BaseDomain *pDomain, DWORD InitialBucketSize); + PinnedHeapHandleTable(DWORD InitialBucketSize); ~PinnedHeapHandleTable(); // Allocate handles from the pinned heap handle table. @@ -141,9 +141,6 @@ class PinnedHeapHandleTable // synchronized by m_Crst PinnedHeapHandleBucket *m_pHead; - // We need to know the containing domain so we know where to allocate handles - BaseDomain *m_pDomain; - // The size of the PinnedHeapHandleBucket. // synchronized by m_Crst DWORD m_NextBucketSize; @@ -456,16 +453,12 @@ class BaseDomain class AssemblyIterator; friend class AssemblyIterator; - // Static initialization. - static void Attach(); - //**************************************************************************************** // // Initialization/shutdown routines for every instance of an BaseDomain. BaseDomain(); virtual ~BaseDomain() {} - void Init(); virtual BOOL IsAppDomain() { LIMITED_METHOD_DAC_CONTRACT; return FALSE; } @@ -486,111 +479,15 @@ class BaseDomain // will be properly serialized) OBJECTREF *AllocateObjRefPtrsInLargeTable(int nRequested, DynamicStaticsInfo* pStaticsInfo = NULL, MethodTable *pMTToFillWithStaticBoxes = NULL, bool isClassInitdeByUpdatingStaticPointer = false); - //**************************************************************************************** - // Handles - -#if !defined(DACCESS_COMPILE) - IGCHandleStore* GetHandleStore() - { - LIMITED_METHOD_CONTRACT; - return m_handleStore; - } - - OBJECTHANDLE CreateTypedHandle(OBJECTREF object, HandleType type) - { - WRAPPER_NO_CONTRACT; - return ::CreateHandleCommon(m_handleStore, object, type); - } - - OBJECTHANDLE CreateHandle(OBJECTREF object) - { - WRAPPER_NO_CONTRACT; - CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL) - return ::CreateHandle(m_handleStore, object); - } - - OBJECTHANDLE CreateWeakHandle(OBJECTREF object) - { - WRAPPER_NO_CONTRACT; - return ::CreateWeakHandle(m_handleStore, object); - } - - OBJECTHANDLE CreateShortWeakHandle(OBJECTREF object) - { - WRAPPER_NO_CONTRACT; - return ::CreateShortWeakHandle(m_handleStore, object); - } - - OBJECTHANDLE CreateLongWeakHandle(OBJECTREF object) - { - WRAPPER_NO_CONTRACT; - CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL) - return ::CreateLongWeakHandle(m_handleStore, object); - } - - OBJECTHANDLE CreateStrongHandle(OBJECTREF object) - { - WRAPPER_NO_CONTRACT; - return ::CreateStrongHandle(m_handleStore, object); - } - - OBJECTHANDLE CreatePinningHandle(OBJECTREF object) - { - WRAPPER_NO_CONTRACT; - return ::CreatePinningHandle(m_handleStore, object); - } - - OBJECTHANDLE CreateWeakInteriorHandle(OBJECTREF object, void* pInteriorPointerLocation) - { - WRAPPER_NO_CONTRACT; - return ::CreateWeakInteriorHandle(m_handleStore, object, pInteriorPointerLocation); - } - -#if defined(FEATURE_COMINTEROP) || defined(FEATURE_COMWRAPPERS) - OBJECTHANDLE CreateRefcountedHandle(OBJECTREF object) - { - WRAPPER_NO_CONTRACT; - return ::CreateRefcountedHandle(m_handleStore, object); - } -#endif // FEATURE_COMINTEROP || FEATURE_COMWRAPPERS - - OBJECTHANDLE CreateDependentHandle(OBJECTREF primary, OBJECTREF secondary) - { - WRAPPER_NO_CONTRACT; - return ::CreateDependentHandle(m_handleStore, primary, secondary); - } - -#endif // DACCESS_COMPILE - - CrstExplicitInit * GetLoaderAllocatorReferencesLock() - { - LIMITED_METHOD_CONTRACT; - return &m_crstLoaderAllocatorReferences; - } - - static CrstStatic* GetMethodTableExposedClassObjectLock() - { - LIMITED_METHOD_CONTRACT; - return &m_MethodTableExposedClassObjectCrst; - } - protected: //**************************************************************************************** // Helper method to initialize the large heap handle table. void InitPinnedHeapHandleTable(); - // Used to protect the reference lists in the collectible loader allocators attached to this appdomain - CrstExplicitInit m_crstLoaderAllocatorReferences; - - IGCHandleStore* m_handleStore; - // The pinned heap handle table. PinnedHeapHandleTable *m_pPinnedHeapHandleTable; - // Protects allocation of slot IDs for thread statics - static CrstStatic m_MethodTableExposedClassObjectCrst; - #ifdef DACCESS_COMPILE public: virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags, bool enumThis) = 0; @@ -894,6 +791,18 @@ class AppDomain : public BaseDomain return &m_crstGenericDictionaryExpansionLock; } + CrstExplicitInit* GetLoaderAllocatorReferencesLock() + { + LIMITED_METHOD_CONTRACT; + return &m_crstLoaderAllocatorReferences; + } + + CrstExplicitInit* GetMethodTableExposedClassObjectLock() + { + LIMITED_METHOD_CONTRACT; + return &m_MethodTableExposedClassObjectCrst; + } + private: JitListLock m_JITLock; ListLock m_ClassInitLock; @@ -901,6 +810,76 @@ class AppDomain : public BaseDomain ListLock m_NativeTypeLoadLock; CrstExplicitInit m_crstGenericDictionaryExpansionLock; + // Used to protect the reference lists in the collectible loader allocators attached to the app domain + CrstExplicitInit m_crstLoaderAllocatorReferences; + + // Protects allocation of slot IDs for thread statics + CrstExplicitInit m_MethodTableExposedClassObjectCrst; + +#if !defined(DACCESS_COMPILE) +public: // Handles + IGCHandleStore* GetHandleStore() + { + LIMITED_METHOD_CONTRACT; + return m_handleStore; + } + + OBJECTHANDLE CreateTypedHandle(OBJECTREF object, HandleType type) + { + WRAPPER_NO_CONTRACT; + return ::CreateHandleCommon(m_handleStore, object, type); + } + + OBJECTHANDLE CreateHandle(OBJECTREF object) + { + WRAPPER_NO_CONTRACT; + CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL) + return ::CreateHandle(m_handleStore, object); + } + + OBJECTHANDLE CreateLongWeakHandle(OBJECTREF object) + { + WRAPPER_NO_CONTRACT; + CONDITIONAL_CONTRACT_VIOLATION(ModeViolation, object == NULL) + return ::CreateLongWeakHandle(m_handleStore, object); + } + + OBJECTHANDLE CreateStrongHandle(OBJECTREF object) + { + WRAPPER_NO_CONTRACT; + return ::CreateStrongHandle(m_handleStore, object); + } + + OBJECTHANDLE CreatePinningHandle(OBJECTREF object) + { + WRAPPER_NO_CONTRACT; + return ::CreatePinningHandle(m_handleStore, object); + } + + OBJECTHANDLE CreateWeakInteriorHandle(OBJECTREF object, void* pInteriorPointerLocation) + { + WRAPPER_NO_CONTRACT; + return ::CreateWeakInteriorHandle(m_handleStore, object, pInteriorPointerLocation); + } + +#if defined(FEATURE_COMINTEROP) || defined(FEATURE_COMWRAPPERS) + OBJECTHANDLE CreateRefcountedHandle(OBJECTREF object) + { + WRAPPER_NO_CONTRACT; + return ::CreateRefcountedHandle(m_handleStore, object); + } +#endif // FEATURE_COMINTEROP || FEATURE_COMWRAPPERS + + OBJECTHANDLE CreateDependentHandle(OBJECTREF primary, OBJECTREF secondary) + { + WRAPPER_NO_CONTRACT; + return ::CreateDependentHandle(m_handleStore, primary, secondary); + } +#endif // DACCESS_COMPILE + +private: + IGCHandleStore* m_handleStore; + protected: // Multi-thread safe access to the list of assemblies class DomainAssemblyList diff --git a/src/coreclr/vm/ceemain.cpp b/src/coreclr/vm/ceemain.cpp index 1b309fef76eab7..38c47a9749684f 100644 --- a/src/coreclr/vm/ceemain.cpp +++ b/src/coreclr/vm/ceemain.cpp @@ -828,11 +828,9 @@ void EEStartupHelper() VirtualCallStubManager::InitStatic(); - // Setup the domains. Threads are started in a default domain. // Static initialization - BaseDomain::Attach(); SystemDomain::Attach(); // Start up the EE initializing all the global variables @@ -844,7 +842,6 @@ void EEStartupHelper() JitHost::Init(); - #ifndef TARGET_UNIX if (!RegisterOutOfProcessWatsonCallbacks()) { @@ -946,7 +943,6 @@ void EEStartupHelper() MethodDesc::Init(); #endif - Assembly::Initialize(); SystemDomain::System()->Init(); diff --git a/src/coreclr/vm/loaderallocator.cpp b/src/coreclr/vm/loaderallocator.cpp index 1ed751ed22dd80..cd5ca66f660fa4 100644 --- a/src/coreclr/vm/loaderallocator.cpp +++ b/src/coreclr/vm/loaderallocator.cpp @@ -200,14 +200,14 @@ BOOL LoaderAllocator::CheckAddReference_Unlocked(LoaderAllocator *pOtherLA) { THROWS; MODE_ANY; + PRECONDITION(pOtherLA != this); + PRECONDITION(IsCollectible()); + PRECONDITION(Id()->GetType() == LAT_Assembly); } CONTRACTL_END; - // This must be checked before calling this function - _ASSERTE(pOtherLA != this); - // This function requires the that loader allocator lock have been taken. - _ASSERTE(GetDomain()->GetLoaderAllocatorReferencesLock()->OwnedByCurrentThread()); + _ASSERTE(GetAppDomain()->GetLoaderAllocatorReferencesLock()->OwnedByCurrentThread()); if (m_LoaderAllocatorReferences.Lookup(pOtherLA) == NULL) { @@ -238,7 +238,7 @@ BOOL LoaderAllocator::EnsureReference(LoaderAllocator *pOtherLA) CONTRACTL_END; // Check if this lock can be taken in all places that the function is called - _ASSERTE(GetDomain()->GetLoaderAllocatorReferencesLock()->Debug_CanTake()); + _ASSERTE(GetAppDomain()->GetLoaderAllocatorReferencesLock()->Debug_CanTake()); if (!IsCollectible()) return FALSE; @@ -249,7 +249,8 @@ BOOL LoaderAllocator::EnsureReference(LoaderAllocator *pOtherLA) if (!pOtherLA->IsCollectible()) return FALSE; - CrstHolder ch(GetDomain()->GetLoaderAllocatorReferencesLock()); + _ASSERTE(Id()->GetType() == LAT_Assembly); + CrstHolder ch(GetAppDomain()->GetLoaderAllocatorReferencesLock()); return CheckAddReference_Unlocked(pOtherLA); } @@ -265,12 +266,13 @@ BOOL LoaderAllocator::EnsureInstantiation(Module *pDefiningModule, Instantiation BOOL fNewReferenceNeeded = FALSE; // Check if this lock can be taken in all places that the function is called - _ASSERTE(GetDomain()->GetLoaderAllocatorReferencesLock()->Debug_CanTake()); + _ASSERTE(GetAppDomain()->GetLoaderAllocatorReferencesLock()->Debug_CanTake()); if (!IsCollectible()) return FALSE; - CrstHolder ch(GetDomain()->GetLoaderAllocatorReferencesLock()); + _ASSERTE(Id()->GetType() == LAT_Assembly); + CrstHolder ch(GetAppDomain()->GetLoaderAllocatorReferencesLock()); if (pDefiningModule != NULL) { @@ -1022,7 +1024,7 @@ void LoaderAllocator::SetupManagedTracking(LOADERALLOCATORREF * pKeepLoaderAlloc initLoaderAllocator.Call(args); - m_hLoaderAllocatorObjectHandle = GetDomain()->CreateLongWeakHandle(*pKeepLoaderAllocatorAlive); + m_hLoaderAllocatorObjectHandle = AppDomain::GetCurrentDomain()->CreateLongWeakHandle(*pKeepLoaderAllocatorAlive); RegisterHandleForCleanup(m_hLoaderAllocatorObjectHandle); } diff --git a/src/coreclr/vm/stringliteralmap.cpp b/src/coreclr/vm/stringliteralmap.cpp index 168ab5503f4ca9..ba1937f4f3eb06 100644 --- a/src/coreclr/vm/stringliteralmap.cpp +++ b/src/coreclr/vm/stringliteralmap.cpp @@ -298,7 +298,7 @@ GlobalStringLiteralMap::GlobalStringLiteralMap() : m_StringToEntryHashTable(NULL) , m_MemoryPool(NULL) , m_HashTableCrstGlobal(CrstGlobalStrLiteralMap) -, m_PinnedHeapHandleTable(SystemDomain::System(), GLOBAL_STRING_TABLE_BUCKET_SIZE) +, m_PinnedHeapHandleTable(GLOBAL_STRING_TABLE_BUCKET_SIZE) { CONTRACTL { diff --git a/src/coreclr/vm/typehandle.cpp b/src/coreclr/vm/typehandle.cpp index d5fea81cb4841d..5116f1aec0cfc3 100644 --- a/src/coreclr/vm/typehandle.cpp +++ b/src/coreclr/vm/typehandle.cpp @@ -342,7 +342,7 @@ void TypeHandle::AllocateManagedClassObject(RUNTIMETYPEHANDLE* pDest) { // Allocate RuntimeType on a frozen segment // Take a lock here since we don't want to allocate redundant objects which won't be collected - CrstHolder exposedClassLock(AppDomain::GetMethodTableExposedClassObjectLock()); + CrstHolder exposedClassLock(AppDomain::GetCurrentDomain()->GetMethodTableExposedClassObjectLock()); if (VolatileLoad(pDest) == 0) { diff --git a/src/libraries/Common/src/Interop/Interop.Ldap.cs b/src/libraries/Common/src/Interop/Interop.Ldap.cs index 4020dd0fe89bbb..90c0ba997cd962 100644 --- a/src/libraries/Common/src/Interop/Interop.Ldap.cs +++ b/src/libraries/Common/src/Interop/Interop.Ldap.cs @@ -182,14 +182,14 @@ internal struct LDAP_TIMEVAL [StructLayout(LayoutKind.Sequential)] internal sealed class BerVal { - public int bv_len; - public IntPtr bv_val = IntPtr.Zero; + public CLong bv_len; + public nint bv_val = nint.Zero; #if NET [CustomMarshaller(typeof(BerVal), MarshalMode.ManagedToUnmanagedIn, typeof(PinningMarshaller))] internal static unsafe class PinningMarshaller { - public static ref int GetPinnableReference(BerVal managed) => ref (managed is null ? ref Unsafe.NullRef() : ref managed.bv_len); + public static ref CLong GetPinnableReference(BerVal managed) => ref (managed is null ? ref Unsafe.NullRef() : ref managed.bv_len); // All usages in our currently supported scenarios will always go through GetPinnableReference public static int* ConvertToUnmanaged(BerVal _) => throw new UnreachableException(); diff --git a/src/libraries/Fuzzing/DotnetFuzzing/Dictionaries/assemblynameinfo.dict b/src/libraries/Fuzzing/DotnetFuzzing/Dictionaries/assemblynameinfo.dict new file mode 100644 index 00000000000000..f15a4c6c721737 --- /dev/null +++ b/src/libraries/Fuzzing/DotnetFuzzing/Dictionaries/assemblynameinfo.dict @@ -0,0 +1,16 @@ +"MyAssemblyName, Version=1.0.0.0, PublicKeyToken=b77a5c561934e089" +"System.IO.Pipelines.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb" +"System.IO.Pipelines.Tests, PublicKey=null" +"Abc, ProcessorArchitecture=X86" +"Abc, ProcessorArchitecture=Amd64" +"Abc, ProcessorArchitecture=Arm" +"Abc, ProcessorArchitecture=MSIL" +"Abc, ContentType=WindowsRuntime" +"Abc, Retargetable=Yes" +"Esc\\[aped" +"MyAssemblyName, Version=1.0.0.0, PublicKeyToken=b77a5c561934e089", "MyAssemblyName, Version=1.0.0.0, PublicKeyToken=b77a5c561934e089" +"MyAssemblyName, Version=1.0.0.0, PublicKey=00000000000000000400000000000000", "MyAssemblyName, Version=1.0.0.0, PublicKeyToken=b77a5c561934e089" +"TerraFX.Interop.Windows, PublicKey=002400000c800000940000000602000000240000525341310004000001000100897039f5ff762b25b9ba982c3f5836c34e299279c33df505bf806a07bccdf0e1216e661943f557b954cb18422ed522a5b3174b85385052677f39c4ce19f30a1ddbaa507054bc5943461651f396afc612cd80419c5ee2b5277571ff65f51d14ba99e4e4196de0f393e89850a465f019dbdc365ed5e81bbafe1370f54efd254ba8, TerraFX.Interop.Windows, PublicKeyToken=35b01b53313a6f7e" +"aaaa, language=en-en" +"aaaa, foo=bar, foo=baz" +"aa/name " \ No newline at end of file diff --git a/src/libraries/Fuzzing/DotnetFuzzing/Fuzzers/AssemblyNameInfoFuzzer.cs b/src/libraries/Fuzzing/DotnetFuzzing/Fuzzers/AssemblyNameInfoFuzzer.cs index e4ce320c40f67b..9ce1bd255c7b69 100644 --- a/src/libraries/Fuzzing/DotnetFuzzing/Fuzzers/AssemblyNameInfoFuzzer.cs +++ b/src/libraries/Fuzzing/DotnetFuzzing/Fuzzers/AssemblyNameInfoFuzzer.cs @@ -4,6 +4,7 @@ using System.Buffers; using System.Reflection.Metadata; using System.Runtime.InteropServices; +using System.Text; namespace DotnetFuzzing.Fuzzers { @@ -13,9 +14,12 @@ internal sealed class AssemblyNameInfoFuzzer : IFuzzer public string[] TargetCoreLibPrefixes => []; + public string Dictionary => "assemblynameinfo.dict"; + public void FuzzTarget(ReadOnlySpan bytes) { - ReadOnlySpan chars = MemoryMarshal.Cast(bytes); + Span chars = new char[Encoding.UTF8.GetCharCount(bytes)]; + Encoding.UTF8.GetChars(bytes, chars); using PooledBoundedMemory inputPoisonedBefore = PooledBoundedMemory.Rent(chars, PoisonPagePlacement.Before); using PooledBoundedMemory inputPoisonedAfter = PooledBoundedMemory.Rent(chars, PoisonPagePlacement.After); @@ -26,19 +30,51 @@ public void FuzzTarget(ReadOnlySpan bytes) private static void Test(PooledBoundedMemory inputPoisoned) { - bool shouldSucceed = AssemblyNameInfo.TryParse(inputPoisoned.Span, out _); - - try + if (AssemblyNameInfo.TryParse(inputPoisoned.Span, out AssemblyNameInfo? fromTryParse)) { - AssemblyNameInfo.Parse(inputPoisoned.Span); + AssemblyNameInfo fromParse = AssemblyNameInfo.Parse(inputPoisoned.Span); + + Assert.Equal(fromTryParse.Name, fromParse.Name); + Assert.Equal(fromTryParse.FullName, fromParse.FullName); + Assert.Equal(fromTryParse.CultureName, fromParse.CultureName); + Assert.Equal(fromTryParse.Flags, fromParse.Flags); + Assert.Equal(fromTryParse.Version, fromParse.Version); + Assert.SequenceEqual(fromTryParse.PublicKeyOrToken.AsSpan(), fromParse.PublicKeyOrToken.AsSpan()); + + Assert.Equal(fromTryParse.ToAssemblyName().Name, fromParse.ToAssemblyName().Name); + Assert.Equal(fromTryParse.ToAssemblyName().Version, fromParse.ToAssemblyName().Version); + Assert.Equal(fromTryParse.ToAssemblyName().ContentType, fromParse.ToAssemblyName().ContentType); + Assert.Equal(fromTryParse.ToAssemblyName().CultureName, fromParse.ToAssemblyName().CultureName); + + Assert.Equal(fromTryParse.Name, fromParse.ToAssemblyName().Name); + Assert.Equal(fromTryParse.CultureName, fromParse.ToAssemblyName().CultureName); + Assert.Equal(fromTryParse.Version, fromParse.ToAssemblyName().Version); + + // AssemblyNameInfo.FullName can be different than AssemblyName.FullName: + // AssemblyNameInfo includes public key, AssemblyName only its Token. + + try + { + Assert.Equal(fromTryParse.ToAssemblyName().FullName, fromParse.ToAssemblyName().FullName); + } + catch (System.Security.SecurityException) + { + // AssemblyName.FullName performs public key validation, AssemblyNameInfo does not (on purpose). + } } - catch (ArgumentException) + else { - Assert.Equal(false, shouldSucceed); - return; - } + try + { + _ = AssemblyNameInfo.Parse(inputPoisoned.Span); + } + catch (ArgumentException) + { + return; + } - Assert.Equal(true, shouldSucceed); + throw new Exception("Parsing was supposed to fail!"); + } } } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/CoreBindingHelpers.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/CoreBindingHelpers.cs index 3433544bf9ee74..10dcb779a928dd 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/CoreBindingHelpers.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/CoreBindingHelpers.cs @@ -968,15 +968,31 @@ private void EmitBindingLogicForComplexMember( initKind = InitializationKind.SimpleAssignment; } - Action? writeOnSuccess = !canSet - ? null - : bindedValueIdentifier => - { - if (memberAccessExpr != bindedValueIdentifier) - { - _writer.WriteLine($"{memberAccessExpr} = {bindedValueIdentifier};"); - } - }; + Action? writeOnSuccess = !canSet + ? null + : (bindedValueIdentifier, tempIdentifierStoringExpr) => + { + if (memberAccessExpr != bindedValueIdentifier) + { + _writer.WriteLine($"{memberAccessExpr} = {bindedValueIdentifier};"); + + if (tempIdentifierStoringExpr is not null) + { + _writer.WriteLine($"{tempIdentifierStoringExpr}"); + } + + if (member.CanGet && _typeIndex.CanInstantiate(effectiveMemberType)) + { + EmitEndBlock(); + EmitStartBlock("else"); + _writer.WriteLine($"{memberAccessExpr} = {memberAccessExpr};"); + } + } + else + { + _writer.WriteLine($"{tempIdentifierStoringExpr}"); + } + }; EmitBindingLogic( effectiveMemberType, @@ -994,7 +1010,7 @@ private void EmitBindingLogic( string configArgExpr, InitializationKind initKind, ValueDefaulting valueDefaulting, - Action? writeOnSuccess = null) + Action? writeOnSuccess = null) { if (!_typeIndex.HasBindableMembers(type)) { @@ -1022,15 +1038,14 @@ private void EmitBindingLogic( } else if (initKind is InitializationKind.None && type.IsValueType) { - EmitBindingLogic(tempIdentifier, InitializationKind.Declaration); - _writer.WriteLine($"{memberAccessExpr} = {tempIdentifier};"); + EmitBindingLogic(tempIdentifier, InitializationKind.Declaration, $"{memberAccessExpr} = {tempIdentifier};"); } else { EmitBindingLogic(memberAccessExpr, initKind); } - void EmitBindingLogic(string instanceToBindExpr, InitializationKind initKind) + void EmitBindingLogic(string instanceToBindExpr, InitializationKind initKind, string? tempIdentifierStoringExpr = null) { string bindCoreCall = $@"{nameof(MethodsToGen_CoreBindingHelper.BindCore)}({configArgExpr}, ref {instanceToBindExpr}, defaultValueIfNotFound: {FormatDefaultValueIfNotFound()}, {Identifier.binderOptions});"; @@ -1060,7 +1075,7 @@ void EmitBindingLogic(string instanceToBindExpr, InitializationKind initKind) void EmitBindCoreCall() { _writer.WriteLine(bindCoreCall); - writeOnSuccess?.Invoke(instanceToBindExpr); + writeOnSuccess?.Invoke(instanceToBindExpr, tempIdentifierStoringExpr); } string FormatDefaultValueIfNotFound() => valueDefaulting == ValueDefaulting.CallSetter ? "true" : "false"; diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.TestClasses.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.TestClasses.cs index 74de2804741042..31278be1121952 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.TestClasses.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.TestClasses.cs @@ -198,6 +198,20 @@ public record TypeWithRecursionThroughCollections public List? List { get; set; } } + public class TypeWithValueMutatorPropertySetter + { + private string _value = "Uninitialized"; + public string Value + { + get { return _value; } + set + { + _value = value == "Uninitialized" ? "Initialized" : value; + } + } + public ISet SomeSet { get; set; } = new HashSet(StringComparer.OrdinalIgnoreCase); + } + public record RecordWithArrayParameter(string[] Array); public readonly record struct ReadonlyRecordStructTypeOptions(string Color, int Length); diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs index 9e95c80643ed20..b1f4ffb264a920 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs @@ -1625,6 +1625,34 @@ public void BindToRecursiveTypesTest() Assert.Equal(1, instance.List[1].Values.Count); } + /// + /// This test ensures that the property setter is invoked during binding, even when there is no configuration for the property. + /// + [Fact] + public void PropertySetterCalledTest() + { + string jsonConfig = @"{ + ""Configuration"": { + ""SomeSet"": [ + ""path"" + ] + } + }"; + + var configuration = new ConfigurationBuilder() + .AddJsonStream(new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(jsonConfig))) + .Build(); + + TypeWithValueMutatorPropertySetter t1 = new(); + Assert.Equal(0, t1.SomeSet.Count); + Assert.Equal("Uninitialized", t1.Value); + + TypeWithValueMutatorPropertySetter t2 = configuration.GetSection("Configuration").Get()!; + Assert.Equal(1, t2.SomeSet.Count); + Assert.True(t2.SomeSet.Contains("path")); + Assert.Equal("Initialized", t2.Value); + } + [Fact] public void CanBindReadonlyRecordStructOptions() { diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind.generated.txt index 6b35d5b73afd4f..eafca53839991b 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind.generated.txt @@ -159,6 +159,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section2, ref temp4, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp4; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section5) { @@ -167,6 +171,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp7; } + else + { + instance.MyDictionary = instance.MyDictionary; + } if (AsConfigWithChildren(configuration.GetSection("MyComplexDictionary")) is IConfigurationSection section8) { @@ -175,6 +183,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyComplexDictionary = temp10; } + else + { + instance.MyComplexDictionary = instance.MyComplexDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Instance.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Instance.generated.txt index ed6db21e40afc9..b8114b76f70dc3 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Instance.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Instance.generated.txt @@ -123,6 +123,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section2, ref temp4, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp4; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section5) { @@ -131,6 +135,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp7; } + else + { + instance.MyDictionary = instance.MyDictionary; + } if (AsConfigWithChildren(configuration.GetSection("MyComplexDictionary")) is IConfigurationSection section8) { @@ -139,6 +147,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyComplexDictionary = temp10; } + else + { + instance.MyComplexDictionary = instance.MyComplexDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Instance_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Instance_BinderOptions.generated.txt index c8abf9d79fb7da..7eaabd7a89ab23 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Instance_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Instance_BinderOptions.generated.txt @@ -123,6 +123,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section2, ref temp4, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp4; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section5) { @@ -131,6 +135,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp7; } + else + { + instance.MyDictionary = instance.MyDictionary; + } if (AsConfigWithChildren(configuration.GetSection("MyComplexDictionary")) is IConfigurationSection section8) { @@ -139,6 +147,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyComplexDictionary = temp10; } + else + { + instance.MyComplexDictionary = instance.MyComplexDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Key_Instance.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Key_Instance.generated.txt index ee106169a27ee1..ed66e64fde8f9c 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Key_Instance.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Bind_Key_Instance.generated.txt @@ -123,6 +123,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section2, ref temp4, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp4; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section5) { @@ -131,6 +135,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp7; } + else + { + instance.MyDictionary = instance.MyDictionary; + } if (AsConfigWithChildren(configuration.GetSection("MyComplexDictionary")) is IConfigurationSection section8) { @@ -139,6 +147,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyComplexDictionary = temp10; } + else + { + instance.MyComplexDictionary = instance.MyComplexDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get.generated.txt index 61b94ba858cb02..5745fe8f16ace8 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get.generated.txt @@ -157,6 +157,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp7; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyArray")) is IConfigurationSection section8) { @@ -165,6 +169,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyArray = temp10; } + else + { + instance.MyArray = instance.MyArray; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section11) { @@ -173,6 +181,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section11, ref temp13, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp13; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } public static void BindCore(IConfiguration configuration, ref global::Program.MyClass2 instance, bool defaultValueIfNotFound, BinderOptions? binderOptions) diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_T.generated.txt index 205783d6a98214..a4bf3676be7418 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_T.generated.txt @@ -138,6 +138,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section4, ref temp6, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp6; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyArray")) is IConfigurationSection section7) { @@ -146,6 +150,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section7, ref temp9, defaultValueIfNotFound: false, binderOptions); instance.MyArray = temp9; } + else + { + instance.MyArray = instance.MyArray; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section10) { @@ -154,6 +162,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section10, ref temp12, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp12; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_T_BinderOptions.generated.txt index 8b4644d2b27c91..0ea405142fe29b 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ConfigurationBinder/Version1/Get_T_BinderOptions.generated.txt @@ -138,6 +138,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section4, ref temp6, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp6; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyArray")) is IConfigurationSection section7) { @@ -146,6 +150,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section7, ref temp9, defaultValueIfNotFound: false, binderOptions); instance.MyArray = temp9; } + else + { + instance.MyArray = instance.MyArray; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section10) { @@ -154,6 +162,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section10, ref temp12, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp12; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/BindConfiguration.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/BindConfiguration.generated.txt index 12dc3a77b0ed3f..a5fa9894a9e57a 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/BindConfiguration.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/BindConfiguration.generated.txt @@ -141,6 +141,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section3, ref temp5, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp5; } + else + { + instance.MyList = instance.MyList; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/BindConfigurationWithConfigureActions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/BindConfigurationWithConfigureActions.generated.txt index 103423d5b0bcd5..8ed59c5e13746e 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/BindConfigurationWithConfigureActions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/BindConfigurationWithConfigureActions.generated.txt @@ -141,6 +141,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section3, ref temp5, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp5; } + else + { + instance.MyList = instance.MyList; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/Bind_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/Bind_T.generated.txt index 4ca0ba31f4aca6..a74b4934b12ab4 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/Bind_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/Bind_T.generated.txt @@ -147,6 +147,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section3, ref temp5, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp5; } + else + { + instance.MyList = instance.MyList; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/Bind_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/Bind_T_BinderOptions.generated.txt index a8cc253765c046..efafd0eb6a5b1e 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/Bind_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/OptionsBuilder/Version1/Bind_T_BinderOptions.generated.txt @@ -141,6 +141,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section3, ref temp5, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp5; } + else + { + instance.MyList = instance.MyList; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T.generated.txt index 417f221d0aabd2..b379e4993ea2e9 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T.generated.txt @@ -174,6 +174,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp7; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyList2")) is IConfigurationSection section8) { @@ -182,6 +186,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyList2 = temp10; } + else + { + instance.MyList2 = instance.MyList2; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section11) { @@ -190,6 +198,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section11, ref temp13, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp13; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_BinderOptions.generated.txt index 98580f73b919fb..8a52959bc613ec 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_BinderOptions.generated.txt @@ -174,6 +174,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp7; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyList2")) is IConfigurationSection section8) { @@ -182,6 +186,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyList2 = temp10; } + else + { + instance.MyList2 = instance.MyList2; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section11) { @@ -190,6 +198,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section11, ref temp13, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp13; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_name.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_name.generated.txt index 25d182f7ac1fb9..2ab4a08cd8fb14 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_name.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_name.generated.txt @@ -174,6 +174,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp7; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyList2")) is IConfigurationSection section8) { @@ -182,6 +186,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyList2 = temp10; } + else + { + instance.MyList2 = instance.MyList2; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section11) { @@ -190,6 +198,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section11, ref temp13, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp13; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_name_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_name_BinderOptions.generated.txt index 7e4337e45c1432..4d87b2e4d2d1b9 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_name_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/ServiceCollection/Version1/Configure_T_name_BinderOptions.generated.txt @@ -168,6 +168,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp7; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyList2")) is IConfigurationSection section8) { @@ -176,6 +180,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyList2 = temp10; } + else + { + instance.MyList2 = instance.MyList2; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section11) { @@ -184,6 +192,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section11, ref temp13, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp13; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version1/Collections.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version1/Collections.generated.txt index c261c340aaf256..b0f90ddf5b4165 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version1/Collections.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version1/Collections.generated.txt @@ -145,6 +145,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section1, ref temp3, defaultValueIfNotFound: false, binderOptions); instance.CustomDictionary = temp3; } + else + { + instance.CustomDictionary = instance.CustomDictionary; + } if (AsConfigWithChildren(configuration.GetSection("CustomList")) is IConfigurationSection section4) { @@ -153,6 +157,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section4, ref temp6, defaultValueIfNotFound: false, binderOptions); instance.CustomList = temp6; } + else + { + instance.CustomList = instance.CustomList; + } if (AsConfigWithChildren(configuration.GetSection("IReadOnlyList")) is IConfigurationSection section7) { @@ -161,6 +169,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section7, ref temp9, defaultValueIfNotFound: false, binderOptions); instance.IReadOnlyList = temp9; } + else + { + instance.IReadOnlyList = instance.IReadOnlyList; + } if (AsConfigWithChildren(configuration.GetSection("IReadOnlyDictionary")) is IConfigurationSection section10) { @@ -169,6 +181,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section10, ref temp12, defaultValueIfNotFound: false, binderOptions); instance.IReadOnlyDictionary = temp12; } + else + { + instance.IReadOnlyDictionary = instance.IReadOnlyDictionary; + } if (AsConfigWithChildren(configuration.GetSection("CollectionStructExplicit")) is IConfigurationSection section13) { @@ -178,6 +194,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration instance.CollectionStructExplicit = temp15; temp14 = temp15; } + else + { + instance.CollectionStructExplicit = instance.CollectionStructExplicit; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version1/UnsupportedTypes.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version1/UnsupportedTypes.generated.txt index 9f784cc0193ddb..4cdd6685f6ac79 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version1/UnsupportedTypes.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version1/UnsupportedTypes.generated.txt @@ -159,6 +159,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section4, ref temp6, defaultValueIfNotFound: false, binderOptions); instance.List = temp6; } + else + { + instance.List = instance.List; + } if (AsConfigWithChildren(configuration.GetSection("Array")) is IConfigurationSection section7) { @@ -167,6 +171,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section7, ref temp9, defaultValueIfNotFound: false, binderOptions); instance.Array = temp9; } + else + { + instance.Array = instance.Array; + } if (AsConfigWithChildren(configuration.GetSection("Record")) is IConfigurationSection section10) { @@ -175,6 +183,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section10, ref temp12, defaultValueIfNotFound: false, binderOptions); instance.Record = temp12; } + else + { + instance.Record = instance.Record; + } } public static global::Record InitializeRecordAction(IConfiguration configuration, BinderOptions? binderOptions) diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind.generated.txt index baca17797df7aa..85ebf4c500e360 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind.generated.txt @@ -150,6 +150,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section2, ref temp4, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp4; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section5) { @@ -158,6 +162,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp7; } + else + { + instance.MyDictionary = instance.MyDictionary; + } if (AsConfigWithChildren(configuration.GetSection("MyComplexDictionary")) is IConfigurationSection section8) { @@ -166,6 +174,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyComplexDictionary = temp10; } + else + { + instance.MyComplexDictionary = instance.MyComplexDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Instance.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Instance.generated.txt index 55fc88c6e54f7d..f090695e031bfc 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Instance.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Instance.generated.txt @@ -120,6 +120,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section2, ref temp4, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp4; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section5) { @@ -128,6 +132,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp7; } + else + { + instance.MyDictionary = instance.MyDictionary; + } if (AsConfigWithChildren(configuration.GetSection("MyComplexDictionary")) is IConfigurationSection section8) { @@ -136,6 +144,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyComplexDictionary = temp10; } + else + { + instance.MyComplexDictionary = instance.MyComplexDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Instance_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Instance_BinderOptions.generated.txt index a1c971d891ea53..fae095fdf9047c 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Instance_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Instance_BinderOptions.generated.txt @@ -120,6 +120,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section2, ref temp4, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp4; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section5) { @@ -128,6 +132,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp7; } + else + { + instance.MyDictionary = instance.MyDictionary; + } if (AsConfigWithChildren(configuration.GetSection("MyComplexDictionary")) is IConfigurationSection section8) { @@ -136,6 +144,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyComplexDictionary = temp10; } + else + { + instance.MyComplexDictionary = instance.MyComplexDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Key_Instance.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Key_Instance.generated.txt index b3aa0044f92289..ec1527b06b9302 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Key_Instance.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Bind_Key_Instance.generated.txt @@ -120,6 +120,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section2, ref temp4, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp4; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section5) { @@ -128,6 +132,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp7; } + else + { + instance.MyDictionary = instance.MyDictionary; + } if (AsConfigWithChildren(configuration.GetSection("MyComplexDictionary")) is IConfigurationSection section8) { @@ -136,6 +144,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyComplexDictionary = temp10; } + else + { + instance.MyComplexDictionary = instance.MyComplexDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get.generated.txt index 25f336d16d22da..b1c4087f510f3e 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get.generated.txt @@ -154,6 +154,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp7; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyArray")) is IConfigurationSection section8) { @@ -162,6 +166,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyArray = temp10; } + else + { + instance.MyArray = instance.MyArray; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section11) { @@ -170,6 +178,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section11, ref temp13, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp13; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } public static void BindCore(IConfiguration configuration, ref global::Program.MyClass2 instance, bool defaultValueIfNotFound, BinderOptions? binderOptions) diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_T.generated.txt index ae367c81fd0682..438b31ea5a373b 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_T.generated.txt @@ -135,6 +135,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section4, ref temp6, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp6; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyArray")) is IConfigurationSection section7) { @@ -143,6 +147,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section7, ref temp9, defaultValueIfNotFound: false, binderOptions); instance.MyArray = temp9; } + else + { + instance.MyArray = instance.MyArray; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section10) { @@ -151,6 +159,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section10, ref temp12, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp12; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_T_BinderOptions.generated.txt index 938d15f5734da5..e3b4d79b987a49 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ConfigurationBinder/Version1/Get_T_BinderOptions.generated.txt @@ -135,6 +135,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section4, ref temp6, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp6; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyArray")) is IConfigurationSection section7) { @@ -143,6 +147,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section7, ref temp9, defaultValueIfNotFound: false, binderOptions); instance.MyArray = temp9; } + else + { + instance.MyArray = instance.MyArray; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section10) { @@ -151,6 +159,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section10, ref temp12, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp12; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/BindConfiguration.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/BindConfiguration.generated.txt index 3bf1c7fffb3d17..2f96ede4aa3fb0 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/BindConfiguration.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/BindConfiguration.generated.txt @@ -132,6 +132,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section3, ref temp5, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp5; } + else + { + instance.MyList = instance.MyList; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/BindConfigurationWithConfigureActions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/BindConfigurationWithConfigureActions.generated.txt index 68fd25284f96d0..96ede4c24d3614 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/BindConfigurationWithConfigureActions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/BindConfigurationWithConfigureActions.generated.txt @@ -132,6 +132,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section3, ref temp5, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp5; } + else + { + instance.MyList = instance.MyList; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/Bind_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/Bind_T.generated.txt index 79b3242d6bda99..340cfa41f749ce 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/Bind_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/Bind_T.generated.txt @@ -138,6 +138,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section3, ref temp5, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp5; } + else + { + instance.MyList = instance.MyList; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/Bind_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/Bind_T_BinderOptions.generated.txt index 8451a8071657a7..640cb5b5afeedf 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/Bind_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/OptionsBuilder/Version1/Bind_T_BinderOptions.generated.txt @@ -132,6 +132,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section3, ref temp5, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp5; } + else + { + instance.MyList = instance.MyList; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T.generated.txt index 4acfc2c04b2a44..3f926839b122f8 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T.generated.txt @@ -168,6 +168,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp7; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyList2")) is IConfigurationSection section8) { @@ -176,6 +180,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyList2 = temp10; } + else + { + instance.MyList2 = instance.MyList2; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section11) { @@ -184,6 +192,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section11, ref temp13, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp13; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_BinderOptions.generated.txt index 99c67141401cdd..0dd10a3677ff6a 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_BinderOptions.generated.txt @@ -168,6 +168,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp7; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyList2")) is IConfigurationSection section8) { @@ -176,6 +180,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyList2 = temp10; } + else + { + instance.MyList2 = instance.MyList2; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section11) { @@ -184,6 +192,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section11, ref temp13, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp13; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_name.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_name.generated.txt index 07fa717a301681..bdc65cf2f22fd7 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_name.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_name.generated.txt @@ -168,6 +168,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp7; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyList2")) is IConfigurationSection section8) { @@ -176,6 +180,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyList2 = temp10; } + else + { + instance.MyList2 = instance.MyList2; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section11) { @@ -184,6 +192,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section11, ref temp13, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp13; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_name_BinderOptions.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_name_BinderOptions.generated.txt index 20a36e76d994df..9b3ee20e9cd67c 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_name_BinderOptions.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/ServiceCollection/Version1/Configure_T_name_BinderOptions.generated.txt @@ -162,6 +162,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section5, ref temp7, defaultValueIfNotFound: false, binderOptions); instance.MyList = temp7; } + else + { + instance.MyList = instance.MyList; + } if (AsConfigWithChildren(configuration.GetSection("MyList2")) is IConfigurationSection section8) { @@ -170,6 +174,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section8, ref temp10, defaultValueIfNotFound: false, binderOptions); instance.MyList2 = temp10; } + else + { + instance.MyList2 = instance.MyList2; + } if (AsConfigWithChildren(configuration.GetSection("MyDictionary")) is IConfigurationSection section11) { @@ -178,6 +186,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section11, ref temp13, defaultValueIfNotFound: false, binderOptions); instance.MyDictionary = temp13; } + else + { + instance.MyDictionary = instance.MyDictionary; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Version1/Collections.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Version1/Collections.generated.txt index 8c25f92341eba5..8fed2d02c2075f 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Version1/Collections.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Version1/Collections.generated.txt @@ -142,6 +142,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section1, ref temp3, defaultValueIfNotFound: false, binderOptions); instance.CustomDictionary = temp3; } + else + { + instance.CustomDictionary = instance.CustomDictionary; + } if (AsConfigWithChildren(configuration.GetSection("CustomList")) is IConfigurationSection section4) { @@ -150,6 +154,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section4, ref temp6, defaultValueIfNotFound: false, binderOptions); instance.CustomList = temp6; } + else + { + instance.CustomList = instance.CustomList; + } if (AsConfigWithChildren(configuration.GetSection("IReadOnlyList")) is IConfigurationSection section7) { @@ -158,6 +166,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section7, ref temp9, defaultValueIfNotFound: false, binderOptions); instance.IReadOnlyList = temp9; } + else + { + instance.IReadOnlyList = instance.IReadOnlyList; + } if (AsConfigWithChildren(configuration.GetSection("IReadOnlyDictionary")) is IConfigurationSection section10) { @@ -166,6 +178,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section10, ref temp12, defaultValueIfNotFound: false, binderOptions); instance.IReadOnlyDictionary = temp12; } + else + { + instance.IReadOnlyDictionary = instance.IReadOnlyDictionary; + } if (AsConfigWithChildren(configuration.GetSection("CollectionStructExplicit")) is IConfigurationSection section13) { @@ -175,6 +191,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration instance.CollectionStructExplicit = temp15; temp14 = temp15; } + else + { + instance.CollectionStructExplicit = instance.CollectionStructExplicit; + } } diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Version1/UnsupportedTypes.generated.txt b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Version1/UnsupportedTypes.generated.txt index 509dbb05c39c81..0b119b30f4eb17 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Version1/UnsupportedTypes.generated.txt +++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/netcoreapp/Version1/UnsupportedTypes.generated.txt @@ -153,6 +153,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section4, ref temp6, defaultValueIfNotFound: false, binderOptions); instance.List = temp6; } + else + { + instance.List = instance.List; + } if (AsConfigWithChildren(configuration.GetSection("Array")) is IConfigurationSection section7) { @@ -161,6 +165,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section7, ref temp9, defaultValueIfNotFound: false, binderOptions); instance.Array = temp9; } + else + { + instance.Array = instance.Array; + } if (AsConfigWithChildren(configuration.GetSection("Record")) is IConfigurationSection section10) { @@ -169,6 +177,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration BindCore(section10, ref temp12, defaultValueIfNotFound: false, binderOptions); instance.Record = temp12; } + else + { + instance.Record = instance.Record; + } } public static global::Record InitializeRecordAction(IConfiguration configuration, BinderOptions? binderOptions) diff --git a/src/libraries/System.Composition.Convention/src/PACKAGE.md b/src/libraries/System.Composition.Convention/src/PACKAGE.md new file mode 100644 index 00000000000000..4f6e1fdc2358cf --- /dev/null +++ b/src/libraries/System.Composition.Convention/src/PACKAGE.md @@ -0,0 +1,97 @@ +## About + + + +`System.Composition.Convention` is part of the Managed Extensibility Framework (MEF) 2.0, a composition library for .NET that enables dependency injection through attributes or conventions. + +This package simplifies the process of applying consistent patterns for part exports, imports, and metadata by using convention-based configurations. +It is useful for scenarios where you want to avoid repetitive attribute-based decoration and instead define conventions for registering types in your composition container. + +## Key Features + + + +* Configure exports, imports, and metadata for parts using conventions rather than attributes. +* Allows defining conventions through a fluent API, making configuration more flexible and readable. + +## How to Use + + + +Configure parts for composition without using attributes. + +```csharp +using System.Composition.Convention; +using System.Composition.Hosting; + +var conventions = new ConventionBuilder(); + +// Apply conventions: any class that implements ILogger will be exported as ILogger +conventions + .ForTypesDerivedFrom() + .Export(); + +var configuration = new ContainerConfiguration() + .WithPart(conventions) + .WithPart(conventions); + +using CompositionHost container = configuration.CreateContainer(); + +var loggers = container.GetExports(); + +foreach (var logger in loggers) +{ + logger.Log("Hello, World!"); +} +// FileLogger: Hello, World! +// ConsoleLogger: Hello, World! + +public interface ILogger +{ + void Log(string message); +} + +public class FileLogger : ILogger +{ + public void Log(string message) => Console.WriteLine($"FileLogger: {message}"); +} + +public class ConsoleLogger : ILogger +{ + public void Log(string message) => Console.WriteLine($"ConsoleLogger: {message}"); +} +``` + +## Main Types + + + +The main types provided by this library are: + +* `System.Composition.Convention.ConventionBuilder` +* `System.Composition.Convention.PartConventionBuilder` +* `System.Composition.Convention.ParameterImportConventionBuilder` + +## Additional Documentation + + + +* [API documentation](https://learn.microsoft.com/dotnet/api/system.composition.convention) +* [Managed Extensibility Framework (MEF)](https://learn.microsoft.com/dotnet/framework/mef/) + +## Related Packages + + + +* [System.Composition](https://www.nuget.org/packages/System.Composition) +* [System.Composition.AttributedModel](https://www.nuget.org/packages/System.Composition.AttributedModel) +* [System.Composition.Hosting](https://www.nuget.org/packages/System.Composition.Hosting) +* [System.Composition.Runtime](https://www.nuget.org/packages/System.Composition.Runtime) +* [System.Composition.TypedParts](https://www.nuget.org/packages/System.Composition.TypedParts) + +## Feedback & Contributing + + + +System.Composition.Convention is released as open source under the [MIT license](https://licenses.nuget.org/MIT). +Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime). diff --git a/src/libraries/System.Composition.Convention/src/System.Composition.Convention.csproj b/src/libraries/System.Composition.Convention/src/System.Composition.Convention.csproj index 8e1f44ee3df72d..2544944eec76ea 100644 --- a/src/libraries/System.Composition.Convention/src/System.Composition.Convention.csproj +++ b/src/libraries/System.Composition.Convention/src/System.Composition.Convention.csproj @@ -6,19 +6,10 @@ Microsoft false true - Provides types that support using Managed Extensibility Framework with a convention-based configuration model. - -Commonly Used Types: -System.Composition.Convention.ConventionBuilder -System.Composition.Convention.ExportConventionBuilder -System.Composition.Convention.ImportConventionBuilder -System.Composition.Convention.PartConventionBuilder -System.Composition.Convention.ParameterImportConventionBuilder + Provides types that support using Managed Extensibility Framework (MEF) with a convention-based configuration model. disable $(NoWarn);nullable - - false diff --git a/src/libraries/System.Composition.Hosting/src/PACKAGE.md b/src/libraries/System.Composition.Hosting/src/PACKAGE.md new file mode 100644 index 00000000000000..9f5556e7a4d7b7 --- /dev/null +++ b/src/libraries/System.Composition.Hosting/src/PACKAGE.md @@ -0,0 +1,80 @@ +## About + + + +`System.Composition.Hosting` is part of the Managed Extensibility Framework (MEF) 2.0, a composition library for .NET that enables dependency injection through attributes or conventions. + +This package provides core services for creating composition containers. +It offers tools to configure and manage the composition of parts within your application, facilitating dependency injection and enabling modular architectures. + +## Key Features + + + +* Create and manage composition containers for dynamic dependency injection. + +## How to Use + + + +Create a composition host and compose parts. + +```csharp +using System.Composition; +using System.Composition.Hosting; + +// Create a container configuration +var configuration = new ContainerConfiguration() + .WithPart(); + +// Create the composition host (container) +using CompositionHost container = configuration.CreateContainer(); + +// Get an instance of the service +var service = container.GetExport(); +service.Run(); +// Service is running! + +public interface IService +{ + void Run(); +} + +[Export(typeof(IService))] +public class Service : IService +{ + public void Run() => Console.WriteLine("Service is running!"); +} +``` + +## Main Types + + + +The main type provided by this library is: + +* `System.Composition.CompositionHost` + +## Additional Documentation + + + +* [API documentation](https://learn.microsoft.com/dotnet/api/system.composition.hosting) +* [Managed Extensibility Framework (MEF)](https://learn.microsoft.com/dotnet/framework/mef/) + +## Related Packages + + + +* [System.Composition](https://www.nuget.org/packages/System.Composition) +* [System.Composition.AttributedModel](https://www.nuget.org/packages/System.Composition.AttributedModel) +* [System.Composition.Convention](https://www.nuget.org/packages/System.Composition.Convention) +* [System.Composition.Runtime](https://www.nuget.org/packages/System.Composition.Runtime) +* [System.Composition.TypedParts](https://www.nuget.org/packages/System.Composition.TypedParts) + +## Feedback & Contributing + + + +System.Composition.Hosting is released as open source under the [MIT license](https://licenses.nuget.org/MIT). +Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime). diff --git a/src/libraries/System.Composition.Hosting/src/System.Composition.Hosting.csproj b/src/libraries/System.Composition.Hosting/src/System.Composition.Hosting.csproj index cd017f48b69398..18d027e8ad14bb 100644 --- a/src/libraries/System.Composition.Hosting/src/System.Composition.Hosting.csproj +++ b/src/libraries/System.Composition.Hosting/src/System.Composition.Hosting.csproj @@ -7,15 +7,10 @@ Microsoft false true - Provides Managed Extensibility Framework types that are useful to developers of extensible applications, or hosts. - -Commonly Used Types: -System.Composition.Hosting.CompositionHost + Provides Managed Extensibility Framework (MEF) types that are useful to developers of extensible applications, or hosts. disable $(NoWarn);nullable - - false diff --git a/src/libraries/System.Composition.Runtime/src/PACKAGE.md b/src/libraries/System.Composition.Runtime/src/PACKAGE.md new file mode 100644 index 00000000000000..177bb8026881e2 --- /dev/null +++ b/src/libraries/System.Composition.Runtime/src/PACKAGE.md @@ -0,0 +1,87 @@ +## About + + + +`System.Composition.Runtime` is part of the Managed Extensibility Framework (MEF) 2.0, a composition library for .NET that enables dependency injection through attributes or conventions. + +This package enables the discovery and composition of parts in applications using MEF 2.0. +It offers the runtime implementation needed for managing composable parts, resolving dependencies, and dynamically wiring components together. + +## Key Features + + + +* Facilitates runtime discovery and composition of parts. + +## How to Use + + + +Resolve dependencies on the fly and can be useful for dynamically loaded components or plugins. + +```csharp +using System.Composition; +using System.Composition.Hosting; + +var configuration = new ContainerConfiguration() + .WithPart(); + +using CompositionHost container = configuration.CreateContainer(); + +var consumer = new Consumer(container); +consumer.Execute(); +// Service is running. + +public interface IService +{ + void Run(); +} + +[Export(typeof(IService))] +public class Service : IService +{ + public void Run() => Console.WriteLine("Service is running."); +} + +public class Consumer(CompositionContext context) +{ + public void Execute() + { + // Use the context to resolve the service + var service = context.GetExport(); + service.Run(); + } +} +``` + +## Main Types + + + +The main type provided by this library is: + +* `System.Composition.CompositionContext` + +## Additional Documentation + + + +* [API documentation](https://learn.microsoft.com/dotnet/api/system.composition.compositioncontext) +* [Managed Extensibility Framework (MEF)](https://learn.microsoft.com/dotnet/framework/mef/) + +## Related Packages + + + +* [System.Composition](https://www.nuget.org/packages/System.Composition) +* [System.Composition.AttributedModel](https://www.nuget.org/packages/System.Composition.AttributedModel) +* [System.Composition.Convention](https://www.nuget.org/packages/System.Composition.Convention) +* [System.Composition.Hosting](https://www.nuget.org/packages/System.Composition.Hosting) +* [System.Composition.TypedParts](https://www.nuget.org/packages/System.Composition.TypedParts) + +## Feedback & Contributing + + + +System.Composition.Runtime is released as open source under the [MIT license](https://licenses.nuget.org/MIT). +Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime). diff --git a/src/libraries/System.Composition.Runtime/src/System.Composition.Runtime.csproj b/src/libraries/System.Composition.Runtime/src/System.Composition.Runtime.csproj index 57ee9457ea35ba..93ef06e572afeb 100644 --- a/src/libraries/System.Composition.Runtime/src/System.Composition.Runtime.csproj +++ b/src/libraries/System.Composition.Runtime/src/System.Composition.Runtime.csproj @@ -7,15 +7,10 @@ Microsoft false true - Contains runtime components of the Managed Extensibility Framework. - -Commonly Used Types: -System.Composition.CompositionContext + Contains runtime components of the Managed Extensibility Framework (MEF). disable $(NoWarn);nullable - - false diff --git a/src/libraries/System.Composition.TypedParts/src/PACKAGE.md b/src/libraries/System.Composition.TypedParts/src/PACKAGE.md new file mode 100644 index 00000000000000..de02f4525c8668 --- /dev/null +++ b/src/libraries/System.Composition.TypedParts/src/PACKAGE.md @@ -0,0 +1,88 @@ +## About + + + +`System.Composition.TypedParts` is part of the Managed Extensibility Framework (MEF) 2.0, a composition library for .NET that enables dependency injection through attributes or conventions. + +Provides `ContainerConfiguration` and some extension methods for the Managed Extensibility Framework (MEF). + +## Key Features + + + +* Provides container configuration. + +## How to Use + + + +Register parts from an entire assembly. + +```csharp +using System.Composition; +using System.Composition.Hosting; +using System.Reflection; + +// Register all parts from the current assembly +var configuration = new ContainerConfiguration() + .WithAssembly(Assembly.GetExecutingAssembly()); + +using CompositionHost container = configuration.CreateContainer(); + +var handlers = container.GetExports(); +foreach (var handler in handlers) +{ + handler.Handle(); +} +// HandlerA is handling. +// HandlerB is handling. + +public interface IHandler +{ + void Handle(); +} + +[Export(typeof(IHandler))] +public class HandlerA : IHandler +{ + public void Handle() => Console.WriteLine("HandlerA is handling."); +} + +[Export(typeof(IHandler))] +public class HandlerB : IHandler +{ + public void Handle() => Console.WriteLine("HandlerB is handling."); +} +``` + +## Main Types + + + +The main types provided by this library are: + +* `System.Composition.Hosting.ContainerConfiguration` +* `System.Composition.CompositionContextExtensions` + +## Additional Documentation + + + +* [Managed Extensibility Framework (MEF)](https://learn.microsoft.com/dotnet/framework/mef/) + +## Related Packages + + + +* [System.Composition](https://www.nuget.org/packages/System.Composition) +* [System.Composition.AttributedModel](https://www.nuget.org/packages/System.Composition.AttributedModel) +* [System.Composition.Convention](https://www.nuget.org/packages/System.Composition.Convention) +* [System.Composition.Hosting](https://www.nuget.org/packages/System.Composition.Hosting) +* [System.Composition.Runtime](https://www.nuget.org/packages/System.Composition.Runtime) + +## Feedback & Contributing + + + +System.Composition.TypedParts is released as open source under the [MIT license](https://licenses.nuget.org/MIT). +Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime). diff --git a/src/libraries/System.Composition.TypedParts/src/System.Composition.TypedParts.csproj b/src/libraries/System.Composition.TypedParts/src/System.Composition.TypedParts.csproj index 4e82792a39994e..3a2874d9d3f0b4 100644 --- a/src/libraries/System.Composition.TypedParts/src/System.Composition.TypedParts.csproj +++ b/src/libraries/System.Composition.TypedParts/src/System.Composition.TypedParts.csproj @@ -8,16 +8,10 @@ Microsoft false true - Provides some extension methods for the Managed Extensibility Framework. - -Commonly Used Types: -System.Composition.CompositionContextExtensions -System.Composition.Hosting.ContainerConfiguration + Provides container configuration and some extension methods for the Managed Extensibility Framework (MEF). disable $(NoWarn);nullable - - false diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs index 15b3cd86effafb..f364b8e44e19e3 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs +++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs @@ -128,7 +128,7 @@ internal static unsafe int BindToDirectory(ConnectionHandle ld, string who, stri passwordPtr = LdapPal.StringToPtr(passwd); BerVal passwordBerval = new BerVal { - bv_len = MemoryMarshal.CreateReadOnlySpanFromNullTerminated((byte*)passwordPtr).Length, + bv_len = new CLong(MemoryMarshal.CreateReadOnlySpanFromNullTerminated((byte*)passwordPtr).Length), bv_val = passwordPtr, }; diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/SafeHandles.Linux.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/SafeHandles.Linux.cs index 24d660de645fd8..70d25cb99f2346 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/SafeHandles.Linux.cs +++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/SafeHandles.Linux.cs @@ -65,7 +65,7 @@ internal SafeBerHandle(BerVal value) : base(true) // In Linux if bv_val is null ber_init will segFault instead of returning IntPtr.Zero. // In Linux if bv_len is 0 ber_init returns a valid pointer which will then fail when trying to use it, // so we fail early by throwing exception if this is the case. - if (value.bv_val == IntPtr.Zero || value.bv_len == 0) + if (value.bv_val == IntPtr.Zero || value.bv_len.Value == 0) { throw new BerConversionException(); } diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs index 735018bc8bb091..a0d09e2712921c 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs +++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/BerConverter.cs @@ -269,15 +269,15 @@ public static byte[] Encode(string format, params object[] value) Marshal.PtrToStructure(flattenptr, binaryValue); } - if (binaryValue == null || binaryValue.bv_len == 0) + if (binaryValue == null || binaryValue.bv_len.Value == 0) { encodingResult = Array.Empty(); } else { - encodingResult = new byte[binaryValue.bv_len]; + encodingResult = new byte[binaryValue.bv_len.Value]; - Marshal.Copy(binaryValue.bv_val, encodingResult, 0, binaryValue.bv_len); + Marshal.Copy(binaryValue.bv_val, encodingResult, 0, (int)binaryValue.bv_len.Value); } } finally @@ -315,12 +315,12 @@ internal static object[] TryDecode(string format, byte[] value, out bool decodeS if (value == null) { - berValue.bv_len = 0; + berValue.bv_len = new CLong(0); berValue.bv_val = IntPtr.Zero; } else { - berValue.bv_len = value.Length; + berValue.bv_len = new CLong(value.Length); berValue.bv_val = Marshal.AllocHGlobal(value.Length); Marshal.Copy(value, 0, berValue.bv_val, value.Length); } @@ -498,8 +498,8 @@ private static byte[] DecodingByteArrayHelper(SafeBerHandle berElement, char fmt { Marshal.PtrToStructure(result, binaryValue); - byteArray = new byte[binaryValue.bv_len]; - Marshal.Copy(binaryValue.bv_val, byteArray, 0, binaryValue.bv_len); + byteArray = new byte[binaryValue.bv_len.Value]; + Marshal.Copy(binaryValue.bv_val, byteArray, 0, (int)binaryValue.bv_len.Value); } } else @@ -539,7 +539,7 @@ private static unsafe int EncodingMultiByteArrayHelper(SafeBerHandle berElement, if (byteArray != null) { - managedBervalArray[i].bv_len = byteArray.Length; + managedBervalArray[i].bv_len = new CLong(byteArray.Length); managedBervalArray[i].bv_val = Marshal.AllocHGlobal(byteArray.Length); Marshal.Copy(byteArray, 0, managedBervalArray[i].bv_val, byteArray.Length); } @@ -606,8 +606,8 @@ private static byte[][] DecodingMultiByteArrayHelper(SafeBerHandle berElement, c BerVal ber = new BerVal(); Marshal.PtrToStructure(tempPtr, ber); - byte[] berArray = new byte[ber.bv_len]; - Marshal.Copy(ber.bv_val, berArray, 0, ber.bv_len); + byte[] berArray = new byte[ber.bv_len.Value]; + Marshal.Copy(ber.bv_val, berArray, 0, (int)ber.bv_len.Value); binaryList.Add(berArray); diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/DirectoryControl.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/DirectoryControl.cs index f47bc50318b946..ba0f714b2b02f0 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/DirectoryControl.cs +++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/common/DirectoryControl.cs @@ -756,8 +756,8 @@ public override unsafe byte[] GetValue() _directoryControlValue = null; if (value != null) { - _directoryControlValue = new byte[value.bv_len]; - Marshal.Copy(value.bv_val, _directoryControlValue, 0, value.bv_len); + _directoryControlValue = new byte[value.bv_len.Value]; + Marshal.Copy(value.bv_val, _directoryControlValue, 0, (int)value.bv_len.Value); } } finally diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.cs index 4be0407a9eea9b..1125bfd568d385 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.cs +++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.cs @@ -629,7 +629,7 @@ private unsafe int SendRequestHelper(DirectoryRequest request, ref int messageID berValuePtr = new BerVal { - bv_len = byteArray.Length, + bv_len = new CLong(byteArray.Length), bv_val = Marshal.AllocHGlobal(byteArray.Length) }; Marshal.Copy(byteArray, 0, berValuePtr.bv_val, byteArray.Length); @@ -695,7 +695,7 @@ private unsafe int SendRequestHelper(DirectoryRequest request, ref int messageID { berValuePtr = new BerVal() { - bv_len = val.Length, + bv_len = new CLong(val.Length), bv_val = Marshal.AllocHGlobal(val.Length) }; Marshal.Copy(val, 0, berValuePtr.bv_val, val.Length); @@ -1222,7 +1222,7 @@ internal static LdapControl[] BuildControlArray(DirectoryControlCollection contr // Get the control type. ldctl_oid = LdapPal.StringToPtr(((DirectoryControl)controlList[i]).Type), - // Get the control cricality. + // Get the control criticality. ldctl_iscritical = ((DirectoryControl)controlList[i]).IsCritical }; @@ -1234,7 +1234,7 @@ internal static LdapControl[] BuildControlArray(DirectoryControlCollection contr // Treat the control value as null. managedControls[i].ldctl_value = new BerVal { - bv_len = 0, + bv_len = new CLong(0), bv_val = IntPtr.Zero }; } @@ -1242,10 +1242,10 @@ internal static LdapControl[] BuildControlArray(DirectoryControlCollection contr { managedControls[i].ldctl_value = new BerVal { - bv_len = byteControlValue.Length, + bv_len = new CLong(byteControlValue.Length), bv_val = Marshal.AllocHGlobal(sizeof(byte) * byteControlValue.Length) }; - Marshal.Copy(byteControlValue, 0, managedControls[i].ldctl_value.bv_val, managedControls[i].ldctl_value.bv_len); + Marshal.Copy(byteControlValue, 0, managedControls[i].ldctl_value.bv_val, (int)managedControls[i].ldctl_value.bv_len.Value); } } } @@ -1330,13 +1330,13 @@ internal static unsafe LdapMod[] BuildAttributes(CollectionBase directoryAttribu berValues[j] = new BerVal() { - bv_len = byteArray.Length, + bv_len = new CLong(byteArray.Length), bv_val = Marshal.AllocHGlobal(byteArray.Length) }; // need to free the memory allocated on the heap when we are done ptrToFree.Add(berValues[j].bv_val); - Marshal.Copy(byteArray, 0, berValues[j].bv_val, berValues[j].bv_len); + Marshal.Copy(byteArray, 0, berValues[j].bv_val, (int)berValues[j].bv_len.Value); } } @@ -1485,10 +1485,10 @@ internal async ValueTask ConstructResponseAsync(int messageId { val = new BerVal(); Marshal.PtrToStructure(requestValue, val); - if (val.bv_len != 0 && val.bv_val != IntPtr.Zero) + if (val.bv_len.Value != 0 && val.bv_val != IntPtr.Zero) { - requestValueArray = new byte[val.bv_len]; - Marshal.Copy(val.bv_val, requestValueArray, 0, val.bv_len); + requestValueArray = new byte[val.bv_len.Value]; + Marshal.Copy(val.bv_val, requestValueArray, 0, (int)val.bv_len.Value); } } @@ -1806,10 +1806,10 @@ internal DirectoryAttribute ConstructAttribute(IntPtr entryMessage, IntPtr attri BerVal bervalue = new BerVal(); Marshal.PtrToStructure(tempPtr, bervalue); byte[] byteArray; - if (bervalue.bv_len > 0 && bervalue.bv_val != IntPtr.Zero) + if (bervalue.bv_len.Value > 0 && bervalue.bv_val != IntPtr.Zero) { - byteArray = new byte[bervalue.bv_len]; - Marshal.Copy(bervalue.bv_val, byteArray, 0, bervalue.bv_len); + byteArray = new byte[bervalue.bv_len.Value]; + Marshal.Copy(bervalue.bv_val, byteArray, 0, (int)bervalue.bv_len.Value); attribute.Add(byteArray); } @@ -1944,8 +1944,8 @@ private static DirectoryControl ConstructControl(IntPtr controlPtr) Debug.Assert(control.ldctl_oid != IntPtr.Zero); string controlType = LdapPal.PtrToString(control.ldctl_oid); - byte[] bytes = new byte[control.ldctl_value.bv_len]; - Marshal.Copy(control.ldctl_value.bv_val, bytes, 0, control.ldctl_value.bv_len); + byte[] bytes = new byte[control.ldctl_value.bv_len.Value]; + Marshal.Copy(control.ldctl_value.bv_val, bytes, 0, (int)control.ldctl_value.bv_len.Value); bool criticality = control.ldctl_iscritical; diff --git a/src/libraries/System.Memory/tests/Base64/Base64ValidationUnitTests.cs b/src/libraries/System.Memory/tests/Base64/Base64ValidationUnitTests.cs index 62b978c60c5e1a..f95399ae420919 100644 --- a/src/libraries/System.Memory/tests/Base64/Base64ValidationUnitTests.cs +++ b/src/libraries/System.Memory/tests/Base64/Base64ValidationUnitTests.cs @@ -9,6 +9,29 @@ namespace System.Buffers.Text.Tests { public class Base64ValidationUnitTests : Base64TestBase { + [Theory] + [InlineData("= ")] + [InlineData("= =")] + [InlineData("+ +=")] + [InlineData("A=")] + [InlineData("A==")] + [InlineData("44==")] + [InlineData(" A==")] + [InlineData("AAAAA ==")] + [InlineData("\tLLLL\t=\r")] + [InlineData("6066=")] + [InlineData("6066==")] + [InlineData("SM==")] + [InlineData("SM =")] + [InlineData("s\rEs\r\r==")] + public void BasicValidationEdgeCaseScenario(string base64UrlText) + { + Assert.False(Base64.IsValid(base64UrlText.AsSpan(), out int decodedLength)); + Assert.Equal(0, decodedLength); + Span dest = new byte[Base64.GetMaxDecodedFromUtf8Length(base64UrlText.Length)]; + Assert.Equal(OperationStatus.InvalidData, Base64.DecodeFromUtf8(base64UrlText.ToUtf8Span(), dest, out _, out _)); + } + [Fact] public void BasicValidationBytes() { diff --git a/src/libraries/System.Memory/tests/Base64Url/Base64UrlValidationUnitTests.cs b/src/libraries/System.Memory/tests/Base64Url/Base64UrlValidationUnitTests.cs index 0ee3abcd9153a2..092d45d2370d17 100644 --- a/src/libraries/System.Memory/tests/Base64Url/Base64UrlValidationUnitTests.cs +++ b/src/libraries/System.Memory/tests/Base64Url/Base64UrlValidationUnitTests.cs @@ -10,6 +10,7 @@ namespace System.Buffers.Text.Tests public class Base64UrlValidationUnitTests : Base64TestBase { [Theory] + [InlineData("=")] [InlineData("==")] [InlineData("-%")] [InlineData("A=")] @@ -19,10 +20,17 @@ public class Base64UrlValidationUnitTests : Base64TestBase [InlineData("AAAAA ==")] [InlineData("\tLLLL\t=\r")] [InlineData("6066=")] + [InlineData("6066==")] + [InlineData("SM==")] + [InlineData("SM=")] + [InlineData("sEs==")] + [InlineData("s\rEs\r\r==")] public void BasicValidationEdgeCaseScenario(string base64UrlText) { Assert.False(Base64Url.IsValid(base64UrlText.AsSpan(), out int decodedLength)); Assert.Equal(0, decodedLength); + Span dest = new byte[Base64Url.GetMaxDecodedLength(base64UrlText.Length)]; + Assert.Equal(OperationStatus.InvalidData, Base64Url.DecodeFromChars(base64UrlText.AsSpan(), dest, out _, out _)); } [Fact] @@ -258,6 +266,10 @@ public void ValidateWithPaddingReturnsCorrectCountChars(string utf8WithByteToBeI Assert.True(Base64Url.IsValid(utf8BytesWithByteToBeIgnored)); Assert.True(Base64Url.IsValid(utf8BytesWithByteToBeIgnored, out int decodedLength)); Assert.Equal(expectedLength, decodedLength); + + Span dest = new byte[Base64Url.GetMaxDecodedLength(utf8WithByteToBeIgnored.Length)]; + Assert.Equal(OperationStatus.Done, Base64Url.DecodeFromChars(utf8WithByteToBeIgnored.AsSpan(), dest, out _, out decodedLength)); + Assert.Equal(expectedLength, decodedLength); } [Theory] diff --git a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/run-docker-compose.ps1 b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/run-docker-compose.ps1 index 2b16072e2e6b70..67e28756d9dfd3 100755 --- a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/run-docker-compose.ps1 +++ b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/run-docker-compose.ps1 @@ -16,6 +16,14 @@ Param( $REPO_ROOT_DIR = $(git -C "$PSScriptRoot" rev-parse --show-toplevel) $COMPOSE_FILE = "$PSScriptRoot/docker-compose.yml" +# This is a workaround for an issue with 1es-windows-2022-open, which should be eventually removed. +# See comments in /eng/pipelines/libraries/stress/ssl.yml for more info. +$dockerComposeCmd = $env:DOCKER_COMPOSE_CMD +if (!(Test-Path $dockerComposeCmd)) +{ + $dockerComposeCmd = "docker-compose" +} + # Build runtime libraries and place in a docker image if ($buildCurrentLibraries) @@ -60,7 +68,7 @@ if ($useWindowsContainers) $originalErrorPreference = $ErrorActionPreference $ErrorActionPreference = 'Continue' try { - docker-compose --log-level DEBUG --file "$COMPOSE_FILE" build $BUILD_ARGS.Split() 2>&1 | ForEach-Object { "$_" } + & $dockerComposeCmd --log-level DEBUG --file "$COMPOSE_FILE" build $BUILD_ARGS.Split() 2>&1 | ForEach-Object { "$_" } if ($LASTEXITCODE -ne 0) { throw "docker-compose exited with error code $LASTEXITCODE" } @@ -89,5 +97,5 @@ if (!$buildOnly) $env:HTTPSTRESS_CLIENT_ARGS = $clientStressArgs $env:HTTPSTRESS_SERVER_ARGS = $serverStressArgs - docker-compose --file "$COMPOSE_FILE" up --abort-on-container-exit + & $dockerComposeCmd --file "$COMPOSE_FILE" up --abort-on-container-exit } diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs index bc95ab0f054cd2..3cd8bf5c679f2a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics; using System.Runtime.CompilerServices; -using static System.Buffers.Text.Base64Helper; namespace System.Buffers.Text { @@ -94,33 +94,33 @@ public bool ValidateAndDecodeLength(char lastChar, int length, int paddingCount, [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ValidateAndDecodeLength(byte lastChar, int length, int paddingCount, out int decodedLength) { - // Padding is optional for Base64Url, so need to account remainder. If remainder is 1, then it's invalid. -#if NET - (uint whole, uint remainder) = uint.DivRem((uint)(length), 4); - if (remainder == 1 || (remainder > 1 && (remainder - paddingCount == 1 || paddingCount == remainder))) - { - decodedLength = 0; - return false; - } - - decodedLength = (int)((whole * 3) + (remainder > 0 ? remainder - 1 : 0) - paddingCount); -#else + // Padding is optional for Base64Url, so need to account remainder. int remainder = (int)((uint)length % 4); - if (remainder == 1 || (remainder > 1 && (remainder - paddingCount == 1 || paddingCount == remainder))) + + if (paddingCount != 0) { - decodedLength = 0; - return false; + length -= paddingCount; + remainder = (int)((uint)length % 4); + + // if there is a padding, there should be remainder and the sum of remainder and padding should not exceed 4 + if (remainder == 0 || remainder + paddingCount > 4) + { + decodedLength = 0; + return false; + } } - decodedLength = (length >> 2) * 3 + (remainder > 0 ? remainder - 1 : 0) - paddingCount; -#endif - int decoded = default(Base64DecoderByte).DecodingMap[lastChar]; - if (((remainder == 3 || paddingCount == 1) && (decoded & 0x03) != 0) || - ((remainder == 2 || paddingCount == 2) && (decoded & 0x0F) != 0)) + decodedLength = (length >> 2) * 3 + (remainder > 0 ? remainder - 1 : 0); + + if (remainder > 0) { - // unused lower bits are not 0, reject input - decodedLength = 0; - return false; + int decoded = default(Base64UrlDecoderByte).DecodingMap[lastChar]; + switch (remainder) + { + case 1: return false; // 1 byte is not decodable => invalid. + case 2: return ((decoded & 0x0F) == 0); // if unused lower 4 bits are set to 0 + case 3: return ((decoded & 0x03) == 0); // if unused lower 2 bits are set to 0 + } } return true; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/InvariantModeCasing.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/InvariantModeCasing.cs index 809b42ac74c1fd..5c6dfadf073bd2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/InvariantModeCasing.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/InvariantModeCasing.cs @@ -215,7 +215,7 @@ internal static int CompareStringIgnoreCase(ref char strA, int lengthA, ref char continue; } - return (int)codePointA - (int)codePointB; + return (int)aUpper - (int)bUpper; } return lengthA - lengthB; diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/Invariant/InvariantMode.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/Invariant/InvariantMode.cs index 3b72d1d219cf34..91b098cd505b68 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/Invariant/InvariantMode.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/Invariant/InvariantMode.cs @@ -1257,5 +1257,18 @@ private static byte[] GetExpectedInvariantOrdinalSortKey(ReadOnlySpan inpu return memoryStream.ToArray(); } + + [Fact] + public void TestChainStringComparisons() + { + var s1 = "бал"; + var s2 = "Бан"; + var s3 = "Д"; + + // If s1 < s2 and s2 < s3, then s1 < s3 + Assert.True(string.Compare(s1, s2, StringComparison.OrdinalIgnoreCase) < 0); + Assert.True(string.Compare(s2, s3, StringComparison.OrdinalIgnoreCase) < 0); + Assert.True(string.Compare(s1, s3, StringComparison.OrdinalIgnoreCase) < 0); + } } } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngKeyCreationOptions.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngKeyCreationOptions.cs index f3f3e7fb423219..9a7155b09022a8 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngKeyCreationOptions.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngKeyCreationOptions.cs @@ -15,8 +15,21 @@ public enum CngKeyCreationOptions : int None = 0x00000000, MachineKey = 0x00000020, // NCRYPT_MACHINE_KEY_FLAG OverwriteExistingKey = 0x00000080, // NCRYPT_OVERWRITE_KEY_FLAG + + /// + /// Indicates a key should be protected with Virtualization-based security (VBS). + /// PreferVbs = 0x00010000, // NCRYPT_PREFER_VBS_FLAG + + /// + /// Indicates a key must be protected with Virtualization-based security (VBS). + /// RequireVbs = 0x00020000, // NCRYPT_REQUIRE_VBS_FLAG + + /// + /// Instructs Virtualization-based security (VBS) to protect the client key with a per-boot key + /// when combined with or . + /// UsePerBootKey = 0x00040000, // NCRYPT_USE_PER_BOOT_KEY_FLAG } } diff --git a/src/mono/mono/component/debugger-agent.c b/src/mono/mono/component/debugger-agent.c index 82b4633ae73a21..1de2a9e18b6875 100644 --- a/src/mono/mono/component/debugger-agent.c +++ b/src/mono/mono/component/debugger-agent.c @@ -10529,8 +10529,9 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf) break; } } - - while ((f = mono_class_get_fields_internal (k, &iter))) { + //Above for loop might end if 'k' is null , ensure 'k' is not + //null before passing it to mono_class_get_fields_internal to avoid crash + while (k && (f = mono_class_get_fields_internal (k, &iter))) { if (mono_class_get_field_token (f) == field_token) { goto get_field_value; } diff --git a/src/tests/Common/Directory.Build.targets b/src/tests/Common/Directory.Build.targets index ec1ce62d3ed702..c19defed8fc210 100644 --- a/src/tests/Common/Directory.Build.targets +++ b/src/tests/Common/Directory.Build.targets @@ -42,7 +42,7 @@ `build -c debug -rc checked`, the corresponding test command is `src/tests/build -checked -p:LibrariesConfiguration=debug`, instead of `-debug -p:RuntimeConfiguration=checked`. That forces us to either pass the `HostConfiguration=debug` explicitly or fix this disparity; both of which will break the dev workflow. - + As a workaround, we will first check if the directory pointed by `HostConfiguration` exists, then check `LibrariesConfiguration`. --> diff --git a/src/tests/Common/GenerateHWIntrinsicTests/GenerateHWIntrinsicTests_Arm.cs b/src/tests/Common/GenerateHWIntrinsicTests/GenerateHWIntrinsicTests_Arm.cs index 457808946c3dde..c8bf71ecc4be42 100644 --- a/src/tests/Common/GenerateHWIntrinsicTests/GenerateHWIntrinsicTests_Arm.cs +++ b/src/tests/Common/GenerateHWIntrinsicTests/GenerateHWIntrinsicTests_Arm.cs @@ -220,6 +220,67 @@ } }"; +const string VecReduceUnOpTest_VectorValidationLogicForCndSel = @" + { + var hasFailed = (mask[0] != 0 ? {ValidateReduceOpResult}: (falseVal[0] != result[0])); + + if (hasFailed) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + var iterResult = (mask[i] != 0) ? 0 : falseVal[i]; + if (mask[i] != 0) + { + // Pick the trueValue + if (iterResult != result[i]) + { + succeeded = false; + break; + } + } + else + { + // For false, the values are merged with destination, and we do not know + // those contents would be, so skip verification for them. + } + } + } + }"; + +const string VecReduceUnOpTest_VectorValidationLogicForCndSel_FalseValue = @" + { + var hasFailed = (mask[0] != 0) ? (trueVal[0] != result[0]): {ValidateReduceOpResult}; + if (hasFailed) + { + succeeded = false; + } + else + { + for (var i = 1; i < RetElementCount; i++) + { + var iterResult = (mask[i] != 0) ? trueVal[i] : 0; + if (mask[i] != 0) + { + // Pick the trueValue + if (iterResult != result[i]) + { + succeeded = false; + break; + } + } + else + { + // For false, the values are merged with destination, and we do not know + // those contents would be, so skip verification for them. + } + } + } + }"; + const string VecReduceOpTest_ValidationLogic = @"if ({ValidateReduceOpResult}) { succeeded = false; @@ -293,7 +354,7 @@ ("_SveImmTernOpFirstArgTestTemplate.template", "SveVecImmTernOpFirstArgTest.template", new Dictionary { ["TemplateName"] = "Simple", ["TemplateValidationLogic"] = SimpleVecOpTest_ValidationLogic, ["TemplateValidationLogicForCndSel"] = SimpleTernVecOpTest_ValidationLogicForCndSel, ["TemplateValidationLogicForCndSel_FalseValue"] = SimpleTernVecOpTest_ValidationLogicForCndSel_FalseValue }), ("_SveScalarTernOpTestTemplate.template", "SveScalarTernOpTest.template", new Dictionary { ["TemplateName"] = "Simple", ["TemplateValidationLogic"] = SimpleScalarOpTest_ValidationLogic }), ("_SveImm2UnaryOpTestTemplate.template", "SveVecImm2UnOpTest.template", new Dictionary { ["TemplateName"] = "Imm", ["TemplateValidationLogic"] = SimpleVecOpTest_ValidationLogic }), - ("_SveMinimalUnaryOpTestTemplate.template", "SveVecReduceUnOpTest.template", new Dictionary { ["TemplateName"] = "Simple", ["TemplateValidationLogic"] = VecReduceOpTest_ValidationLogic }), + ("_SveMinimalUnaryOpTestTemplate.template", "SveVecReduceUnOpTest.template", new Dictionary { ["TemplateName"] = "Simple", ["TemplateValidationLogic"] = VecReduceOpTest_ValidationLogic, ["TemplateValidationLogicForCndSel"] = VecReduceUnOpTest_VectorValidationLogicForCndSel, ["TemplateValidationLogicForCndSel_FalseValue"] = VecReduceUnOpTest_VectorValidationLogicForCndSel_FalseValue }), ("_SveMasklessUnaryOpTestTemplate.template", "SveMasklessSimpleVecOpTest.template", new Dictionary { ["TemplateName"] = "Simple", ["TemplateValidationLogic"] = SimpleVecOpTest_ValidationLogic }), ("_SveVecAndScalarOpTest.template", "SveVecAndScalarOpTest.template", new Dictionary { ["TemplateName"] = "Simple", ["TemplateValidationLogic"] = SimpleVecOpTest_VectorValidationLogic }), ("_SveMasklessBinaryOpTestTemplate.template", "SveMasklessVecBinOpTest.template", new Dictionary { ["TemplateName"] = "Simple", ["TemplateValidationLogic"] = SimpleVecOpTest_ValidationLogic }), diff --git a/src/tests/Common/XUnitLogChecker/XUnitLogChecker.csproj b/src/tests/Common/XUnitLogChecker/XUnitLogChecker.csproj index f17c40f9928f98..e1b5822a4fbff1 100644 --- a/src/tests/Common/XUnitLogChecker/XUnitLogChecker.csproj +++ b/src/tests/Common/XUnitLogChecker/XUnitLogChecker.csproj @@ -5,7 +5,7 @@ $(NetCoreAppToolCurrent) true true - true + true false lld $(ROOTFS_DIR) diff --git a/src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs b/src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs index fb993a0dd1edba..2f1237dc44403d 100644 --- a/src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs +++ b/src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.IO; +using System.Linq; using System.Text; using Microsoft.CodeAnalysis; @@ -40,7 +41,13 @@ public BasicTestMethod(IMethodSymbol method, .FullyQualifiedWithoutGlobalNamespace); Method = method.Name; DisplayNameForFiltering = $"{ContainingType}.{Method}({args})"; - TestNameExpression = displayNameExpression ?? $"\"{externAlias}::{ContainingType}.{Method}({args})\""; + + // Make arguments interpolated expressions to avoid issues with string arguments. + ImmutableArray argumentsForName = arguments.IsDefaultOrEmpty + ? ImmutableArray.Empty + : arguments.Select(arg => $"{{{arg}}}").ToImmutableArray(); + + TestNameExpression = displayNameExpression ?? $"$\"{externAlias}::{ContainingType}.{Method}({string.Join(", ", argumentsForName)})\""; if (method.IsStatic) { diff --git a/src/tests/JIT/HardwareIntrinsics/Arm/Shared/_SveMinimalUnaryOpTestTemplate.template b/src/tests/JIT/HardwareIntrinsics/Arm/Shared/_SveMinimalUnaryOpTestTemplate.template index 782f77de3520ea..5de4a13faa6ad0 100644 --- a/src/tests/JIT/HardwareIntrinsics/Arm/Shared/_SveMinimalUnaryOpTestTemplate.template +++ b/src/tests/JIT/HardwareIntrinsics/Arm/Shared/_SveMinimalUnaryOpTestTemplate.template @@ -50,6 +50,12 @@ namespace JIT.HardwareIntrinsics.Arm // Validates passing an instance member of a struct works test.RunStructFldScenario(); + + // Validates executing the test inside conditional, with op3 as falseValue + test.ConditionalSelect_FalseOp(); + + // Validates executing the test inside conditional, with op3 as zero + test.ConditionalSelect_ZeroOp(); } else { @@ -139,9 +145,12 @@ namespace JIT.HardwareIntrinsics.Arm private static readonly int Op1ElementCount = Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>() / sizeof({Op1BaseType}); private static readonly int RetElementCount = Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>() / sizeof({RetBaseType}); + private static {RetBaseType}[] _maskData = new {RetBaseType}[RetElementCount]; private static {Op1BaseType}[] _data1 = new {Op1BaseType}[Op1ElementCount]; + private {RetVectorType}<{RetBaseType}> _mask; private {Op1VectorType}<{Op1BaseType}> _fld1; + private {RetVectorType}<{RetBaseType}> _falseFld; private DataTable _dataTable; @@ -149,8 +158,12 @@ namespace JIT.HardwareIntrinsics.Arm { Succeeded = true; + for (var i = 0; i < RetElementCount; i++) { _maskData[i] = ({RetBaseType})(TestLibrary.Generator.Get{RetBaseType}() % 2); } + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetVectorType}<{RetBaseType}>, byte>(ref _mask), ref Unsafe.As<{RetBaseType}, byte>(ref _maskData[0]), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); + for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; } Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref _fld1), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>()); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetVectorType}<{RetBaseType}>, byte>(ref _falseFld), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; } _dataTable = new DataTable(_data1, new {RetBaseType}[RetElementCount], LargestVectorSize); @@ -239,6 +252,66 @@ namespace JIT.HardwareIntrinsics.Arm test.RunStructFldScenario(this); } + public void ConditionalSelect_FalseOp() + { + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_mask - operation in trueValue"); + ConditionalSelectScenario_TrueValue(_mask, _fld1, _falseFld); + + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_zero - operation in trueValue"); + ConditionalSelectScenario_TrueValue({RetVectorType}<{RetBaseType}>.Zero, _fld1, _falseFld); + + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_all - operation in trueValue"); + ConditionalSelectScenario_TrueValue({RetVectorType}<{RetBaseType}>.AllBitsSet, _fld1, _falseFld); + + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_mask - operation in falseValue"); + ConditionalSelectScenario_FalseValue(_mask, _fld1, _falseFld); + + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_zero - operation in falseValue"); + ConditionalSelectScenario_FalseValue({RetVectorType}<{RetBaseType}>.Zero, _fld1, _falseFld); + + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_all - operation in falseValue"); + ConditionalSelectScenario_FalseValue({RetVectorType}<{RetBaseType}>.AllBitsSet, _fld1, _falseFld); + } + + public void ConditionalSelect_ZeroOp() + { + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_mask - operation in trueValue"); + ConditionalSelectScenario_TrueValue(_mask, _fld1, {RetVectorType}<{RetBaseType}>.Zero); + + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_zero - operation in trueValue"); + ConditionalSelectScenario_TrueValue({RetVectorType}<{RetBaseType}>.Zero, _fld1, {RetVectorType}<{RetBaseType}>.Zero); + + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_all - operation in trueValue"); + ConditionalSelectScenario_TrueValue({RetVectorType}<{RetBaseType}>.AllBitsSet, _fld1, {RetVectorType}<{RetBaseType}>.Zero); + + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_mask - operation in falseValue"); + ConditionalSelectScenario_FalseValue(_mask, _fld1, {RetVectorType}<{RetBaseType}>.Zero); + + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_zero - operation in falseValue"); + ConditionalSelectScenario_FalseValue({RetVectorType}<{RetBaseType}>.Zero, _fld1, {RetVectorType}<{RetBaseType}>.Zero); + + TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_all - operation in falseValue"); + ConditionalSelectScenario_FalseValue({RetVectorType}<{RetBaseType}>.AllBitsSet, _fld1, {RetVectorType}<{RetBaseType}>.Zero); + } + + [method: MethodImpl(MethodImplOptions.AggressiveInlining)] + private void ConditionalSelectScenario_TrueValue({RetVectorType}<{RetBaseType}> mask, {Op1VectorType}<{Op1BaseType}> op1, {RetVectorType}<{RetBaseType}> falseOp) + { + var result = Sve.ConditionalSelect(mask, {Isa}.{Method}(op1), falseOp); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateConditionalSelectResult_TrueValue(mask, op1, falseOp, _dataTable.outArrayPtr); + } + + [method: MethodImpl(MethodImplOptions.AggressiveInlining)] + private void ConditionalSelectScenario_FalseValue({RetVectorType}<{RetBaseType}> mask, {Op1VectorType}<{Op1BaseType}> op1, {RetVectorType}<{RetBaseType}> trueOp) + { + var result = Sve.ConditionalSelect(mask, trueOp, {Isa}.{Method}(op1)); + + Unsafe.Write(_dataTable.outArrayPtr, result); + ValidateConditionalSelectResult_FalseValue(mask, op1, trueOp, _dataTable.outArrayPtr); + } + public void RunUnsupportedScenario() { TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario)); @@ -260,6 +333,62 @@ namespace JIT.HardwareIntrinsics.Arm } } + private void ValidateConditionalSelectResult_TrueValue({RetVectorType}<{RetBaseType}> maskOp, {Op1VectorType}<{Op1BaseType}> leftOp, {RetVectorType}<{RetBaseType}> falseOp, void* output, [CallerMemberName] string method = "") + { + {RetBaseType}[] mask = new {RetBaseType}[RetElementCount]; + {Op1BaseType}[] firstOp = new {Op1BaseType}[Op1ElementCount]; + {RetBaseType}[] falseVal = new {RetBaseType}[RetElementCount]; + {RetBaseType}[] result = new {RetBaseType}[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref mask[0]), maskOp); + Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref firstOp[0]), leftOp); + Unsafe.WriteUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref falseVal[0]), falseOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref result[0]), ref Unsafe.AsRef(output), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); + + bool succeeded = true; + {TemplateValidationLogicForCndSel} + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sve)}.{nameof({Isa}.{Method})}<{RetBaseType}>({RetVectorType}<{RetBaseType}>, {RetVectorType}<{RetBaseType}>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" mask: ({string.Join(", ", mask)})"); + TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" falseOp: ({string.Join(", ", falseVal)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + + private void ValidateConditionalSelectResult_FalseValue({RetVectorType}<{RetBaseType}> maskOp, {Op1VectorType}<{Op1BaseType}> leftOp, {RetVectorType}<{RetBaseType}> trueOp, void* output, [CallerMemberName] string method = "") + { + {RetBaseType}[] mask = new {RetBaseType}[RetElementCount]; + {Op1BaseType}[] firstOp = new {Op1BaseType}[Op1ElementCount]; + {RetBaseType}[] trueVal = new {RetBaseType}[RetElementCount]; + {RetBaseType}[] result = new {RetBaseType}[RetElementCount]; + + Unsafe.WriteUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref mask[0]), maskOp); + Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref firstOp[0]), leftOp); + Unsafe.WriteUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref trueVal[0]), trueOp); + Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref result[0]), ref Unsafe.AsRef(output), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>()); + + bool succeeded = true; + {TemplateValidationLogicForCndSel_FalseValue} + + if (!succeeded) + { + TestLibrary.TestFramework.LogInformation($"{nameof(Sve)}.{nameof({Isa}.{Method})}<{RetBaseType}>({RetVectorType}<{RetBaseType}>, {RetVectorType}<{RetBaseType}>): {method} failed:"); + TestLibrary.TestFramework.LogInformation($" mask: ({string.Join(", ", mask)})"); + TestLibrary.TestFramework.LogInformation($"firstOp: ({string.Join(", ", firstOp)})"); + TestLibrary.TestFramework.LogInformation($" trueOp: ({string.Join(", ", trueVal)})"); + TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})"); + TestLibrary.TestFramework.LogInformation(string.Empty); + + Succeeded = false; + } + } + private void ValidateResult({Op1VectorType}<{Op1BaseType}> op1, void* result, [CallerMemberName] string method = "") { {Op1BaseType}[] inArray1 = new {Op1BaseType}[Op1ElementCount]; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106868/Runtime_106868.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106868/Runtime_106868.cs new file mode 100644 index 00000000000000..0134bab599463c --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106868/Runtime_106868.cs @@ -0,0 +1,57 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +using System.Runtime.CompilerServices; +using Xunit; + +// Generated by Fuzzlyn v2.3 on 2024-08-23 10:17:54 +// Run on Arm64 Windows +// Seed: 14752078066107523191-vectort,vector64,vector128,armsve +// Reduced from 52.7 KiB to 0.7 KiB in 00:00:54 +// Hits JIT assert in Release: +// Assertion failed '!"Got unexpected instruction format after MOVPRFX"' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Emit code' (IL size 54; hash 0xade6b36b; FullOpts) +// +// File: C:\dev\dotnet\runtime2\src\coreclr\jit\emitarm64sve.cpp Line: 18623 +// + +using System; +using System.Numerics; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.Arm; + +public struct S2 +{ + public Vector F2; +} + +public class Runtime_106868 +{ + public static S2 s_1; + + public static int M4() + { + Vector vr17 = default(Vector); + var vr11 = Vector.Create(0); + var vr8 = Sve.SubtractSaturate(vr17, vr11); + return 1; + } + + [Fact] + public static void TestEntryPoint() + { + if (Sve.IsSupported) + { + var vr12 = Vector.Create(0); + var vr13 = Vector.Create(0); + var vr14 = M4(); + var vr15 = Vector128.CreateScalar(vr14).AsVector(); + var vr16 = Sve.AndAcross(vr13); + s_1.F2 = Sve.ConditionalSelect(vr12, vr16, vr15); + Consume(s_1.F2); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void Consume(Vector v) + { + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106868/Runtime_106868.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_106868/Runtime_106868.csproj new file mode 100644 index 00000000000000..1352ebe3277bc7 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106868/Runtime_106868.csproj @@ -0,0 +1,9 @@ + + + True + $(NoWarn),SYSLIB5003 + + + + + diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106871/Runtime_106871.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106871/Runtime_106871.cs new file mode 100644 index 00000000000000..c69558571a31de --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106871/Runtime_106871.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +using System.Runtime.CompilerServices; +using Xunit; + +// Generated by Fuzzlyn v2.3 on 2024-08-23 10:47:43 +// Run on Arm64 Windows +// Seed: 6363239363759785984-vectort,vector64,vector128,armsve +// Reduced from 29.6 KiB to 0.8 KiB in 00:00:27 +// Debug: Prints 0 line(s) +// Release: Prints 1 line(s) +using System; +using System.Numerics; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.Arm; + +public class Runtime_106871 +{ + [Fact] + public static void TestEntryPoint() + { + if (Sve.IsSupported) + { + var vr11 = (byte)1; + var vr12 = Vector128.CreateScalar(vr11).AsVector(); + var vr13 = Vector.Create(1); + var vr14 = Vector.Create(1); + var vr15 = (byte)Sve.ConditionalExtractAfterLastActiveElement(vr13, 0, vr14); + var vr16 = Vector128.CreateScalar(vr15).AsVector(); + var vr17 = Vector.Create(0); + var vr18 = (byte)1; + var vr19 = Vector128.CreateScalar(vr18).AsVector(); + var vr20 = Sve.MinAcross(vr19); + var vr21 = Sve.ConditionalSelect(vr16, vr20, vr17); + if (Sve.TestFirstTrue(vr12, vr21)) + { + System.Console.WriteLine(0); + } + } + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106871/Runtime_106871.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_106871/Runtime_106871.csproj new file mode 100644 index 00000000000000..1352ebe3277bc7 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106871/Runtime_106871.csproj @@ -0,0 +1,9 @@ + + + True + $(NoWarn),SYSLIB5003 + + + + + diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106872/Runtime_106872.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106872/Runtime_106872.cs new file mode 100644 index 00000000000000..16de557d30335c --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106872/Runtime_106872.cs @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +using System.Runtime.CompilerServices; +using Xunit; + +// Generated by Fuzzlyn v2.3 on 2024-08-23 10:51:00 +// Run on Arm64 Windows +// Seed: 11139641262794602128-vectort,vector64,vector128,armsve +// Reduced from 38.6 KiB to 0.6 KiB in 00:00:32 +// Hits JIT assert in Release: +// Assertion failed 'intrin.op3->IsVectorZero()' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Generate code' (IL size 100; hash 0xade6b36b; FullOpts) +// +// File: C:\dev\dotnet\runtime2\src\coreclr\jit\hwintrinsiccodegenarm64.cpp Line: 755 +// +using System; +using System.Numerics; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.Arm; + +public class C2 +{ + public Vector F3; +} + +public class Runtime_106872 +{ + public static C2[] s_1 = { new C2() }; + + [Fact] + public static void TestEntryPoint() + { + if (Sve.IsSupported) + { + var vr4 = Vector128.CreateScalar(728.8837854670671d).AsVector(); + var vr5 = Vector128.CreateScalar(1103.750484880559d).AsVector(); + var vr6 = Vector128.CreateScalar(-1881.6772519539704d).AsVector(); + var vr7 = s_1[0].F3; + s_1[0].F3 = Sve.ConditionalSelect(vr4, Sve.AddSequentialAcross(vr6, vr7), vr5); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void Consume(Vector v) + { + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106872/Runtime_106872.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_106872/Runtime_106872.csproj new file mode 100644 index 00000000000000..1352ebe3277bc7 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106872/Runtime_106872.csproj @@ -0,0 +1,9 @@ + + + True + $(NoWarn),SYSLIB5003 + + + + + diff --git a/src/tests/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests.cs b/src/tests/ilasm/MethodImplOptions/MethodImplOptionsTests.cs similarity index 57% rename from src/tests/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests.cs rename to src/tests/ilasm/MethodImplOptions/MethodImplOptionsTests.cs index 741b0fcd20034b..f674e4abaa6f37 100644 --- a/src/tests/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests.cs +++ b/src/tests/ilasm/MethodImplOptions/MethodImplOptionsTests.cs @@ -5,10 +5,14 @@ using System.Diagnostics; using System.IO; using System.Text.RegularExpressions; +using Xunit; -public static class MethodImplOptionsTests +public class MethodImplOptionsTests : IDisposable { - public static int Main() + private string _ilasmFile; + private string _ildasmFile; + + public MethodImplOptionsTests() { const int Pass = 100; const int Fail = 101; @@ -17,12 +21,12 @@ public static int Main() if (string.IsNullOrWhiteSpace(coreRoot)) { Console.WriteLine("Environment variable is not set: 'CORE_ROOT'"); - return Fail; + throw new InvalidOperationException("Environment variable is not set: 'CORE_ROOT'"); } if (!Directory.Exists(coreRoot)) { Console.WriteLine($"Did not find CORE_ROOT directory: {coreRoot}"); - return Fail; + throw new InvalidOperationException("Did not find CORE_ROOT directory"); } var nativeExeExtensions = new string[] { string.Empty, ".exe" }; @@ -42,68 +46,41 @@ public static int Main() if (!found) { Console.WriteLine($"Did not find ilasm or ildasm in CORE_ROOT directory: {coreRoot}"); - return Fail; + throw new InvalidOperationException("Did not find ilasm or ildasm in CORE_ROOT directory"); } - bool allPassed = true; - allPassed &= - RunMethodImplOptionsTest( - ilasmFile, - ildasmFile, - "AggressiveOptimizationTest", - "MiAggressiveOptimization.il", - "aggressiveoptimization"); - return allPassed ? Pass : Fail; + _ilasmFile = ilasmFile; + _ildasmFile = ildasmFile; } - private static bool RunMethodImplOptionsTest( - string ilasmFile, - string ildasmFile, + [Theory] + [InlineData("AggressiveOptimizationTest", "MiAggressiveOptimization.il", "aggressiveoptimization")] + public void RunMethodImplOptionsTest( string testName, string ilFileName, string ilDisasmAttributeKeyword) { Console.WriteLine(testName); - try - { - string disasmIlFileName; - ProcessStartInfo ilasmPsi, ildasmPsi; - GetIlasmProcessStartInfos(ilasmFile, ildasmFile, ilFileName, out disasmIlFileName, out ilasmPsi, out ildasmPsi); + string disasmIlFileName; + ProcessStartInfo ilasmPsi, ildasmPsi; + GetIlasmProcessStartInfos(_ilasmFile, _ildasmFile, ilFileName, out disasmIlFileName, out ilasmPsi, out ildasmPsi); - Process ilasmProcess = Process.Start(ilasmPsi); - ilasmProcess.WaitForExit(); - if (ilasmProcess.ExitCode != 0) - { - Console.WriteLine($"ilasm failed with exit code: {ilasmProcess.ExitCode}"); - return false; - } + Process ilasmProcess = Process.Start(ilasmPsi); + ilasmProcess.WaitForExit(); + Assert.Equal(0, ilasmProcess.ExitCode); - Process ildasmProcess = Process.Start(ildasmPsi); - ildasmProcess.WaitForExit(); - if (ildasmProcess.ExitCode != 0) - { - Console.WriteLine($"ildasm failed with exit code: {ildasmProcess.ExitCode}"); - return false; - } + Process ildasmProcess = Process.Start(ildasmPsi); + ildasmProcess.WaitForExit(); + Assert.Equal(0, ildasmProcess.ExitCode); - string disasmIl = File.ReadAllText(disasmIlFileName); - var findMainAttributeRegex = - new Regex( - @"\bvoid\s+Main\s*\(\s*\).*?\b" + ilDisasmAttributeKeyword + @"\b", - RegexOptions.Compiled | RegexOptions.Multiline); - if (!findMainAttributeRegex.IsMatch(disasmIl)) - { - Console.WriteLine($"Attribute '{ilDisasmAttributeKeyword}' did not round-trip through ilasm and ildasm"); - return false; - } - } - catch (Exception ex) - { - Console.WriteLine(ex); - return false; - } - return true; + string disasmIl = File.ReadAllText(disasmIlFileName); + var findMainAttributeRegex = + new Regex( + @"\bvoid\s+Main\s*\(\s*\).*?\b" + ilDisasmAttributeKeyword + @"\b", + RegexOptions.Compiled | RegexOptions.Multiline); + + Assert.True(findMainAttributeRegex.IsMatch(disasmIl), $"Attribute '{ilDisasmAttributeKeyword}' did not round-trip through ilasm and ildasm"); } private static void GetIlasmProcessStartInfos( @@ -137,4 +114,6 @@ private static void GetIlasmProcessStartInfos( disasmIlFileName = $"{Path.GetFileNameWithoutExtension(ilFileName)}_dis{Path.GetExtension(ilFileName)}"; ildasmPsi.Arguments = $"-out={disasmIlFileName} {asmDllFileName}"; } + + public void Dispose() {} } diff --git a/src/tests/ilasm/System/Runtime/CompilerServices/MiAggressiveOptimization.il b/src/tests/ilasm/MethodImplOptions/MiAggressiveOptimization.il similarity index 100% rename from src/tests/ilasm/System/Runtime/CompilerServices/MiAggressiveOptimization.il rename to src/tests/ilasm/MethodImplOptions/MiAggressiveOptimization.il diff --git a/src/tests/ilasm/PortablePdb/IlasmPortablePdbTests.csproj b/src/tests/ilasm/PortablePdb/IlasmPortablePdbTests.csproj deleted file mode 100644 index b03148c6df7635..00000000000000 --- a/src/tests/ilasm/PortablePdb/IlasmPortablePdbTests.csproj +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - diff --git a/src/tests/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests.csproj b/src/tests/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests.csproj deleted file mode 100644 index a7fdfc08922087..00000000000000 --- a/src/tests/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - Exe - - true - - - - - - - Always - - - diff --git a/src/tests/ilasm/ilasm_tests.csproj b/src/tests/ilasm/ilasm_tests.csproj new file mode 100644 index 00000000000000..c174bb2a7de627 --- /dev/null +++ b/src/tests/ilasm/ilasm_tests.csproj @@ -0,0 +1,71 @@ + + + true + + true + + true + + + + + + + + + + + + + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + TestFiles\%(FileName)%(Extension) + + + Always + MiAggressiveOptimization.il + + + + diff --git a/src/tests/issues.targets b/src/tests/issues.targets index a01fe5835c8520..815f1c39a64fea 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -731,10 +731,7 @@ Expectations about finalization order - - Specific to CoreCLR - - + Specific to CoreCLR @@ -1687,21 +1684,6 @@ https://github.com/dotnet/runtime/issues/34072 - - needs triage - - - needs triage - - - needs triage - - - needs triage - - - needs triage - These tests are not supposed to be run with mono. @@ -3107,12 +3089,6 @@ needs triage - - needs triage - - - needs triage - https://github.com/dotnet/runtime/issues/41472 @@ -3270,9 +3246,6 @@ needs triage - - needs triage - needs triage @@ -3333,9 +3306,6 @@ https://github.com/dotnet/runtime/issues/54913 - - https://github.com/dotnet/runtime/issues/54906 - https://github.com/dotnet/runtime/issues/54905 @@ -3510,14 +3480,6 @@ GC_API 0|1|2 - - System.IO.FileNotFoundException: Could not load file or assembly 'xunit.runner.utility.netcoreapp10, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c' or one of its dependencies. - - - - Environment variable is not set: 'CORE_ROOT' - - System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') @@ -3717,12 +3679,6 @@ timeout - - Did not find ilasm or ildasm in CORE_ROOT directory - - - Did not find ilasm or ildasm in CORE_ROOT directory - Can't find file dotnet-diagnostic-{pid}-*-socket @@ -3840,8 +3796,6 @@ - - diff --git a/src/tests/profiler/Directory.Build.targets b/src/tests/profiler/Directory.Build.targets new file mode 100644 index 00000000000000..ebae5726a1450b --- /dev/null +++ b/src/tests/profiler/Directory.Build.targets @@ -0,0 +1,9 @@ + + + + + + true + false + + \ No newline at end of file diff --git a/src/tests/profiler/profiler.csproj b/src/tests/profiler/profiler.csproj new file mode 100644 index 00000000000000..357481d3417c2a --- /dev/null +++ b/src/tests/profiler/profiler.csproj @@ -0,0 +1,13 @@ + + + + true + + true + + + + + + + \ No newline at end of file