Skip to content

Commit c9ebb0e

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] Expression compilation overwrites types to static types if from "dart:"
When the VM has an `int` it often represents it as a `_Smi` (which extends `_IntegerImplementation` which implements `int`), but the interface member for e.g. `+` on `_Smi` is `_IntegerImplementation.+` and `_IntegerImplementation` is not special-cased in `isSpecialCasedBinaryOperator` (but `int` and `num` is, so using `int` having the interface member `num.+` makes `isSpecialCasedBinaryOperator` return true if the type is `int` but false if the type is `_Smi`). Not knowing which specialized types the VM could send for more general types that are then specialized in the compiler this CL fixes the issue (linked below) by using the static types of definitions from `dart:`. Fixes #61894 Change-Id: I66cb2d44d5762719b14b51cb139fa0df6b00468f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459420 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 59905c4 commit c9ebb0e

18 files changed

+189
-34
lines changed

pkg/front_end/lib/src/base/incremental_compiler.dart

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import 'package:kernel/kernel.dart'
3535
DynamicType,
3636
Expression,
3737
ExtensionType,
38+
Field,
3839
FunctionNode,
3940
InterfaceType,
4041
Library,
@@ -43,6 +44,7 @@ import 'package:kernel/kernel.dart'
4344
Name,
4445
NamedNode,
4546
Node,
47+
Nullability,
4648
Procedure,
4749
ProcedureKind,
4850
Reference,
@@ -51,13 +53,12 @@ import 'package:kernel/kernel.dart'
5153
Supertype,
5254
TreeNode,
5355
TypeParameter,
56+
TypeParameterType,
5457
VariableDeclaration,
5558
VariableGet,
5659
VariableSet,
5760
VisitorDefault,
58-
VisitorVoidMixin,
59-
TypeParameterType,
60-
Field;
61+
VisitorVoidMixin;
6162
import 'package:kernel/kernel.dart' as kernel show Combinator;
6263
import 'package:kernel/reference_from_index.dart';
6364
import 'package:kernel/target/changed_structure_notifier.dart'
@@ -1947,6 +1948,22 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
19471948
usedDefinitions[def.key] = substitution.substituteType(
19481949
def.value.type,
19491950
);
1951+
} else if (existingType is InterfaceType &&
1952+
existingType.classNode.enclosingLibrary.importUri.isScheme(
1953+
"dart",
1954+
)) {
1955+
// The VM tells us about a type from the platform.
1956+
// We use the static type instead because the compiler for
1957+
// instance special case int in certain places which is - by the
1958+
// VM - often described as _Smi.
1959+
DartType usedType = substitution.substituteType(def.value.type);
1960+
if (existingType.nullability == Nullability.nonNullable &&
1961+
usedType.nullability == Nullability.nullable) {
1962+
// If a statically nullable type is known to be non-null,
1963+
// we keep that information though.
1964+
usedType = usedType.toNonNull();
1965+
}
1966+
usedDefinitions[def.key] = usedType;
19501967
}
19511968
}
19521969
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Errors: {
22
}
3-
static method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::_GrowableList<#lib1::A> list) → dynamic
4-
return list.{dart.core::_GrowableList::first}{#lib1::A}{dynamic}.value;
3+
static method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::List<#lib1::A> list) → dynamic
4+
return list.{dart.core::Iterable::first}{#lib1::A}{dynamic}.value;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Errors: {
22
}
3-
static method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::_GrowableList<#lib1::A> list) → dynamic
4-
return list.{dart.core::_GrowableList::first}{#lib1::A}{dynamic}._value;
3+
static method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::List<#lib1::A> list) → dynamic
4+
return list.{dart.core::Iterable::first}{#lib1::A}{dynamic}._value;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Errors: {
22
}
3-
static method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::_OneByteString foo, dart.core::_GrowableList<dart.core::String> list) → dynamic
3+
static method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::String foo, dart.core::List<dart.core::String> list) → dynamic
44
return foo;

pkg/front_end/testcases/expression/evaluate_const_local_02.expression.yaml.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Errors: {
22
}
3-
static method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::_GrowableList<dart.core::String> list, dart.core::_OneByteString input) → dynamic
3+
static method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::List<dart.core::String> list, dart.core::String input) → dynamic
44
return #C1;
55
constants {
66
#C1 = "hello from foo"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Errors: {
22
}
3-
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(lowered dart.core::_Smi #this) → dynamic
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(lowered dart.core::int #this) → dynamic
44
return #this;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Errors: {
22
}
3-
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::_Smi offset, lowered dart.core::_OneByteString #this) → dynamic
4-
return offset.{dart.core::_IntegerImplementation::+}(#this.{dart.core::_StringBase::length}{dart.core::int}){(dart.core::num) → dart.core::num};
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::int offset, lowered dart.core::String #this) → dynamic
4+
return offset.{dart.core::num::+}(#this.{dart.core::String::length}{dart.core::int}){(dart.core::num) → dart.core::int};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Errors: {
22
}
3-
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(lowered dart.core::_Smi #this) → dynamic
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(lowered dart.core::int #this) → dynamic
44
return #this;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Errors: {
22
}
3-
static method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::_OneByteString str) → dynamic
3+
static method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::String str) → dynamic
44
return #lib1::_extension#0|get#isNullOrEmpty(str);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Errors: {
22
}
3-
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(lowered dart.core::_OneByteString #this, dart.core::_OneByteString str) → dynamic
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(lowered dart.core::String #this, dart.core::String str) → dynamic
44
return str;

0 commit comments

Comments
 (0)