Files
sdk/pkg/kernel/lib/src/assumptions.dart
T
Johnni Winther 8467186ca0 [kernel] Initial migration of package kernel wave 1
This CL completes the migration of the first wave of
interdependent libraries in package:kernel, including ast.dart.

In order to ensure non-nullability on AST properties, the Transformer
has been split in 2 variants: Transformer which doesn't support
removal of nodes and RemovingTransformer which supports removal where
allowed by the context using 'removal sentinels'.

Start reviewing Transformer and RemovingTransformer in visitors.dart
since many of the changes are caused by the changes here.

Included in the migration are the mixin_deduplication.dart and
unreachable_code_elimination.dart since these needed porting to
the RemovingTransformer which was aided by opting in the libraries
which only depended on ast.dart.

TEST=existing

Change-Id: I9e63b985bd24896c25edd4ee51e37770187bcc17
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184786
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2021-02-18 16:01:17 +00:00

54 lines
1.6 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import '../ast.dart';
/// Pairs of [TypeParameter]s that are currently assumed to be
/// equivalent.
///
/// This is used to compute the equivalence relation on types coinductively.
class Assumptions {
Map<TypeParameter, TypeParameter> _assumptionMap =
new Map<TypeParameter, TypeParameter>.identity();
void _addAssumption(TypeParameter a, TypeParameter b) {
assert(!_assumptionMap.containsKey(a));
_assumptionMap[a] = b;
}
/// Assume that [a] and [b] are equivalent.
void assume(TypeParameter a, TypeParameter b) {
_addAssumption(a, b);
}
void _removeAssumption(TypeParameter a, TypeParameter b) {
TypeParameter? assumption = _assumptionMap.remove(a);
assert(identical(assumption, b));
}
/// Remove the assumption that [a] and [b] are equivalent.
void forget(TypeParameter a, TypeParameter b) {
_removeAssumption(a, b);
}
/// Returns `true` if [a] and [b] are assumed to be equivalent.
bool isAssumed(TypeParameter a, TypeParameter b) {
return identical(_assumptionMap[a], b);
}
@override
String toString() {
StringBuffer sb = new StringBuffer();
sb.write('Assumptions(');
String comma = '';
_assumptionMap.forEach((TypeParameter a, TypeParameter b) {
sb.write('$comma$a (${identityHashCode(a)})->'
'$b (${identityHashCode(b)})');
comma = ',';
});
sb.write(')');
return sb.toString();
}
}