@@ -201,6 +201,10 @@ void BytecodeReaderHelper::ReadCode(const Function& function,
201201 ASSERT (code_offset > 0 );
202202
203203 AlternativeReadingScope alt (&reader_, code_offset);
204+ // This scope is needed to set active_class_->enclosing_ which is used to
205+ // assign parent function for function types.
206+ ActiveEnclosingFunctionScope active_enclosing_function (active_class_,
207+ &function);
204208
205209 const intptr_t flags = reader_.ReadUInt ();
206210 const bool has_exceptions_table =
@@ -251,7 +255,7 @@ void BytecodeReaderHelper::ReadCode(const Function& function,
251255 // TODO(alexmarkov): allocate deopt_ids for closures separately
252256 DeoptIdScope deopt_id_scope (thread_, 0 );
253257
254- ReadConstantPool (function, pool);
258+ ReadConstantPool (function, pool, 0 );
255259 }
256260
257261 // Read bytecode and attach to function.
@@ -653,7 +657,17 @@ void BytecodeReaderHelper::ReadTypeParametersDeclaration(
653657 // Do not set type parameters for factories, as VM uses class type
654658 // parameters instead.
655659 parameterized_function.set_type_parameters (type_parameters);
656- function_type_type_parameters_ = &type_parameters;
660+ if (parameterized_function.IsSignatureFunction ()) {
661+ if (function_type_type_parameters_ == nullptr ) {
662+ function_type_type_parameters_ = &type_parameters;
663+ } else {
664+ function_type_type_parameters_ = &TypeArguments::Handle (
665+ Z, function_type_type_parameters_->ConcatenateTypeParameters (
666+ Z, type_parameters));
667+ }
668+ } else {
669+ ASSERT (function_type_type_parameters_ == nullptr );
670+ }
657671 }
658672
659673 // Step b) Fill in the bounds of all [TypeParameter]s.
@@ -664,8 +678,9 @@ void BytecodeReaderHelper::ReadTypeParametersDeclaration(
664678 }
665679}
666680
667- void BytecodeReaderHelper::ReadConstantPool (const Function& function,
668- const ObjectPool& pool) {
681+ intptr_t BytecodeReaderHelper::ReadConstantPool (const Function& function,
682+ const ObjectPool& pool,
683+ intptr_t start_index) {
669684 TIMELINE_DURATION (Thread::Current (), CompilerVerbose,
670685 " BytecodeReaderHelper::ReadConstantPool" );
671686
@@ -721,7 +736,7 @@ void BytecodeReaderHelper::ReadConstantPool(const Function& function,
721736 String& name = String::Handle (Z);
722737 const String* simpleInstanceOf = nullptr ;
723738 const intptr_t obj_count = pool.Length ();
724- for (intptr_t i = 0 ; i < obj_count; ++i) {
739+ for (intptr_t i = start_index ; i < obj_count; ++i) {
725740 const intptr_t tag = reader_.ReadTag ();
726741 switch (tag) {
727742 case ConstantPoolTag::kInvalid :
@@ -799,11 +814,30 @@ void BytecodeReaderHelper::ReadConstantPool(const Function& function,
799814 intptr_t closure_index = reader_.ReadUInt ();
800815 obj = closures_->At (closure_index);
801816 ASSERT (obj.IsFunction ());
802- } break ;
817+ // Set current entry.
818+ pool.SetTypeAt (i, ObjectPool::EntryType::kTaggedObject ,
819+ ObjectPool::Patchability::kNotPatchable );
820+ pool.SetObjectAt (i, obj);
821+
822+ // This scope is needed to set active_class_->enclosing_ which is used
823+ // to assign parent function for function types.
824+ ActiveEnclosingFunctionScope active_enclosing_function (
825+ active_class_, &Function::Cast (obj));
826+
827+ // Read constant pool until corresponding EndClosureFunctionScope.
828+ i = ReadConstantPool (function, pool, i + 1 );
829+
830+ // Proceed with the rest of entries.
831+ continue ;
832+ }
803833 case ConstantPoolTag::kEndClosureFunctionScope : {
804- // Entry is not used and set to null.
834+ // EndClosureFunctionScope entry is not used and set to null.
805835 obj = Object::null ();
806- } break ;
836+ pool.SetTypeAt (i, ObjectPool::EntryType::kTaggedObject ,
837+ ObjectPool::Patchability::kNotPatchable );
838+ pool.SetObjectAt (i, obj);
839+ return i;
840+ }
807841 case ConstantPoolTag::kNativeEntry : {
808842 name = ReadString ();
809843 obj = NativeEntry (function, name);
@@ -854,6 +888,8 @@ void BytecodeReaderHelper::ReadConstantPool(const Function& function,
854888 ObjectPool::Patchability::kNotPatchable );
855889 pool.SetObjectAt (i, obj);
856890 }
891+
892+ return obj_count - 1 ;
857893}
858894
859895RawBytecode* BytecodeReaderHelper::ReadBytecode (const ObjectPool& pool) {
@@ -1405,6 +1441,11 @@ RawObject* BytecodeReaderHelper::ReadObjectContents(uint32_t header) {
14051441 : Function::null_function (),
14061442 TokenPosition::kNoSource ));
14071443
1444+ // This scope is needed to set active_class_->enclosing_ which is used
1445+ // to assign parent function for function types.
1446+ ActiveEnclosingFunctionScope active_enclosing_function (
1447+ active_class_, &signature_function);
1448+
14081449 return ReadFunctionSignature (
14091450 signature_function, (flags & kFlagHasOptionalPositionalParams ) != 0 ,
14101451 (flags & kFlagHasOptionalNamedParams ) != 0 ,
@@ -1710,6 +1751,12 @@ RawObject* BytecodeReaderHelper::ReadType(intptr_t tag) {
17101751 ? *active_class_->enclosing
17111752 : Function::null_function (),
17121753 TokenPosition::kNoSource ));
1754+
1755+ // This scope is needed to set active_class_->enclosing_ which is used to
1756+ // assign parent function for function types.
1757+ ActiveEnclosingFunctionScope active_enclosing_function (
1758+ active_class_, &signature_function);
1759+
17131760 // TODO(alexmarkov): skip type finalization
17141761 return ReadFunctionSignature (
17151762 signature_function, (flags & kFlagHasOptionalPositionalParams ) != 0 ,
@@ -3014,8 +3061,6 @@ RawError* BytecodeReader::ReadFunctionBytecode(Thread* thread,
30143061
30153062 ActiveClassScope active_class_scope (&active_class, &klass);
30163063 ActiveMemberScope active_member (&active_class, &outermost_function);
3017- ActiveTypeParametersScope active_type_params (&active_class, function,
3018- zone);
30193064
30203065 BytecodeComponentData bytecode_component (
30213066 &Array::Handle (zone, translation_helper.GetBytecodeComponent ()));
0 commit comments