Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Nullable annotation for System.IO.Pipelines #41407

Merged
merged 6 commits into from
Oct 14, 2019
Merged

Conversation

buyaa-n
Copy link
Member

@buyaa-n buyaa-n commented Sep 27, 2019

Contributes to #40623
cc: @dotnet/nullablefc

@buyaa-n
Copy link
Member Author

buyaa-n commented Oct 2, 2019

@stephentoub @safern build failed for full framework, seems don't have nullable attributes added System\IO\Pipelines\BufferSegmentStack.cs(26,29): error CS0246: The type or namespace name 'NotNullWhenAttribute' could not be found (are you missing a using directive or an assembly reference?) what we should do?

@safern
Copy link
Member

safern commented Oct 3, 2019

build failed for full framework, seems don't have nullable attributes added System\IO\Pipelines\BufferSegmentStack.cs(26,29): error CS0246: The type or namespace name 'NotNullWhenAttribute' could not be found (are you missing a using directive or an assembly reference?) what we should do?

You need to include this file in the src csproj: https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/Diagnostics/CodeAnalysis/NullableAttributes.cs

Add it under this ItemGroup

<ItemGroup Condition="'$(TargetGroup)'=='netstandard'">
<Compile Include="System\IO\Pipelines\StreamExtensions.netstandard.cs" />
<Compile Include="System\IO\Pipelines\ThreadPoolScheduler.netstandard.cs" />
<Compile Include="System\IO\Pipelines\CancellationTokenExtensions.netstandard.cs" />
</ItemGroup>

You also need to add a DefineConstants under this property group:

<PropertyGroup>
<Configurations>netcoreapp-Debug;netcoreapp-Release;netcoreapp3.0-Debug;netcoreapp3.0-Release;netstandard-Debug;netstandard-Release</Configurations>
</PropertyGroup>

  <PropertyGroup>
    <DefineConstants>$(DefineConstants);INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
    <Configurations>netcoreapp-Debug;netcoreapp-Release;netcoreapp3.0-Debug;netcoreapp3.0-Release;netstandard-Debug;netstandard-Release</Configurations>
  </PropertyGroup>

We need to include those attributes when the TargetGroup is netstandard. The configurations for this project are:

<PropertyGroup>
<PackageConfigurations>
netstandard;
netcoreapp3.0;
</PackageConfigurations>
<BuildConfigurations>
$(PackageConfigurations);
netcoreapp;
</BuildConfigurations>
</PropertyGroup>

So whenever we build for uap/netfx it will use the netstandard versionless build configuration, which translates to netstandard2.0 that doesn't have those attributes defined.

@buyaa-n
Copy link
Member Author

buyaa-n commented Oct 3, 2019

@safern added the reference, thank you!

@@ -106,7 +107,7 @@ public void SetNext(BufferSegment segment)

while (segment.Next != null)
{
segment.NextSegment.RunningIndex = segment.RunningIndex + segment.Length;
segment.NextSegment!.RunningIndex = segment.RunningIndex + segment.Length;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidfowl, is it correct that this is accessing NextSegment but the while above is using Next? It's not clear to me what the difference is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems at least better assert it instead bang.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually confused me as well 😄 . I think they are the same. I'm not sure why we're using Next for the null check.

Copy link
Member Author

@buyaa-n buyaa-n Oct 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidfowl do you want to change segment.Next null check with segment.NextSegment with this PR or its fine as is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to leave it as is and merge this PR, we can revisit later if needed

@buyaa-n
Copy link
Member Author

buyaa-n commented Oct 8, 2019

@stephentoub @safern please re review

@buyaa-n buyaa-n merged commit 48363ac into dotnet:master Oct 14, 2019
@buyaa-n buyaa-n deleted the io_pipelines branch November 1, 2019 21:07
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Nullable annotation for System.IO.Pipelines

Commit migrated from dotnet/corefx@48363ac
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