Skip to content

Commit 4ab8408

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/kernel/bytecode] Support partial tear-off instantiation constants in bytecode generator and bytecode reader
Change-Id: I24855274df292903646844bb56ece0c35a62e9ef Reviewed-on: https://dart-review.googlesource.com/68300 Reviewed-by: Régis Crelier <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 62a2752 commit 4ab8408

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

pkg/vm/lib/bytecode/constant_pool.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ type ConstantSubtypeTestCache extends ConstantPoolEntry {
162162
Byte tag = 24;
163163
}
164164
165+
type ConstantPartialTearOffInstantiation extends ConstantPoolEntry {
166+
Byte tag = 25;
167+
ConstantIndex tearOffConstant;
168+
ConstantIndex typeArguments;
169+
}
170+
165171
*/
166172

167173
enum ConstantTag {
@@ -190,6 +196,7 @@ enum ConstantTag {
190196
kEndClosureFunctionScope,
191197
kNativeEntry,
192198
kSubtypeTestCache,
199+
kPartialTearOffInstantiation
193200
}
194201

195202
abstract class ConstantPoolEntry {
@@ -258,6 +265,8 @@ abstract class ConstantPoolEntry {
258265
return new ConstantNativeEntry.readFromBinary(source);
259266
case ConstantTag.kSubtypeTestCache:
260267
return new ConstantSubtypeTestCache.readFromBinary(source);
268+
case ConstantTag.kPartialTearOffInstantiation:
269+
return new ConstantPartialTearOffInstantiation.readFromBinary(source);
261270
}
262271
throw 'Unexpected constant tag $tag';
263272
}
@@ -1088,6 +1097,42 @@ class ConstantSubtypeTestCache extends ConstantPoolEntry {
10881097
bool operator ==(other) => identical(this, other);
10891098
}
10901099

1100+
class ConstantPartialTearOffInstantiation extends ConstantPoolEntry {
1101+
final int tearOffConstantIndex;
1102+
final int typeArgumentsConstantIndex;
1103+
1104+
ConstantPartialTearOffInstantiation(
1105+
this.tearOffConstantIndex, this.typeArgumentsConstantIndex);
1106+
1107+
@override
1108+
ConstantTag get tag => ConstantTag.kPartialTearOffInstantiation;
1109+
1110+
@override
1111+
void writeValueToBinary(BinarySink sink) {
1112+
sink.writeUInt30(tearOffConstantIndex);
1113+
sink.writeUInt30(typeArgumentsConstantIndex);
1114+
}
1115+
1116+
ConstantPartialTearOffInstantiation.readFromBinary(BinarySource source)
1117+
: tearOffConstantIndex = source.readUInt(),
1118+
typeArgumentsConstantIndex = source.readUInt();
1119+
1120+
@override
1121+
String toString() {
1122+
return 'PartialTearOffInstantiation tear-off CP#$tearOffConstantIndex type-args CP#$typeArgumentsConstantIndex';
1123+
}
1124+
1125+
@override
1126+
int get hashCode =>
1127+
_combineHashes(tearOffConstantIndex, typeArgumentsConstantIndex);
1128+
1129+
@override
1130+
bool operator ==(other) =>
1131+
other is ConstantPartialTearOffInstantiation &&
1132+
this.tearOffConstantIndex == other.tearOffConstantIndex &&
1133+
this.typeArgumentsConstantIndex == other.typeArgumentsConstantIndex;
1134+
}
1135+
10911136
class ConstantPool {
10921137
final List<ConstantPoolEntry> entries = <ConstantPoolEntry>[];
10931138
final Map<ConstantPoolEntry, int> _canonicalizationCache =

pkg/vm/lib/bytecode/gen_bytecode.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,12 @@ class ConstantEmitter extends ConstantVisitor<int> {
24572457
@override
24582458
int visitTypeLiteralConstant(TypeLiteralConstant node) =>
24592459
cp.add(new ConstantType(node.type));
2460+
2461+
@override
2462+
int visitPartialInstantiationConstant(PartialInstantiationConstant node) =>
2463+
cp.add(new ConstantPartialTearOffInstantiation(
2464+
node.tearOffConstant.accept(this),
2465+
cp.add(new ConstantTypeArguments(node.types))));
24602466
}
24612467

24622468
class UnsupportedOperationError {

runtime/vm/compiler/frontend/bytecode_reader.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ intptr_t BytecodeMetadataHelper::ReadPoolEntries(const Function& function,
113113
kEndClosureFunctionScope,
114114
kNativeEntry,
115115
kSubtypeTestCache,
116+
kPartialTearOffInstantiation,
116117
};
117118

118119
enum InvocationKind {
@@ -458,6 +459,25 @@ intptr_t BytecodeMetadataHelper::ReadPoolEntries(const Function& function,
458459
case ConstantPoolTag::kSubtypeTestCache: {
459460
obj = SubtypeTestCache::New();
460461
} break;
462+
case ConstantPoolTag::kPartialTearOffInstantiation: {
463+
intptr_t tearoff_index = helper_->ReadUInt();
464+
ASSERT(tearoff_index < i);
465+
const Closure& old_closure = Closure::CheckedHandle(
466+
helper_->zone_, pool.ObjectAt(tearoff_index));
467+
468+
intptr_t type_args_index = helper_->ReadUInt();
469+
ASSERT(type_args_index < i);
470+
type_args ^= pool.ObjectAt(type_args_index);
471+
472+
obj = Closure::New(
473+
TypeArguments::Handle(helper_->zone_,
474+
old_closure.instantiator_type_arguments()),
475+
TypeArguments::Handle(helper_->zone_,
476+
old_closure.function_type_arguments()),
477+
type_args, Function::Handle(helper_->zone_, old_closure.function()),
478+
Context::Handle(helper_->zone_, old_closure.context()), Heap::kOld);
479+
obj = H.Canonicalize(Instance::Cast(obj));
480+
} break;
461481
default:
462482
UNREACHABLE();
463483
}

0 commit comments

Comments
 (0)