mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
[ddc] Fix non-hermetic batch mode crashes
Storing core types in a static caused data to leak between compiles of separate tests. Compiler crashes on one test could trigger failures on another. Fixes: https://github.com/dart-lang/sdk/issues/50044 Change-Id: Ia688a8544576fc0b7ee1bc41ac68a3611c376b8b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263144 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
parent
a1b669fda1
commit
20ad5db3ab
|
@ -336,7 +336,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
_syncIterableClass = sdk.getClass('dart:_js_helper', 'SyncIterable'),
|
||||
_asyncStarImplClass = sdk.getClass('dart:async', '_AsyncStarImpl'),
|
||||
_assertInteropMethod = sdk.getTopLevelMember(
|
||||
'dart:_runtime', 'assertInterop') as Procedure;
|
||||
'dart:_runtime', 'assertInterop') as Procedure,
|
||||
_futureOrNormalizer = FutureOrNormalizer(_coreTypes);
|
||||
|
||||
@override
|
||||
Library? get currentLibrary => _currentLibrary;
|
||||
|
@ -355,6 +356,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
InterfaceType get internalSymbolType =>
|
||||
_coreTypes.legacyRawType(_coreTypes.internalSymbolClass);
|
||||
|
||||
final FutureOrNormalizer _futureOrNormalizer;
|
||||
|
||||
/// Module can be emitted only once, and the compiler can be reused after
|
||||
/// only in incremental mode, for expression compilation only.
|
||||
js_ast.Program emitModule(Component component) {
|
||||
|
@ -942,7 +945,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
}
|
||||
return _emitInterfaceType(t, emitNullability: emitNullability);
|
||||
} else if (t is FutureOrType) {
|
||||
var normalizedType = normalizeFutureOr(t, _coreTypes);
|
||||
var normalizedType = _futureOrNormalizer.normalize(t);
|
||||
if (normalizedType is FutureOrType) {
|
||||
_declareBeforeUse(_coreTypes.deprecatedFutureOrClass);
|
||||
var typeRep = _emitFutureOrTypeWithArgument(
|
||||
|
@ -2933,7 +2936,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
|
||||
@override
|
||||
js_ast.Expression visitFutureOrType(FutureOrType type) {
|
||||
var normalizedType = normalizeFutureOr(type, _coreTypes);
|
||||
var normalizedType = _futureOrNormalizer.normalize(type);
|
||||
return normalizedType is FutureOrType
|
||||
? _emitFutureOrType(normalizedType)
|
||||
: normalizedType.accept(this);
|
||||
|
|
|
@ -7,11 +7,6 @@ import 'package:kernel/core_types.dart';
|
|||
import 'package:kernel/kernel.dart';
|
||||
import 'package:kernel/src/replacement_visitor.dart';
|
||||
|
||||
/// Normalizes all `FutureOr` types found in [type].
|
||||
DartType normalizeFutureOr(DartType type, CoreTypes coreTypes) =>
|
||||
type.accept1(_FutureOrNormalizer.instance(coreTypes), Variance.unrelated) ??
|
||||
type;
|
||||
|
||||
/// Visit methods returns a normalized version of `FutureOr` types or `null` if
|
||||
/// no normalization was applied.
|
||||
///
|
||||
|
@ -23,15 +18,14 @@ DartType normalizeFutureOr(DartType type, CoreTypes coreTypes) =>
|
|||
///
|
||||
/// Any changes to the normalization logic here should be mirrored in the
|
||||
/// classes.dart runtime library method named `normalizeFutureOr`.
|
||||
class _FutureOrNormalizer extends ReplacementVisitor {
|
||||
class FutureOrNormalizer extends ReplacementVisitor {
|
||||
final CoreTypes _coreTypes;
|
||||
|
||||
static _FutureOrNormalizer? _instance;
|
||||
FutureOrNormalizer(this._coreTypes);
|
||||
|
||||
_FutureOrNormalizer._(this._coreTypes);
|
||||
|
||||
factory _FutureOrNormalizer.instance(CoreTypes coreTypes) =>
|
||||
_instance ?? (_instance = _FutureOrNormalizer._(coreTypes));
|
||||
/// Normalizes all `FutureOr` types found in [type].
|
||||
DartType normalize(DartType type) =>
|
||||
type.accept1(this, Variance.unrelated) ?? type;
|
||||
|
||||
@override
|
||||
DartType? visitFutureOrType(FutureOrType futureOr, int variance) {
|
||||
|
|
Loading…
Reference in a new issue