Revert "[kernel] Change dill representation of doubles"

This reverts commit 6e2536f585 as it
breaks flutter hot_reload test.

Bug: https://github.com/flutter/flutter/issues/17202
Change-Id: I36261a1aec5ec2196c3a02cc0da0dc0833337004
Reviewed-on: https://dart-review.googlesource.com/53460
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev 2018-05-02 20:25:58 +00:00 committed by commit-bot@chromium.org
parent 9a7e1f64a2
commit b298fc6d8f
8 changed files with 20 additions and 58 deletions

View file

@ -42,8 +42,6 @@ type UInt30 extends UInt {
type UInt32 = big endian 32-bit unsigned integer
type Double = Double-precision floating-point number.
type List<T> {
UInt length;
T[length] items;
@ -713,7 +711,7 @@ type BigIntLiteral extends Expression {
type DoubleLiteral extends Expression {
Byte tag = 40;
Double value;
StringReference valueString;
}
type TrueLiteral extends Expression {
@ -876,7 +874,7 @@ type IntConstant extends Constant {
type DoubleConstant extends Constant {
Byte tag = 3;
Double value;
StringReference value;
}
type StringConstant extends Constant {

View file

@ -97,22 +97,6 @@ class BinaryBuilder {
readByte();
}
final Float64List _doubleBuffer = new Float64List(1);
Uint8List _doubleBufferUint8;
double readDouble() {
_doubleBufferUint8 ??= _doubleBuffer.buffer.asUint8List();
_doubleBufferUint8[0] = readByte();
_doubleBufferUint8[1] = readByte();
_doubleBufferUint8[2] = readByte();
_doubleBufferUint8[3] = readByte();
_doubleBufferUint8[4] = readByte();
_doubleBufferUint8[5] = readByte();
_doubleBufferUint8[6] = readByte();
_doubleBufferUint8[7] = readByte();
return _doubleBuffer[0];
}
List<int> readByteList() {
List<int> bytes = new Uint8List(readUInt());
bytes.setRange(0, bytes.length, _bytes, _byteOffset);
@ -190,7 +174,7 @@ class BinaryBuilder {
case ConstantTag.IntConstant:
return new IntConstant((readExpression() as IntLiteral).value);
case ConstantTag.DoubleConstant:
return new DoubleConstant(readDouble());
return new DoubleConstant(double.parse(readStringReference()));
case ConstantTag.StringConstant:
return new StringConstant(readStringReference());
case ConstantTag.MapConstant:
@ -1351,7 +1335,7 @@ class BinaryBuilder {
case Tag.BigIntLiteral:
return new IntLiteral(int.parse(readStringReference()));
case Tag.DoubleLiteral:
return new DoubleLiteral(readDouble());
return new DoubleLiteral(double.parse(readStringReference()));
case Tag.TrueLiteral:
return new BoolLiteral(true);
case Tag.FalseLiteral:

View file

@ -154,7 +154,7 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
writeInteger(constant.value);
} else if (constant is DoubleConstant) {
writeByte(ConstantTag.DoubleConstant);
writeDouble(constant.value);
writeStringReference('${constant.value}');
} else if (constant is StringConstant) {
writeByte(ConstantTag.StringConstant);
writeStringReference(constant.value);
@ -1246,12 +1246,13 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
@override
void visitDoubleLiteral(DoubleLiteral node) {
writeByte(Tag.DoubleLiteral);
writeDouble(node.value);
}
writeDouble(double value) {
_sink.addDouble(value);
// TODO: Pick a better format for double literals.
writeByte(Tag.DoubleLiteral);
writeStringReference('$value');
}
@override
@ -2204,20 +2205,8 @@ class BufferedSink {
int length = 0;
int flushedLength = 0;
Float64List _doubleBuffer = new Float64List(1);
Uint8List _doubleBufferUint8;
BufferedSink(this._sink);
void addDouble(double d) {
_doubleBufferUint8 ??= _doubleBuffer.buffer.asUint8List();
_doubleBuffer[0] = d;
addByte4(_doubleBufferUint8[0], _doubleBufferUint8[1],
_doubleBufferUint8[2], _doubleBufferUint8[3]);
addByte4(_doubleBufferUint8[4], _doubleBufferUint8[5],
_doubleBufferUint8[6], _doubleBufferUint8[7]);
}
void addByte(int byte) {
_buffer[length++] = byte;
if (length == SIZE) {

View file

@ -135,7 +135,7 @@ class Tag {
/// Internal version of kernel binary format.
/// Bump it when making incompatible changes in kernel binaries.
/// Keep in sync with runtime/vm/kernel_binary.h.
static const int BinaryFormatVersion = 5;
static const int BinaryFormatVersion = 4;
}
abstract class ConstantTag {

View file

@ -1548,7 +1548,7 @@ void StreamingScopeBuilder::VisitExpression() {
builder_->ReadUInt(); // read value.
return;
case kDoubleLiteral:
builder_->ReadDouble(); // read value.
builder_->SkipStringReference(); // read index into string table.
return;
case kTrueLiteral:
return;
@ -3542,7 +3542,8 @@ void StreamingConstantEvaluator::EvaluateIntLiteral(bool is_negative) {
}
void StreamingConstantEvaluator::EvaluateDoubleLiteral() {
result_ = Double::New(builder_->ReadDouble(), Heap::kOld); // read value.
result_ = Double::New(H.DartString(builder_->ReadStringReference()),
Heap::kOld); // read string reference.
result_ = H.Canonicalize(result_);
}
@ -6021,10 +6022,6 @@ uint32_t KernelReaderHelper::PeekUInt() {
return reader_.ReadUInt();
}
double KernelReaderHelper::ReadDouble() {
return reader_.ReadDouble();
}
uint32_t KernelReaderHelper::PeekListLength() {
AlternativeReadingScope alt(&reader_);
return reader_.ReadListLength();
@ -6492,7 +6489,7 @@ void KernelReaderHelper::SkipExpression() {
ReadUInt(); // read value.
return;
case kDoubleLiteral:
ReadDouble(); // read value.
SkipStringReference(); // read index into string table.
return;
case kTrueLiteral:
return;
@ -8985,7 +8982,8 @@ Fragment StreamingFlowGraphBuilder::BuildDoubleLiteral(
if (position != NULL) *position = TokenPosition::kNoSource;
Double& constant = Double::ZoneHandle(
Z, Double::NewCanonical(ReadDouble())); // read double.
Z, Double::NewCanonical(
H.DartString(ReadStringReference()))); // read string reference.
return Constant(constant);
}
@ -10819,7 +10817,8 @@ const Array& ConstantHelper::ReadConstantTable() {
break;
}
case kDoubleConstant: {
temp_instance_ = Double::New(builder_.ReadDouble(), Heap::kOld);
temp_instance_ = Double::New(
H.DartString(builder_.ReadStringReference()), Heap::kOld);
temp_instance_ = H.Canonicalize(temp_instance_);
break;
}

View file

@ -1040,7 +1040,6 @@ class KernelReaderHelper {
uint32_t ReadUInt();
uint32_t ReadUInt32();
uint32_t PeekUInt();
double ReadDouble();
uint32_t PeekListLength();
StringIndex ReadStringReference();
NameIndex ReadCanonicalNameReference();

View file

@ -19,7 +19,7 @@ namespace kernel {
// Keep in sync with package:kernel/lib/binary/tag.dart.
static const uint32_t kMagicProgramFile = 0x90ABCDEFu;
static const uint32_t kBinaryFormatVersion = 5;
static const uint32_t kBinaryFormatVersion = 4;
// Keep in sync with package:kernel/lib/binary/tag.dart
#define KERNEL_TAG_LIST(V) \
@ -213,14 +213,6 @@ class Reader : public ValueObject {
return value;
}
double ReadDouble() {
ASSERT((size_ >= 8) && (offset_ >= 0) && (offset_ <= size_ - 8));
double value = ReadUnaligned(
reinterpret_cast<const double*>(&this->buffer()[offset_]));
offset_ += 8;
return value;
}
uint32_t ReadUInt() {
ASSERT((size_ >= 1) && (offset_ >= 0) && (offset_ <= size_ - 1));

View file

@ -82,7 +82,8 @@ class SimpleExpressionConverter {
return true;
case kDoubleLiteral:
simple_value_ = &Double::ZoneHandle(
Z, Double::New(builder_->ReadDouble(), Heap::kOld)); // read value.
Z, Double::New(H.DartString(builder_->ReadStringReference()),
Heap::kOld)); // read string reference.
*simple_value_ = H.Canonicalize(*simple_value_);
return true;
case kTrueLiteral: