Place generator body in same unit as entry

Change-Id: I897bf8011bde7fcc1acb081c75f17429b948e109
Reviewed-on: https://dart-review.googlesource.com/54524
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
diff --git a/pkg/compiler/lib/src/deferred_load.dart b/pkg/compiler/lib/src/deferred_load.dart
index 430c1bf..a2375d3 100644
--- a/pkg/compiler/lib/src/deferred_load.dart
+++ b/pkg/compiler/lib/src/deferred_load.dart
@@ -1246,4 +1246,12 @@
         _constantToUnit[constant] == null || _constantToUnit[constant] == unit);
     _constantToUnit[constant] = unit;
   }
+
+  /// Registers [newEntity] to be emitted in the same output unit as
+  /// [existingEntity];
+  void registerColocatedMembers(
+      MemberEntity existingEntity, MemberEntity newEntity) {
+    assert(_entityToUnit[newEntity] == null);
+    _entityToUnit[newEntity] = outputUnitForMember(existingEntity);
+  }
 }
diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart
index 5576a63..2d21372 100644
--- a/pkg/compiler/lib/src/ssa/builder_kernel.dart
+++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart
@@ -1019,6 +1019,8 @@
 
     // Tail-call body.
     JGeneratorBody body = _elementMap.getGeneratorBody(function);
+    backend.outputUnitData.registerColocatedMembers(function, body);
+
     // Is 'buildAsyncBody' the best location for the entry?
     var sourceInformation = _sourceInformationBuilder.buildAsyncBody();