Skip to content

Commit

Permalink
Improve type of typed-array load
Browse files Browse the repository at this point in the history
- Typed array elements are never null, but type inference sometimes
  thinks they are.

- Annotated isNan and isFinite as pure.

Change-Id: I5fffd237374444db27665009cf550b26563bcf55
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98046
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
  • Loading branch information
rakudrama authored and commit-bot@chromium.org committed Mar 27, 2019
1 parent e5bc8c2 commit f226f4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 8 additions & 4 deletions pkg/compiler/lib/src/ssa/invoke_dynamic_specializers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,28 @@ class IndexSpecializer extends InvokeDynamicSpecializer {
JCommonElements commonElements,
JClosedWorld closedWorld,
OptimizationTestLog log) {
var abstractValueDomain = closedWorld.abstractValueDomain;
if (instruction.inputs[1]
.isIndexablePrimitive(closedWorld.abstractValueDomain)
.isIndexablePrimitive(abstractValueDomain)
.isPotentiallyFalse) {
return null;
}
if (instruction.inputs[2]
.isInteger(closedWorld.abstractValueDomain)
.isInteger(abstractValueDomain)
.isPotentiallyFalse &&
options.parameterCheckPolicy.isEmitted) {
// We want the right checked mode error.
return null;
}
AbstractValue receiverType =
instruction.getDartReceiver(closedWorld).instructionType;
AbstractValue type = AbstractValueFactory.inferredTypeForSelector(
AbstractValue elementType = AbstractValueFactory.inferredTypeForSelector(
instruction.selector, receiverType, results);
if (abstractValueDomain.isTypedArray(receiverType).isDefinitelyTrue) {
elementType = abstractValueDomain.excludeNull(elementType);
}
HIndex converted = new HIndex(instruction.inputs[1], instruction.inputs[2],
instruction.selector, type);
instruction.selector, elementType);
log?.registerIndex(instruction, converted);
return converted;
}
Expand Down
10 changes: 8 additions & 2 deletions sdk/lib/_internal/js_runtime/lib/js_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ class JSNumber extends Interceptor implements double {

bool get isNegative => (this == 0) ? (1 / this) < 0 : this < 0;

bool get isNaN => JS('bool', r'isNaN(#)', this);
bool get isNaN => JS(
'returns:bool;effects:none;depends:none;throws:never;gvn:true',
r'isNaN(#)',
this);

bool get isInfinite {
return JS('bool', r'# == (1/0)', this) || JS('bool', r'# == (-1/0)', this);
}

bool get isFinite => JS('bool', r'isFinite(#)', this);
bool get isFinite => JS(
'returns:bool;effects:none;depends:none;throws:never;gvn:true',
r'isFinite(#)',
this);

JSNumber remainder(num b) {
if (b is! num) throw argumentErrorValue(b);
Expand Down

0 comments on commit f226f4f

Please sign in to comment.