Skip to content

Commit 2e2d7bd

Browse files
authored
Build Threading.Tasks.DataFlow and ComponentModel.Annotations for NetCoreAppCurrent (#48667)
* Build Threading.Tasks.DataFlow and ComponentModel.Annotations for NetCoreAppCurrent Fix #48662 * Fix the build to enable FEATURE_TRACING.
1 parent 03d414b commit 2e2d7bd

15 files changed

+83
-60
lines changed

src/libraries/System.ComponentModel.Annotations/src/System.ComponentModel.Annotations.csproj

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.1</TargetFrameworks>
3+
<TargetFrameworks>$(NetCoreAppCurrent);netstandard2.1</TargetFrameworks>
4+
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
45
<Nullable>enable</Nullable>
56
<!--
67
Since many resource strings in this library are shown to an end-user,
@@ -59,4 +60,16 @@
5960
<Compile Include="$(CommonPath)System\NotImplemented.cs"
6061
Link="Common\System\NotImplemented.cs" />
6162
</ItemGroup>
63+
<ItemGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">
64+
<Reference Include="System.Collections" />
65+
<Reference Include="System.Collections.Concurrent" />
66+
<Reference Include="System.ComponentModel" />
67+
<Reference Include="System.ComponentModel.Primitives" />
68+
<Reference Include="System.ComponentModel.TypeConverter" />
69+
<Reference Include="System.Linq" />
70+
<Reference Include="System.Runtime" />
71+
<Reference Include="System.Resources.ResourceManager" />
72+
<Reference Include="System.Text.RegularExpressions" />
73+
<Reference Include="System.Threading" />
74+
</ItemGroup>
6275
</Project>

src/libraries/System.Threading.Tasks.Dataflow/src/Base/DataflowBlock.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private bool RunPredicate(T item)
133133

134134
/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Targets/Member[@name="OfferMessage"]/*' />
135135
#pragma warning disable 8617
136-
DataflowMessageStatus ITargetBlock<T>.OfferMessage(DataflowMessageHeader messageHeader, T messageValue, ISourceBlock<T> source, bool consumeToAccept)
136+
DataflowMessageStatus ITargetBlock<T>.OfferMessage(DataflowMessageHeader messageHeader, T messageValue, ISourceBlock<T>? source, bool consumeToAccept)
137137
#pragma warning restore 8617
138138
{
139139
// Validate arguments. Some targets may have a null source, but FilteredLinkPropagator
@@ -939,7 +939,7 @@ public static TOutput Receive<TOutput>(
939939

940940
// Do fast path checks for both cancellation and data already existing.
941941
cancellationToken.ThrowIfCancellationRequested();
942-
TOutput fastCheckedItem;
942+
TOutput? fastCheckedItem;
943943
var receivableSource = source as IReceivableSourceBlock<TOutput>;
944944
if (receivableSource != null && receivableSource.TryReceive(null, out fastCheckedItem))
945945
{
@@ -995,7 +995,7 @@ private static Task<TOutput> ReceiveCore<TOutput>(
995995
{
996996
try
997997
{
998-
TOutput fastCheckedItem;
998+
TOutput? fastCheckedItem;
999999
if (receivableSource.TryReceive(null, out fastCheckedItem))
10001000
{
10011001
return Task.FromResult<TOutput>(fastCheckedItem);
@@ -1091,7 +1091,7 @@ private static Task<TOutput> ReceiveCoreByLinking<TOutput>(ISourceBlock<TOutput>
10911091
// So we are racing to dispose of the unlinker.
10921092
if (Volatile.Read(ref target._cleanupReserved))
10931093
{
1094-
IDisposable disposableUnlink = Interlocked.CompareExchange(ref target._unlink, null, unlink);
1094+
IDisposable? disposableUnlink = Interlocked.CompareExchange<IDisposable?>(ref target._unlink, null, unlink);
10951095
if (disposableUnlink != null) disposableUnlink.Dispose();
10961096
}
10971097
}
@@ -1173,7 +1173,7 @@ DataflowMessageStatus ITargetBlock<T>.OfferMessage(DataflowMessageHeader message
11731173
{
11741174
// Accept the message if possible and complete this task with the message's value.
11751175
bool consumed = true;
1176-
T acceptedValue = consumeToAccept ? source!.ConsumeMessage(messageHeader, this, out consumed) : messageValue;
1176+
T? acceptedValue = consumeToAccept ? source!.ConsumeMessage(messageHeader, this, out consumed) : messageValue;
11771177
if (consumed)
11781178
{
11791179
status = DataflowMessageStatus.Accepted;
@@ -1962,7 +1962,7 @@ private static bool TryChooseFromSource<T>(
19621962
Debug.Assert(scheduler != null, "Expected a non-null scheduler");
19631963

19641964
// Try to receive from the source. If we can't, bail.
1965-
T result;
1965+
T? result;
19661966
var receivableSource = source as IReceivableSourceBlock<T>;
19671967
if (receivableSource == null || !receivableSource.TryReceive(out result))
19681968
{
@@ -2198,7 +2198,7 @@ public DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader, T
21982198
if (consumeToAccept)
21992199
{
22002200
bool consumed;
2201-
messageValue = source!.ConsumeMessage(messageHeader, this, out consumed);
2201+
messageValue = source!.ConsumeMessage(messageHeader, this, out consumed)!;
22022202
if (!consumed) return DataflowMessageStatus.NotAvailable;
22032203
}
22042204

src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ internal DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader,
387387
Debug.Assert(source != null, "We must have thrown if source == null && consumeToAccept == true.");
388388

389389
bool consumed;
390-
messageValue = source.ConsumeMessage(messageHeader, _owningBatch, out consumed);
390+
messageValue = source.ConsumeMessage(messageHeader, _owningBatch, out consumed)!;
391391
if (!consumed) return DataflowMessageStatus.NotAvailable;
392392
}
393393

@@ -1004,7 +1004,7 @@ private void ConsumeReservedMessagesNonGreedy()
10041004
KeyValuePair<ISourceBlock<T>, KeyValuePair<DataflowMessageHeader, T>> sourceAndMessage = reserved[i];
10051005
reserved[i] = default(KeyValuePair<ISourceBlock<T>, KeyValuePair<DataflowMessageHeader, T>>); // in case of exception from ConsumeMessage
10061006
bool consumed;
1007-
T consumedValue = sourceAndMessage.Key.ConsumeMessage(sourceAndMessage.Value.Key, _owningBatch, out consumed);
1007+
T? consumedValue = sourceAndMessage.Key.ConsumeMessage(sourceAndMessage.Value.Key, _owningBatch, out consumed);
10081008
if (!consumed)
10091009
{
10101010
// The protocol broke down, so throw an exception, as this is fatal. Before doing so, though,
@@ -1056,7 +1056,7 @@ private void ConsumeReservedMessagesGreedyBounded()
10561056
KeyValuePair<ISourceBlock<T>, KeyValuePair<DataflowMessageHeader, T>> sourceAndMessage = reserved[i];
10571057
reserved[i] = default(KeyValuePair<ISourceBlock<T>, KeyValuePair<DataflowMessageHeader, T>>); // in case of exception from ConsumeMessage
10581058
bool consumed;
1059-
T consumedValue = sourceAndMessage.Key.ConsumeMessage(sourceAndMessage.Value.Key, _owningBatch, out consumed);
1059+
T? consumedValue = sourceAndMessage.Key.ConsumeMessage(sourceAndMessage.Value.Key, _owningBatch, out consumed);
10601060
if (consumed)
10611061
{
10621062
var consumedMessage = new KeyValuePair<DataflowMessageHeader, T>(sourceAndMessage.Value.Key, consumedValue!);

src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchedJoinBlock.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public BatchedJoinBlock(int batchSize, GroupingDataflowBlockOptions dataflowBloc
7272
// messages, and thus when there may be a few stragglers we need to make a batch out of.
7373
Action createBatchAction = () =>
7474
{
75-
if (_target1.Count > 0 || _target2.Count > 0)
75+
if (_target1!.Count > 0 || _target2!.Count > 0)
7676
{
77-
_source.AddMessage(Tuple.Create(_target1.GetAndEmptyMessages(), _target2.GetAndEmptyMessages()));
77+
_source.AddMessage(Tuple.Create(_target1.GetAndEmptyMessages(), _target2!.GetAndEmptyMessages()));
7878
}
7979
};
8080

@@ -329,9 +329,9 @@ public BatchedJoinBlock(int batchSize, GroupingDataflowBlockOptions dataflowBloc
329329
// messages, and thus when there may be a few stragglers we need to make a batch out of.
330330
Action createBatchAction = () =>
331331
{
332-
if (_target1.Count > 0 || _target2.Count > 0 || _target3.Count > 0)
332+
if (_target1!.Count > 0 || _target2!.Count > 0 || _target3!.Count > 0)
333333
{
334-
_source.AddMessage(Tuple.Create(_target1.GetAndEmptyMessages(), _target2.GetAndEmptyMessages(), _target3.GetAndEmptyMessages()));
334+
_source.AddMessage(Tuple.Create(_target1.GetAndEmptyMessages(), _target2!.GetAndEmptyMessages(), _target3!.GetAndEmptyMessages()));
335335
}
336336
};
337337

@@ -598,7 +598,7 @@ public DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader, T
598598
Debug.Assert(source != null, "We must have thrown if source == null && consumeToAccept == true.");
599599

600600
bool consumed;
601-
messageValue = source.ConsumeMessage(messageHeader, this, out consumed);
601+
messageValue = source.ConsumeMessage(messageHeader, this, out consumed)!;
602602
if (!consumed) return DataflowMessageStatus.NotAvailable;
603603
}
604604
_messages.Add(messageValue!);

src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BroadcastBlock.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ DataflowMessageStatus ITargetBlock<T>.OfferMessage(DataflowMessageHeader message
191191
Debug.Assert(source != null, "We must have thrown if source == null && consumeToAccept == true.");
192192

193193
bool consumed;
194-
messageValue = source.ConsumeMessage(messageHeader, this, out consumed);
194+
messageValue = source.ConsumeMessage(messageHeader, this, out consumed)!;
195195
if (!consumed) return DataflowMessageStatus.NotAvailable;
196196
}
197197

@@ -352,7 +352,7 @@ private bool ConsumeAndStoreOneMessageIfAvailable()
352352
bool consumed = false;
353353
try
354354
{
355-
T consumedValue = sourceAndMessage.Key.ConsumeMessage(sourceAndMessage.Value, this, out consumed);
355+
T? consumedValue = sourceAndMessage.Key.ConsumeMessage(sourceAndMessage.Value, this, out consumed);
356356
if (consumed)
357357
{
358358
_source.AddMessage(consumedValue!);
@@ -577,7 +577,7 @@ internal bool TryReceive(Predicate<TOutput>? filter, [MaybeNullWhen(false)] out
577577
// synchronizing with other activities on the block.
578578
// We don't want to execute the user-provided cloning delegate
579579
// while holding the lock.
580-
TOutput message;
580+
TOutput? message;
581581
bool isValid;
582582
lock (OutgoingLock)
583583
{
@@ -607,7 +607,7 @@ internal bool TryReceiveAll([NotNullWhen(true)] out IList<TOutput>? items)
607607
{
608608
// Try to receive the one item this block may have.
609609
// If we can, give back an array of one item. Otherwise, give back null.
610-
TOutput item;
610+
TOutput? item;
611611
if (TryReceive(null, out item))
612612
{
613613
items = new TOutput[] { item };
@@ -683,7 +683,7 @@ private void OfferCurrentMessageToNewTarget(ITargetBlock<TOutput> target)
683683
Common.ContractAssertMonitorStatus(ValueLock, held: false);
684684

685685
// Get the current message if there is one
686-
TOutput currentMessage;
686+
TOutput? currentMessage;
687687
bool isValid;
688688
lock (ValueLock)
689689
{
@@ -725,7 +725,7 @@ private bool OfferToTargets()
725725
Common.ContractAssertMonitorStatus(ValueLock, held: false);
726726

727727
DataflowMessageHeader header = default(DataflowMessageHeader);
728-
TOutput message = default(TOutput);
728+
TOutput? message = default(TOutput);
729729
int numDequeuedMessages = 0;
730730
lock (ValueLock)
731731
{
@@ -1053,7 +1053,7 @@ internal IDisposable LinkTo(ITargetBlock<TOutput> target, DataflowLinkOptions li
10531053
if (!messageHeader.IsValid) throw new ArgumentException(SR.Argument_InvalidMessageHeader, nameof(messageHeader));
10541054
if (target == null) throw new ArgumentNullException(nameof(target));
10551055

1056-
TOutput valueToClone;
1056+
TOutput? valueToClone;
10571057
lock (OutgoingLock) // We may currently be calling out under this lock to the target; requires it to be reentrant
10581058
{
10591059
lock (ValueLock)
@@ -1125,7 +1125,7 @@ internal void ReleaseReservation(DataflowMessageHeader messageHeader, ITargetBlo
11251125
// If someone else holds the reservation, bail.
11261126
if (_nextMessageReservedFor != target) throw new InvalidOperationException(SR.InvalidOperation_MessageNotReservedByTarget);
11271127

1128-
TOutput messageToReoffer;
1128+
TOutput? messageToReoffer;
11291129
lock (ValueLock)
11301130
{
11311131
// If this is not the message at the head of the queue, bail

src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BufferBlock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ DataflowMessageStatus ITargetBlock<T>.OfferMessage(DataflowMessageHeader message
118118
Debug.Assert(source != null, "We must have thrown if source == null && consumeToAccept == true.");
119119

120120
bool consumed;
121-
messageValue = source.ConsumeMessage(messageHeader, this, out consumed);
121+
messageValue = source.ConsumeMessage(messageHeader, this, out consumed)!;
122122
if (!consumed) return DataflowMessageStatus.NotAvailable;
123123
}
124124

@@ -354,7 +354,7 @@ private bool ConsumeAndStoreOneMessageIfAvailable()
354354
bool consumed = false;
355355
try
356356
{
357-
T consumedValue = sourceAndMessage.Key.ConsumeMessage(sourceAndMessage.Value, this, out consumed);
357+
T? consumedValue = sourceAndMessage.Key.ConsumeMessage(sourceAndMessage.Value, this, out consumed);
358358
if (consumed)
359359
{
360360
_source.AddMessage(consumedValue!);

src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/JoinBlock.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public JoinBlock(GroupingDataflowBlockOptions dataflowBlockOptions)
6969
_sharedResources = new JoinBlockTargetSharedResources(this, targets,
7070
() =>
7171
{
72-
_source.AddMessage(Tuple.Create(_target1.GetOneMessage(), _target2.GetOneMessage()));
72+
_source.AddMessage(Tuple.Create(_target1!.GetOneMessage(), _target2!.GetOneMessage()));
7373
},
7474
exception =>
7575
{
76-
Volatile.Write(ref _sharedResources._hasExceptions, true);
76+
Volatile.Write(ref _sharedResources!._hasExceptions, true);
7777
_source.AddException(exception);
7878
},
7979
dataflowBlockOptions);
@@ -297,10 +297,10 @@ public JoinBlock(GroupingDataflowBlockOptions dataflowBlockOptions)
297297
// Configure the targets
298298
var targets = new JoinBlockTargetBase[3];
299299
_sharedResources = new JoinBlockTargetSharedResources(this, targets,
300-
() => _source.AddMessage(Tuple.Create(_target1.GetOneMessage(), _target2.GetOneMessage(), _target3.GetOneMessage())),
300+
() => _source.AddMessage(Tuple.Create(_target1!.GetOneMessage(), _target2!.GetOneMessage(), _target3!.GetOneMessage())),
301301
exception =>
302302
{
303-
Volatile.Write(ref _sharedResources._hasExceptions, true);
303+
Volatile.Write(ref _sharedResources!._hasExceptions, true);
304304
_source.AddException(exception);
305305
},
306306
dataflowBlockOptions);
@@ -660,7 +660,7 @@ internal override bool ConsumeReservedMessage()
660660
Debug.Assert(_nonGreedy!.ReservedMessage.Key != null, "This target must have a reserved message");
661661

662662
bool consumed;
663-
T consumedValue = _nonGreedy.ReservedMessage.Key.ConsumeMessage(_nonGreedy.ReservedMessage.Value, this, out consumed);
663+
T? consumedValue = _nonGreedy.ReservedMessage.Key.ConsumeMessage(_nonGreedy.ReservedMessage.Value, this, out consumed);
664664

665665
// Null out our reservation
666666
_nonGreedy.ReservedMessage = default(KeyValuePair<ISourceBlock<T>, DataflowMessageHeader>);
@@ -721,7 +721,7 @@ internal override bool ConsumeOnePostponedMessage()
721721

722722
// Try to consume the popped message
723723
bool consumed;
724-
T consumedValue = next.Key.ConsumeMessage(next.Value, this, out consumed);
724+
T? consumedValue = next.Key.ConsumeMessage(next.Value, this, out consumed);
725725
if (consumed)
726726
{
727727
lock (_sharedResources.IncomingLock)
@@ -861,7 +861,7 @@ DataflowMessageStatus ITargetBlock<T>.OfferMessage(DataflowMessageHeader message
861861
Debug.Assert(source != null, "We must have thrown if source == null && consumeToAccept == true.");
862862

863863
bool consumed;
864-
messageValue = source.ConsumeMessage(messageHeader, this, out consumed);
864+
messageValue = source.ConsumeMessage(messageHeader, this, out consumed)!;
865865
if (!consumed) return DataflowMessageStatus.NotAvailable;
866866
}
867867
if (_sharedResources._boundingState != null && HasTheHighestNumberOfMessagesAvailable) _sharedResources._boundingState.CurrentCount += 1; // track this new item against our bound

src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformBlock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private TransformBlock(Func<TInput, TOutput>? transformSync, Func<TInput, Task<T
171171
private void ProcessMessage(Func<TInput, TOutput> transform, KeyValuePair<TInput, long> messageWithId)
172172
{
173173
// Process the input message to get the output message
174-
TOutput outputItem = default(TOutput);
174+
TOutput? outputItem = default(TOutput);
175175
bool itemIsValid = false;
176176
try
177177
{
@@ -272,7 +272,7 @@ private void AsyncCompleteProcessMessageWithTask(Task<TOutput> completed, KeyVal
272272

273273
bool isBounded = _target.IsBounded;
274274
bool gotOutputItem = false;
275-
TOutput outputItem = default(TOutput);
275+
TOutput? outputItem = default(TOutput);
276276

277277
switch (completed.Status)
278278
{

src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/WriteOnceBlock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ bool IReceivableSourceBlock<T>.TryReceiveAll([NotNullWhen(true)] out IList<T>? i
287287
// Try to receive the one item this block may have.
288288
// If we can, give back an array of one item. Otherwise,
289289
// give back null.
290-
T item;
290+
T? item;
291291
if (TryReceive(null, out item))
292292
{
293293
items = new T[] { item };
@@ -357,7 +357,7 @@ DataflowMessageStatus ITargetBlock<T>.OfferMessage(DataflowMessageHeader message
357357
if (consumeToAccept)
358358
{
359359
bool consumed;
360-
messageValue = source!.ConsumeMessage(messageHeader, this, out consumed);
360+
messageValue = source!.ConsumeMessage(messageHeader, this, out consumed)!;
361361
if (!consumed) return DataflowMessageStatus.NotAvailable;
362362
}
363363

0 commit comments

Comments
 (0)