Skip to content

Commit 11cc292

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2j] Add TypeEnvironmentStructure and TypeRecipe
These will be tracked through SSA to generate correct recipe strings. Change-Id: Ifebeead0f39d87be3208c673e34793145c64cf23 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106181 Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent d342402 commit 11cc292

4 files changed

Lines changed: 102 additions & 11 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library dart2js.js_model.type_recipe;
6+
7+
import '../elements/types.dart';
8+
9+
/// A TypeEnvironmentStructure describes the shape or layout of a reified type
10+
/// environment.
11+
///
12+
/// A type environment maps type parameter variables to type values. The type
13+
/// variables are mostly elided in the runtime representation, replaced by
14+
/// indexes into the reified environment.
15+
abstract class TypeEnvironmentStructure {}
16+
17+
/// A singleton type environment maps a binds a single value.
18+
class SingletonTypeEnvironmentStructure extends TypeEnvironmentStructure {
19+
final TypeVariableType variable;
20+
21+
SingletonTypeEnvironmentStructure(this.variable);
22+
23+
@override
24+
String toString() => 'SingletonTypeEnvironmentStructure($variable)';
25+
}
26+
27+
/// A type environment containing an interface type and/or a tuple of function
28+
/// type parameters.
29+
class FullTypeEnvironmentStructure extends TypeEnvironmentStructure {
30+
final InterfaceType classType;
31+
final List<TypeVariableType> bindings;
32+
33+
FullTypeEnvironmentStructure({this.classType, this.bindings = const []});
34+
35+
@override
36+
String toString() => 'FullTypeEnvironmentStructure($classType, $bindings)';
37+
}
38+
39+
/// A TypeRecipe is evaluated against a type environment to produce either a
40+
/// type, or another type environment.
41+
abstract class TypeRecipe {}
42+
43+
/// A recipe that yields a reified type.
44+
class TypeExpressionRecipe extends TypeRecipe {
45+
final DartType type;
46+
47+
TypeExpressionRecipe(this.type);
48+
49+
@override
50+
String toString() => 'TypeExpressionRecipe($type)';
51+
}
52+
53+
/// A recipe that yields a reified type environment.
54+
abstract class TypeEnvironmentRecipe extends TypeRecipe {}
55+
56+
/// A recipe that yields a reified type environment that binds a single generic
57+
/// function type parameter.
58+
class SingletonTypeEnvironmentRecipe extends TypeEnvironmentRecipe {
59+
final DartType type;
60+
61+
SingletonTypeEnvironmentRecipe(this.type);
62+
63+
@override
64+
String toString() => 'SingletonTypeEnvironmentRecipe($type)';
65+
}
66+
67+
/// A recipe that yields a reified type environment that binds a class instance
68+
/// type and/or a tuple of types, usually generic function type arguments.
69+
///
70+
/// With no class is also used as a tuple of types.
71+
class FullTypeEnvironmentRecipe extends TypeEnvironmentRecipe {
72+
/// Type expression for the interface type of a class scope. `null` for
73+
/// environments outside a class scope or a class scope where no supertype is
74+
/// generic, or where optimization has determined that no use of the
75+
/// environment requires any of the class type variables.
76+
final InterfaceType classType;
77+
78+
// Type expressions for the tuple of function type arguments.
79+
final List<DartType> types;
80+
81+
FullTypeEnvironmentRecipe({this.classType, this.types = const []});
82+
83+
@override
84+
String toString() => 'FullTypeEnvironmentRecipe($classType, $types)';
85+
}

pkg/compiler/lib/src/ssa/codegen.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,31 +3333,31 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
33333333

33343334
@override
33353335
visitIsTest(HIsTest node) {
3336-
throw UnimplementedError('SsaCodeGenerator.visitIsTest');
3336+
throw UnimplementedError('SsaCodeGenerator.visitIsTest $node');
33373337
}
33383338

33393339
@override
33403340
visitAsCheck(HAsCheck node) {
3341-
throw UnimplementedError('SsaCodeGenerator.visitAsCheck');
3341+
throw UnimplementedError('SsaCodeGenerator.visitAsCheck $node');
33423342
}
33433343

33443344
@override
33453345
visitSubtypeCheck(HSubtypeCheck node) {
3346-
throw UnimplementedError('SsaCodeGenerator.visitSubtypeCheck');
3346+
throw UnimplementedError('SsaCodeGenerator.visitSubtypeCheck $node');
33473347
}
33483348

33493349
@override
33503350
visitLoadType(HLoadType node) {
3351-
throw UnimplementedError('SsaCodeGenerator.visitLoadType');
3351+
throw UnimplementedError('SsaCodeGenerator.visitLoadType $node');
33523352
}
33533353

33543354
@override
33553355
visitTypeEval(HTypeEval node) {
3356-
throw UnimplementedError('SsaCodeGenerator.visitTypeEval');
3356+
throw UnimplementedError('SsaCodeGenerator.visitTypeEval $node');
33573357
}
33583358

33593359
@override
33603360
visitTypeBind(HTypeBind node) {
3361-
throw UnimplementedError('SsaCodeGenerator.visitTypeBind');
3361+
throw UnimplementedError('SsaCodeGenerator.visitTypeBind $node');
33623362
}
33633363
}

pkg/compiler/lib/src/ssa/nodes.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import '../elements/types.dart';
1414
import '../inferrer/abstract_value_domain.dart';
1515
import '../io/source_information.dart';
1616
import '../js/js.dart' as js;
17+
import '../js_model/type_recipe.dart' show TypeEnvironmentStructure, TypeRecipe;
1718
import '../native/behavior.dart';
1819
import '../universe/selector.dart' show Selector;
1920
import '../universe/side_effects.dart' show SideEffects;
@@ -4462,9 +4463,11 @@ class HLoadType extends HRtiInstruction {
44624463

44634464
/// Evaluates an Rti type recipe in an Rti environment.
44644465
class HTypeEval extends HRtiInstruction {
4465-
DartType typeExpression; // TODO(sra); Allow a type environment expression.
4466+
TypeEnvironmentStructure envStructure;
4467+
TypeRecipe typeExpression;
44664468

4467-
HTypeEval(HInstruction environment, this.typeExpression, AbstractValue type)
4469+
HTypeEval(HInstruction environment, this.envStructure, this.typeExpression,
4470+
AbstractValue type)
44684471
: super([environment], type) {
44694472
setUseGvn();
44704473
}

pkg/compiler/lib/src/ssa/type_builder.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'nodes.dart';
77
import '../elements/entities.dart';
88
import '../elements/types.dart';
99
import '../inferrer/abstract_value_domain.dart';
10+
import '../js_model/type_recipe.dart';
1011
import '../io/source_information.dart';
1112
import '../universe/use.dart' show TypeUse;
1213
import '../world.dart';
@@ -282,9 +283,11 @@ abstract class TypeBuilder {
282283
// TODO(sra): Locate type environment.
283284
HInstruction environment =
284285
builder.graph.addConstantString("env", _closedWorld);
285-
HInstruction rti =
286-
HTypeEval(environment, argument, _abstractValueDomain.dynamicType)
287-
..sourceInformation = sourceInformation;
286+
// TODO(sra): Determine environment structure from context.
287+
TypeEnvironmentStructure structure = null;
288+
HInstruction rti = HTypeEval(environment, structure,
289+
TypeExpressionRecipe(argument), _abstractValueDomain.dynamicType)
290+
..sourceInformation = sourceInformation;
288291
builder.add(rti);
289292
return rti;
290293
}

0 commit comments

Comments
 (0)