[vm/nnbd] Use NNBD flags from AsExpression, IsExpression

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 <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Alexander Markov 2020-02-03 20:20:26 +00:00 committed by commit-bot@chromium.org
parent a97c23b939
commit e1e2604ff1
2 changed files with 27 additions and 7 deletions

View file

@ -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.

View file

@ -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;