Skip to content

Commit 73d9a8d

Browse files
rakudramaCommit Queue
authored and
Commit Queue
committed
[dart2js] Cleanup
Rename DummyInterceptorConstantValue to DummyConstantValue. It was actually used as a dummy *receiver* argument and could be used against any unused parameter. Remove unused CompilerOptions argument in SSA as-checks and is-tests. Pass the checked input explicitly to facilitate testing on other inputs (e.g. to do partial redundancy elimination by pushing the operation into the arms of a phi.) Change-Id: I4b450bfcf5fc877de731bf83201e3c9248ffcb0c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433104 Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent 0ac78fb commit 73d9a8d

File tree

14 files changed

+63
-78
lines changed

14 files changed

+63
-78
lines changed

pkg/compiler/lib/src/constants/values.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum ConstantValueKind {
2929
interceptor,
3030
javaScriptObject,
3131
jsName,
32-
dummyInterceptor,
32+
dummy,
3333
lateSentinel,
3434
unreachable,
3535
instantiation,
@@ -62,10 +62,7 @@ abstract class ConstantValueVisitor<R, A> {
6262
covariant JavaScriptObjectConstantValue constant,
6363
covariant A arg,
6464
);
65-
R visitDummyInterceptor(
66-
covariant DummyInterceptorConstantValue constant,
67-
covariant A arg,
68-
);
65+
R visitDummy(covariant DummyConstantValue constant, covariant A arg);
6966
R visitLateSentinel(
7067
covariant LateSentinelConstantValue constant,
7168
covariant A arg,
@@ -826,14 +823,14 @@ class JsNameConstantValue extends ConstantValue {
826823
}
827824
}
828825

829-
/// A constant used as the dummy receiver value for intercepted calls with
830-
/// a known non-interceptor target.
831-
// TODO(sra): Rename fo 'DummyReceiverConstantValue'.
832-
class DummyInterceptorConstantValue extends ConstantValue {
833-
factory DummyInterceptorConstantValue() =>
834-
const DummyInterceptorConstantValue._();
826+
/// A constant used as an argument or receiver when the target does not use the
827+
/// corresponding parameter. Used as the dummy receiver value for calls using
828+
/// the intercepted calling convention when the target is 'self-intercepting'
829+
/// and does not use the explicit receiver parameter.
830+
class DummyConstantValue extends ConstantValue {
831+
factory DummyConstantValue() => const DummyConstantValue._();
835832

836-
const DummyInterceptorConstantValue._();
833+
const DummyConstantValue._();
837834

838835
@override
839836
bool get isDummy => true;
@@ -843,20 +840,20 @@ class DummyInterceptorConstantValue extends ConstantValue {
843840

844841
@override
845842
R accept<R, A>(ConstantValueVisitor<R, A> visitor, A arg) {
846-
return visitor.visitDummyInterceptor(this, arg);
843+
return visitor.visitDummy(this, arg);
847844
}
848845

849846
@override
850847
DartType getType(CommonElements types) => types.dynamicType;
851848

852849
@override
853-
ConstantValueKind get kind => ConstantValueKind.dummyInterceptor;
850+
ConstantValueKind get kind => ConstantValueKind.dummy;
854851

855852
@override
856-
String toDartText(DartTypes? dartTypes) => 'dummy_interceptor()';
853+
String toDartText(DartTypes? dartTypes) => 'dummy()';
857854

858855
@override
859-
String toStructuredText(DartTypes? dartTypes) => 'DummyInterceptorConstant()';
856+
String toStructuredText(DartTypes? dartTypes) => 'DummyConstant()';
860857
}
861858

862859
/// A constant used to represent the sentinel for uninitialized late fields and

pkg/compiler/lib/src/inferrer/typemasks/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ConstantValueTypeMasks extends ConstantValueVisitor<TypeMask, Null> {
5555
}
5656

5757
@override
58-
TypeMask visitDummyInterceptor(DummyInterceptorConstantValue constant, _) =>
58+
TypeMask visitDummy(DummyConstantValue constant, _) =>
5959
_abstractValueDomain.dynamicType;
6060

6161
@override

pkg/compiler/lib/src/js_backend/constant_emitter.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ class ModularConstantEmitter
162162
}
163163

164164
@override
165-
js_ast.Expression visitDummyInterceptor(
166-
DummyInterceptorConstantValue constant, [
167-
_,
168-
]) {
165+
js_ast.Expression visitDummy(DummyConstantValue constant, [_]) {
169166
return js_ast.LiteralNumber('0');
170167
}
171168

pkg/compiler/lib/src/js_backend/impact_transformer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class CodegenImpactTransformer {
119119
break;
120120
case ConstantValueKind.bool:
121121
case ConstantValueKind.double:
122-
case ConstantValueKind.dummyInterceptor:
122+
case ConstantValueKind.dummy:
123123
case ConstantValueKind.function:
124124
case ConstantValueKind.int:
125125
case ConstantValueKind.interceptor:

pkg/compiler/lib/src/js_backend/namer.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,8 +1498,8 @@ class ConstantNamingVisitor implements ConstantValueVisitor<void, Null> {
14981498
}
14991499

15001500
@override
1501-
void visitDummyInterceptor(DummyInterceptorConstantValue constant, [_]) {
1502-
add('dummy_interceptor');
1501+
void visitDummy(DummyConstantValue constant, [_]) {
1502+
add('dummy');
15031503
}
15041504

15051505
@override
@@ -1669,10 +1669,10 @@ class ConstantCanonicalHasher implements ConstantValueVisitor<int, Null> {
16691669
}
16701670

16711671
@override
1672-
int visitDummyInterceptor(DummyInterceptorConstantValue constant, [_]) {
1672+
int visitDummy(DummyConstantValue constant, [_]) {
16731673
throw failedAt(
16741674
noLocationSpannable,
1675-
'DummyInterceptorConstantValue should never be named and '
1675+
'DummyConstantValue should never be named and '
16761676
'never be subconstant',
16771677
);
16781678
}

pkg/compiler/lib/src/js_emitter/constant_ordering.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,7 @@ class _ConstantOrdering
162162
}
163163

164164
@override
165-
int visitDummyInterceptor(
166-
DummyInterceptorConstantValue a,
167-
DummyInterceptorConstantValue b,
168-
) {
169-
// Never emitted.
165+
int visitDummy(DummyConstantValue a, DummyConstantValue b) {
170166
return 0;
171167
}
172168

pkg/compiler/lib/src/js_model/js_to_frontend_map.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,7 @@ class _ConstantConverter implements ConstantValueVisitor<ConstantValue, Null> {
317317
@override
318318
StringConstantValue visitString(StringConstantValue constant, _) => constant;
319319
@override
320-
DummyInterceptorConstantValue visitDummyInterceptor(
321-
DummyInterceptorConstantValue constant,
322-
_,
323-
) => constant;
320+
DummyConstantValue visitDummy(DummyConstantValue constant, _) => constant;
324321
@override
325322
LateSentinelConstantValue visitLateSentinel(
326323
LateSentinelConstantValue constant,

pkg/compiler/lib/src/serialization/sink.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ class DataSinkWriter {
10211021
writeConstant(constant.referenced);
10221022
writeOutputUnitReference(constant.unit);
10231023
break;
1024-
case ConstantValueKind.dummyInterceptor:
1024+
case ConstantValueKind.dummy:
10251025
break;
10261026
case ConstantValueKind.lateSentinel:
10271027
break;

pkg/compiler/lib/src/serialization/source.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,8 +1335,8 @@ class DataSourceReader {
13351335
ConstantValue constant = readConstant();
13361336
OutputUnit unit = readOutputUnitReference();
13371337
return DeferredGlobalConstantValue(constant, unit);
1338-
case ConstantValueKind.dummyInterceptor:
1339-
return DummyInterceptorConstantValue();
1338+
case ConstantValueKind.dummy:
1339+
return DummyConstantValue();
13401340
case ConstantValueKind.lateSentinel:
13411341
return LateSentinelConstantValue();
13421342
case ConstantValueKind.unreachable:

pkg/compiler/lib/src/ssa/interceptor_finalizer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class SsaFinalizeInterceptors extends HBaseVisitor<void>
269269

270270
void _replaceReceiverArgumentWithDummy(HInvoke node, int receiverIndex) {
271271
assert(!node.isCallOnInterceptor, 'node: $node');
272-
ConstantValue constant = DummyInterceptorConstantValue();
272+
ConstantValue constant = DummyConstantValue();
273273
HConstant dummy = _graph.addConstant(constant, _closedWorld);
274274
node.replaceInput(receiverIndex, dummy);
275275
}

pkg/compiler/lib/src/ssa/nodes.dart

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import '../js_model/js_world.dart' show JClosedWorld;
3131
import '../js_model/type_recipe.dart'
3232
show TypeEnvironmentStructure, TypeRecipe, TypeExpressionRecipe;
3333
import '../native/behavior.dart';
34-
import '../options.dart';
3534
import '../universe/selector.dart' show Selector;
3635
import '../universe/side_effects.dart' show SideEffects;
3736
import '../util/util.dart';
@@ -1952,9 +1951,7 @@ abstract class HInvoke extends HInstruction
19521951
final receiver = inputs[1].nonCheck();
19531952
if (interceptor == receiver) {
19541953
_isCallOnInterceptor = false;
1955-
} else if (receiver case HConstant(
1956-
constant: DummyInterceptorConstantValue(),
1957-
)) {
1954+
} else if (receiver case HConstant(constant: DummyConstantValue())) {
19581955
_isCallOnInterceptor = false;
19591956
}
19601957
}
@@ -4542,13 +4539,16 @@ class HIsTest extends HInstruction {
45424539
HInstruction get typeInput => inputs[0];
45434540
HInstruction get checkedInput => inputs[1];
45444541

4545-
AbstractBool evaluate(JClosedWorld closedWorld, CompilerOptions options) =>
4542+
/// Returns the value of the test (true/false/maybe). Pass [this.checkedInput]
4543+
/// as [input] to evaluate this test in place. [input] is provided as an
4544+
/// argument so that other inputs can be tested, for example, to test for
4545+
/// partial redundancy between a phi's inputs.
4546+
AbstractBool evaluateOn(HInstruction input, JClosedWorld closedWorld) =>
45464547
_typeTest(
4547-
checkedInput,
4548+
input,
45484549
dartType,
45494550
checkedAbstractValue,
45504551
closedWorld,
4551-
options,
45524552
isCast: false,
45534553
);
45544554

@@ -4587,13 +4587,13 @@ class HIsTestSimple extends HInstruction {
45874587

45884588
HInstruction get checkedInput => inputs[0];
45894589

4590-
AbstractBool evaluate(JClosedWorld closedWorld, CompilerOptions options) =>
4590+
/// See [HIsTest.evaluateOn].
4591+
AbstractBool evaluateOn(HInstruction input, JClosedWorld closedWorld) =>
45914592
_typeTest(
4592-
checkedInput,
4593+
input,
45934594
dartType,
45944595
checkedAbstractValue,
45954596
closedWorld,
4596-
options,
45974597
isCast: false,
45984598
);
45994599

@@ -4617,8 +4617,7 @@ AbstractBool _typeTest(
46174617
HInstruction expression,
46184618
DartType dartType,
46194619
AbstractValueWithPrecision checkedAbstractValue,
4620-
JClosedWorld closedWorld,
4621-
CompilerOptions options, {
4620+
JClosedWorld closedWorld, {
46224621
required bool isCast,
46234622
}) {
46244623
JCommonElements commonElements = closedWorld.commonElements;
@@ -4753,15 +4752,17 @@ class HAsCheck extends HCheck {
47534752
return isTypeError == other.isTypeError;
47544753
}
47554754

4756-
bool isRedundant(JClosedWorld closedWorld, CompilerOptions options) =>
4757-
_typeTest(
4758-
checkedInput,
4759-
checkedTypeExpression,
4760-
checkedType,
4761-
closedWorld,
4762-
options,
4763-
isCast: true,
4764-
).isDefinitelyTrue;
4755+
/// Returns 'true` is the check always passes. Provide [this.checkedInput] as
4756+
/// [input] to evaluate this check in place. [input] is provided as an
4757+
/// argument so that other inputs can be tested, for example, to test for
4758+
/// partial redundancy between a phi's inputs.
4759+
bool isRedundantOn(HInstruction input, JClosedWorld closedWorld) => _typeTest(
4760+
input,
4761+
checkedTypeExpression,
4762+
checkedType,
4763+
closedWorld,
4764+
isCast: true,
4765+
).isDefinitelyTrue;
47654766

47664767
@override
47674768
String toString() {
@@ -4796,15 +4797,14 @@ class HAsCheckSimple extends HCheck {
47964797
@override
47974798
R accept<R>(HVisitor<R> visitor) => visitor.visitAsCheckSimple(this);
47984799

4799-
bool isRedundant(JClosedWorld closedWorld, CompilerOptions options) =>
4800-
_typeTest(
4801-
checkedInput,
4802-
dartType,
4803-
checkedType,
4804-
closedWorld,
4805-
options,
4806-
isCast: true,
4807-
).isDefinitelyTrue;
4800+
/// See [HAsCheck.isRedundantOn].
4801+
bool isRedundantOn(HInstruction input, JClosedWorld closedWorld) => _typeTest(
4802+
input,
4803+
dartType,
4804+
checkedType,
4805+
closedWorld,
4806+
isCast: true,
4807+
).isDefinitelyTrue;
48084808

48094809
@override
48104810
_GvnType get _gvnType => _GvnType.asCheckSimple;

pkg/compiler/lib/src/ssa/optimize.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ class SsaInstructionSimplifier extends HBaseVisitor<HInstruction>
26332633
node.checkedTypeExpression = recipe.type;
26342634
}
26352635

2636-
if (node.isRedundant(_closedWorld, _options)) {
2636+
if (node.isRedundantOn(node.checkedInput, _closedWorld)) {
26372637
return node.checkedInput;
26382638
}
26392639

@@ -2659,7 +2659,7 @@ class SsaInstructionSimplifier extends HBaseVisitor<HInstruction>
26592659

26602660
@override
26612661
HInstruction visitAsCheckSimple(HAsCheckSimple node) {
2662-
if (node.isRedundant(_closedWorld, _options)) {
2662+
if (node.isRedundantOn(node.checkedInput, _closedWorld)) {
26632663
return node.checkedInput;
26642664
}
26652665
return node;
@@ -2675,7 +2675,7 @@ class SsaInstructionSimplifier extends HBaseVisitor<HInstruction>
26752675
node.dartType = recipe.type;
26762676
}
26772677

2678-
AbstractBool result = node.evaluate(_closedWorld, _options);
2678+
AbstractBool result = node.evaluateOn(node.checkedInput, _closedWorld);
26792679
if (result.isDefinitelyFalse) {
26802680
_metrics.countIsTestDecided.add();
26812681
return _graph.addConstantBool(false, _closedWorld);
@@ -2724,7 +2724,7 @@ class SsaInstructionSimplifier extends HBaseVisitor<HInstruction>
27242724

27252725
@override
27262726
HInstruction visitIsTestSimple(HIsTestSimple node) {
2727-
AbstractBool result = node.evaluate(_closedWorld, _options);
2727+
AbstractBool result = node.evaluateOn(node.checkedInput, _closedWorld);
27282728
if (result.isDefinitelyFalse) {
27292729
_metrics.countIsTestDecided.add();
27302730
return _graph.addConstantBool(false, _closedWorld);

pkg/compiler/lib/src/ssa/type_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ abstract class TypeBuilder {
7070
// similar operation on `registry`; otherwise, this one might not be needed.
7171
builder.registry.registerTypeUse(TypeUse.isCheck(type));
7272
if (other is HAsCheck &&
73-
other.isRedundant(builder.closedWorld, builder.options)) {
73+
other.isRedundantOn(other.checkedInput, builder.closedWorld)) {
7474
return original;
7575
}
7676
return other;

pkg/compiler/test/helpers/shared_helper.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,8 @@ class ConstantToTextVisitor
254254
_unsupported(constant);
255255

256256
@override
257-
void visitDummyInterceptor(
258-
DummyInterceptorConstantValue constant,
259-
StringBuffer sb,
260-
) => _unsupported(constant);
257+
void visitDummy(DummyConstantValue constant, StringBuffer sb) =>
258+
_unsupported(constant);
261259

262260
@override
263261
void visitLateSentinel(LateSentinelConstantValue constant, StringBuffer sb) =>

0 commit comments

Comments
 (0)