[dart2js] Migrate inferrer/type_graph_inferrer to null safety.

Change-Id: Ib6f82a9b7fd58d7185f4d3b9997f2c0eacfa33cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267248
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
This commit is contained in:
Nate Biggs
2022-11-03 16:18:40 +00:00
committed by Commit Queue
parent 217c18f296
commit beacf3d7bf
2 changed files with 20 additions and 28 deletions
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.10
library type_graph_inferrer;
import 'package:kernel/ast.dart' as ir;
@@ -13,8 +11,8 @@ import '../compiler_interfaces.dart';
import '../elements/entities.dart';
import '../js_backend/inferred_data.dart';
import '../js_model/elements.dart' show JClosureCallMethod;
import '../js_model/js_world.dart';
import '../js_model/locals.dart';
import '../world.dart';
import 'abstract_value_domain.dart';
import 'engine.dart';
import 'engine.dart' as engine;
@@ -22,8 +20,8 @@ import 'type_graph_nodes.dart';
import 'types.dart';
class TypeGraphInferrer implements TypesInferrer {
InferrerEngine inferrer;
final JClosedWorld closedWorld;
late InferrerEngine inferrer;
final JsClosedWorld closedWorld;
final CompilerInferrerFacade _compiler;
final GlobalLocalsMap _globalLocalsMap;
@@ -61,7 +59,7 @@ class TypeGraphInferrer implements TypesInferrer {
_inferredDataBuilder);
}
Iterable<MemberEntity> /*?*/ getCallersOfForTesting(MemberEntity element) {
Iterable<MemberEntity>? getCallersOfForTesting(MemberEntity element) {
return inferrer.getCallersOfForTesting(element);
}
@@ -74,12 +72,11 @@ class TypeGraphInferrer implements TypesInferrer {
void createMemberResults(
MemberEntity member, MemberTypeInformation typeInformation) {
GlobalTypeInferenceElementData data =
inferrer.dataOfMember(member).compress();
final data = inferrer.dataOfMember(member).compress();
bool isJsInterop = closedWorld.nativeData.isJsInteropMember(member);
AbstractValue returnType;
AbstractValue type;
late AbstractValue returnType;
AbstractValue? type;
if (isJsInterop) {
returnType = type = abstractValueDomain.dynamicType;
@@ -93,8 +90,7 @@ class TypeGraphInferrer implements TypesInferrer {
bool throwsAlways =
// Always throws if the return type was inferred to be non-null empty.
returnType != null &&
abstractValueDomain.isEmpty(returnType).isDefinitelyTrue;
abstractValueDomain.isEmpty(returnType).isDefinitelyTrue;
bool isCalledOnce = typeInformation.isCalledOnce();
@@ -108,8 +104,8 @@ class TypeGraphInferrer implements TypesInferrer {
(MemberEntity member, MemberTypeInformation typeInformation) {
createMemberResults(member, typeInformation);
if (member is JClosureCallMethod) {
ClosureRepresentationInfo info =
closedWorld.closureDataLookup.getScopeInfo(member);
final info = closedWorld.closureDataLookup.getScopeInfo(member)
as ClosureRepresentationInfo;
info.forEachFreeVariable(_globalLocalsMap.getLocalsMap(member),
(Local from, FieldEntity to) {
freeVariables.add(to);
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.10
library type_graph_inferrer;
import 'package:kernel/ast.dart' as ir;
@@ -13,8 +11,8 @@ import '../compiler_interfaces.dart';
import '../elements/entities.dart';
import '../js_backend/inferred_data.dart';
import '../js_model/elements.dart' show JClosureCallMethod;
import '../js_model/js_world.dart';
import '../js_model/locals.dart';
import '../world.dart';
import '../inferrer/abstract_value_domain.dart';
import 'engine.dart';
import 'engine.dart' as engine;
@@ -22,8 +20,8 @@ import 'type_graph_nodes.dart';
import 'types.dart';
class TypeGraphInferrer implements TypesInferrer {
InferrerEngine inferrer;
final JClosedWorld closedWorld;
late InferrerEngine inferrer;
final JsClosedWorld closedWorld;
final CompilerInferrerFacade _compiler;
final GlobalLocalsMap _globalLocalsMap;
@@ -61,7 +59,7 @@ class TypeGraphInferrer implements TypesInferrer {
_inferredDataBuilder);
}
Iterable<MemberEntity> /*?*/ getCallersOfForTesting(MemberEntity element) {
Iterable<MemberEntity>? getCallersOfForTesting(MemberEntity element) {
return inferrer.getCallersOfForTesting(element);
}
@@ -74,12 +72,11 @@ class TypeGraphInferrer implements TypesInferrer {
void createMemberResults(
MemberEntity member, MemberTypeInformation typeInformation) {
GlobalTypeInferenceElementData data =
inferrer.dataOfMember(member).compress();
final data = inferrer.dataOfMember(member).compress();
bool isJsInterop = closedWorld.nativeData.isJsInteropMember(member);
AbstractValue returnType;
AbstractValue type;
late AbstractValue returnType;
AbstractValue? type;
if (isJsInterop) {
returnType = type = abstractValueDomain.dynamicType;
@@ -93,8 +90,7 @@ class TypeGraphInferrer implements TypesInferrer {
bool throwsAlways =
// Always throws if the return type was inferred to be non-null empty.
returnType != null &&
abstractValueDomain.isEmpty(returnType).isDefinitelyTrue;
abstractValueDomain.isEmpty(returnType).isDefinitelyTrue;
bool isCalledOnce = typeInformation.isCalledOnce();
@@ -108,8 +104,8 @@ class TypeGraphInferrer implements TypesInferrer {
(MemberEntity member, MemberTypeInformation typeInformation) {
createMemberResults(member, typeInformation);
if (member is JClosureCallMethod) {
ClosureRepresentationInfo info =
closedWorld.closureDataLookup.getScopeInfo(member);
final info = closedWorld.closureDataLookup.getScopeInfo(member)
as ClosureRepresentationInfo;
info.forEachFreeVariable(_globalLocalsMap.getLocalsMap(member),
(Local from, FieldEntity to) {
freeVariables.add(to);