Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Build.UnitTests/BackEnd/Lookup_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ public void Removes()
lookup.AddNewItem(item2);

// Remove one item
lookup.RemoveItem(item1);
lookup.RemoveItems("i1", [item1]);

// We see one item
Assert.Single(lookup.GetItems("i1"));
Assert.Equal("a2", lookup.GetItems("i1").First().EvaluatedInclude);

// Remove the other item
lookup.RemoveItem(item2);
lookup.RemoveItems("i1", [item2]);

// We see no items
Assert.Empty(lookup.GetItems("i1"));
Expand Down Expand Up @@ -326,7 +326,7 @@ public void RemoveItemPopulatedInLowerScope()
Assert.Single(lookup.GetItems("i1"));

// Remove that item
lookup.RemoveItem(item1);
lookup.RemoveItems("i1", [item1]);

// We see no items
Assert.Empty(lookup.GetItems("i1"));
Expand Down Expand Up @@ -372,7 +372,7 @@ public void RemoveItemAddedInLowerScope()
Assert.Single(lookup.GetItems("i1"));

// Remove that item
lookup.RemoveItem(item1);
lookup.RemoveItems("i1", [item1]);

// We see no items
Assert.Empty(lookup.GetItems("i1"));
Expand Down Expand Up @@ -824,7 +824,7 @@ public void ModifyItemModifiedInPreviousScope()
// Add an item with m=m1 and n=n1
ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath);
item1.SetMetadata("m", "m1");
lookup.PopulateWithItem(item1);
table1.Add(item1);

lookup.EnterScope("x");

Expand Down Expand Up @@ -865,7 +865,7 @@ public void ModifyItemTwiceInSameScope1()
// Add an item with m=m1 and n=n1
ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath);
item1.SetMetadata("m", "m1");
lookup.PopulateWithItem(item1);
table1.Add(item1);

lookup.EnterScope("x");

Expand Down Expand Up @@ -902,7 +902,7 @@ public void ModifyItemTwiceInSameScope2()
item1.SetMetadata("m", "m1");
item1.SetMetadata("n", "n1");
item1.SetMetadata("o", "o1");
lookup.PopulateWithItem(item1);
table1.Add(item1);

Lookup.Scope enteredScope = lookup.EnterScope("x");

Expand Down Expand Up @@ -1028,7 +1028,7 @@ public void ModifyItemPreviouslyModifiedAndGottenThroughGetItem()
// Add an item with m=m1 and n=n1
ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath);
item1.SetMetadata("m", "m1");
lookup.PopulateWithItem(item1);
table1.Add(item1);

Lookup.Scope enteredScope = lookup.EnterScope("x");

Expand Down Expand Up @@ -1132,7 +1132,7 @@ public void RemoveItemPreviouslyModifiedAndGottenThroughGetItem()
// Add an item with m=m1 and n=n1
ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath);
item1.SetMetadata("m", "m1");
lookup.PopulateWithItem(item1);
table1.Add(item1);

lookup.EnterScope("x");

Expand All @@ -1149,7 +1149,7 @@ public void RemoveItemPreviouslyModifiedAndGottenThroughGetItem()
ProjectItemInstance item1b = group2.First();

// Remove the item
lookup.RemoveItem(item1b);
lookup.RemoveItems(item1.ItemType, [item1b]);

// There's now no items at all
ICollection<ProjectItemInstance> group3 = lookup.GetItems(item1.ItemType);
Expand Down Expand Up @@ -1186,7 +1186,7 @@ public void RemoveItemFromProjectPreviouslyModifiedAndGottenThroughGetItem()
ProjectItemInstance item1b = group2.First();

// Remove the item
lookup.RemoveItem(item1b);
lookup.RemoveItems(item1.ItemType, [item1b]);

// There's now no items at all
ICollection<ProjectItemInstance> group3 = lookup.GetItems(item1.ItemType);
Expand Down
3 changes: 2 additions & 1 deletion src/Build.UnitTests/BackEnd/TargetUpToDateChecker_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ public void MultiInputItemsThatCorrelatesWithMultipleTransformOutputItems()

