Skip to content

Commit

Permalink
[dart2js] Change Enumset.operator +/- to Enumset.add/remove.
Browse files Browse the repository at this point in the history
Change-Id: I92a97911531b699c5fc17cc37d5540c3fc44e63d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396566
Commit-Queue: Mayank Patke <[email protected]>
Reviewed-by: Stephen Adams <[email protected]>
  • Loading branch information
fishythefish authored and Commit Queue committed Nov 21, 2024
1 parent 9f5217d commit 723cbc1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/common/codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact {
bool get usesInterceptor => _usesInterceptor;

void registerAsyncMarker(AsyncMarker asyncMarker) {
_asyncMarkers += asyncMarker;
_asyncMarkers = _asyncMarkers.add(asyncMarker);
}

@override
Expand Down
24 changes: 12 additions & 12 deletions pkg/compiler/lib/src/inferrer/type_graph_nodes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ abstract class TypeInformation {
}

void giveUp(InferrerEngine inferrer, {bool clearInputs = true}) {
_flags += _Flag.abandonInferencing;
_flags = _flags.add(_Flag.abandonInferencing);
// Do not remove [this] as a user of nodes in [inputs],
// because our tracing analysis could be interested in tracing
// this node.
Expand Down Expand Up @@ -275,14 +275,14 @@ abstract class TypeInformation {
// Do not remove users because the tracing analysis could be interested
// in tracing the users of this node.
_inputs = STOP_TRACKING_INPUTS_MARKER;
_flags += _Flag.abandonInferencing;
_flags += _Flag.isStable;
_flags = _flags.add(_Flag.abandonInferencing);
_flags = _flags.add(_Flag.isStable);
}

void maybeResume() {
if (!mightResume) return;
_flags -= _Flag.abandonInferencing;
_flags -= _Flag.doNotEnqueue;
_flags = _flags.remove(_Flag.abandonInferencing);
_flags = _flags.remove(_Flag.doNotEnqueue);
}

/// Destroys information not needed after type inference.
Expand Down Expand Up @@ -501,10 +501,10 @@ abstract class MemberTypeInformation extends ElementTypeInformation
void markCalled() {
if (_flags.contains(_Flag.isCalled)) {
if (!_flags.contains(_Flag.isCalledMoreThanOnce)) {
_flags += _Flag.isCalledMoreThanOnce;
_flags = _flags.add(_Flag.isCalledMoreThanOnce);
}
} else {
_flags += _Flag.isCalled;
_flags = _flags.add(_Flag.isCalled);
}
}

Expand Down Expand Up @@ -809,7 +809,7 @@ class ParameterTypeInformation extends ElementTypeInformation {
.abstractValue,
_inputType = abstractValueDomain.uncomputedType,
super._internal() {
_flags += _Flag.isClosureParameter;
_flags = _flags.add(_Flag.isClosureParameter);
}

ParameterTypeInformation.static(
Expand All @@ -834,7 +834,7 @@ class ParameterTypeInformation extends ElementTypeInformation {
_createInstanceMemberStaticType(abstractValueDomain, type, _method),
_inputType = abstractValueDomain.uncomputedType,
super._withInputs() {
_flags += _Flag.isInstanceMemberParameter;
_flags = _flags.add(_Flag.isInstanceMemberParameter);
_flags = _flags.update(_Flag.isVirtual, isVirtual);
}

Expand Down Expand Up @@ -1223,12 +1223,12 @@ class DynamicCallSiteTypeInformation<T extends ir.Node>
}

void invalidateTargetsIncludeComplexNoSuchMethod() {
_flags -= _Flag.hasTargetsIncludeComplexNoSuchMethod;
_flags = _flags.remove(_Flag.hasTargetsIncludeComplexNoSuchMethod);
}

bool targetsIncludeComplexNoSuchMethod(InferrerEngine inferrer) {
if (!_hasTargetsIncludeComplexNoSuchMethod) {
_flags += _Flag.hasTargetsIncludeComplexNoSuchMethod;
_flags = _flags.add(_Flag.hasTargetsIncludeComplexNoSuchMethod);
final value = targets.any((target) => inferrer.memberHierarchyBuilder
.anyTargetMember(target, (MemberEntity e) {
return e.isFunction &&
Expand Down Expand Up @@ -1572,7 +1572,7 @@ class ClosureCallSiteTypeInformation extends CallSiteTypeInformation {
/// type.
class ConcreteTypeInformation extends TypeInformation {
ConcreteTypeInformation(super.type) : super.untracked() {
_flags += _Flag.isStable;
_flags = _flags.add(_Flag.isStable);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/ir/impact_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ class ImpactBuilder extends ir.RecursiveVisitor implements ImpactRegistry {
}

void _registerFeature(_Feature feature) {
_data._features += feature;
_data._features = _data._features.add(feature);
}

void _registerTypeUse(ir.DartType type, _TypeUseKind kind) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/compiler/lib/src/js_backend/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ EnumSet<PragmaAnnotation> processMemberAnnotations(
String suffix = data.suffix;
final annotation = PragmaAnnotation.lookupMap[suffix];
if (annotation != null) {
annotations += annotation;
annotations = annotations.add(annotation);

if (data.options != null && !annotation.hasOption) {
reporter.reportErrorMessage(
Expand Down Expand Up @@ -210,7 +210,7 @@ EnumSet<PragmaAnnotation> processMemberAnnotations(
"with @pragma('dart2js:${other.name}')."
});
reportedExclusions.update(
annotation, (exclusions) => exclusions + other,
annotation, (exclusions) => exclusions.add(other),
ifAbsent: () => EnumSet.fromValue(other));
}
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/compiler/lib/src/universe/class_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ class ClassHierarchyNode {
{required bool add}) {
ClassHierarchyNode? parent = parentNode;
if (add) {
_mask -= Instantiation.UNINSTANTIATED;
_mask += instantiation;
_mask = _mask.remove(Instantiation.UNINSTANTIATED);
_mask = _mask.add(instantiation);
while (parent != null) {
parent._updateInstantiatedSubclassCount(1);
parent = parent.parentNode;
}
} else {
_mask -= instantiation;
_mask = _mask.remove(instantiation);
if (_mask.isEmpty) {
_mask += Instantiation.UNINSTANTIATED;
_mask = _mask.add(Instantiation.UNINSTANTIATED);
}
while (parent != null) {
parent._updateInstantiatedSubclassCount(-1);
Expand Down Expand Up @@ -183,12 +183,12 @@ class ClassHierarchyNode {
bool after = isIndirectlyInstantiated;
if (before != after) {
if (after) {
_mask -= Instantiation.UNINSTANTIATED;
_mask += Instantiation.INDIRECTLY_INSTANTIATED;
_mask = _mask.remove(Instantiation.UNINSTANTIATED);
_mask = _mask.add(Instantiation.INDIRECTLY_INSTANTIATED);
} else {
_mask -= Instantiation.INDIRECTLY_INSTANTIATED;
_mask = _mask.remove(Instantiation.INDIRECTLY_INSTANTIATED);
if (_mask.isEmpty) {
_mask += Instantiation.UNINSTANTIATED;
_mask = _mask.add(Instantiation.UNINSTANTIATED);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/compiler/lib/src/util/enumset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@ extension type const EnumSet<E extends Enum>(Bitset mask) {

/// Returns a set containing all enum values in [this] as well as [enumValue].
@useResult
EnumSet<E> operator +(E enumValue) => EnumSet(mask.union(enumValue.mask(0)));
EnumSet<E> add(E enumValue) => EnumSet(mask.union(enumValue.mask(0)));

/// Returns a set containing all enum values in [this] except for [enumValue].
@useResult
EnumSet<E> operator -(E enumValue) =>
EnumSet(mask.setMinus(enumValue.mask(0)));
EnumSet<E> remove(E enumValue) => EnumSet(mask.setMinus(enumValue.mask(0)));

/// Returns a set with the bit for [value] enabled or disabled depending on
/// [state].
@useResult
EnumSet<E> update(E value, bool state) => state ? this + value : this - value;
EnumSet<E> update(E value, bool state) => state ? add(value) : remove(value);

/// Returns a new set containing all values in both this and the [other] set.
@useResult
Expand Down
36 changes: 19 additions & 17 deletions pkg/compiler/test/model/enumset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,36 @@ void testAddRemoveContains() {

check(0, []);

enumSet += Enum.B;
enumSet = enumSet.add(Enum.B);
check(2, [Enum.B]);

enumSet += Enum.F;
enumSet = enumSet.add(Enum.F);
check(34, [Enum.F, Enum.B]);

enumSet += Enum.A;
enumSet = enumSet.add(Enum.A);
check(35, [Enum.F, Enum.B, Enum.A]);

enumSet += Enum.A;
enumSet = enumSet.add(Enum.A);
check(35, [Enum.F, Enum.B, Enum.A]);

enumSet -= Enum.C;
enumSet = enumSet.remove(Enum.C);
check(35, [Enum.F, Enum.B, Enum.A]);

enumSet -= Enum.B;
enumSet = enumSet.remove(Enum.B);
check(33, [Enum.F, Enum.A]);

enumSet -= Enum.A;
enumSet = enumSet.remove(Enum.A);
check(32, [Enum.F]);

enumSet = EnumSet.empty();
check(0, []);

enumSet += Enum.A;
enumSet += Enum.B;
enumSet += Enum.C;
enumSet += Enum.D;
enumSet += Enum.E;
enumSet += Enum.F;
enumSet = enumSet.add(Enum.A);
enumSet = enumSet.add(Enum.B);
enumSet = enumSet.add(Enum.C);
enumSet = enumSet.add(Enum.D);
enumSet = enumSet.add(Enum.E);
enumSet = enumSet.add(Enum.F);
check(63, [Enum.F, Enum.E, Enum.D, Enum.C, Enum.B, Enum.A]);
}

Expand Down Expand Up @@ -107,8 +107,8 @@ void testConstructorsIntersects() {
check(emptyA, emptyD);
check(emptyA, emptyE);

EnumSet<Enum> singleA = const EnumSet<Enum>.empty() + Enum.C;
EnumSet<Enum> singleB = EnumSet<Enum>.empty() + Enum.C;
EnumSet<Enum> singleA = const EnumSet<Enum>.empty().add(Enum.C);
EnumSet<Enum> singleB = EnumSet<Enum>.empty().add(Enum.C);
EnumSet<Enum> singleC = const EnumSet<Enum>.fromRawBits(4);
EnumSet<Enum> singleD = EnumSet<Enum>.fromRawBits(4);
EnumSet<Enum> singleE = EnumSet<Enum>.fromValues([Enum.C]);
Expand All @@ -121,8 +121,10 @@ void testConstructorsIntersects() {
check(singleA, singleE);
check(singleA, singleF);

EnumSet<Enum> multiA = const EnumSet<Enum>.empty() + Enum.A + Enum.D + Enum.F;
EnumSet<Enum> multiB = EnumSet<Enum>.empty() + Enum.A + Enum.D + Enum.F;
EnumSet<Enum> multiA =
const EnumSet<Enum>.empty().add(Enum.A).add(Enum.D).add(Enum.F);
EnumSet<Enum> multiB =
EnumSet<Enum>.empty().add(Enum.A).add(Enum.D).add(Enum.F);
EnumSet<Enum> multiC = const EnumSet<Enum>.fromRawBits(41);
EnumSet<Enum> multiD = EnumSet<Enum>.fromRawBits(41);
EnumSet<Enum> multiE = EnumSet<Enum>.fromValues([Enum.F, Enum.A, Enum.D]);
Expand Down

0 comments on commit 723cbc1

Please sign in to comment.