Skip to content

Commit

Permalink
Fix multi item provider
Browse files Browse the repository at this point in the history
  • Loading branch information
chsienki committed Mar 18, 2021
1 parent 198d93a commit 87b8f97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class C { }
gst = new GraphStateTable.Builder(previous);

// we need to compact the sources too.
//
// presumably the sources need special treatment in terms of 'update' and 'compact' that happens *outside* the graph table

// remove some things
((MultiItemValueProvider<string>)sources.Strings.node).RemoveValue(0);
Expand Down
15 changes: 8 additions & 7 deletions src/Compilers/Core/Portable/SourceGeneration/ValueProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Collections.Immutable;
using System.Text;
using System.Linq;

using System.Diagnostics;

namespace Microsoft.CodeAnalysis
{
Expand Down Expand Up @@ -64,27 +64,28 @@ class MultiItemValueProvider<T> : AbstractNode<T>

bool hasChanged = false;

bool isAllCached = false;

internal MultiItemValueProvider(IEnumerable<T> initialValue)
{
FillBuilder(initialValue, EntryState.Added);
}

//TODO: is there a way we can add a 'dummy' entry to the state table that will hold our own state?

internal override StateTable<T> UpdateStateTable(GraphStateTable.Builder stateTable, StateTable<T> previousTable)
{
if (isAllCached && !hasChanged)
if (!hasChanged)
return previousTable;

//PROTOYPE: threading. This can race. need to atomically free and replace
var newTable = _currentBuilder.ToImmutableAndFree();
_currentBuilder = new StateTable<T>.Builder();
foreach (var entry in newTable)
{
var state = entry.state == EntryState.Removed ? EntryState.Removed : EntryState.Cached;
_currentBuilder.AddEntries(ImmutableArray.Create(entry.item), state);
if (entry.state != EntryState.Removed)
{
_currentBuilder.AddEntries(ImmutableArray.Create(entry.item), EntryState.Cached);
}
}
isAllCached = true;
hasChanged = false;
return newTable;
}
Expand Down

0 comments on commit 87b8f97

Please sign in to comment.