// Even though they were all up to date, we still expect to see an empty marker
// so that lookups can correctly *not* find items of that type
Assert.True(changedTargetInputs.HasEmptyMarker("MoreItems"));
Assert.True(changedTargetInputs.ItemTypes.Contains("MoreItems"));
Assert.Empty(changedTargetInputs["MoreItems"]);
}

[Fact]
Expand Down
3 changes: 2 additions & 1 deletion src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -1282,7 +1283,7 @@ private void InitializeHost(bool throwOnExecute)
itemsByName.Add(item2);
_twoItems = new ITaskItem[] { new TaskItem(item), new TaskItem(item2) };

_bucket = new ItemBucket(new Dictionary<string, ICollection<ProjectItemInstance>>().Keys, new Dictionary<string, string>(), new Lookup(itemsByName, new PropertyDictionary<ProjectPropertyInstance>()), 0);
_bucket = new ItemBucket(FrozenSet<string>.Empty, new Dictionary<string, string>(), new Lookup(itemsByName, new PropertyDictionary<ProjectPropertyInstance>()), 0);
_bucket.Initialize(null);
_host.FindTask(null);
_host.InitializeForBatch(talc, _bucket, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Collections;
Expand Down Expand Up @@ -311,6 +312,7 @@ private static List<ItemBucket> BucketConsumedItems(
ErrorUtilities.VerifyThrow(consumedMetadataReferences.Count > 0, "Need item metadata consumed by the batchable object.");

var buckets = new List<ItemBucket>();
FrozenSet<string> itemNames = itemListsToBeBatched.Keys.ToFrozenSet(MSBuildNameIgnoreCaseComparer.Default);

// Get and iterate through the list of item names that we're supposed to batch on.
foreach (KeyValuePair<string, ICollection<ProjectItemInstance>> entry in itemListsToBeBatched)
Expand Down Expand Up @@ -346,7 +348,7 @@ private static List<ItemBucket> BucketConsumedItems(
}
else
{
matchingBucket = new ItemBucket(itemListsToBeBatched.Keys, itemMetadataValues, lookup, buckets.Count);
matchingBucket = new ItemBucket(itemNames, itemMetadataValues, lookup, buckets.Count);
if (loggingContext != null)
{
matchingBucket.Initialize(loggingContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private void ExecuteRemove(ProjectItemGroupTaskItemInstance child, ItemBucket bu
child.Location);
}

bucket.Lookup.RemoveItems(itemsToRemove);
bucket.Lookup.RemoveItems(child.ItemType, itemsToRemove);
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/Build/BackEnd/Components/RequestBuilder/ItemBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Build.BackEnd.Logging;
Expand Down Expand Up @@ -74,7 +75,7 @@ private ItemBucket(Dictionary<string, string> metadata)
/// <param name="lookup">The <see cref="Lookup"/> to use for the items in the bucket.</param>
/// <param name="bucketSequenceNumber">A sequence number indication what order the buckets were created in.</param>
internal ItemBucket(
Dictionary<string, ICollection<ProjectItemInstance>>.KeyCollection itemNames, // PERF: directly use the KeyCollection to avoid boxing the enumerator.
FrozenSet<string> itemNames,
Dictionary<string, string> metadata,
Lookup lookup,
int bucketSequenceNumber)
Expand All @@ -87,15 +88,9 @@ internal ItemBucket(
// Push down the items, so that item changes in this batch are not visible to parallel batches
_lookupEntry = _lookup.EnterScope("ItemBucket()");

// Add empty item groups for each of the item names, so that (unless items are added to this bucket) there are
// Truncate lookups for each of the item names, so that (unless items are added to this bucket) there are
// no item types visible in this bucket among the item types being batched on
if (itemNames != null)
{
foreach (string name in itemNames)
{
_lookup.PopulateWithItems(name, new List<ProjectItemInstance>());
}
}
_lookup.TruncateLookupsForItemTypes(itemNames);

_metadata = metadata;

Expand Down
Loading