Skip to content

Commit

Permalink
Merge branch 'main' into seal
Browse files Browse the repository at this point in the history
  • Loading branch information
filipnavara authored Mar 19, 2024
2 parents f214014 + 6d412f4 commit 8d36989
Show file tree
Hide file tree
Showing 169 changed files with 2,463 additions and 2,391 deletions.
80 changes: 38 additions & 42 deletions docs/design/features/byreflike-generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,61 @@ The expansion of ByRefLike types as Generic parameters does not relax restrictio

## API Proposal

Support for the following will be indicated by a new property. For .NET 7, the feature will be marked with `RequiresPreviewFeaturesAttribute` to indicate it is in [preview](https://github.com/dotnet/designs/blob/main/accepted/2021/preview-features/preview-features.md).
A new `GenericParameterAttributes` value will be defined which also represents metadata defined in the `CorGenericParamAttr` enumeration.

```diff
namespace System.Runtime.CompilerServices
namespace System.Reflection
{
public static partial class RuntimeFeature
[Flags]
public enum GenericParameterAttributes
{
+ /// <summary>
+ /// Represents a runtime feature where byref-like types can be used in Generic parameters.
+ /// </summary>
+ public const string GenericsAcceptByRefLike = nameof(GenericsAcceptByRefLike);
+ AcceptByRefLike = 0x0020
}
}
```

The compiler will need an indication for existing troublesome APIs where ByRefLike types will be permissable, but where the failure will be handled at runtime. An attribute will be created and added to these APIs.
```diff
typedef enum CorGenericParamAttr
{
+ gpAcceptByRefLike = 0x0020 // type argument can be ByRefLike
} CorGenericParamAttr;
```

The expansion of metadata will impact at least the following:

- ILDasm/ILAsm/`System.Reflection.Metadata`/`System.Reflection.Emit` &ndash; https://github.com/dotnet/runtime
- Cecil &ndash; https://github.com/jbevain/cecil
- IL Trimmer &ndash; https://github.com/dotnet/runtime/tree/main/src/tools/illink
- F# &ndash; https://github.com/fsharp/fsharp
- C++/CLI &ndash; The MSVC team

### Troublesome API mitigation

If existing types are expected to add ByRefLike support, it is possible they contain previously valid APIs that will become invalid when ByRefLike types are permitted. A potential mitigation for this would be create an attribute to indicate to compilers that specific APIs are validated at run-time not compile-time. What follows is a potential solution.

The compiler will be imbued with knowledge of an API that tells it where ByRefLike types will be permissable and where the failure will be handled by the runtime. The compiler will only respect the attribute that is defined in the same assembly containing `System.Object`.

```csharp
namespace System.Runtime.CompilerServices
{
/// <summary>
/// Indicates to the compiler that constraint checks should be suppressed
/// and will instead be enforced at run-time.
/// Indicates to the compiler the ByRefLike constraint check should be suppressed.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property)]
internal sealed class SuppressConstraintChecksAttribute : Attribute
{ }
/// <remarks>
/// The checking will be suppressed for both the signature and method body. These
/// checks are deferred and will be enforced at run-time.
/// </remarks>
/// <seealso href="https://github.com/dotnet/runtime/issues/99788">Design discussion</seealso>
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
internal sealed class SuppressByRefLikeConstraintChecksAttribute : Attribute
{
/// <summary>Initializes the attribute.</summary>
public SuppressByRefLikeConstraintChecksAttribute() { }
}
}
```

Troublesome APIs:
Current examples of APIs that would need the attribute applied:

- [`Span<T>`](https://docs.microsoft.com/dotnet/api/system.span-1)
- `public Span(T[]? array);`
Expand All @@ -73,34 +97,6 @@ Troublesome APIs:
- `public static implicit operator ReadOnlySpan<T>(ArraySegment<T> segment);`
- `public static implicit operator ReadOnlySpan<T>(T[]? array);`

A new `GenericParameterAttributes` value will be defined which also represents metadata defined in the `CorGenericParamAttr` enumeration.

```diff
namespace System.Reflection
{
[Flags]
public enum GenericParameterAttributes
{
+ AcceptByRefLike = 0x0020
}
}
```

```diff
typedef enum CorGenericParamAttr
{
+ gpAcceptByRefLike = 0x0020 // type argument can be ByRefLike
} CorGenericParamAttr;
```

The expansion of metadata will impact at least the following:

- ILDasm/ILAsm/`System.Reflection.Metadata`/`System.Reflection.Emit` &ndash; https://github.com/dotnet/runtime
- Cecil &ndash; https://github.com/jbevain/cecil
- IL Trimmer &ndash; https://github.com/dotnet/runtime/tree/main/src/tools/illink
- F# &ndash; https://github.com/fsharp/fsharp
- C++/CLI &ndash; The MSVC team

## Semantic Proposal

An API that is a JIT-time intrinsic will be needed to determine if a parameter is ByRefLike. This API would represent a check to occur at JIT time to avoid taking paths that would be invalid for some values of `T`. The existing `Type.IsByRefLike` property will be made an intrinsic (e.g., `typeof(T).IsByRefLike`).
Expand Down
1 change: 1 addition & 0 deletions eng/Publishing.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
$(ArtifactsPackagesDir)**\*.zip;
$(ArtifactsPackagesDir)**\*.deb;
$(ArtifactsPackagesDir)**\*.rpm;
$(ArtifactsPackagesDir)**\*.pkg;
$(ArtifactsPackagesDir)**\*.exe;
$(ArtifactsPackagesDir)**\*.msi"
Exclude="$(ArtifactsPackagesDir)**\Symbols.runtime.tar.gz" />
Expand Down
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
<SourceBuild RepoName="emsdk" ManagedOnly="true" />
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="9.0.0-alpha.1.24155.1">
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="9.0.0-alpha.1.24162.2">
<Uri>https://github.com/dotnet/source-build-reference-packages</Uri>
<Sha>768378e775fc5ddc99d41f2c4d1c78182f326ea7</Sha>
<Sha>c0b5d69a1a1513528c77fffff708c7502d57c35c</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<!-- Intermediate is necessary for source build. -->
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageVersionNet7>7.0.$([MSBuild]::Add($([System.Version]::Parse('$(PackageVersionNet8)').Build),14))</PackageVersionNet7>
<PackageVersionNet6>6.0.$([MSBuild]::Add($([System.Version]::Parse('$(PackageVersionNet7)').Build),11))</PackageVersionNet6>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
<PreReleaseVersionIteration>3</PreReleaseVersionIteration>
<PreReleaseVersionIteration>4</PreReleaseVersionIteration>
<!-- Enable to remove prerelease label. -->
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">false</StabilizePackageVersion>
<DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/common/global-build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ parameters:
preBuildSteps: []
enableRichCodeNavigation: false
richCodeNavigationLanguage: 'csharp'
disableComponentGovernance: false
disableComponentGovernance: ''

jobs:
- template: /eng/common/templates/job/job.yml
Expand Down
8 changes: 5 additions & 3 deletions eng/pipelines/common/templates/runtimes/xplat-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ parameters:
timeoutInMinutes: ''
enableMicrobuild: ''
gatherAssetManifests: false
disableComponentGovernance: false
disableComponentGovernance: ''

variables: {} ## any extra variables to add to the defaults defined below

Expand Down Expand Up @@ -64,9 +64,11 @@ jobs:
${{ if eq(parameters.osGroup, 'windows') }}:
agentOs: windows

# Disable component governance if requested or on musl machines where it does not work well
${{ if or(eq(parameters.disableComponentGovernance, true), eq(parameters.osSubGroup, '_musl')) }}:
# Component governance does not work on musl machines
${{ if eq(parameters.osSubGroup, '_musl') }}:
disableComponentGovernance: true
${{ else }}:
disableComponentGovernance: ${{ parameters.disableComponentGovernance }}

# Setting this results in the arcade job template including a step
# that gathers asset manifests and publishes them to pipeline
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/coreclr/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extends:
#
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/templates/global-build-job.yml
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: debug
platforms:
- linux_arm
Expand All @@ -69,7 +69,7 @@ extends:
#
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/templates/global-build-job.yml
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: release
platforms:
- linux_arm
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/coreclr/libraries-gcstress-extra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ extends:
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: checked
buildConfig: Release
helixQueueGroup: libraries
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
platformGroup: gcstress
jobParameters:
# Default timeout is 150 minutes (2.5 hours), which is not enough for stress.
timeoutInMinutes: 660
buildArgs: -s clr+libs -c $(_BuildConfig) -lc Release
buildArgs: -s clr+libs+libs.tests -rc Checked -c $(_BuildConfig) /p:ArchiveTests=true
postBuildSteps:
- template: /eng/pipelines/libraries/helix.yml
parameters:
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/coreclr/libraries-gcstress0x3-gcstress0xc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ extends:
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: checked
buildConfig: release
helixQueueGroup: libraries
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
platformGroup: gcstress
jobParameters:
# Default timeout is 150 minutes (2.5 hours), which is not enough for stress.
timeoutInMinutes: 660
buildArgs: -s clr+libs -c $(_BuildConfig) -lc Release
buildArgs: -s clr+libs+libs.tests -rc Checked -c $(_BuildConfig) /p:ArchiveTests=true
postBuildSteps:
- template: /eng/pipelines/libraries/helix.yml
parameters:
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/coreclr/libraries-jitstress-random.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extends:
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: checked
buildConfig: Release
helixQueueGroup: libraries
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
platforms:
Expand All @@ -34,7 +34,7 @@ extends:
jobParameters:
# Default timeout is 150 minutes (2.5 hours), which is not enough for stress.
timeoutInMinutes: 360
buildArgs: -s clr+libs -c $(_BuildConfig) -lc Release
buildArgs: -s clr+libs+libs.tests -rc Checked -c $(_BuildConfig) /p:ArchiveTests=true
postBuildSteps:
- template: /eng/pipelines/libraries/helix.yml
parameters:
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/coreclr/libraries-jitstress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extends:
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: checked
buildConfig: Release
helixQueueGroup: libraries
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
platforms:
Expand All @@ -34,7 +34,7 @@ extends:
jobParameters:
# Default timeout is 150 minutes (2.5 hours), which is not enough for stress.
timeoutInMinutes: 360
buildArgs: -s clr+libs -c $(_BuildConfig) -lc Release
buildArgs: -s clr+libs+libs.tests -rc Checked -c $(_BuildConfig) /p:ArchiveTests=true
postBuildSteps:
- template: /eng/pipelines/libraries/helix.yml
parameters:
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/coreclr/libraries-jitstress2-jitstressregs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extends:
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: checked
buildConfig: Release
helixQueueGroup: libraries
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
platforms:
Expand All @@ -34,7 +34,7 @@ extends:
jobParameters:
# Default timeout is 150 minutes (2.5 hours), which is not enough for stress.
timeoutInMinutes: 360
buildArgs: -s clr+libs -c $(_BuildConfig) -lc Release
buildArgs: -s clr+libs+libs.tests -rc Checked -c $(_BuildConfig) /p:ArchiveTests=true
postBuildSteps:
- template: /eng/pipelines/libraries/helix.yml
parameters:
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/coreclr/libraries-jitstressregs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extends:
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: checked
buildConfig: Release
helixQueueGroup: libraries
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
platforms:
Expand All @@ -34,7 +34,7 @@ extends:
jobParameters:
# Default timeout is 150 minutes (2.5 hours), which is not enough for stress.
timeoutInMinutes: 360
buildArgs: -s clr+libs -c $(_BuildConfig) -lc Release
buildArgs: -s clr+libs+libs.tests -rc Checked -c $(_BuildConfig) /p:ArchiveTests=true
postBuildSteps:
- template: /eng/pipelines/libraries/helix.yml
parameters:
Expand Down
8 changes: 4 additions & 4 deletions eng/pipelines/coreclr/libraries-pgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ extends:
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: checked
buildConfig: Release
helixQueueGroup: libraries
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
platforms:
- windows_arm64
jobParameters:
# Default timeout is 150 minutes (2.5 hours), which is not enough for stress.
timeoutInMinutes: 660
buildArgs: -s clr+libs -c $(_BuildConfig) -lc Release
buildArgs: -s clr+libs+libs.tests -rc Checked -c $(_BuildConfig) /p:ArchiveTests=true
postBuildSteps:
- template: /eng/pipelines/libraries/helix.yml
parameters:
Expand All @@ -41,7 +41,7 @@ extends:
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: checked
buildConfig: Release
helixQueueGroup: libraries
helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
platforms:
Expand All @@ -53,7 +53,7 @@ extends:
jobParameters:
# Default timeout is 150 minutes (2.5 hours), which is not enough for stress.
timeoutInMinutes: 660
buildArgs: -s clr+libs -c $(_BuildConfig) -lc Release
buildArgs: -s clr+libs+libs.tests -rc Checked -c $(_BuildConfig) /p:ArchiveTests=true
postBuildSteps:
- template: /eng/pipelines/libraries/helix.yml
parameters:
Expand Down
17 changes: 17 additions & 0 deletions eng/pipelines/coreclr/perf-non-wasm-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,23 @@ jobs:
runKind: micro
runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
logicalmachine: 'perfowl'

# run coreclr perfviper microbenchmarks perf job
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/coreclr/templates/perf-job.yml
buildConfig: release
runtimeFlavor: coreclr
platforms:
- linux_x64
- windows_x64
jobParameters:
testGroup: perf
liveLibrariesBuildConfig: Release
projectFile: microbenchmarks.proj
runKind: micro
runJobTemplate: /eng/pipelines/coreclr/templates/run-performance-job.yml
logicalmachine: 'perfviper'

# run coreclr perfowl microbenchmarks perf gdv3 jobs
- template: /eng/pipelines/common/platform-matrix.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
artifactFileName: 'CheckedJIT_$(osGroup)$(osSubgroup)_$(archType)$(archiveExtension)'
artifactName: 'CheckedJIT_$(osGroup)$(osSubgroup)_$(archType)'
displayName: 'JIT checked build'
cleanupUnpackFolder: false
cleanUnpackFolder: false

# Download jit release builds
- template: /eng/pipelines/common/download-artifact-step.yml
Expand All @@ -51,4 +51,4 @@ jobs:
artifactFileName: 'ReleaseJIT_$(osGroup)$(osSubgroup)_$(archType)$(archiveExtension)'
artifactName: 'ReleaseJIT_$(osGroup)$(osSubgroup)_$(archType)'
displayName: 'JIT release build'
cleanupUnpackFolder: false
cleanUnpackFolder: false
4 changes: 2 additions & 2 deletions eng/pipelines/coreclr/templates/superpmi-diffs-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
artifactFileName: 'CheckedJIT_$(osGroup)$(osSubgroup)_$(archType)$(archiveExtension)'
artifactName: 'CheckedJIT_$(osGroup)$(osSubgroup)_$(archType)'
displayName: 'JIT checked build'
cleanupUnpackFolder: false
cleanUnpackFolder: false

- ${{ if in(parameters.diffType, 'tpdiff', 'all') }}:
# Download jit release builds
Expand All @@ -69,4 +69,4 @@ jobs:
artifactFileName: 'ReleaseJIT_$(osGroup)$(osSubgroup)_$(archType)$(archiveExtension)'
artifactName: 'ReleaseJIT_$(osGroup)$(osSubgroup)_$(archType)'
displayName: 'JIT release build'
cleanupUnpackFolder: false
cleanUnpackFolder: false
2 changes: 1 addition & 1 deletion eng/pipelines/coreclr/templates/superpmi-replay-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
artifactFileName: 'CheckedJIT_$(osGroup)$(osSubgroup)_$(archType)$(archiveExtension)'
artifactName: 'CheckedJIT_$(osGroup)$(osSubgroup)_$(archType)'
displayName: 'JIT checked build'
cleanupUnpackFolder: false
cleanUnpackFolder: false
Loading

0 comments on commit 8d36989

Please sign in to comment.