Skip to content

Commit

Permalink
[vm/kernel/bytecode] Support partial tear-off instantiation constants…
Browse files Browse the repository at this point in the history
… in bytecode generator and bytecode reader

Change-Id: I24855274df292903646844bb56ece0c35a62e9ef
Reviewed-on: https://dart-review.googlesource.com/68300
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
  • Loading branch information
alexmarkov authored and commit-bot@chromium.org committed Aug 2, 2018
1 parent 62a2752 commit 4ab8408
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/vm/lib/bytecode/constant_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ type ConstantSubtypeTestCache extends ConstantPoolEntry {
Byte tag = 24;
}
type ConstantPartialTearOffInstantiation extends ConstantPoolEntry {
Byte tag = 25;
ConstantIndex tearOffConstant;
ConstantIndex typeArguments;
}
*/

enum ConstantTag {
Expand Down Expand Up @@ -190,6 +196,7 @@ enum ConstantTag {
kEndClosureFunctionScope,
kNativeEntry,
kSubtypeTestCache,
kPartialTearOffInstantiation
}

abstract class ConstantPoolEntry {
Expand Down Expand Up @@ -258,6 +265,8 @@ abstract class ConstantPoolEntry {
return new ConstantNativeEntry.readFromBinary(source);
case ConstantTag.kSubtypeTestCache:
return new ConstantSubtypeTestCache.readFromBinary(source);
case ConstantTag.kPartialTearOffInstantiation:
return new ConstantPartialTearOffInstantiation.readFromBinary(source);
}
throw 'Unexpected constant tag $tag';
}
Expand Down Expand Up @@ -1088,6 +1097,42 @@ class ConstantSubtypeTestCache extends ConstantPoolEntry {
bool operator ==(other) => identical(this, other);
}

class ConstantPartialTearOffInstantiation extends ConstantPoolEntry {
final int tearOffConstantIndex;
final int typeArgumentsConstantIndex;

ConstantPartialTearOffInstantiation(
this.tearOffConstantIndex, this.typeArgumentsConstantIndex);

@override
ConstantTag get tag => ConstantTag.kPartialTearOffInstantiation;

@override
void writeValueToBinary(BinarySink sink) {
sink.writeUInt30(tearOffConstantIndex);
sink.writeUInt30(typeArgumentsConstantIndex);
}

ConstantPartialTearOffInstantiation.readFromBinary(BinarySource source)
: tearOffConstantIndex = source.readUInt(),
typeArgumentsConstantIndex = source.readUInt();

@override
String toString() {
return 'PartialTearOffInstantiation tear-off CP#$tearOffConstantIndex type-args CP#$typeArgumentsConstantIndex';
}

@override
int get hashCode =>
_combineHashes(tearOffConstantIndex, typeArgumentsConstantIndex);

@override
bool operator ==(other) =>
other is ConstantPartialTearOffInstantiation &&
this.tearOffConstantIndex == other.tearOffConstantIndex &&
this.typeArgumentsConstantIndex == other.typeArgumentsConstantIndex;
}

class ConstantPool {
final List<ConstantPoolEntry> entries = <ConstantPoolEntry>[];
final Map<ConstantPoolEntry, int> _canonicalizationCache =
Expand Down
6 changes: 6 additions & 0 deletions pkg/vm/lib/bytecode/gen_bytecode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2457,6 +2457,12 @@ class ConstantEmitter extends ConstantVisitor<int> {
@override
int visitTypeLiteralConstant(TypeLiteralConstant node) =>
cp.add(new ConstantType(node.type));

@override
int visitPartialInstantiationConstant(PartialInstantiationConstant node) =>
cp.add(new ConstantPartialTearOffInstantiation(
node.tearOffConstant.accept(this),
cp.add(new ConstantTypeArguments(node.types))));
}

class UnsupportedOperationError {
Expand Down
20 changes: 20 additions & 0 deletions runtime/vm/compiler/frontend/bytecode_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ intptr_t BytecodeMetadataHelper::ReadPoolEntries(const Function& function,
kEndClosureFunctionScope,
kNativeEntry,
kSubtypeTestCache,
kPartialTearOffInstantiation,
};

enum InvocationKind {
Expand Down Expand Up @@ -458,6 +459,25 @@ intptr_t BytecodeMetadataHelper::ReadPoolEntries(const Function& function,
case ConstantPoolTag::kSubtypeTestCache: {
obj = SubtypeTestCache::New();
} break;
case ConstantPoolTag::kPartialTearOffInstantiation: {
intptr_t tearoff_index = helper_->ReadUInt();
ASSERT(tearoff_index < i);
const Closure& old_closure = Closure::CheckedHandle(
helper_->zone_, pool.ObjectAt(tearoff_index));

intptr_t type_args_index = helper_->ReadUInt();
ASSERT(type_args_index < i);
type_args ^= pool.ObjectAt(type_args_index);

obj = Closure::New(
TypeArguments::Handle(helper_->zone_,
old_closure.instantiator_type_arguments()),
TypeArguments::Handle(helper_->zone_,
old_closure.function_type_arguments()),
type_args, Function::Handle(helper_->zone_, old_closure.function()),
Context::Handle(helper_->zone_, old_closure.context()), Heap::kOld);
obj = H.Canonicalize(Instance::Cast(obj));
} break;
default:
UNREACHABLE();
}
Expand Down

0 comments on commit 4ab8408

Please sign in to comment.