From e1e2604ff1b275606fc1946e1d34fb3e95663d44 Mon Sep 17 00:00:00 2001 From: Alexander Markov Date: Mon, 3 Feb 2020 20:20:26 +0000 Subject: [PATCH] [vm/nnbd] Use NNBD flags from AsExpression, IsExpression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the VM-specific follow-up to https://dart-review.googlesource.com/c/sdk/+/133100 Change-Id: Iaa8728d2e0afebf421f9c65c3b3a48b286af5970 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134200 Reviewed-by: RĂ©gis Crelier Commit-Queue: Alexander Markov --- .../frontend/kernel_binary_flowgraph.cc | 21 ++++++++++++------- runtime/vm/kernel_binary.h | 13 ++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc index 3db08e1ea6f..b9adf899122 100644 --- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc +++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc @@ -3572,17 +3572,21 @@ Fragment StreamingFlowGraphBuilder::BuildIsExpression(TokenPosition* p) { TokenPosition position = ReadPosition(); // read position. if (p != NULL) *p = position; + NNBDMode nnbd_mode; if (translation_helper_.info().kernel_binary_version() >= 38) { - // TODO(alexmarkov): Handle flags. - ReadFlags(); // read flags. + const uint8_t flags = ReadFlags(); // read flags. + nnbd_mode = ((flags & kIsExpressionFlagForNonNullableByDefault) != 0) + ? NNBDMode::kOptedInLib + : NNBDMode::kLegacyLib; + } else { + nnbd_mode = parsed_function()->function().nnbd_mode(); } + ASSERT(nnbd_mode == parsed_function()->function().nnbd_mode()); Fragment instructions = BuildExpression(); // read operand. const AbstractType& type = T.BuildType(); // read type. - const NNBDMode nnbd_mode = parsed_function()->function().nnbd_mode(); - // The VM does not like an instanceOf call with a dynamic type. We need to // special case this situation by detecting a top type. if (type.IsTopType(nnbd_mode)) { @@ -3628,14 +3632,17 @@ Fragment StreamingFlowGraphBuilder::BuildAsExpression(TokenPosition* p) { TokenPosition position = ReadPosition(); // read position. if (p != NULL) *p = position; - // TODO(alexmarkov): Handle new flags. const uint8_t flags = ReadFlags(); // read flags. - const bool is_type_error = (flags & (1 << 0)) != 0; + const bool is_type_error = (flags & kAsExpressionFlagTypeError) != 0; + const NNBDMode nnbd_mode = + ((flags & kAsExpressionFlagForNonNullableByDefault) != 0) + ? NNBDMode::kOptedInLib + : NNBDMode::kLegacyLib; + ASSERT(nnbd_mode == parsed_function()->function().nnbd_mode()); Fragment instructions = BuildExpression(); // read operand. const AbstractType& type = T.BuildType(); // read type. - const NNBDMode nnbd_mode = parsed_function()->function().nnbd_mode(); if (type.IsInstantiated() && type.IsTopType(nnbd_mode)) { // We already evaluated the operand on the left and just leave it there as // the result of the `obj as dynamic` expression. diff --git a/runtime/vm/kernel_binary.h b/runtime/vm/kernel_binary.h index 2a68fe5c898..187d3c0c72a 100644 --- a/runtime/vm/kernel_binary.h +++ b/runtime/vm/kernel_binary.h @@ -171,6 +171,19 @@ enum Variance { kLegacyCovariant = 4, }; +// Keep in sync with package:kernel/lib/ast.dart +enum AsExpressionFlags { + kAsExpressionFlagTypeError = 1 << 0, + kAsExpressionFlagCovarianceCheck = 1 << 1, + kAsExpressionFlagForDynamic = 1 << 2, + kAsExpressionFlagForNonNullableByDefault = 1 << 3, +}; + +// Keep in sync with package:kernel/lib/ast.dart +enum IsExpressionFlags { + kIsExpressionFlagForNonNullableByDefault = 1 << 0, +}; + static const int SpecializedIntLiteralBias = 3; static const int LibraryCountFieldCountFromEnd = 1; static const int SourceTableFieldCountFromFirstLibraryOffset = 6;