Skip to content

Commit 28f8bcd

Browse files
authored
Merge branch 'dotnet:main' into patch-1
2 parents db275f7 + 170c1b9 commit 28f8bcd

File tree

124 files changed

+5961
-1023
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+5961
-1023
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Recommended reading to better understand source generators,
2+
[Roslyn Source Generators Cookbook](https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.cookbook.md).
3+
4+
[Project guidance](./project-guidelines.md#directory-layout)
5+
6+
[Packaging guidance](./libraries-packaging.md#analyzers--source-generators)
7+
8+
## Source Generator Best Practices
9+
10+
### DOs
11+
12+
- **DO** generate code that looks as if a developer would write it manually.
13+
- **DO** emit strings rather than using the Roslyn Syntax API for better performance.
14+
- **DO** use consistent indentation and formatting in generated code.
15+
- **DO** generators should use the [`IIncrementalGenerator`](https://learn.microsoft.com/dotnet/api/microsoft.codeanalysis.iincrementalgenerator) interface.
16+
- **DO** set `<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>` in the source generator project and then don't use any of the banned APIs it lists.
17+
- **DO** set `<IsRoslynComponent>true</IsRoslynComponent>` in the source generator project to enable debugging support in Visual Studio.
18+
- **DO** disable the following Roslyn warning, `RS2008`, in the source generator project (that is, `<NoWarn>$(NoWarn);RS2008</NoWarn>`). The reported issue is handled differently in the runtime repo.
19+
- **DO** emit diagnostics from a separate [analyzer](https://learn.microsoft.com/visualstudio/extensibility/getting-started-with-roslyn-analyzers). The analyzer and source generator can be in the same assembly.
20+
- **DO** cache intermediate results to avoid redundant computation.
21+
- **DO** consider the impact on build time and optimize accordingly.
22+
- **DO** have separate projects for testing the generator and testing the code generated by the generator.
23+
- **DO** use the Roslyn Testing SDK to test the generator (and any corresponding analyzers).
24+
25+
### DON'Ts
26+
27+
- **DON'T** use the Roslyn Syntax API for emitting source code.
28+
- **DON'T** perform expensive operations during the generation process unless absolutely necessary.
29+
- **DON'T** emit code that introduces runtime dependencies not explicitly referenced by the project.
30+
- **DON'T** emit code that would trigger compiler warnings in normal usage scenarios.
31+
- **DON'T** emit diagnostics from the generator itself, emit them from an [analyzer](https://learn.microsoft.com/visualstudio/extensibility/getting-started-with-roslyn-analyzers).

docs/design/datacontracts/Loader.md

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ record struct ModuleLookupTables(
3131

3232
``` csharp
3333
ModuleHandle GetModuleHandle(TargetPointer module);
34+
TargetPointer GetRootAssembly();
3435
TargetPointer GetAssembly(ModuleHandle handle);
36+
TargetPointer GetPEAssembly(ModuleHandle handle);
37+
bool TryGetLoadedImageContents(ModuleHandle handle, out TargetPointer baseAddress, out uint size, out uint imageFlags);
38+
bool TryGetSymbolStream(ModuleHandle handle, out TargetPointer buffer, out uint size);
39+
bool IsProbeExtensionResultValid(ModuleHandle handle);
3540
ModuleFlags GetFlags(ModuleHandle handle);
3641
string GetPath(ModuleHandle handle);
3742
string GetFileName(ModuleHandle handle);
@@ -49,12 +54,14 @@ Data descriptors used:
4954
| Data Descriptor Name | Field | Meaning |
5055
| --- | --- | --- |
5156
| `Module` | `Assembly` | Assembly of the Module |
57+
| `Module` | `PEAssembly` | PEAssembly of the Module |
5258
| `Module` | `Base` | Pointer to start of PE file in memory |
5359
| `Module` | `Flags` | Assembly of the Module |
5460
| `Module` | `LoaderAllocator` | LoaderAllocator of the Module |
5561
| `Module` | `ThunkHeap` | Pointer to the thunk heap |
5662
| `Module` | `Path` | Path of the Module (UTF-16, null-terminated) |
5763
| `Module` | `FileName` | File name of the Module (UTF-16, null-terminated) |
64+
| `Module` | `GrowableSymbolStream` | Pointer to the in memory symbol stream |
5865
| `Module` | `FieldDefToDescMap` | Mapping table |
5966
| `Module` | `ManifestModuleReferencesMap` | Mapping table |
6067
| `Module` | `MemberRefToDescMap` | Mapping table |
@@ -64,18 +71,92 @@ Data descriptors used:
6471
| `ModuleLookupMap` | `TableData` | Start of the mapping table's data |
6572
| `ModuleLookupMap` | `SupportedFlagsMask` | Mask for flag bits on lookup map entries |
6673
| `ModuleLookupMap` | `Count` | Number of TargetPointer sized entries in this section of the map |
67-
| `ModuleLookupMap` | `Next` | Pointer to next ModuleLookupMap segment for this map
68-
| `Assembly` | `IsCollectible` | Flag indicating if this is module may be collected
74+
| `ModuleLookupMap` | `Next` | Pointer to next ModuleLookupMap segment for this map |
75+
| `Assembly` | `IsCollectible` | Flag indicating if this is module may be collected |
76+
| `PEAssembly` | `PEImage` | Pointer to the PEAssembly's PEImage |
77+
| `PEImage` | `LoadedImageLayout` | Pointer to the PEImage's loaded PEImageLayout |
78+
| `PEImage` | `ProbeExtensionResult` | PEImage's ProbeExtensionResult |
79+
| `ProbeExtensionResult` | `Type` | Type of ProbeExtensionResult |
80+
| `PEImageLayout` | `Base` | Base address of the image layout |
81+
| `PEImageLayout` | `Size` | Size of the image layout |
82+
| `PEImageLayout` | `Flags` | Flags associated with the PEImageLayout |
83+
| `CGrowableSymbolStream` | `Buffer` | Pointer to the raw symbol stream buffer start |
84+
| `CGrowableSymbolStream` | `Size` | Size of the raw symbol stream buffer |
85+
| `AppDomain` | `RootAssembly` | Pointer to the root assembly |
86+
87+
Global variables used:
88+
| Global Name | Type | Purpose |
89+
| --- | --- | --- |
90+
| `AppDomain` | TargetPointer | Pointer to the global AppDomain |
91+
6992

7093
``` csharp
7194
ModuleHandle GetModuleHandle(TargetPointer modulePointer)
7295
{
7396
return new ModuleHandle(modulePointer);
7497
}
7598

99+
TargetPointer GetRootAssembly()
100+
{
101+
TargetPointer appDomainPointer = _target.ReadGlobalPointer(Constants.Globals.AppDomain);
102+
AppDomain appDomain = // read AppDomain object starting at appDomainPointer
103+
return appDomain.RootAssembly;
104+
}
105+
76106
TargetPointer GetAssembly(ModuleHandle handle)
77107
{
78-
return target.ReadPointer(handle.Address + /* Module::Assrembly offset */);
108+
return target.ReadPointer(handle.Address + /* Module::Assembly offset */);
109+
}
110+
111+
TargetPointer GetPEAssembly(ModuleHandle handle)
112+
{
113+
return target.ReadPointer(handle.Address + /* Module::PEAssembly offset */);
114+
}
115+
116+
bool TryGetLoadedImageContents(ModuleHandle handle, out TargetPointer baseAddress, out uint size, out uint imageFlags)
117+
{
118+
baseAddress = TargetPointer.Null;
119+
size = 0;
120+
imageFlags = 0;
121+
122+
TargetPointer peAssembly = target.ReadPointer(handle.Address + /* Module::PEAssembly offset */);
123+
if (peAssembly == 0) return false; // no loaded PEAssembly
124+
125+
TargetPointer peImage = target.ReadPointer(peAssembly + /* PEAssembly::PEImage offset */);
126+
if(peImage == 0) return false; // no loaded PEImage
127+
128+
TargetPointer peImageLayout = target.ReadPointer(peImage + /* PEImage::LoadedImageLayout offset */);
129+
130+
baseAddress = target.ReadPointer(peImageLayout + /* PEImageLayout::Base offset */);
131+
size = target.Read<uint>(peImageLayout + /* PEImageLayout::Size offset */);
132+
imageFlags = target.Read<uint>(peImageLayout + /* PEImageLayout::Flags offset */);
133+
return true;
134+
}
135+
136+
bool TryGetSymbolStream(ModuleHandle handle, out TargetPointer buffer, out uint size)
137+
{
138+
buffer = TargetPointer.Null;
139+
size = 0;
140+
141+
TargetPointer growableSymbolStream = target.ReadPointer(handle.Address + /* Module::GrowableSymbolStream offset */);
142+
if (growableSymbolStream == 0) return false; // no GrowableSymbolStream found
143+
144+
buffer = target.ReadPointer(growableSymbolStream + /* CGrowableSymbolStream::Buffer offset */);
145+
size = target.Read<uint>(growableSymbolStream + /* CGrowableSymbolStream::Size offset */);
146+
return true;
147+
}
148+
149+
bool IsProbeExtensionResultValid(ModuleHandle handle)
150+
{
151+
TargetPointer peAssembly = target.ReadPointer(handle.Address + /* Module::PEAssembly offset */);
152+
if (peAssembly == 0) return false; // no loaded PEAssembly
153+
154+
TargetPointer peImage = target.ReadPointer(peAssembly + /* PEAssembly::PEImage offset */);
155+
if(peImage == 0) return false; // no loaded PEImage
156+
157+
TargetPointer probeExtensionResult = target.ReadPointer(peImage + /* PEImage::ProbeExtensionResult offset */);
158+
int type = target.Read<int>(probeExtensionResult + /* ProbeExtensionResult::Type offset */);
159+
return type != 0; // 0 is the invalid type. See assemblyprobeextension.h for details
79160
}
80161

81162
ModuleFlags GetFlags(ModuleHandle handle)

eng/Publishing.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
<ShouldGenerateProductVersionFiles Condition="'$(OutputRID)' == 'win-x64' and ('$(DotNetBuildPass)' == '' or '$(DotNetBuildPass)' == '1')">true</ShouldGenerateProductVersionFiles>
8787
<ShouldGenerateProductVersionFiles Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</ShouldGenerateProductVersionFiles>
8888
</PropertyGroup>
89+
<PropertyGroup Condition="'$(DotNetBuildOrchestrator)' != 'true'">
90+
<ShouldGenerateProductVersionFiles Condition="'$(DotNetFinalPublish)' == 'true'">true</ShouldGenerateProductVersionFiles>
91+
</PropertyGroup>
8992

9093
<Target Name="GenerateProductVersionFiles"
9194
DependsOnTargets="GetNonStableProductVersion"

eng/Version.Details.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
<SourceBuild RepoName="emsdk" ManagedOnly="true" />
7272
</Dependency>
7373
<!-- Intermediate is necessary for source build. -->
74-
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="10.0.620402">
74+
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="10.0.621001">
7575
<Uri>https://github.com/dotnet/source-build-reference-packages</Uri>
76-
<Sha>14f833124983b36ac4083338d0cad6caefce2489</Sha>
76+
<Sha>1df7df81ac783e63aa7fbccb0232ad20fb128b15</Sha>
7777
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
7878
</Dependency>
7979
<!-- Intermediate is necessary for source build. -->
@@ -376,30 +376,30 @@
376376
<Uri>https://github.com/dotnet/runtime-assets</Uri>
377377
<Sha>207b0aac7c32b425a684734a70ba78bfdddb9e48</Sha>
378378
</Dependency>
379-
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="5.0.0-1.25212.1">
379+
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="5.0.0-1.25214.5">
380380
<Uri>https://github.com/dotnet/roslyn</Uri>
381-
<Sha>65ce1f581703f0c34f81937dcb3dc080bc169c81</Sha>
381+
<Sha>959bcb76028fa383d6e1388c60bef630c75470d3</Sha>
382382
</Dependency>
383-
<Dependency Name="Microsoft.CodeAnalysis" Version="5.0.0-1.25212.1">
383+
<Dependency Name="Microsoft.CodeAnalysis" Version="5.0.0-1.25214.5">
384384
<Uri>https://github.com/dotnet/roslyn</Uri>
385-
<Sha>65ce1f581703f0c34f81937dcb3dc080bc169c81</Sha>
385+
<Sha>959bcb76028fa383d6e1388c60bef630c75470d3</Sha>
386386
</Dependency>
387-
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="5.0.0-1.25212.1">
387+
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="5.0.0-1.25214.5">
388388
<Uri>https://github.com/dotnet/roslyn</Uri>
389-
<Sha>65ce1f581703f0c34f81937dcb3dc080bc169c81</Sha>
389+
<Sha>959bcb76028fa383d6e1388c60bef630c75470d3</Sha>
390390
</Dependency>
391-
<Dependency Name="Microsoft.CodeAnalysis.Analyzers" Version="3.12.0-beta1.25212.1">
391+
<Dependency Name="Microsoft.CodeAnalysis.Analyzers" Version="3.12.0-beta1.25214.5">
392392
<Uri>https://github.com/dotnet/roslyn</Uri>
393-
<Sha>65ce1f581703f0c34f81937dcb3dc080bc169c81</Sha>
393+
<Sha>959bcb76028fa383d6e1388c60bef630c75470d3</Sha>
394394
</Dependency>
395395
<Dependency Name="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.0-preview.25127.1">
396396
<Uri>https://github.com/dotnet/roslyn-analyzers</Uri>
397397
<Sha>345816fb41f40db5463ecc9b4308d29fbc0e4eaf</Sha>
398398
</Dependency>
399399
<!-- Intermediate is necessary for source build. -->
400-
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="5.0.0-1.25212.1">
400+
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="5.0.0-1.25214.5">
401401
<Uri>https://github.com/dotnet/roslyn</Uri>
402-
<Sha>65ce1f581703f0c34f81937dcb3dc080bc169c81</Sha>
402+
<Sha>959bcb76028fa383d6e1388c60bef630c75470d3</Sha>
403403
<SourceBuild RepoName="roslyn" ManagedOnly="true" />
404404
</Dependency>
405405
<Dependency Name="Microsoft.DotNet.ApiCompat.Task" Version="10.0.100-preview.3.25173.9">

eng/Versions.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636
</ItemGroup>
3737
<PropertyGroup>
3838
<!-- dotnet/roslyn-analyzers dependencies -->
39-
<MicrosoftCodeAnalysisAnalyzersVersion>3.12.0-beta1.25212.1</MicrosoftCodeAnalysisAnalyzersVersion>
39+
<MicrosoftCodeAnalysisAnalyzersVersion>3.12.0-beta1.25214.5</MicrosoftCodeAnalysisAnalyzersVersion>
4040
<MicrosoftCodeAnalysisNetAnalyzersVersion>10.0.0-preview.25127.1</MicrosoftCodeAnalysisNetAnalyzersVersion>
4141
<!-- dotnet/roslyn dependencies -->
4242
<!--
4343
These versions should not be used by any project that contributes to the design-time experience in VS, such as an analyzer, code-fix, or generator assembly.
4444
Any tools that contribute to the design-time experience should use the MicrosoftCodeAnalysisVersion_LatestVS property above to ensure
4545
they do not break the local dev experience.
4646
-->
47-
<MicrosoftCodeAnalysisCSharpVersion>5.0.0-1.25212.1</MicrosoftCodeAnalysisCSharpVersion>
48-
<MicrosoftCodeAnalysisVersion>5.0.0-1.25212.1</MicrosoftCodeAnalysisVersion>
49-
<MicrosoftNetCompilersToolsetVersion>5.0.0-1.25212.1</MicrosoftNetCompilersToolsetVersion>
47+
<MicrosoftCodeAnalysisCSharpVersion>5.0.0-1.25214.5</MicrosoftCodeAnalysisCSharpVersion>
48+
<MicrosoftCodeAnalysisVersion>5.0.0-1.25214.5</MicrosoftCodeAnalysisVersion>
49+
<MicrosoftNetCompilersToolsetVersion>5.0.0-1.25214.5</MicrosoftNetCompilersToolsetVersion>
5050
</PropertyGroup>
5151
<!--
5252
For source generator support we need to target multiple versions of Roslyn in order to be able to run on older versions of Roslyn.

eng/pipelines/runtime-official.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ extends:
473473
targetFolder: $(Build.SourcesDirectory)/artifacts/workloadPackages
474474
flattenFolders: true
475475

476-
buildArgs: -s mono.workloads -c $(_BuildConfig) -restore -build -publish /p:PackageSource=$(Build.SourcesDirectory)/artifacts/workloadPackages /p:WorkloadOutputPath=$(Build.SourcesDirectory)/artifacts/workloads /p:ShouldGenerateProductVersionFiles=true /p:EnableDefaultRidSpecificArtifacts=false
476+
buildArgs: -s mono.workloads -c $(_BuildConfig) -restore -build -publish /p:PackageSource=$(Build.SourcesDirectory)/artifacts/workloadPackages /p:WorkloadOutputPath=$(Build.SourcesDirectory)/artifacts/workloads /p:EnableDefaultRidSpecificArtifacts=false
477477

478478
isOfficialBuild: true
479479
timeoutInMinutes: 120

eng/pipelines/runtime.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,16 @@ extends:
818818
#
819819
# WebAssembly legs
820820
#
821+
- template: /eng/pipelines/common/templates/wasm-library-tests.yml
822+
parameters:
823+
platforms:
824+
- browser_wasm
825+
alwaysRun: ${{ variables.isRollingBuild }}
826+
extraBuildArgs: /p:AotHostArchitecture=x64 /p:AotHostOS=$(_hostedOS)
827+
scenarios:
828+
- WasmTestOnChrome
829+
- WasmTestOnFirefox
830+
821831
- template: /eng/pipelines/common/templates/wasm-library-tests.yml
822832
parameters:
823833
platforms:

eng/testing/linker/project.csproj.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<MicrosoftNetCoreAppRuntimePackDir>{MicrosoftNetCoreAppRuntimePackDir}</MicrosoftNetCoreAppRuntimePackDir>
5454

5555
<RepositoryEngineeringDir>{RepositoryEngineeringDir}</RepositoryEngineeringDir>
56-
<_ExtraTrimmerArgs>{ExtraTrimmerArgs} $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs>
56+
<_ExtraTrimmerArgs>{ExtraTrimmerArgs} $(_ExtraTrimmerArgs) --dump-dependencies</_ExtraTrimmerArgs>
5757
{AdditionalProperties}
5858

5959
<!-- Needed for PublishAot -->

src/coreclr/System.Private.CoreLib/src/System/Runtime/ExceptionServices/AsmOffsets.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ class AsmOffsets
5959
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x148;
6060
#elif TARGET_X86
6161
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
62-
public const int SIZEOF__StackFrameIterator = 0x3c4;
63-
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x3b2;
64-
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x3c0;
62+
public const int SIZEOF__StackFrameIterator = 0x3cc;
63+
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x3ba;
64+
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x3c8;
6565
#else // TARGET_64BIT
6666
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
67-
public const int SIZEOF__StackFrameIterator = 0xc4;
68-
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0xb2;
69-
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0xc0;
67+
public const int SIZEOF__StackFrameIterator = 0xcc;
68+
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0xba;
69+
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0xc8;
7070
#endif // TARGET_64BIT
7171

7272
#else // DEBUG
@@ -116,14 +116,14 @@ class AsmOffsets
116116
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x140;
117117
#elif TARGET_X86
118118
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
119-
public const int SIZEOF__StackFrameIterator = 0x3bc;
120-
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x3aa;
121-
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x3b8;
119+
public const int SIZEOF__StackFrameIterator = 0x3c4;
120+
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0x3b2;
121+
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0x3c0;
122122
#else // TARGET_64BIT
123123
public const int OFFSETOF__REGDISPLAY__m_pCurrentContext = 0x4;
124-
public const int SIZEOF__StackFrameIterator = 0xbc;
125-
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0xaa;
126-
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0xb8;
124+
public const int SIZEOF__StackFrameIterator = 0xc4;
125+
public const int OFFSETOF__StackFrameIterator__m_isRuntimeWrappedExceptions = 0xb2;
126+
public const int OFFSETOF__StackFrameIterator__m_AdjustedControlPC = 0xc0;
127127
#endif // TARGET_64BIT
128128

129129
#endif // DEBUG

0 commit comments

Comments
 (0)