[dart2js] Erase '*' in runtime type objects.

Change-Id: Ieeb98b79cd03a81cacd10506c977e96306a6330b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137822
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
This commit is contained in:
Mayank Patke 2020-03-04 16:15:05 +00:00 committed by commit-bot@chromium.org
parent a0c3b4fedb
commit 3c2a6c26e2
2 changed files with 22 additions and 38 deletions

View file

@ -770,10 +770,13 @@ Type getRuntimeType(object) {
Type createRuntimeType(Rti rti) {
_Type type = Rti._getCachedRuntimeType(rti);
if (type != null) return type;
// TODO(fishythefish, https://github.com/dart-lang/language/issues/428) For
// NNBD transition, canonicalization may be needed. It might be possible to
// generate a star-free recipe from the canonical recipe and evaluate that.
type = _Type(rti);
String recipe = Rti._getCanonicalRecipe(rti);
String starErasedRecipe = JS('String', '#.replace(/\\*/g, "")', recipe);
if (starErasedRecipe == recipe) {
return _Type(rti);
}
Rti starErasedRti = _Universe.eval(_theUniverse(), starErasedRecipe, true);
type = Rti._getCachedRuntimeType(starErasedRti) ?? _Type(starErasedRti);
Rti._setCachedRuntimeType(rti, type);
return type;
}
@ -786,15 +789,9 @@ Type typeLiteral(String recipe) {
/// Implementation of [Type] based on Rti.
class _Type implements Type {
final Rti _rti;
int _hashCode;
_Type(this._rti);
int get hashCode => _hashCode ??= Rti._getCanonicalRecipe(_rti).hashCode;
@pragma('dart2js:noInline')
bool operator ==(other) {
return (other is _Type) && identical(_rti, other._rti);
_Type(this._rti) : assert(Rti._getCachedRuntimeType(_rti) == null) {
Rti._setCachedRuntimeType(_rti, this);
}
@override
@ -1195,13 +1192,8 @@ String _rtiToString(Rti rti, List<String> genericContext) {
if (kind == Rti.kindStar) {
Rti starArgument = Rti._getStarArgument(rti);
String s = _rtiToString(starArgument, genericContext);
int argumentKind = Rti._getKind(starArgument);
if (argumentKind == Rti.kindFunction ||
argumentKind == Rti.kindGenericFunction) {
s = '(' + s + ')';
}
return s + '*';
return _rtiToString(starArgument, genericContext);
// TODO(fishythefish): Add a flag to enable printing '*'.
}
if (kind == Rti.kindQuestion) {

View file

@ -771,10 +771,13 @@ Type getRuntimeType(object) {
Type createRuntimeType(Rti rti) {
_Type? type = Rti._getCachedRuntimeType(rti);
if (type != null) return type;
// TODO(fishythefish, https://github.com/dart-lang/language/issues/428) For
// NNBD transition, canonicalization may be needed. It might be possible to
// generate a star-free recipe from the canonical recipe and evaluate that.
type = _Type(rti);
String recipe = Rti._getCanonicalRecipe(rti);
String starErasedRecipe = JS('String', '#.replace(/\\*/g, "")', recipe);
if (starErasedRecipe == recipe) {
return _Type(rti);
}
Rti starErasedRti = _Universe.eval(_theUniverse(), starErasedRecipe, true);
type = Rti._getCachedRuntimeType(starErasedRti) ?? _Type(starErasedRti);
Rti._setCachedRuntimeType(rti, type);
return type;
}
@ -787,15 +790,9 @@ Type typeLiteral(String recipe) {
/// Implementation of [Type] based on Rti.
class _Type implements Type {
final Rti _rti;
int? _hashCode;
_Type(this._rti);
int get hashCode => _hashCode ??= Rti._getCanonicalRecipe(_rti).hashCode;
@pragma('dart2js:noInline')
bool operator ==(other) {
return (other is _Type) && identical(_rti, other._rti);
_Type(this._rti) : assert(Rti._getCachedRuntimeType(_rti) == null) {
Rti._setCachedRuntimeType(_rti, this);
}
@override
@ -1196,13 +1193,8 @@ String _rtiToString(Rti rti, List<String>? genericContext) {
if (kind == Rti.kindStar) {
Rti starArgument = Rti._getStarArgument(rti);
String s = _rtiToString(starArgument, genericContext);
int argumentKind = Rti._getKind(starArgument);
if (argumentKind == Rti.kindFunction ||
argumentKind == Rti.kindGenericFunction) {
s = '(' + s + ')';
}
return s + '*';
return _rtiToString(starArgument, genericContext);
// TODO(fishythefish): Add a flag to enable printing '*'.
}
if (kind == Rti.kindQuestion) {