@@ -559,33 +559,25 @@ Fragment StreamingFlowGraphBuilder::SetupCapturedParameters(
559
559
}
560
560
561
561
Fragment StreamingFlowGraphBuilder::InitSuspendableFunction (
562
- const Function& dart_function) {
562
+ const Function& dart_function,
563
+ const AbstractType* emitted_value_type) {
563
564
Fragment body;
564
565
if (dart_function.IsAsyncFunction ()) {
565
- const auto & result_type =
566
- AbstractType::Handle (Z, dart_function.result_type ());
567
- auto & type_args = TypeArguments::ZoneHandle (Z);
568
- if (result_type.IsType () &&
569
- (Class::Handle (Z, result_type.type_class ()).IsFutureClass () ||
570
- result_type.IsFutureOrType ())) {
571
- ASSERT (result_type.IsFinalized ());
572
- type_args = Type::Cast (result_type).GetInstanceTypeArguments (H.thread ());
573
- }
574
-
566
+ ASSERT (emitted_value_type != nullptr );
567
+ auto & type_args = TypeArguments::ZoneHandle (Z, TypeArguments::New (1 ));
568
+ type_args.SetTypeAt (0 , *emitted_value_type);
569
+ type_args = Class::Handle (Z, IG->object_store ()->future_class ())
570
+ .GetInstanceTypeArguments (H.thread (), type_args);
575
571
body += TranslateInstantiatedTypeArguments (type_args);
576
572
body += B->Call1ArgStub (TokenPosition::kNoSource ,
577
573
Call1ArgStubInstr::StubId::kInitAsync );
578
574
body += Drop ();
579
575
} else if (dart_function.IsAsyncGenerator ()) {
580
- const auto & result_type =
581
- AbstractType::Handle (Z, dart_function.result_type ());
582
- auto & type_args = TypeArguments::ZoneHandle (Z);
583
- if (result_type.IsType () &&
584
- (result_type.type_class () == IG->object_store ()->stream_class ())) {
585
- ASSERT (result_type.IsFinalized ());
586
- type_args = Type::Cast (result_type).GetInstanceTypeArguments (H.thread ());
587
- }
588
-
576
+ ASSERT (emitted_value_type != nullptr );
577
+ auto & type_args = TypeArguments::ZoneHandle (Z, TypeArguments::New (1 ));
578
+ type_args.SetTypeAt (0 , *emitted_value_type);
579
+ type_args = Class::Handle (Z, IG->object_store ()->stream_class ())
580
+ .GetInstanceTypeArguments (H.thread (), type_args);
589
581
body += TranslateInstantiatedTypeArguments (type_args);
590
582
body += B->Call1ArgStub (TokenPosition::kNoSource ,
591
583
Call1ArgStubInstr::StubId::kInitAsyncStar );
@@ -595,15 +587,11 @@ Fragment StreamingFlowGraphBuilder::InitSuspendableFunction(
595
587
SuspendInstr::StubId::kYieldAsyncStar );
596
588
body += Drop ();
597
589
} else if (dart_function.IsSyncGenerator ()) {
598
- const auto & result_type =
599
- AbstractType::Handle (Z, dart_function.result_type ());
600
- auto & type_args = TypeArguments::ZoneHandle (Z);
601
- if (result_type.IsType () &&
602
- (result_type.type_class () == IG->object_store ()->iterable_class ())) {
603
- ASSERT (result_type.IsFinalized ());
604
- type_args = Type::Cast (result_type).GetInstanceTypeArguments (H.thread ());
605
- }
606
-
590
+ ASSERT (emitted_value_type != nullptr );
591
+ auto & type_args = TypeArguments::ZoneHandle (Z, TypeArguments::New (1 ));
592
+ type_args.SetTypeAt (0 , *emitted_value_type);
593
+ type_args = Class::Handle (Z, IG->object_store ()->iterable_class ())
594
+ .GetInstanceTypeArguments (H.thread (), type_args);
607
595
body += TranslateInstantiatedTypeArguments (type_args);
608
596
body += B->Call1ArgStub (TokenPosition::kNoSource ,
609
597
Call1ArgStubInstr::StubId::kInitSyncStar );
@@ -618,6 +606,8 @@ Fragment StreamingFlowGraphBuilder::InitSuspendableFunction(
618
606
if (scope->num_context_variables () > 0 ) {
619
607
body += CloneContext (scope->context_slots ());
620
608
}
609
+ } else {
610
+ ASSERT (emitted_value_type == nullptr );
621
611
}
622
612
return body;
623
613
}
@@ -784,17 +774,30 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction(
784
774
785
775
LocalVariable* first_parameter = nullptr ;
786
776
TokenPosition token_position = TokenPosition::kNoSource ;
777
+ const AbstractType* emitted_value_type = nullptr ;
787
778
{
788
779
AlternativeReadingScope alt (&reader_);
789
780
FunctionNodeHelper function_node_helper (this );
790
781
function_node_helper.ReadUntilExcluding (
791
782
FunctionNodeHelper::kPositionalParameters );
792
- intptr_t list_length = ReadListLength (); // read number of positionals.
793
- if (list_length > 0 ) {
794
- intptr_t first_parameter_offset = ReaderOffset () + data_program_offset_;
795
- first_parameter = LookupVariable (first_parameter_offset);
783
+ {
784
+ AlternativeReadingScope alt2 (&reader_);
785
+ intptr_t list_length = ReadListLength (); // read number of positionals.
786
+ if (list_length > 0 ) {
787
+ intptr_t first_parameter_offset = ReaderOffset () + data_program_offset_;
788
+ first_parameter = LookupVariable (first_parameter_offset);
789
+ }
796
790
}
797
791
token_position = function_node_helper.position_ ;
792
+ if (dart_function.IsSuspendableFunction ()) {
793
+ function_node_helper.ReadUntilExcluding (
794
+ FunctionNodeHelper::kEmittedValueType );
795
+ if (ReadTag () == kSomething ) {
796
+ emitted_value_type = &T.BuildType (); // read emitted value type.
797
+ } else {
798
+ UNREACHABLE ();
799
+ }
800
+ }
798
801
}
799
802
800
803
auto graph_entry = flow_graph_builder_->graph_entry_ =
@@ -833,7 +836,7 @@ FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction(
833
836
// objects than necessary during GC.
834
837
const Fragment body =
835
838
ClearRawParameters (dart_function) + B->BuildNullAssertions () +
836
- InitSuspendableFunction (dart_function) +
839
+ InitSuspendableFunction (dart_function, emitted_value_type ) +
837
840
BuildFunctionBody (dart_function, first_parameter, is_constructor);
838
841
839
842
auto extra_entry_point_style =
0 commit comments