Skip to content

Commit 588aa6b

Browse files
committed
revert "use collection expressions in (non-test) sources (dotnet#10758)"
1 parent 7ad4e1c commit 588aa6b

File tree

112 files changed

+394
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+394
-378
lines changed

src/Build/BackEnd/BuildManager/BuildManager.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ IEnumerable<ILogger> AppendDebuggingLoggers(IEnumerable<ILogger> loggers)
668668

669669
var logger = new BinaryLogger { Parameters = binlogPath };
670670

671-
return (loggers ?? [logger]);
671+
return (loggers ?? Enumerable.Empty<ILogger>()).Concat(new[] { logger });
672672
}
673673

674674
void InitializeCaches()
@@ -1522,7 +1522,7 @@ private BuildRequestConfiguration CreateConfiguration(Project project, BuildRequ
15221522

15231523
if (existingConfiguration == null)
15241524
{
1525-
existingConfiguration = new BuildRequestConfiguration(GetNewConfigurationId(), new BuildRequestData(newInstance, []), null /* use the instance's tools version */);
1525+
existingConfiguration = new BuildRequestConfiguration(GetNewConfigurationId(), new BuildRequestData(newInstance, Array.Empty<string>()), null /* use the instance's tools version */);
15261526
}
15271527
else
15281528
{
@@ -1830,7 +1830,7 @@ void IssueBuildSubmissionToSchedulerImpl(BuildSubmission submission, bool allowM
18301830
}
18311831
}
18321832

1833-
BuildRequestBlocker blocker = new BuildRequestBlocker(-1, [], [submission.BuildRequest]);
1833+
BuildRequestBlocker blocker = new BuildRequestBlocker(-1, Array.Empty<string>(), new[] { submission.BuildRequest });
18341834

18351835
HandleNewRequest(Scheduler.VirtualNode, blocker);
18361836
}

