Skip to content

Conversation

@elinor-fung
Copy link
Member

Some more p/invokes could easily be made blittable (inlinable during JIT) - found while prototyping a DllImport source generator.

cc @AaronRobinsonMSFT @jkoritzinsky

@ghost ghost added the area-Interop-coreclr label Jun 17, 2021
@GrabYourPitchforks
Copy link
Member

Is there any concern that switching between ref / out and raw pointers might confuse callers as to which variables they're required to zero-init and which variables the callee will zero-init?

@AaronRobinsonMSFT
Copy link
Member

Is there any concern that switching between ref / out and raw pointers might confuse callers as to which variables they're required to zero-init and which variables the callee will zero-init?

@GrabYourPitchforks Aren't all locals zero-init right now? I didn't see any uses of the SkipLocalsInitAttribute.

@GrabYourPitchforks
Copy link
Member

@AaronRobinsonMSFT Nearly all libraries auto-compile with SkipLocalsInit injected by the build process.

<PropertyGroup>
<SkipLocalsInit Condition="'$(SkipLocalsInit)' == '' and '$(MSBuildProjectExtension)' == '.csproj' and '$(IsNETCoreAppSrc)' == 'true' and ($([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppCurrent)')))">true</SkipLocalsInit>
</PropertyGroup>
<!--Instructs compiler not to emit .locals init, using SkipLocalsInitAttribute.-->
<Choose>
<When Condition="'$(SkipLocalsInit)' == 'true'">
<PropertyGroup >
<!-- This is needed to use the SkipLocalsInitAttribute. -->
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(CommonPath)SkipLocalsInit.cs" Link="Common\SkipLocalsInit.cs" />
</ItemGroup>
</When>
</Choose>

@jkotas
Copy link
Member

jkotas commented Jun 17, 2021

SkipLocalsInitAttribute is set globally for the whole repo.

I am not particularly worried about the changes in this PR. THe blast radius is minimal (just affect immediate wrappers that deal with other interop intricacies), and some of the changes look like a geneneral improvement:

@AaronRobinsonMSFT
Copy link
Member

Nearly all libraries auto-compile with SkipLocalsInit injected by the build process.

Didn't know that - thanks.

@elinor-fung elinor-fung merged commit cff5854 into dotnet:main Jun 18, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jul 18, 2021
@elinor-fung elinor-fung deleted the pinvokeBlittable branch September 14, 2021 15:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants