Skip to content

Commit 9aea1f3

Browse files
fishythefishcommit-bot@chromium.org
authored andcommitted
[dart2js] Eliminate redundant function kind checks.
Change-Id: I97c8cea7a00b361cce6aed1f893913dcf8b9d867 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112780 Commit-Queue: Mayank Patke <fishythefish@google.com> Reviewed-by: Stephen Adams <sra@google.com>
1 parent 62aa02e commit 9aea1f3

File tree

1 file changed

+23
-21
lines changed
  • sdk/lib/_internal/js_runtime/lib

1 file changed

+23
-21
lines changed

sdk/lib/_internal/js_runtime/lib/rti.dart

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,11 +1909,15 @@ bool _isSubtype(universe, Rti s, sEnv, Rti t, tEnv) {
19091909
}
19101910
}
19111911

1912-
if (isEitherFunctionKind(t)) {
1912+
if (isGenericFunctionKind(t)) {
1913+
return _isGenericFunctionSubtype(universe, s, sEnv, t, tEnv);
1914+
}
1915+
1916+
if (isFunctionKind(t)) {
19131917
return _isFunctionSubtype(universe, s, sEnv, t, tEnv);
19141918
}
19151919

1916-
if (isEitherFunctionKind(s)) {
1920+
if (isFunctionKind(s) || isGenericFunctionKind(s)) {
19171921
return isFunctionType(t);
19181922
}
19191923

@@ -1924,25 +1928,25 @@ bool _isSubtype(universe, Rti s, sEnv, Rti t, tEnv) {
19241928
return _isSubtypeOfInterface(universe, s, sEnv, tName, tArgs, tEnv);
19251929
}
19261930

1931+
bool _isGenericFunctionSubtype(universe, Rti s, sEnv, Rti t, tEnv) {
1932+
assert(isGenericFunctionKind(t));
1933+
if (!isGenericFunctionKind(s)) return false;
1934+
1935+
var sBounds = Rti._getGenericFunctionBounds(s);
1936+
var tBounds = Rti._getGenericFunctionBounds(t);
1937+
if (!typesEqual(sBounds, tBounds)) return false;
1938+
// TODO(fishythefish): Extend [sEnv] and [tEnv] with bindings for the [s]
1939+
// and [t] type parameters to enable checking the bound against
1940+
// non-type-parameter terms.
1941+
1942+
return _isFunctionSubtype(universe, Rti._getGenericFunctionBase(s), sEnv,
1943+
Rti._getGenericFunctionBase(t), tEnv);
1944+
}
1945+
19271946
// TODO(fishythefish): Support required named parameters.
19281947
bool _isFunctionSubtype(universe, Rti s, sEnv, Rti t, tEnv) {
1929-
assert(isEitherFunctionKind(t));
1930-
if (!isEitherFunctionKind(s)) return false;
1931-
1932-
if (isGenericFunctionKind(s)) {
1933-
if (!isGenericFunctionKind(t)) return false;
1934-
var sBounds = Rti._getGenericFunctionBounds(s);
1935-
var tBounds = Rti._getGenericFunctionBounds(t);
1936-
if (!typesEqual(sBounds, tBounds)) return false;
1937-
// TODO(fishythefish): Extend [sEnv] and [tEnv] with bindings for the [s]
1938-
// and [t] type parameters to enable checking the bound against
1939-
// non-type-parameter terms.
1940-
1941-
s = Rti._getGenericFunctionBase(s);
1942-
t = Rti._getGenericFunctionBase(t);
1943-
} else if (isGenericFunctionKind(t)) {
1944-
return false;
1945-
}
1948+
assert(isFunctionKind(t));
1949+
if (!isFunctionKind(s)) return false;
19461950

19471951
Rti sReturnType = Rti._getReturnType(s);
19481952
Rti tReturnType = Rti._getReturnType(t);
@@ -2136,8 +2140,6 @@ bool isJsInteropType(Rti t) => Rti._getKind(t) == Rti.kindAny;
21362140

21372141
bool isFutureOrType(Rti t) => Rti._getKind(t) == Rti.kindFutureOr;
21382142

2139-
bool isEitherFunctionKind(Rti t) =>
2140-
isFunctionKind(t) || isGenericFunctionKind(t);
21412143
bool isFunctionKind(Rti t) => Rti._getKind(t) == Rti.kindFunction;
21422144
bool isGenericFunctionKind(Rti t) => Rti._getKind(t) == Rti.kindGenericFunction;
21432145

0 commit comments

Comments
 (0)