src/Build/BackEnd/BuildManager/BuildSubmission.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public override BuildResult Execute()
187187
ExecuteAsync(null, null, _legacyThreadingSemantics);
188188
if (_legacyThreadingSemantics)
189189
{
190-
RequestBuilder.WaitWithBuilderThreadStart([WaitHandle], false, legacyThreadingData, SubmissionId);
190+
RequestBuilder.WaitWithBuilderThreadStart(new[] { WaitHandle }, false, legacyThreadingData, SubmissionId);
191191
}
192192
else
193193
{

src/Build/BackEnd/Client/MSBuildClient.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,10 @@ private bool TryLaunchServer()
467467

468468
try
469469
{
470-
string[] msBuildServerOptions =
471-
[
470+
string[] msBuildServerOptions = new string[] {
472471
"/nologo",
473472
"/nodemode:8"
474-
];
473+
};
475474
NodeLauncher nodeLauncher = new NodeLauncher();
476475
CommunicationsUtilities.Trace("Starting Server...");
477476
Process msbuildProcess = nodeLauncher.Start(_msbuildLocation, string.Join(" ", msBuildServerOptions), nodeId: 0);

src/Build/BackEnd/Client/MSBuildClientPacketPump.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,14 @@ private void RunReadLoop(Stream localStream, ManualResetEvent localPacketPumpShu
205205
// will be returned by WaitAny if multiple wait handles are signalled. We prefer to have the
206206
// terminate event triggered so that we cannot get into a situation where packets are being
207207
// spammed to the client and it never gets an opportunity to shutdown.
208-
WaitHandle[] handles =
209-
[
210-
localPacketPumpShutdownEvent,
208+
WaitHandle[] handles = new WaitHandle[] {
209+
localPacketPumpShutdownEvent,
211210
#if FEATURE_APM
212-
result.AsyncWaitHandle
211+
result.AsyncWaitHandle
213212
#else
214-
((IAsyncResult)readTask).AsyncWaitHandle
213+
((IAsyncResult)readTask).AsyncWaitHandle
215214
#endif
216-
];
215+
};
217216
int waitId = WaitHandle.WaitAny(handles);
218217
switch (waitId)
219218
{

src/Build/BackEnd/Components/Communications/DetouredNodeLauncher.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ public Process Start(string msbuildLocation, string commandLineArgs, int nodeId)
107107
FileAccessPolicy.AllowAll | FileAccessPolicy.ReportAccess);
108108

109109
// Support shared compilation
110-
info.FileAccessManifest.ChildProcessesToBreakawayFromSandbox =
111-
[
110+
info.FileAccessManifest.ChildProcessesToBreakawayFromSandbox = new BreakawayChildProcess[]
111+
{
112112
#if RUNTIME_TYPE_NETCORE
113113
new BreakawayChildProcess(NativeMethodsShared.IsWindows ? "dotnet.exe" : "dotnet", "vbcscompiler.dll", CommandLineArgsSubstringContainmentIgnoreCase: true)
114114
#else
115115
new BreakawayChildProcess(NativeMethodsShared.IsWindows ? "VBCSCompiler.exe" : "VBCSCompiler")
116116
#endif
117-
];
117+
};
118118
info.FileAccessManifest.MonitorChildProcesses = true;
119119
info.FileAccessManifest.IgnoreReparsePoints = true;
120120
info.FileAccessManifest.UseExtraThreadToDrainNtClose = false;

src/Build/BackEnd/Components/Communications/NodeEndpointInProc.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private void PacketPumpProc()
420420
// will be returned by WaitAny if multiple wait handles are signalled. We prefer to have the
421421
// terminate event triggered so that we cannot get into a situation where packets are being
422422
// spammed to the endpoint and it never gets an opportunity to shutdown.
423-
WaitHandle[] handles = [_terminatePacketPump, _packetAvailable];
423+
WaitHandle[] handles = new WaitHandle[] { _terminatePacketPump, _packetAvailable };
424424

425425
bool exitLoop = false;
426426
do

src/Build/BackEnd/Components/Logging/ProjectLoggingContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static ProjectStartedEventArgs CreateProjectStarted(
207207
{
208208
if (projectProperties is null)
209209
{
210-
properties = [];
210+
properties = Enumerable.Empty<DictionaryEntry>();
211211
}
212212
else if (Traits.LogAllEnvironmentVariables)
213213
{
@@ -218,7 +218,7 @@ private static ProjectStartedEventArgs CreateProjectStarted(
218218
properties = projectProperties.Filter(p => p is not EnvironmentDerivedProjectPropertyInstance || EnvironmentUtilities.IsWellKnownEnvironmentDerivedProperty(p.Name), p => new DictionaryEntry(p.Name, p.EvaluatedValue));
219219
}
220220

221-
items = projectItems?.GetCopyOnReadEnumerable(item => new DictionaryEntry(item.ItemType, new TaskItem(item))) ?? [];
221+
items = projectItems?.GetCopyOnReadEnumerable(item => new DictionaryEntry(item.ItemType, new TaskItem(item))) ?? Enumerable.Empty<DictionaryEntry>();
222222
}
223223

224224
if (projectProperties != null &&

src/Build/BackEnd/Components/ProjectCache/CacheContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public CacheContext(
3030
MSBuildFileSystemBase fileSystem,
3131
ProjectGraph? graph = null,
3232
IReadOnlyCollection<ProjectGraphEntryPoint>? graphEntryPoints = null)
33-
: this(pluginSettings, fileSystem, requestedTargets: [], graph, graphEntryPoints)
33+
: this(pluginSettings, fileSystem, requestedTargets: Array.Empty<string>(), graph, graphEntryPoints)
3434
{
3535
}
3636

src/Build/BackEnd/Components/ProjectCache/ProjectCacheService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public void PostCacheRequest(CacheRequest cacheRequest, CancellationToken cancel
454454

455455
BuildRequestData buildRequest = new BuildRequestData(
456456
cacheRequest.Configuration.Project,
457-
cacheRequest.Submission.BuildRequestData?.TargetNames.ToArray() ?? []);
457+
cacheRequest.Submission.BuildRequestData?.TargetNames.ToArray() ?? Array.Empty<string>());
458458
BuildEventContext buildEventContext = _loggingService.CreateProjectCacheBuildEventContext(
459459
cacheRequest.Submission.SubmissionId,
460460
evaluationId: cacheRequest.Configuration.Project.EvaluationId,
@@ -650,7 +650,7 @@ private IReadOnlyCollection<ProjectGraphEntryPoint> GetGraphEntryPoints(BuildReq
650650
}
651651
else
652652
{
653-
return [new ProjectGraphEntryPoint(configuration.ProjectFullPath, globalProperties)];
653+
return new[] { new ProjectGraphEntryPoint(configuration.ProjectFullPath, globalProperties) };
654654
}
655655

656656
static IReadOnlyCollection<ProjectGraphEntryPoint> GenerateGraphEntryPointsFromSolutionConfigurationXml(

src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/MSBuild.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ internal static List<string[]> CreateTargetLists(
504504
// Separate target invocations for each individual target.
505505
foreach (string targetName in targets)
506506
{
507-
targetLists.Add([targetName]);
507+
targetLists.Add(new[] { targetName });
508508
}
509509
}
510510
else

src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public async Task BlockOnTargetInProgress(int blockingGlobalRequestId, string bl
402402

403403
RaiseOnBlockedRequest(blockingGlobalRequestId, blockingTarget, partialBuildResult);
404404

405-
WaitHandle[] handles = [_terminateEvent, _continueEvent];
405+
WaitHandle[] handles = new WaitHandle[] { _terminateEvent, _continueEvent };
406406

407407
int handle;
408408
if (IsBuilderUsingLegacyThreadingSemantics(_componentHost, _requestEntry))
@@ -448,7 +448,7 @@ public void Reacquire()
448448
VerifyIsNotZombie();
449449
RaiseOnBlockedRequest(_requestEntry.Request.GlobalRequestId, String.Empty);
450450

451-
WaitHandle[] handles = [_terminateEvent, _continueEvent];
451+
WaitHandle[] handles = new WaitHandle[] { _terminateEvent, _continueEvent };
452452

453453
int handle = WaitHandle.WaitAny(handles);
454454

@@ -506,7 +506,7 @@ public int RequestCores(object monitorLockObject, int requestedCores, bool waitF
506506
RaiseResourceRequest(ResourceRequest.CreateAcquireRequest(_requestEntry.Request.GlobalRequestId, requestedCores, waitForCores));
507507

508508
// Wait for one of two events to be signaled: 1) The build was canceled, 2) The response to our request was received.
509-
WaitHandle[] waitHandles = [_terminateEvent, responseEvent];
509+
WaitHandle[] waitHandles = new WaitHandle[] { _terminateEvent, responseEvent };
510510
int waitResult;
511511

512512
// Drop the lock so that the same task can call ReleaseCores from other threads to unblock itself.
@@ -957,7 +957,7 @@ private async Task<BuildResult[]> StartNewBuildRequests(FullyQualifiedBuildReque
957957
BuildResult[] results;
958958
if (waitForResults)
959959
{
960-
WaitHandle[] handles = [_terminateEvent, _continueEvent];
960+
WaitHandle[] handles = new WaitHandle[] { _terminateEvent, _continueEvent };
961961

962962
int handle;
963963
if (IsBuilderUsingLegacyThreadingSemantics(_componentHost, _requestEntry))

src/Build/BackEnd/Components/RequestBuilder/TaskHost.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ public bool BuildProjectFile(string projectFileName, string[] targetNames, Syste
261261
{
262262
VerifyActiveProxy();
263263
return BuildProjectFilesInParallel(
264-
[projectFileName],
264+
new string[] { projectFileName },
265265
targetNames,
266-
[globalProperties],
267-
[targetOutputs],
268-
[toolsVersion],
266+
new IDictionary[] { globalProperties },
267+
new IDictionary[] { targetOutputs },
268+
new string[] { toolsVersion },
269269
true,
270270
false);
271271
}
@@ -1205,8 +1205,8 @@ private async Task<BuildEngineResult> BuildProjectFilesInParallelAsync(string[]
12051205
BuildResult[] results = await builderCallback.BuildProjects(
12061206
projectFileNames,
12071207
propertyDictionaries,
1208-
toolsVersion ?? [],
1209-
targetNames ?? [],
1208+
toolsVersion ?? Array.Empty<string>(),
1209+
targetNames ?? Array.Empty<string>(),
12101210
waitForResults: true,
12111211
skipNonexistentTargets: skipNonexistentTargets);
12121212

src/Build/BackEnd/Components/Scheduler/SchedulableRequest.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public IEnumerable<string> ActiveTargets
187187
{
188188
get
189189
{
190-
VerifyOneOfStates([SchedulableRequestState.Yielding, SchedulableRequestState.Blocked, SchedulableRequestState.Executing]);
190+
VerifyOneOfStates(new SchedulableRequestState[] { SchedulableRequestState.Yielding, SchedulableRequestState.Blocked, SchedulableRequestState.Executing });
191191
return _activeTargetsWhenBlocked;
192192
}
193193
}
@@ -334,8 +334,8 @@ public void Reacquire()
334334
/// <param name="blockingTarget">Target that we are blocked on which is being built by <paramref name="blockingRequest"/></param>
335335
public void BlockByRequest(SchedulableRequest blockingRequest, string[] activeTargets, string blockingTarget = null)
336336
{
337-
VerifyOneOfStates([SchedulableRequestState.Blocked, SchedulableRequestState.Executing]);
338-
ErrorUtilities.VerifyThrowArgumentNull(blockingRequest);
337+
VerifyOneOfStates(new SchedulableRequestState[] { SchedulableRequestState.Blocked, SchedulableRequestState.Executing });
338+
ErrorUtilities.VerifyThrowArgumentNull(blockingRequest;
339339
ErrorUtilities.VerifyThrowArgumentNull(activeTargets);
340340
ErrorUtilities.VerifyThrow(BlockingTarget == null, "Cannot block again if we're already blocked on a target");
341341

@@ -350,7 +350,7 @@ public void BlockByRequest(SchedulableRequest blockingRequest, string[] activeTa
350350
// to also execute, then that request is not unscheduled (because it was running on the node) and it is not executing (because this condition
351351
// can only occur against requests which are executing on the same node and since the request which called this method is the one currently
352352
// executing on that node, that means the request it is blocked by must either be itself blocked or ready.)
353-
blockingRequest.VerifyOneOfStates([SchedulableRequestState.Yielding, SchedulableRequestState.Blocked, SchedulableRequestState.Ready, SchedulableRequestState.Unscheduled]);
353+
blockingRequest.VerifyOneOfStates(new SchedulableRequestState[] { SchedulableRequestState.Yielding, SchedulableRequestState.Blocked, SchedulableRequestState.Ready, SchedulableRequestState.Unscheduled });
354354

355355
// Update our list of active targets. This has to be done before we detect circular dependencies because we use this information to detect
356356
// re-entrancy circular dependencies.
@@ -371,7 +371,7 @@ public void BlockByRequest(SchedulableRequest blockingRequest, string[] activeTa
371371
/// </summary>
372372
public void UnblockWithPartialResultForBlockingTarget(BuildResult result)
373373
{
374-
VerifyOneOfStates([SchedulableRequestState.Blocked, SchedulableRequestState.Unscheduled]);
374+
VerifyOneOfStates(new SchedulableRequestState[] { SchedulableRequestState.Blocked, SchedulableRequestState.Unscheduled });
375375
ErrorUtilities.VerifyThrowArgumentNull(result);
376376

377377
BlockingRequestKey key = new BlockingRequestKey(result);
@@ -384,7 +384,7 @@ public void UnblockWithPartialResultForBlockingTarget(BuildResult result)
384384
/// </summary>
385385
public void UnblockWithResult(BuildResult result)
386386
{
387-
VerifyOneOfStates([SchedulableRequestState.Blocked, SchedulableRequestState.Unscheduled]);
387+
VerifyOneOfStates(new SchedulableRequestState[] { SchedulableRequestState.Blocked, SchedulableRequestState.Unscheduled });
388388
ErrorUtilities.VerifyThrowArgumentNull(result);
389389

390390
BlockingRequestKey key = new BlockingRequestKey(result);
@@ -400,7 +400,7 @@ public void ResumeExecution(int nodeId)
400400
{
401401
ErrorUtilities.VerifyThrow(_assignedNodeId == Scheduler.InvalidNodeId || _assignedNodeId == nodeId, "Request must always resume on the same node on which it was started.");
402402

403-
VerifyOneOfStates([SchedulableRequestState.Ready, SchedulableRequestState.Unscheduled]);
403+
VerifyOneOfStates(new SchedulableRequestState[] { SchedulableRequestState.Ready, SchedulableRequestState.Unscheduled });
404404
ErrorUtilities.VerifyThrow((_state == SchedulableRequestState.Ready) || !_schedulingData.IsRequestScheduled(this), "Another instance of request {0} is already scheduled.", _request.GlobalRequestId);
405405
ErrorUtilities.VerifyThrow(!_schedulingData.IsNodeWorking(nodeId), "Cannot resume execution of request {0} because node {1} is already working.", _request.GlobalRequestId, nodeId);
406406

@@ -416,7 +416,7 @@ public void ResumeExecution(int nodeId)
416416
/// </summary>
417417
public void Complete(BuildResult result)
418418
{
419-
VerifyOneOfStates([SchedulableRequestState.Ready, SchedulableRequestState.Executing, SchedulableRequestState.Unscheduled]);
419+
VerifyOneOfStates(new SchedulableRequestState[] { SchedulableRequestState.Ready, SchedulableRequestState.Executing, SchedulableRequestState.Unscheduled });
420420
ErrorUtilities.VerifyThrow(_state != SchedulableRequestState.Ready || result.CircularDependency, "Request can only be Completed from the Ready state if the result indicates a circular dependency occurred.");
421421
ErrorUtilities.VerifyThrow(_requestsWeAreBlockedBy.Count == 0, "We can't be complete if we are still blocked on requests.");
422422

src/Build/BackEnd/Components/Scheduler/Scheduler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,7 @@ private void HandleRequestBlockedOnInProgressTarget(SchedulableRequest blockedRe
16271627

16281628
// The request we blocked on couldn't have been executing (because we are) so it must either be yielding (which is ok because
16291629
// it isn't modifying its own state, just running a background process), ready, or still blocked.
1630-
blockingRequest.VerifyOneOfStates([SchedulableRequestState.Yielding, SchedulableRequestState.Ready, SchedulableRequestState.Blocked]);
1630+
blockingRequest.VerifyOneOfStates(new SchedulableRequestState[] { SchedulableRequestState.Yielding, SchedulableRequestState.Ready, SchedulableRequestState.Blocked });
16311631

16321632
// detect the case for https://github.com/dotnet/msbuild/issues/3047
16331633
// if we have partial results AND blocked and blocking share the same configuration AND are blocked on each other
@@ -1651,7 +1651,7 @@ private void HandleRequestBlockedOnInProgressTarget(SchedulableRequest blockedRe
16511651
private void HandleRequestBlockedOnResultsTransfer(SchedulableRequest parentRequest, List<ScheduleResponse> responses)
16521652
{
16531653
// Create the new request which will go to the configuration's results node.
1654-
BuildRequest newRequest = new BuildRequest(parentRequest.BuildRequest.SubmissionId, BuildRequest.ResultsTransferNodeRequestId, parentRequest.BuildRequest.ConfigurationId, [], null, parentRequest.BuildRequest.BuildEventContext, parentRequest.BuildRequest, parentRequest.BuildRequest.BuildRequestDataFlags);
1654+
BuildRequest newRequest = new BuildRequest(parentRequest.BuildRequest.SubmissionId, BuildRequest.ResultsTransferNodeRequestId, parentRequest.BuildRequest.ConfigurationId, Array.Empty<string>(), null, parentRequest.BuildRequest.BuildEventContext, parentRequest.BuildRequest, parentRequest.BuildRequest.BuildRequestDataFlags);
16551655

16561656
// Assign a new global request id - always different from any other.
16571657
newRequest.GlobalRequestId = _nextGlobalRequestId;

src/Build/BackEnd/Components/SdkResolution/DefaultSdkResolver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override SdkResultBase Resolve(SdkReference sdk, SdkResolverContextBase c
3434

3535
return FileUtilities.DirectoryExistsNoThrow(sdkPath)
3636
? factory.IndicateSuccess(sdkPath, string.Empty)
37-
: factory.IndicateFailure([ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("DefaultSDKResolverError", sdk.Name, sdkPath)], null);
37+
: factory.IndicateFailure(new string[] { ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("DefaultSDKResolverError", sdk.Name, sdkPath) }, null);
3838
}
3939
}
4040
}

src/Build/BackEnd/Components/SdkResolution/OutOfProcNodeSdkResolverService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private SdkResult RequestSdkPathFromMainNode(int submissionId, SdkReference sdk,
126126
SendPacket(packet);
127127

128128
// Wait for either the response or a shutdown event. Either event means this thread should return
129-
WaitHandle.WaitAny([_responseReceivedEvent, ShutdownEvent]);
129+
WaitHandle.WaitAny(new WaitHandle[] { _responseReceivedEvent, ShutdownEvent });
130130

131131
// Keep track of the element location of the reference
132132
_lastResponse.ElementLocation = sdkReferenceLocation;

0 commit comments

Comments
 (0)