Skip to content

Commit 64584c1

Browse files
kallentuCommit Queue
authored and
Commit Queue
committed
[web] Move Variance to js_shared/lib/ for shared use.
Moving variance to `js_shared/lib/variance.dart` so we can use the same synced indices when marking variance in both dart2js and ddc. This avoids needing to sync multiple data structures that all represent variance. Bug: #54367 Change-Id: Ia6fda84decd43374c08ed3bd0d0b240071310d9a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341840 Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Nicholas Shahan <[email protected]>
1 parent ee89258 commit 64584c1

File tree

18 files changed

+30
-6
lines changed

18 files changed

+30
-6
lines changed

pkg/compiler/lib/src/common/elements.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:js_shared/variance.dart';
6+
57
import '../common.dart';
68
import '../constants/constant_system.dart' as constant_system;
79
import '../constants/values.dart';

pkg/compiler/lib/src/elements/entities.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ class AsyncMarker {
227227
int get index => values.indexOf(this);
228228
}
229229

230-
/// Values for variance annotations.
231-
/// This needs to be kept in sync with values of `Variance` in `dart:_rti`.
232-
enum Variance { legacyCovariant, covariant, contravariant, invariant }
233-
234230
/// Stripped down super interface for constructor like entities.
235231
///
236232
/// Currently only [ConstructorElement] but later also kernel based Dart

pkg/compiler/lib/src/elements/types.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:js_shared/variance.dart';
6+
57
import '../common/elements.dart' show CommonElements;
68
import '../common/names.dart';
79
import '../options.dart';

pkg/compiler/lib/src/inferrer/powersets/powerset_bits.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:js_shared/variance.dart';
6+
57
import '../../common/elements.dart' show CommonElements;
68
import '../../constants/values.dart';
79
import '../../elements/entities.dart';

pkg/compiler/lib/src/inferrer/typemasks/masks.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
library masks;
66

7+
import 'package:js_shared/variance.dart';
78
import 'package:kernel/ast.dart' as ir;
89

910
import '../../common.dart';

pkg/compiler/lib/src/ir/element_map.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:js_shared/variance.dart';
56
import 'package:kernel/ast.dart' as ir;
67
import 'package:kernel/core_types.dart' as ir;
78

pkg/compiler/lib/src/ir/types.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:js_shared/variance.dart';
6+
57
import '../common/elements.dart';
68
import '../elements/entities.dart';
79
import '../elements/types.dart';

pkg/compiler/lib/src/ir/util.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:js_shared/variance.dart';
56
import 'package:kernel/ast.dart' as ir;
67

78
import '../common.dart';
8-
import '../elements/entities.dart' show AsyncMarker, MemberEntity, Variance;
9+
import '../elements/entities.dart' show AsyncMarker, MemberEntity;
910
import '../universe/record_shape.dart';
1011

1112
/// Returns a textual representation of [node] that include the runtime type and

pkg/compiler/lib/src/js_backend/runtime_types_new.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
library js_backend.runtime_types_new;
66

77
import 'package:js_shared/synced/recipe_syntax.dart';
8+
import 'package:js_shared/variance.dart';
89

910
import '../common/elements.dart' show CommonElements, JCommonElements;
1011
import '../elements/entities.dart';

pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import 'package:js_shared/synced/embedded_names.dart'
3535
RTI_UNIVERSE,
3636
RtiUniverseFieldNames,
3737
TYPES;
38+
import 'package:js_shared/variance.dart';
3839

3940
import 'package:js_ast/src/precedence.dart' as js_precedence;
4041

pkg/compiler/lib/src/js_model/closure.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:js_shared/variance.dart';
56
import 'package:kernel/ast.dart' as ir;
67

78
import '../closure.dart';

pkg/compiler/lib/src/js_model/element_map_impl.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:js_shared/variance.dart';
56
import 'package:kernel/ast.dart' as ir;
67
import 'package:kernel/class_hierarchy.dart' as ir;
78
import 'package:kernel/core_types.dart' as ir;

pkg/compiler/lib/src/js_model/env.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
library dart2js.js_model.env;
66

7+
import 'package:js_shared/variance.dart';
78
import 'package:kernel/ast.dart' as ir;
89

910
import '../constants/values.dart';

pkg/compiler/lib/src/js_model/records.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
/// (Specialization classes have not yet been implemented).
3030
library dart2js.js_model.records;
3131

32+
import 'package:js_shared/variance.dart';
33+
3234
import '../common.dart';
3335
import '../constants/values.dart' show ConstantValue;
3436
import '../elements/entities.dart';

pkg/compiler/lib/src/kernel/element_map_impl.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:js_shared/synced/embedded_names.dart' show JsGetName;
6+
import 'package:js_shared/variance.dart';
67
import 'package:kernel/ast.dart' as ir;
78
import 'package:kernel/class_hierarchy.dart' as ir;
89
import 'package:kernel/core_types.dart' as ir;

pkg/compiler/lib/src/kernel/env.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
library dart2js.kernel.env;
66

7+
import 'package:js_shared/variance.dart';
78
import 'package:kernel/ast.dart' as ir;
89
import 'package:kernel/type_environment.dart' as ir;
910
import 'package:collection/collection.dart' show mergeSort; // a stable sort.

pkg/js_shared/lib/variance.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) 2023, 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+
/// Types of variances for type parameters.
6+
/// This needs to be kept in sync with values of `Variance` in `dart:_rti`.
7+
enum Variance { legacyCovariant, covariant, contravariant, invariant }

sdk/lib/_internal/js_shared/lib/rti.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3240,7 +3240,8 @@ class TypeRule {
32403240
JS('', '#.#', rule, supertype);
32413241
}
32423242

3243-
// This needs to be kept in sync with `Variance` in `entities.dart`.
3243+
// This needs to be kept in sync with `Variance` in
3244+
// `pkg/js_shared/lib/variance.dart`.
32443245
class Variance {
32453246
// TODO(fishythefish): Try bitmask representation.
32463247
static const int legacyCovariant = 0;

0 commit comments

Comments
 (0)