Skip to content

Commit

Permalink
[CFE] Encapsulate int operations in separate classes for VM and JS
Browse files Browse the repository at this point in the history
This refactoring achieves the following:

- Collect the integer operation semantics into one place instead of
having it sprinkled all over the constant evaluator with many
"if (targetingJavaScript)" tests.

- Avoid emitting the internal JavaScriptIntConstant node, which is
serialized as normal DoubleConstant nodes, thus achieving parity
between direct consumers and consumers seeing output that has been
serialized.

- Implement the JavaScript semantics for unsigned right shift.

- Fix truncating divide with a result outside int64 range incorrectly
clamping the result for JS targets.

- Fix positive hex constants >= 2^63 through int.fromEnvironment
producing negative values in dart2js.

- Clarify in Kernel documentation how numeric constants are represented
on VM vs JS targets.

Change-Id: If30bb2c2c77c54eff120b611b059c2ec726c99a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116525
Reviewed-by: Mayank Patke <fishythefish@google.com>
  • Loading branch information
askeksa authored and commit-bot@chromium.org committed Sep 16, 2019
1 parent eb1a375 commit 7799f42
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 246 deletions.
14 changes: 13 additions & 1 deletion pkg/dev_compiler/test/nullable_inference_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,19 @@ Future expectNotNull(String code, String expectedNotNull) async {
var actualNotNull = collector.notNullExpressions
// ConstantExpressions print the table offset - we want to compare
// against the underlying constant value instead.
.map((e) => (e is ConstantExpression ? e.constant : e).toString())
.map((e) {
if (e is ConstantExpression) {
Constant c = e.constant;
if (c is DoubleConstant &&
c.value.isFinite &&
c.value.truncateToDouble() == c.value) {
// Print integer values as integers
return BigInt.from(c.value).toString();
}
return c.toString();
}
return e.toString();
})
// Filter out our own NotNull annotations. The library prefix changes
// per test, so just filter on the suffix.
.where((s) => !s.endsWith('::_NotNull {}'))
Expand Down
Loading

0 comments on commit 7799f42

Please sign in to comment.