Commit Graph
1118 Commits
Author SHA1 Message Date
Jeremy Koritzinsky d40c0ede5f Gracefully emit a diagnostic when the GeneratedDllImport attribute didn't parse quite right and we don't have a valid AttributeData object (#65344) 2022-02-16 11:51:17 -08:00
Jeremy Koritzinsky 8cd701ae16 Update the ConvertToGeneratedDllImport code-fix to support stripping out PreserveSig and transforming the signature when PreserveSig was set to true (#65169) 2022-02-15 16:49:41 -08:00
Viktor Hofer 20e8f905d0 Don't use Targets* helper properties in libs (#64500)
* Don't use Targets* helper properties in libs projs

This change makes it possible to migrate 200+ (ref+src) projects to use
TargetFramework instead of TargetFrameworks which avoids the additional
outer build evaluation and invocation which ultimately makes the overall
build faster.

Targets* properties (i.e. TargetsWindows, TargetsAnyOS, TargetsUnix,
etc.) rely on the TargetFramework property which usually are set
inside a project. The TargetFramework property is only
available before a project specifies it if it's explicitly set in a props
file or if the project is cross-targeting and the outer-build dispatches
into the inner-build. During the dispatch, the TargetFramework property
is passed in as a global property.

Until now that behavior wasn't a problem because every libraries project
cross-targeted (by setting the TargetFrameworks property) even though
many only include a single TargetFramework (i.e. NetCoreAppCurrent).

To allow projects to use the TargetFramework property instead of
TargetFrameworks, the Targets* helper properties can't be calculated
anymore early in a props file as the TargetFramework property isn't set
at that time.

In general, the guidance by the SDK/msbuild team is to not read from the
TargetFramework property before the project sets it
(in a property group). That effectively means that the TargetFramework
property shouldn't be used in props files at all.

Therefore these helper properties can't be used anymore for property
conditions and I'm replacing their usage with TargetPlatformIdentifier
comparisons for both properties and items.
In nearly all cases, the Targets* helper properties can be replaced with
TargetPlatformIdentifier checks on items and in the few cases where
TargetsUnix or TargetsLinux marks multiple tfms as compatible, the exact
tfms must be used instead for the TargetPlatformIdentifier comparison.

Whenever a project needs to condition properties on the platform, I'm
first setting the TargetPlatformIdentifier the same way the SDK sets it
so that the SDK later doesn't need to set it again to avoid the
additional expensive msbuild function call.

* Use TargetFramework singular to avoid outer builds

Use TargetFramework instead of TargetFrameworks property whenever a
projects only targets a single target framework. This avoid unnecessary
outer builds and evaluations and makes the build faster.
2022-02-12 13:07:16 +01:00
Elinor Fung 77d6833b70 Move test with expected crash to outerloop (#65114) 2022-02-11 10:22:24 -08:00
Elinor Fung 49fea67729 Remove GeneratedDllImportAttribute.PreserveSig (#65164) 2022-02-10 19:03:11 -08:00
Jeremy Koritzinsky ccd67b0c44 Move DllImportGenerator to use DisableRuntimeMarshalling for its blittable classification (#64279) 2022-02-10 11:26:14 -08:00
Viktor Hofer 2f7726e3ba Clean-up DllImportGenerator packaging infra (#64810)
* Clean-up DllImportGenerator packaging infra

Most of what DllImportGenerator was trying to achieve via targets or by setting common packaging properties is already handled by libraries common packaging infrastructure (packaging.props) which is imported when a project sets `IsPackable=true`.
2022-02-10 14:15:18 +01:00
Stephen Toub 3ae87395f6 Initial roll out of !! (#64720)
* Bump version of C# compiler

This should be reverted when arcade brings in a new enough compiler.

* Fix a few new warnings from updating compiler

* Enable IDE0190 to employ parameter null checking

* Initial roll out of !!

* Fix more compiler warnings from upgrade, plus some test fixes / reverts

* Fix a few more tests

* Disable profiling test
2022-02-08 16:06:59 -05:00
Jeremy Koritzinsky dbd4cbb402 Set up an analyzer exception filter to make intermittent failures more actionable. (#64836)
Update the Roslyn Testing SDK version and update the DllImportGenerator unit tests to crash in a way that produces a dump for some of our intermittent issues (https://github.com/dotnet/runtime/issues/60909, https://github.com/dotnet/runtime/issues/62223). This mechanism will crash the process during the "exception filter" phase, so it will still have the throwing frame on the stack (no unwinding). Hopefully this will enable us to get more actionable dumps to investigate these issues and determine if they're Roslyn bugs or GC holes.
2022-02-05 09:58:42 -08:00
Viktor Hofer 64f3bae738 Consume renamed TargetFramework package (#64670)
* Consume renamed TargetFramework package

* Rename CoreLibs generator parent dir

Projects under src/libraries/ which are located under a "gen" directory
are automatically treated as source generator projects. Because the
CoreLib generator was placed under a different directory "generators",
it was treated as a RuntimeAssembly which gets binplaced into the
runtime path. The runtime tests then take the assemblies from there and
copy them into their CORE_ROOT directory.

Renaming the CoreLib source generators parent directory fixes that so
that it is treated as source generator and it brings consistency into
src/libraries.
2022-02-03 15:32:50 +01:00
Tanner GoodingandRolf Bjarne Kvinge f2538c6ce0 Expand System.Runtime.InteropServices.NFloat to support the APIs required by Xamarin (#64234)
* Expand System.Runtime.InteropServices.NFloat to support the APIs required by Xamarin

* Apply suggestions from code review

Co-authored-by: Rolf Bjarne Kvinge <[email protected]>

* Adding NFloat tests (p1)

* Temporarily disable negative conversions involving nfloat->nint

* Adjusting the skip condition for the Mono failures

* Adding additional tests covering the NFloat.Is* APIs

* Fixing the IsNormal and IsSubnormal test to account for 64-bit vs 32-bit

Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
2022-01-28 11:04:31 -08:00
Andrii Kurdiumov bd84729d1a Fix minor things in comments to DllImportGenerator (#64088) 2022-01-27 10:48:49 -08:00
Elinor Fung dde66c4cd2 Remove workarounds for RemoteExecutor (dotnet/arcade#5865) (#64360) 2022-01-26 21:01:24 -07:00
Stephen Toub 0ac0071e45 Implement IEquatable<T> on value types overriding Equals (and enable CA1066/1077) (#63690) 2022-01-24 09:43:25 -05:00
Eric StJohn 1d751ba856 Update XUnit to 2.4.2-pre.22 (#63948)
* Update to Xunit build 2.4.2-pre.13

Also pick up latest pre-release of analyzers

* Disambiguate calls to Assert.Equals(double,double,int)

Xunit added a new Assert overload that caused a lot of ambiguous calls.
https://github.com/xunit/xunit/issues/2393

Workaround by casting to double.

* Fix new instances of xUnit2000 diagnostic

* Workaround xUnit2002 issue with implicit cast

Works around https://github.com/xunit/xunit/issues/2395

* Disable xUnit2014 diagnostic

This diagnostic forces the use of Assert.ThrowsAsync for any async method,
however in our case we may want to test that a method will throw
synchronously to avoid regressing that behavior by moving to the async
portion of the method.

* Use AssertExtensions to test for null ArgumentException.ParamName

Workaround https://github.com/xunit/xunit/issues/2396

* Update to Xunit 2.4.2-pre.22

* Fix another ArugmentException.ParamName == null assert
2022-01-20 10:35:50 -08:00
Andrii Kurdiumov 8d5f5267d3 Update links to the project for DllImportGenerator (#63940)
As coincidence, I think `RestoreAdditionalProjectSources` not needed anymore.
2022-01-18 15:23:32 -08:00
Elinor Fung a991e1349e Make ObjectiveC tests in System.Runtime.InteropServices.Tests check exit code for remote execution (#63769) 2022-01-14 07:49:26 -08:00
Tanner Gooding cfe5e98c03 Implement the last of the approved cross platform hardware intrinsics, except shuffle (#63414)
* Exposing Sum<T> for Vector64/128/256<T>

* Adding support for ShiftLeft, ShiftRightArithmetic, and ShiftRightLogical to Vector<T> and Vector64/128/256<T>

* Adding support for Load, LoadAligned, LoadAlignedNonTemporal, and LoadUnsafe to Vector64/128/256<T>

* Adding support for Store, StoreAligned, StoreAlignedNonTemporal, and StoreUnsafe to Vector64/128/256<T>

* Adding support for ExtractMostSignificantBits to Vector64/128/256<T>

* Adding tests covering Vector64/128/256<T>.Sum

* Adding tests covering Vector64/128/256<T>.ShiftLeft, ShiftRightArithmetic, and ShiftRightLogical

* Moving System.Runtime.InteropServices.UnmanagedType down to System.Runtime so the `unmanaged` constraint can be used

* Adding tests covering Vector64/128/256<T>.Load, LoadAligned, LoadAlignedNonTemporal, and LoadUnsafe

* Fixing a few issues in the source and tests to ensure the right paths are being taken

* Adding tests covering Vector64/128/256<T>.Store, StoreAligned, StoreAlignedNonTemporal, and StoreUnsafe

* Adding tests covering Vector64/128/256<T>.ExtractMostSignificantBits

* Ensure AlignedAlloc is matched by AlignedFree

* Fixing a couple test issues and the handling of Scalar.ExtractMostSignificantBit for nint/nuint

* Applying formatting patch

* Ensure gtNewOperNode uses TYP_INT when dealing with the shiftCount

* Fixing a couple ARM64 node types

* Ensure the shift intrinsics use impPopStack().val on ARM64

* Responding to PR feedback
2022-01-12 16:00:04 -08:00
Stephen Toub ce9deb2d06 Special-case ERROR_INVALID_PARAMETER in PosixSignalRegistration.Unregister (#63582) 2022-01-10 20:43:20 -05:00
Elinor Fung b0685e1617 [DllImportGenerator] Remove DLLIMPORTGENERATOR_ENABLED define (#63464) 2022-01-06 17:10:02 -05:00
Elinor Fung 44b9a6ee58 Make DllImportGenerator unit tests' compilations use live refs (#63410) 2022-01-06 14:36:54 -05:00
Elinor Fung ef357af10c [DllImportGenerator] Update buffer size field for custom marshalling (#63316) 2022-01-04 09:22:35 -05:00
Stephen Toub e789b4effb Revert SafeBuffer change around pointer initialization (#63289) 2022-01-03 20:38:58 -05:00
Adeel Mujahid a95cc4d3d8 Parse compiler version in init-compiler.sh (#63126)
When user passes versioned native compiler argument such as
`-clang10.1` or `-gcc9.2` to the top-level `:/build.sh`,
`:/eng/build.sh` transforms that to msbuild property called
`<Compiler>` with raw/unprocessed value.

In coreclr, libs, corehost and tests partitions, we end up calling
`:/eng/native/build-commons.sh`, which slices the compiler name, major
and minor versions, then calls `:/eng/native/gen-buildsys.sh` with
individual components. That is just a pass-thru script for the final
`:/eng/common/native/init-compiler.sh`, where those arguments are
actually used.

In `mono.proj` and `NativeExports.csproj`, we do not use
`build-commons` script, but instead, invoke `init-compiler.sh` directly
with the raw `<Compiler>` property. That causes an error when versioned
native compiler is specified on the command line.

This PR fixes this issue by pushing version parsing code into
`init-compiler.sh` so all its consumers get the same behavior.
2021-12-25 20:30:45 -08:00
Michal Strehovský 4733c70d09 Manifest DllImportSourceGenerator as a generator (#62836) 2021-12-15 08:51:38 -08:00
SingleAccretion ca072ba73c Fix invalid IR in span indexer import (#62709)
* Fix invalid IR in Span[] import

* Re-enable disabled tests
2021-12-13 17:15:49 +03:00
Julien Couvreur ab0de531c8 Escape lower-cased type names (#62507) 2021-12-09 00:05:25 -08:00
Jeremy KoritzinskyandAaron Robinson b83fee9f6e Use GeneratedDllImport throughout System.Private.CoreLib. (#62295)
Co-authored-by: Aaron Robinson <[email protected]>
2021-12-02 16:15:47 -08:00
Jeremy KoritzinskyandAndy Gocke 84b55d9700 Remove workarounds for referencing the DllImport source generator now that we use the RTM sdk. (#62156)
Co-authored-by: Andy Gocke <[email protected]>
2021-11-30 13:48:15 -08:00
Aaron Robinson 7cfcbb0fe6 The DestroyStructure API passes null to the IL marshaller for (#61985)
managed valuetypes. This is an issue with field marshallers of
  nested non-blittable types.
2021-11-24 12:23:22 -07:00
Jeremy KoritzinskyandAaron Robinson 06a0c76a81 Update GetPinnableReference() usage in multi-step custom type marshalling (#61539)
* Update GetPinnableReference() usage in multi-step custom tyep marshalling

Change GetPinnableReference() on a marshaller type to be used as a side effect when marshalling in all cases when a fixed() statement is usable.

Use the Value property getter to get the value to pass to native in all cases.

Update our marshallers and tests to follow this design update.

* Apply suggestions from code review

Co-authored-by: Aaron Robinson <[email protected]>

* Don't emit the assingment to the Value property in the Unmarshal stage when using [Out]

* Fix the unmarshalling conditions

* Fix Utf16StringMarshaller to correctly handle the "null pointer" case now that we're using spans internally for storage in all cases.

Co-authored-by: Aaron Robinson <[email protected]>
2021-11-19 18:16:07 -08:00
Elinor Fung 4254fa30b7 [DllImportGenerator] Don't flag methods with known unsupported UnmanagedType (#61808) 2021-11-18 18:56:00 -07:00
Jeremy Koritzinsky 7f874eee5a Remove race condition from DllImportGenerator build (#61695) 2021-11-17 18:10:56 -08:00
Elinor Fung a508fb574c [DllImportGenerator] Enable on projects without System.Memory and System.Runtime.CompilerServices.Unsafe (#61704) 2021-11-17 09:12:15 -07:00
Elinor Fung 80765225d8 [DllImportGenerator] Stop ignoring QCalls when looking for methods to convert to GeneratedDllImport (#61678) 2021-11-16 15:12:40 -07:00
Elinor Fung 0818df12f8 [DllImportGenerator] Treat pointer fields in structs as blittable regardless of what they point at (#61538) 2021-11-12 19:08:39 -08:00
Aaron Robinson e7600e0080 Remove all DLLIMPORTGENERATOR_ENABLED usage. (#61476)
* Remove all DLLIMPORTGENERATOR_ENABLED usage.

* Explicitly set EnableDllImportGenerator to true in test project.
2021-11-12 11:08:39 -08:00
Elinor Fung 4f43e82fcb [DllImportGenerator] Initialize by-value out array to default (#61431) 2021-11-10 15:27:59 -08:00
Elinor Fung 9dc08dd7d0 Remove BestFitMapping, CallingConvention, and ThrowOnUnmappableChar from GeneratedDllImportAttribute (#61182) 2021-11-05 21:24:50 -07:00
Aaron Robinson f080744f70 Convert to OleDb assembly and last Cryptography DllImport to GeneratedDllImport (#61184)
* Enable DllImport generator for all source projects.

* Convert OleDb to only use GeneratedDllImport.

* Update source generator to distinguish between "no marshalling info"
  which can cause a failure vs "missing support" which enables us to
  fallback to the marshalling forwarder.

* Remove unused DllImports.

* Reuse existing P/Invoke definitions.
2021-11-05 17:09:05 -07:00
Jeremy Koritzinsky 82d667c657 [DllImportGenerator] Use ElementMarshallingGeneratorFactory to create the marshalling generator for collection elements (#61219) 2021-11-04 16:16:30 -07:00
Elinor Fung 22f06831ae [DllImportGenerator] Fix stub generation for char array marshalling (#61188) 2021-11-03 22:49:01 -07:00
Aaron RobinsonandElinor Fung 6527f540e4 Add TFM and version support query to marshaller interface. (#61064)
* Add TFM and version support query to marshaller interface.

* If any marshaller fails to support the current tfm version, fallback
to using the built-in DllImport attribute.

* Add tests for fallback generation on downlevel or generation if marshallers
  are supported on the target framework.

* Convert CreateCompilationWithReferenceAssemblies to CreateCompilation overload.

Co-authored-by: Elinor Fung <[email protected]>
2021-11-02 21:27:34 -07:00
Elinor Fung 8dfaac9649 Mark containing type for generated stub functions as unsafe (#60979) 2021-10-28 18:22:32 -07:00
Jeremy Koritzinsky 1ba75a614e Explicitly emit a diagnostic for ref returns in GeneratedDllImport stubs. (#60720) 2021-10-28 10:51:55 -07:00
Elinor Fung 197ab5f77c [DllImportGenerator] Don't flag methods that already have GeneratedDllImport (#60929) 2021-10-27 17:42:04 -07:00
Elinor Fung c4ba63951e Make PreferredAttributeOrder test ConditionalTheory (#60940) 2021-10-27 17:39:23 -07:00
Krzysztof Wicher 7414b45bfa disable DllImportGenerator.UnitTests.ConvertToGeneratedDllImportAnalyzerTests.TypeRequiresMarshalling_ReportsDiagnostic (#60911) 2021-10-27 16:33:25 +02:00
Adeel Mujahid 7ac806d733 Fix libs.tests build with gcc (#60757) 2021-10-26 16:37:10 -07:00
Viktor Hofer 0964be0ae9 Update slngen and solution files (#60871)
Update slngen tooling to latest stable version and solution files since
a lot changed since the last time they were updated:
- NET7 (removal of older TFMs)
- Source Generators
2021-10-26 21:23:54 +02:00