Skip to content

New change detection for anchor nodes #3941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
39 changes: 6 additions & 33 deletions _test_common/lib/matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,20 @@ class _AssetGraphMatcher extends Matcher {
final Matcher _matcher;

_AssetGraphMatcher(this._expected, this.checkPreviousInputsDigest)
: _matcher = equals(
_graphToList(
_expected,
checkPreviousInputsDigest: checkPreviousInputsDigest,
),
);
: _matcher = equals(_graphToList(_expected));

/// Converts [graph] to a list of [AssetNode], sorted by ID, for comparison.
///
/// If [checkPreviousInputsDigest] is false, removes `previousInputDigest`
/// fields so they won't be compared.
static List<AssetNode> _graphToList(
AssetGraph graph, {
required bool checkPreviousInputsDigest,
}) {
final result = <AssetNode>[];
for (var node in graph.allNodes) {
if (!checkPreviousInputsDigest) {
if (node.type == NodeType.postProcessAnchor) {
node = node.rebuild(
(b) => b..postProcessAnchorNodeState.previousInputsDigest = null,
);
}
}
result.add(node);
}
return result..sort((a, b) => a.id.toString().compareTo(b.id.toString()));
}
static List<AssetNode> _graphToList(AssetGraph graph) =>
graph.allNodes.toList()
..sort((a, b) => a.id.toString().compareTo(b.id.toString()));

@override
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
if (item is! AssetGraph) return false;
return _matcher.matches(
_graphToList(item, checkPreviousInputsDigest: checkPreviousInputsDigest),
matchState,
);
return _matcher.matches(_graphToList(item), matchState);
}

@override
Expand All @@ -76,12 +54,7 @@ class _AssetGraphMatcher extends Matcher {
Map matchState,
bool verbose,
) => _matcher.describeMismatch(
item is AssetGraph
? _graphToList(
item,
checkPreviousInputsDigest: checkPreviousInputsDigest,
)
: '(not an AssetGraph!) $item',
item is AssetGraph ? _graphToList(item) : '(not an AssetGraph!) $item',
mismatchDescription,
matchState,
verbose,
Expand Down
29 changes: 3 additions & 26 deletions build_runner_core/lib/src/asset_graph/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
/// [AssetNode.postProcessAnchorNodeConfiguration].
PostProcessAnchorNodeConfiguration? get postProcessAnchorNodeConfiguration;

/// Additional node state that changes during the build for an
/// [AssetNode.postProcessAnchor].
PostProcessAnchorNodeState? get postProcessAnchorNodeState;

/// The assets that any [Builder] in the build graph declares it may output
/// when run on this asset.
BuiltSet<AssetId> get primaryOutputs;
Expand Down Expand Up @@ -259,9 +255,7 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
..postProcessAnchorNodeConfiguration.actionNumber = actionNumber
..postProcessAnchorNodeConfiguration.builderOptionsId =
builderOptionsId
..postProcessAnchorNodeConfiguration.primaryInput = primaryInput
..postProcessAnchorNodeState.previousInputsDigest =
previousInputsDigest,
..postProcessAnchorNodeConfiguration.primaryInput = primaryInput,
);

factory AssetNode.postProcessAnchorForInputAndAction(
Expand All @@ -279,13 +273,13 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
// Check that configuration and state fields are non-null exactly when the
// node is of the corresponding type.

void check(bool hasType, bool hasConfiguration, bool hasState) {
void check(bool hasType, bool hasConfiguration, [bool? hasState]) {
if (hasType != hasConfiguration) {
throw ArgumentError(
'Node configuration does not match its type: $this',
);
}
if (hasType != hasState) {
if (hasState != null && hasType != hasState) {
throw ArgumentError('Node state does not match its type: $this');
}
}
Expand All @@ -303,7 +297,6 @@ abstract class AssetNode implements Built<AssetNode, AssetNodeBuilder> {
check(
type == NodeType.postProcessAnchor,
postProcessAnchorNodeConfiguration != null,
postProcessAnchorNodeState != null,
);
}
}
Expand Down Expand Up @@ -432,22 +425,6 @@ abstract class PostProcessAnchorNodeConfiguration
) = _$PostProcessAnchorNodeConfiguration;
}

/// State for an [AssetNode.postProcessAnchor].
abstract class PostProcessAnchorNodeState
implements
Built<PostProcessAnchorNodeState, PostProcessAnchorNodeStateBuilder> {
static Serializer<PostProcessAnchorNodeState> get serializer =>
_$postProcessAnchorNodeStateSerializer;

Digest? get previousInputsDigest;

factory PostProcessAnchorNodeState(
void Function(PostProcessAnchorNodeStateBuilder) updates,
) = _$PostProcessAnchorNodeState;

PostProcessAnchorNodeState._();
}

/// Work that needs doing for a node that tracks its inputs.
class PendingBuildAction extends EnumClass {
static Serializer<PendingBuildAction> get serializer =>
Expand Down
Loading
Loading