Skip to content

Commit 41263a4

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2js] Fix for 37502: double ~/ x returns int
http://dartbug.com/37502 shows the type-propagation results of ~/ is double instead of int. Bug: 37502 Change-Id: Iec7b8a876a20784c7d2858305eaa67e9d02a63dd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109889 Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Mayank Patke <[email protected]>
1 parent 211190e commit 41263a4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,15 @@ abstract class BinaryArithmeticSpecializer extends InvokeDynamicSpecializer {
421421
return null;
422422
}
423423

424+
bool inputsAreNum(HInstruction instruction, JClosedWorld closedWorld) {
425+
HInstruction left = instruction.inputs[1];
426+
HInstruction right = instruction.inputs[2];
427+
return left
428+
.isNumberOrNull(closedWorld.abstractValueDomain)
429+
.isDefinitelyTrue &&
430+
right.isNumberOrNull(closedWorld.abstractValueDomain).isDefinitelyTrue;
431+
}
432+
424433
bool inputsArePositiveIntegers(
425434
HInstruction instruction, JClosedWorld closedWorld) {
426435
HInstruction left = instruction.inputs[1];
@@ -713,6 +722,9 @@ class TruncatingDivideSpecializer extends BinaryArithmeticSpecializer {
713722
if (inputsArePositiveIntegers(instruction, closedWorld)) {
714723
return closedWorld.abstractValueDomain.positiveIntType;
715724
}
725+
if (inputsAreNum(instruction, closedWorld)) {
726+
return closedWorld.abstractValueDomain.intType;
727+
}
716728
return super.computeTypeFromInputTypes(instruction, results, closedWorld);
717729
}
718730

tests/compiler/dart2js/codegen/tdiv_test.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,26 @@ const String TEST5 = r"""
5252
foo(param1, param2) {
5353
var a = param1 ? 0xFFFFFFFF : 0;
5454
var b = param2 ? 3 : 4;
55-
return a ~/ param2;
55+
return a ~/ b;
5656
// We could optimize this with range analysis, but type inference summarizes
5757
// '3 or 4' to uint31, which is not >= 2.
5858
// present: '$tdiv'
5959
// absent: '/'
6060
}
6161
""";
6262

63+
const String TEST_REGRESS_37502 = r"""
64+
foo(param1, param2) {
65+
var a = param1 ? 1.2 : 12.3;
66+
var b = param2 ? 3.14 : 2.81;
67+
return (a ~/ b).gcd(2);
68+
// The result of ~/ is int; gcd is defined only on int and is too complex
69+
// to be inlined.
70+
//
71+
// present: 'JSInt_methods.gcd'
72+
}
73+
""";
74+
6375
main() {
6476
runTests() async {
6577
Future check(String test) {
@@ -71,6 +83,7 @@ main() {
7183
await check(TEST3);
7284
await check(TEST4);
7385
await check(TEST5);
86+
await check(TEST_REGRESS_37502);
7487
}
7588

7689
asyncTest(() async {

0 commit comments

Comments
 (0)