Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge feature/use-dllimport-generator to main #59579

Merged
merged 180 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
d60daba
Initial scaffolding for DllImportGenerator
AaronRobinsonMSFT Jul 13, 2020
18ed2b4
Add GENERATE_FORWARDER define to demonstrate the ability to forward
AaronRobinsonMSFT Jul 13, 2020
1021cf0
Check for code snippet compilation errors
AaronRobinsonMSFT Jul 13, 2020
c2a28f6
Add example that runs on Windows to the demo project.
AaronRobinsonMSFT Jul 13, 2020
8968ab3
Update readme with existing experiments (dotnet/runtimelab#8)
AaronRobinsonMSFT Jul 13, 2020
9106576
Update CreateAndExperiment.md (dotnet/runtimelab#32)
jkotas Jul 25, 2020
81a7a3d
Add testing for attribute discovery in cases where the user prefixes
AaronRobinsonMSFT Jul 28, 2020
22bcd43
Merge pull request dotnet/runtimelab#35 from AaronRobinsonMSFT/failur…
AaronRobinsonMSFT Jul 29, 2020
9968397
Collect DllImport details through Roslyn semantic model (dotnet/runti…
AaronRobinsonMSFT Aug 3, 2020
c58dead
Special case boolean/char types in managed/native signatures. (dotnet…
AaronRobinsonMSFT Aug 5, 2020
83fbd4e
Add struct marshalling design doc. (dotnet/runtimelab#45)
jkoritzinsky Aug 17, 2020
0f74067
Add the struct marshalling attributes to Ancillary.Interop and add an…
jkoritzinsky Sep 1, 2020
1104711
Implement infra to support marshalling blittable generics (equivalent…
jkoritzinsky Sep 3, 2020
547a0d1
Update docs to include convention (dotnet/runtimelab#93)
safern Sep 11, 2020
6c25cca
Basic structure for composing stub code (dotnet/runtimelab#87)
elinor-fung Sep 16, 2020
d47569d
Use declaring syntax as a baseline for generated syntax for containin…
jkoritzinsky Sep 17, 2020
4fce845
Move to 3.8.0-3.final Roslyn packages (dotnet/runtimelab#119)
elinor-fung Sep 21, 2020
d415807
Add validation that the StackBufferSize member exists when a stackall…
jkoritzinsky Sep 26, 2020
ced0268
Consume DNNE for testing (dotnet/runtimelab#124)
AaronRobinsonMSFT Sep 26, 2020
6041006
Implement marshaler selection based on metadata model (dotnet/runtime…
jkoritzinsky Sep 29, 2020
ff96442
Fix true and false for the Bool marshaller (dotnet/runtimelab#130)
jkoritzinsky Sep 29, 2020
40a5e2b
Update CreateAnExperiment.md
jkotas Oct 1, 2020
ea4e979
SafeHandle marshalling (dotnet/runtimelab#133)
jkoritzinsky Oct 5, 2020
04d8328
Create test projects (dotnet/runtimelab#149)
AaronRobinsonMSFT Oct 8, 2020
09e1a9d
Boolean and Delegate tests (dotnet/runtimelab#152)
AaronRobinsonMSFT Oct 9, 2020
653aeb3
Report diagnostics in generator (dotnet/runtimelab#158)
elinor-fung Oct 10, 2020
d4393f8
Add Char marshaller (dotnet/runtimelab#212)
AaronRobinsonMSFT Oct 14, 2020
9e6fb96
Fix warnings for analyzer release (dotnet/runtimelab#227)
AaronRobinsonMSFT Oct 14, 2020
25be33e
Create branch template for standalone templates.
safern Oct 9, 2020
6bb8819
Enable nullability checks across DllImportGenerator (dotnet/runtimela…
jkoritzinsky Oct 20, 2020
791a2a6
String marshallers for UTF-16 and UTF-8 (dotnet/runtimelab#249)
elinor-fung Oct 21, 2020
b57e347
Disable nullable checks in integration tests (dotnet/runtimelab#253)
elinor-fung Oct 21, 2020
8f84066
Remove support for the custom marshaller on MarshalAsAttribute. (dotn…
AaronRobinsonMSFT Oct 21, 2020
c5d750f
Add initial blittable struct test (dotnet/runtimelab#230)
AaronRobinsonMSFT Oct 21, 2020
e3a0ede
Add standalone template for experiments that don't need runtime feat…
safern Oct 21, 2020
247b204
Factor out some nullability uses (dotnet/runtimelab#259)
AaronRobinsonMSFT Oct 23, 2020
4e79a8e
Add event for marking the Start/Stop of source generation (dotnet/run…
AaronRobinsonMSFT Oct 23, 2020
0a073bd
Report generator diagnostic when trying to target pre-.NET 5.0 (dotne…
elinor-fung Oct 30, 2020
3cef350
Add analyzer for GeneratedDllImport attribute usage (dotnet/runtimela…
elinor-fung Nov 2, 2020
c9fdb1b
Array marshalling support (dotnet/runtimelab#272)
jkoritzinsky Nov 3, 2020
d746fcb
Fix byte length calculation for UTF-16 strings (dotnet/runtimelab#285)
elinor-fung Nov 3, 2020
d816fda
Merge remote-tracking branch 'dotnet/standalone-template' into dllimp…
jkoritzinsky Nov 4, 2020
01a1930
Add string marshallers for ANSI and platform-defined (dotnet/runtimel…
elinor-fung Nov 5, 2020
e756fa1
Report diagnostic for `BestFitMapping`, `ThrowOnUnmappableChar`, and …
elinor-fung Nov 5, 2020
2e93e69
Apply changes to integrate standalone experiment CI/CD pipeline with …
jkoritzinsky Nov 5, 2020
36da5ae
Upgrade DNNE to 1.0.16
jkoritzinsky Nov 6, 2020
cfd513c
Merge pull request dotnet/runtimelab#308 from jkoritzinsky/dllimportg…
jkoritzinsky Nov 6, 2020
996b4f8
Let enums and pointers go through blittable marshaller (dotnet/runtim…
elinor-fung Nov 6, 2020
8aafa23
Disable packing Demo app, tools, and test assets. (dotnet/runtimelab#…
jkoritzinsky Nov 10, 2020
1719a7c
Fix formatting for some diagnostic messages (dotnet/runtimelab#311)
elinor-fung Nov 13, 2020
a17d5d5
Handle PreserveSig=false (dotnet/runtimelab#323)
elinor-fung Nov 14, 2020
80349fb
Implement the non-blittable type marshalling proposal (dotnet/runtime…
jkoritzinsky Nov 19, 2020
e82452d
Add DynamicallyAccessedMembers attribute to CreateSafeHandle API (dot…
elinor-fung Nov 21, 2020
8a324f2
Apply SkipLocalsInitAttribute to generated stubs. (dotnet/runtimelab#…
AaronRobinsonMSFT Nov 23, 2020
10d3f8a
Fix setting of allocation marker in ANSI string marshaller (dotnet/ru…
elinor-fung Nov 23, 2020
4700722
Handle SetLastError=true (dotnet/runtimelab#360)
elinor-fung Nov 30, 2020
67e674b
Add analyzer to flag converting from DllImport to GeneratedDllImport …
elinor-fung Dec 1, 2020
15c6272
Reliability improvements for array marshalling (dotnet/runtimelab#384)
jkoritzinsky Dec 5, 2020
f037d9e
Update prefix of packages and published assemblies (dotnet/runtimelab…
AaronRobinsonMSFT Dec 7, 2020
d24260a
Support arrays of types with simple custom marshalling (dotnet/runtim…
jkoritzinsky Dec 10, 2020
9bc3120
Implement support for configurable generator options. (dotnet/runtime…
jkoritzinsky Jan 4, 2021
6f0fd0d
Add handling for [In, Out] attributes. (dotnet/runtimelab#380)
jkoritzinsky Jan 4, 2021
c64f379
Update Compatibility doc for struct marshalling (dotnet/runtimelab#548)
jkoritzinsky Jan 11, 2021
14ae620
Add Benchmarks project. (dotnet/runtimelab#538)
jkoritzinsky Jan 11, 2021
8ba6bf0
Test fill-in (dotnet/runtimelab#535)
elinor-fung Jan 11, 2021
5a89cbb
Handle enums when checking if type is considered blittable (dotnet/ru…
elinor-fung Jan 15, 2021
7d5caa0
Add fixer for converting to GeneratedDllImport (dotnet/runtimelab#564)
elinor-fung Jan 20, 2021
a4330b4
Update SafeHandle codegen to match the approved API. (dotnet/runtimel…
jkoritzinsky Jan 20, 2021
06f7050
Fix build errors from an updated SDK/compiler and floating package ve…
jkoritzinsky Apr 9, 2021
59aa9c7
Fix cases when preprocessor definitions are surrounding the method we…
jkoritzinsky Apr 12, 2021
8429569
Rename MarshalEx.SetLastWin32Error -> SetLastPInvokeError (dotnet/run…
elinor-fung Apr 24, 2021
01325b1
Update to Arcade 6.0.0-beta.21222.1 (dotnet/runtimelab#1008)
elinor-fung Apr 26, 2021
c6ccabb
Stop using myget feed (dotnet/runtimelab#1022)
elinor-fung Apr 26, 2021
27ab2e9
Update analysis warning location model to new syntax and clean up ana…
jkoritzinsky Apr 28, 2021
a20fbed
Merge latest standalone-template into feature/DllImportGenerator (dot…
elinor-fung Apr 28, 2021
f524afa
Move docs to top-level directory (dotnet/runtimelab#1034)
elinor-fung Apr 28, 2021
d7a6a6f
Add DLLIMPORTGENERATOR_ENABLED when DllImportGenerator package is ref…
elinor-fung Apr 30, 2021
016ae6f
Switch to the now-built-in Marshal APIs from MarshalEx (dotnet/runtim…
jkoritzinsky Apr 30, 2021
5a0fc06
Handle function pointers (dotnet/runtimelab#1043)
elinor-fung Apr 30, 2021
a4e4279
Fix link (dotnet/runtimelab#1065)
kant2002 May 3, 2021
1e3f71c
Add support for null arrays in the blittable array marshaller's pinni…
jkoritzinsky May 4, 2021
bdd2d21
Add support for abstract SafeHandle types for by-value marshalling. (…
jkoritzinsky May 5, 2021
83a0fe2
Disable the test for the Marshal switch now that it currently is a no…
jkoritzinsky May 6, 2021
4dc5101
Keep target DllImport info in structured data before converting to sy…
jkoritzinsky May 7, 2021
7cd59c4
Make DllImport target function local. (dotnet/runtimelab#1090)
jkoritzinsky May 8, 2021
7570027
Basic infrastructure to enable DllImportGenerator (#52486)
elinor-fung May 10, 2021
1cba6dc
Prepend identifiers with @ symbol since the Roslyn Symbol API strips …
jkoritzinsky May 10, 2021
d205672
Use SemanticModel to discover GeneratedDllImportAttribute. (dotnet/ru…
jkoritzinsky May 18, 2021
7d9a4d9
Support implicit blittability for structs declared in and not exposed…
jkoritzinsky May 18, 2021
cd04650
Move to DllImportGenerator 1.0.0-alpha.21268.4 (#52981)
elinor-fung May 19, 2021
5513d61
Use GeneratedDllImport in System.Diagnostics.FileVersionInfo and Syst…
elinor-fung May 20, 2021
9f32647
Use GeneratedDllImport in System.Console (#52740)
elinor-fung May 20, 2021
0fd1fa1
Require that methods marked with GeneratedDllImport are in types that…
jkoritzinsky May 21, 2021
cbf6a82
Merge remote-tracking branch 'upstream/main' into feature/use-dllimpo…
elinor-fung May 25, 2021
36955b1
Use GeneratedDllImport in System.Security.Cryptography.Encoding (#53111)
elinor-fung May 25, 2021
efaa1fe
Use GeneratedDllImport in System.Security.Cryptography.Algorithms (#5…
elinor-fung May 25, 2021
4f834bc
Use GeneratedDllImport in System.Security.Cryptography.X509Certificat…
elinor-fung May 27, 2021
a7c64c1
Introduce design doc for Span/ReadOnlySpan<T> marshalling (dotnet/run…
jkoritzinsky May 27, 2021
51aaa63
Handle case where void* is a field. (dotnet/runtimelab#1195)
AaronRobinsonMSFT Jun 1, 2021
2ee7b3e
Fix memory leaks for return values and some out params. (dotnet/runti…
jkoritzinsky Jun 3, 2021
3b2fbee
Use GeneratedDllImport in System.Diagnostics.Process (#53702)
elinor-fung Jun 4, 2021
42e903c
Use GeneratedDllImport in System.IO.FileSystem (#53830)
AaronRobinsonMSFT Jun 7, 2021
3a66ebf
Use GeneratedDllImport in System.Net.Security (#53839)
elinor-fung Jun 7, 2021
95552f4
Comment in source that source file is auto-generated. (dotnet/runtime…
AaronRobinsonMSFT Jun 8, 2021
f85171f
Use GeneratedDllImport in System.IO.FileSystem.AccessControl (#53845)
elinor-fung Jun 8, 2021
614ba84
Use GeneratedDllImport in System.Net.Sockets (#53844)
elinor-fung Jun 8, 2021
4aad39d
Use GeneratedDllImport in System.Security.Principal.Windows (#53903)
elinor-fung Jun 8, 2021
061e414
Use GeneratedDllImport in System.Net.Http (#53885)
elinor-fung Jun 8, 2021
9c3d860
Use GeneratedDllImport in System.Net.HttpListener (#53904)
elinor-fung Jun 9, 2021
a3d954f
Implement collection marshaller spec (dotnet/runtimelab#1197)
jkoritzinsky Jun 9, 2021
f8c34f5
Use GeneratedDllImport in System.IO.Pipes (#53947)
elinor-fung Jun 9, 2021
d101839
Add configuration option for Unsafe type name. (dotnet/runtimelab#1217)
jkoritzinsky Jun 9, 2021
3ebfc68
Don't enable DllImport generator for shims (#53973)
elinor-fung Jun 10, 2021
3004aa2
Use GeneratedDllImport in System.Net.NetworkInformation (#53966)
AaronRobinsonMSFT Jun 10, 2021
f0e3844
Use GeneratedDllImport in System.IO.MemoryMappedFiles (#53978)
elinor-fung Jun 10, 2021
e1cab80
Use DLLIMPORTGENERATOR_ENABLED ifdefs for files shared with Microsoft…
elinor-fung Jun 10, 2021
2f50d95
Enable marshalling collections of types with marshallers that have a …
jkoritzinsky Jun 10, 2021
247fb4d
Handle native identifiers for escaped managed identifiers. (dotnet/ru…
jkoritzinsky Jun 10, 2021
6271751
Merge remote-tracking branch 'upstream/main' into HEAD
elinor-fung Jun 11, 2021
bb804ab
Make HmacOneShot blittable
elinor-fung Jun 11, 2021
dca91d1
Implement support for collections of collections marshalling (dotnet/…
jkoritzinsky Jun 12, 2021
f38351f
Implement marshallers for Span and ReadOnlySpan (dotnet/runtimelab#1222)
jkoritzinsky Jun 12, 2021
83d8624
Use GeneratedDllImport in System.IO.Compression.Brotli (#54173)
elinor-fung Jun 14, 2021
557cd36
Use GeneratedDllImport in System.IO.FileSystem.DriveInfo (#54181)
elinor-fung Jun 14, 2021
bfe2f7f
Use GeneratedDllImport in System.IO.FileSystem.Watcher (#54183)
elinor-fung Jun 14, 2021
c0d6093
Use GeneratedDllImport in System.Net.NameResolution (#54191)
elinor-fung Jun 15, 2021
2d929b4
Fix table display (dotnet/runtimelab#1242)
kant2002 Jun 15, 2021
21d9495
Use GeneratedDllImport in System.Net.Ping (#54232)
elinor-fung Jun 15, 2021
37b9b4e
Remove fixed workarounds (dotnet/runtimelab#1247)
AaronRobinsonMSFT Jun 16, 2021
907dec0
Use GeneratedDllImport in Microsoft.Win32.Registry (#54236)
AaronRobinsonMSFT Jun 16, 2021
78804fb
Use GeneratedDllImport in System.Security.Cryptography.Csp (#54290)
elinor-fung Jun 16, 2021
b3d6fb1
Merge remote-tracking branch 'upstream/main' into mergeMain
elinor-fung Jun 18, 2021
b021efe
Forward special P/Invoke attributes to the target DllImport method (d…
jkoritzinsky Jun 22, 2021
0fc1ca2
Fix SafeHandle benchmarks and add string benchmarks (dotnet/runtimela…
jkoritzinsky Jun 22, 2021
9f1e3ea
Only run GuaranteedUnmarshal statements if invoke was successful. (do…
jkoritzinsky Jul 1, 2021
76b147a
Don't emit SkipLocalsInit when it's already active (dotnet/runtimelab…
jkoritzinsky Jul 1, 2021
d7b3dc2
Require using UnmanagedCallConv instead of the CallingConvention fiel…
jkoritzinsky Jul 2, 2021
adf085f
Report diagnostics for bad opt-in marshallers at MarshalUsing use-sit…
jkoritzinsky Jul 7, 2021
9285a1e
Resolve SizeParamIndex to a TypePositionInfo during MarshallingInfo p…
jkoritzinsky Jul 7, 2021
5bc2e29
Update analyzer to correctly handle collection marshallers (dotnet/ru…
jkoritzinsky Jul 8, 2021
86f35c3
Improve diagnostics messages for invalid custom native type marshalli…
jkoritzinsky Jul 9, 2021
108fcdb
Merge branch 'main' of github.com:dotnet/runtime into feature/use-dll…
jkoritzinsky Jul 29, 2021
5f0f7a1
Merge pull request #56565 from jkoritzinsky/merge-main
jkoritzinsky Jul 29, 2021
802e7b9
Update compat doc (dotnet/runtimelab#1379)
elinor-fung Aug 4, 2021
9cdc1e5
Use the repo-local NuGet.config with GetReferenceAssemblies so we can…
jkoritzinsky Aug 6, 2021
02fa63e
Plan for .NET 7 integration (dotnet/runtimelab#1378)
AaronRobinsonMSFT Aug 6, 2021
d8775ee
Move to using the new Roslyn IIncrementalGenerator API for better in-…
jkoritzinsky Sep 8, 2021
2449c46
Refactor DllImportGenerator project for easier extensibility (dotnet/…
jkoritzinsky Sep 10, 2021
7eea82a
Remove duplicate TypeNames.cs and create IntPtr constant. (dotnet/run…
AaronRobinsonMSFT Sep 11, 2021
5b8ce63
Update DllImportGenerator to the latest version (#59117)
jkoritzinsky Sep 14, 2021
81293bf
Merge branch 'main' of https://github.com/dotnet/runtime into merge-main
jkoritzinsky Sep 14, 2021
84796a6
Fix failures in the AllConfigurations build.
jkoritzinsky Sep 14, 2021
111f57b
Merge pull request #59119 from jkoritzinsky/merge-main
jkoritzinsky Sep 15, 2021
fc18f4d
Merge branch 'feature/DllImportGenerator' of /home/jekoritz/scratch/b…
jkoritzinsky Sep 20, 2021
4cfb51f
Hook up DllImportGenerator to the libraries build (excluding solution…
jkoritzinsky Sep 20, 2021
27034bc
Run slngen to regenerate the solution files.
jkoritzinsky Sep 20, 2021
3f1789d
Merge pull request #59363 from jkoritzinsky/port-dllimport-generator
jkoritzinsky Sep 24, 2021
d924fbc
Merge branch 'main' of github.com:dotnet/runtime into merge-main
jkoritzinsky Sep 24, 2021
d7fe7a6
Merge pull request #59577 from jkoritzinsky/merge-main
jkoritzinsky Sep 24, 2021
06b4592
Remove target framework in the call to DllImportGenerator.csproj.
jkoritzinsky Sep 24, 2021
7c87cc1
Add license banner to source. (#59586)
AaronRobinsonMSFT Sep 24, 2021
3f78928
Enable running analyzers on DllImportGenerator and Microsoft.Interop.…
elinor-fung Sep 28, 2021
b7283ef
Make Utf16CharMarshaller pin ref parameters (#59700)
elinor-fung Sep 28, 2021
27d5e8d
Fix null termination for generated marshalling of read-only ref strin…
elinor-fung Sep 28, 2021
752533d
Merge branch 'main' into feature/use-dllimport-generator
jkoritzinsky Sep 30, 2021
853297a
Update DllImportGenerator style to match repo conventions (#59753)
elinor-fung Sep 30, 2021
c97c4df
Change some P/Invokes back to non-blittable + GeneratedDllImport for …
elinor-fung Oct 1, 2021
ea7e817
Merge branch 'main' into feature/use-dllimport-generator
jkoritzinsky Oct 2, 2021
c4a164b
Merge branch 'main' into feature/use-dllimport-generator
jkoritzinsky Oct 4, 2021
b4773b0
Fix IDE0008 in DllImportGenerator and Microsoft.Interop.SourceGenerat…
elinor-fung Oct 4, 2021
d81945e
Fix inconsistencies in order of GeneratedDllImport fields (#60049)
elinor-fung Oct 6, 2021
2dff7cd
Dllimport generator build and test fixes (#59658)
jkoritzinsky Oct 6, 2021
a8b691d
Fix incorrect endif location that broke the build.
jkoritzinsky Oct 6, 2021
78f4fa8
Merge branch 'main' into feature/use-dllimport-generator
jkoritzinsky Oct 7, 2021
cc8ed00
Updates to DllImportGenerator docs (#60211)
elinor-fung Oct 9, 2021
45c1dc3
Re-enable running DllImportGenerator.Tests suite on Mono. (#60259)
jkoritzinsky Oct 11, 2021
8990b0a
Disable ClearPreviousError test on Mono (#60272)
jkoritzinsky Oct 11, 2021
cfe257f
Add design details regarding dynamic buffers in struct marshalling (#…
AaronRobinsonMSFT Oct 14, 2021
39048dd
Undo solution and config changes from DllImportGenerator (#60481)
elinor-fung Oct 15, 2021
5a79d96
Merge branch 'main' into feature/use-dllimport-generator
elinor-fung Oct 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
<Import Project="$(RepositoryEngineeringDir)liveBuilds.targets" />
<Import Project="$(RepositoryEngineeringDir)generators.targets" />
<Import Project="$(RepositoryEngineeringDir)python.targets" />

<PropertyGroup>
Expand All @@ -17,14 +18,14 @@
unconditionally in Microsoft.NETCoreSdk.BundledVersions.props.
-->
<NETCoreAppMaximumVersion>$(MajorVersion).$(MinorVersion)</NETCoreAppMaximumVersion>
<EnableNETAnalyzers Condition="'$(EnableAnalyzers)' != 'true'">false</EnableNETAnalyzers>
<EnableNETAnalyzers Condition="'$(EnableNETAnalyzers)' == ''">$(RunAnalyzers)</EnableNETAnalyzers>
<!-- SDK sets product to assembly but we want it to be our product name -->
<Product>Microsoft%AE .NET</Product>
<!-- Use the .NET product branding version for informational version description -->
<InformationalVersion Condition="'$(InformationalVersion)' == '' and '$(VersionSuffix)' == ''">$(ProductVersion)</InformationalVersion>
<InformationalVersion Condition="'$(InformationalVersion)' == '' and '$(VersionSuffix)' != ''">$(ProductVersion)-$(VersionSuffix)</InformationalVersion>
</PropertyGroup>

<!-- The Default behavior in VS is to show files for the first target framework in TargetFrameworks property.
This is required to show all the files corresponding to all target frameworks in VS. -->
<ItemGroup Condition="'$(DefaultLanguageSourceExtension)' != '' and
Expand Down
95 changes: 95 additions & 0 deletions docs/design/libraries/DllImportGenerator/Compatibility.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Semantic Compatibility

Documentation on compatibility guidance and the current state. The version headings act as a rolling delta between the previous version.

## Version 1

The focus of version 1 is to support `NetCoreApp`. This implies that anything not needed by `NetCoreApp` is subject to change. Only .NET 6+ is supported.

### Semantic changes compared to `DllImportAttribute`

The default value of [`CharSet`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.dllimportattribute.charset) is runtime/language-defined. In the built-in system, the default value of the `CharSet` property is `CharSet.Ansi`. The P/Invoke source generator makes no assumptions about the `CharSet` if it is not explicitly set on `GeneratedDllImportAttribute`. Marshalling of `char` or `string` requires explicitly specifying marshalling information.

The built-in system treats `CharSet.None` as `CharSet.Ansi`. The P/Invoke source generator will treat `CharSet.None` as if the `CharSet` was not set.

[`BestFitMapping`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.dllimportattribute.bestfitmapping) and [`ThrowOnUnmappableChar`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.dllimportattribute.throwonunmappablechar) will not be supported for `GeneratedDllImportAttribute`. These values only have meaning on Windows when marshalling string data (`char`, `string`, `StringBuilder`) as [ANSI](https://docs.microsoft.com/windows/win32/intl/code-pages). As the general recommendation - including from Windows - is to move away from ANSI, the P/Invoke source generator will not support these fields.

[`CallingConvention`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.dllimportattribute.callingconvention) will not be supported for `GeneratedDllImportAttribute`. Users will be required to use the new `UnmanagedCallConvAttribute` attribute instead. This attribute provides support for extensible calling conventions and provides parity with the `UnmanagedCallersOnlyAttribute` attribute and C# function pointer syntax. We will enable our conversion code-fix to automatically convert explicit and known calling convention usage to use the `UnmanagedCallConvAttribute`.

### Required references

The following framework references are required:
- `System.Memory`
- `System.Runtime`
- `System.Runtime.InteropServices`

These are all part of `NetCoreApp` and will be referenced by default unless [implicit framework references are disabled](https://docs.microsoft.com/dotnet/core/project-sdk/msbuild-props#disableimplicitframeworkreferences).

### `char` marshalling

Marshalling of `char` will not be supported when configured with any of the following:
- [`CharSet.Ansi`, `CharSet.Auto`, or `CharSet.None`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.charset) will not be supported.
- [`UnmangedType.U1` or `UnmangedType.I1`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.unmanagedtype)
- No explicit marshalling information - either [`DllImportAttribute.CharSet`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.dllimportattribute.charset) or [`MarshalAsAttribute`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshalasattribute)

For `CharSet.Ansi` and `CharSet.None`, the built-in system used the [system default Windows ANSI code page](https://docs.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte) when on Windows and took the first byte of the UTF-8 encoding on non-Windows platforms. The above reasoning also applies to marshalling of a `char` as `UnmanagedType.U1` and `UnmanagedType.I1`. All approaches are fundamentally flawed and therefore not supported. If a single-byte character is expected to be marshalled it is left to the caller to convert a .NET `char` into a single `byte` prior to calling the native function.

For `CharSet.Auto`, the built-in system relied upon detection at runtime of the platform when determining the targeted encoding. Performing this check in generated code violates the "pay-for-play" principle. Given that there are no scenarios for this feature in `NetCoreApp` it will not be supported.

### `string` marshalling

Marshalling of `string` will not be supported when configured with any of the following:
- [`CharSet.None`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.charset)
- [`UnmangedType.VBByRefStr`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.unmanagedtype)
- No explicit marshalling information - either [`DllImportAttribute.CharSet`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.dllimportattribute.charset) or [`MarshalAsAttribute`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshalasattribute)

When converting from native to managed, the built-in system would throw a [`MarshalDirectiveException`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshaldirectiveexception) if the string's length is over 0x7ffffff0. The generated marshalling code will no longer perform this check.

In the built-in system, marshalling a `string` contains an optimization for parameters passed by value to allocate on the stack (instead of through [`AllocCoTaskMem`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshal.alloccotaskmem)) if the string is below a certain length (MAX_PATH). For UTF-16, this optimization was also applied for parameters passed by read-only reference. The generated marshalling code will include this optimization for read-only reference parameters for non-UTF-16 as well.

When marshalling as [ANSI](https://docs.microsoft.com/windows/win32/intl/code-pages) on Windows (using `CharSet.Ansi` or `UnmanagedType.LPStr`):
- Best-fit mapping will be disabled and no exception will be thrown for unmappable characters. In the built-in system, this behaviour was configured through [`DllImportAttribute.BestFitMapping`] and [`DllImportAttribute.ThrowOnUnmappableChar`]. The generated marshalling code will have the equivalent behaviour of `BestFitMapping=false` and `ThrowOnUnmappableChar=false`.
- No optimization for stack allocation will be performed. Marshalling will always allocate through `AllocCoTaskMem`.

On Windows, marshalling using `CharSet.Auto` is treated as UTF-16. When marshalling a string as UTF-16 by value or by read-only reference, the string is pinned and the pointer passed to the P/Invoke. The generated marshalling code will always pin the input string - even on non-Windows.

### Custom marshaller support

Using a custom marshaller (i.e. [`ICustomMarshaler`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.icustommarshaler)) with the `UnmanagedType.CustomMarshaler` value on `MarshalAsAttribute` is not supported. This also implies `MarshalAsAttribute` fields: [`MarshalTypeRef`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshalasattribute.marshaltyperef), [`MarshalType`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshalasattribute.marshaltype), and [`MarshalCookie`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshalasattribute.marshalcookie) are unsupported.

### Array marshalling

Marshalling of arrays will not be supported when using [`UnmangedType.SafeArray`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.unmanagedtype). This implies that the following `MarshalAsAttribute` fields are unsupported: [`SafeArraySubType`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshalasattribute.safearraysubtype) and [`SafeArrayUserDefinedSubType`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshalasattribute.safearrayuserdefinedsubtype)

Specifying array-specific marshalling members on the `MarshalAsAttribute` such as [`SizeConst`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshalasattribute.sizeconst), [`ArraySubType`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshalasattribute.arraysubtype), and [`SizeParamIndex`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshalasattribute.sizeparamindex) with non-array `UnmanagedType` types is unsupported.

Only single-dimensional arrays are supported for source generated marshalling.

In the source-generated marshalling, arrays will be allocated on the stack (instead of through [`AllocCoTaskMem`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.marshal.alloccotaskmem)) if they are passed by value or by read-only reference if they contain at most 256 bytes of data. The built-in system does not support this optimization for arrays.

### `in` keyword

For some types - blittable or Unicode `char` - passed by read-only reference via the [`in` keyword](https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/in-parameter-modifier), the built-in system simply pins the parameter. The generated marshalling code does the same, such that there is no behavioural difference. A consequence of this behaviour is that any modifications made by the invoked function will be reflected in the caller. It is left to the user to avoid the situation in which `in` is used for a parameter that will actually be modified by the invoked function.

### `LCIDConversion` support

[`LCIDConversionAttribute`](`https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.lcidconversionattribute`) will not be supported for methods marked with `GeneratedDllImportAttribute`.

### `[In, Out]` Attributes

In the source generated marshalling, the `[In]` and `[Out]` attributes will only be supported on parameters passed by value. For by-ref parameters, users should use the `in`, `ref`, or `out` keywords respectively. Additionally, they will only be supported in scenarios where applying them would result in behavior different from the default, such as applying `[Out]` or `[In, Out]` to a by-value non-blittable array parameter. This is in contrast to the built-in system which will allow them in all cases even when they have no effect.

### Struct marshalling

Support for struct marshalling in the source-generated marshalling is described in [StructMarshalling.md](StructMarshalling.md).

### Unsupported types

Unlike the built-in system, the source generator does not support marshalling for the following types:
- [`CriticalHandle`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.criticalhandle)
- [`HandleRef`](https://docs.microsoft.com/dotnet/api/system.runtime.interopservices.handleref)
- [`StringBuilder`](https://docs.microsoft.com/dotnet/api/system.text.stringbuilder)

## Version 0

This version is the built-in IL Stub generation system that is triggered whenever a method marked with `DllImport` is invoked.
47 changes: 47 additions & 0 deletions docs/design/libraries/DllImportGenerator/Diagnostics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generator Diagnostics

For all [Roslyn diagnostics](https://docs.microsoft.com/dotnet/api/microsoft.codeanalysis.diagnostic) reported by the P/Invoke source generator:

| Setting | Value |
| -------- | ------------------ |
| Category | SourceGeneration |
| Severity | Error |
| Enabled | True |

The P/Invoke source generator emits the following diagnostics.

## `DLLIMPORTGEN001`: Specified type is not supported by source-generated P/Invokes

A method marked `GeneratedDllImport` has a parameter or return type that is not supported by source-generated P/Invokes.

```C#
// 'object' without any specific marshalling configuration
[GeneratedDllImport("NativeLib")]
public static partial void Method(object o);
```

## `DLLIMPORTGEN002`: Specified configuration is not supported by source-generated P/Invokes

A method marked `GeneratedDllImport` has configuration that is not supported by source-generated P/Invokes. This may be configuration of the method itself or its parameter or return types.

```C#
// MarshalAs value that does not map to an UnmanagedType
[GeneratedDllImport("NativeLib")]
public static partial void Method([MarshalAs(1)] int i);

// Unsupported field on MarshalAs (SafeArraySubType, SafeArrayUserDefinedSubType, IidParameterIndex)
[GeneratedDllImport("NativeLib")]
public static partial void Method([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BOOL)] bool[] bArr);

// Unsupported combination of MarshalAs and type being marshalled
[GeneratedDllImport("NativeLib")]
public static partial void Method([MarshalAs(UnmanagedType.LPStr)] bool b);
```

## `DLLIMPORTGEN003`: Current target framework is not supported by source-generated P/Invokes

The `GeneratedDllImport` is being used when targeting a framework that is not supported by source-generated P/Invokes. The generated code is currently only compatible with .NET 5.0 or above.

# Analyzer Diagnostics

The P/Invoke source generator library also contains analyzers that emit diagnostics. These diagnostics flag issues around usage (i.e. of P/Invoke and marshalling attributes) rather than the source generation scenario support issues flagged by the generator itself.
Loading