@@ -316,95 +316,98 @@ class InferrerEngine {
316316 _buildWorkQueue ();
317317 metrics.refine1.measure (_refine);
318318
319- // Try to infer element types of lists and compute their escape information.
320- types.allocatedLists.values.forEach ((ListTypeInformation info) {
321- analyzeListAndEnqueue (info);
322- });
323-
324- // Try to infer element types of sets and compute their escape information.
325- types.allocatedSets.values.forEach ((SetTypeInformation info) {
326- analyzeSetAndEnqueue (info);
327- });
319+ metrics.trace.measure (() {
320+ // Try to infer element types of lists and compute their escape information.
321+ types.allocatedLists.values.forEach ((ListTypeInformation info) {
322+ analyzeListAndEnqueue (info);
323+ });
328324
329- // Try to infer the key and value types for maps and compute the values'
330- // escape information.
331- types.allocatedMaps.values.forEach ((MapTypeInformation info) {
332- analyzeMapAndEnqueue (info);
333- });
325+ // Try to infer element types of sets and compute their escape information.
326+ types.allocatedSets.values.forEach ((SetTypeInformation info) {
327+ analyzeSetAndEnqueue (info);
328+ });
334329
335- Set <FunctionEntity > bailedOutOn = Set <FunctionEntity >();
330+ // Try to infer the key and value types for maps and compute the values'
331+ // escape information.
332+ types.allocatedMaps.values.forEach ((MapTypeInformation info) {
333+ analyzeMapAndEnqueue (info);
334+ });
336335
337- // Trace closures to potentially infer argument types.
338- types.allocatedClosures.forEach ((dynamic info) {
339- void trace (
340- Iterable <FunctionEntity > elements, ClosureTracerVisitor tracer) {
341- tracer.run ();
342- if (! tracer.continueAnalyzing) {
343- elements.forEach ((FunctionEntity element) {
344- inferredDataBuilder.registerMightBePassedToApply (element);
345- if (debug.VERBOSE ) {
346- print ("traced closure $element as ${true } (bail)" );
347- }
336+ Set <FunctionEntity > bailedOutOn = Set <FunctionEntity >();
337+
338+ // Trace closures to potentially infer argument types.
339+ types.allocatedClosures.forEach ((dynamic info) {
340+ void trace (
341+ Iterable <FunctionEntity > elements, ClosureTracerVisitor tracer) {
342+ tracer.run ();
343+ if (! tracer.continueAnalyzing) {
344+ elements.forEach ((FunctionEntity element) {
345+ inferredDataBuilder.registerMightBePassedToApply (element);
346+ if (debug.VERBOSE ) {
347+ print ("traced closure $element as ${true } (bail)" );
348+ }
349+ types.strategy.forEachParameter (element, (Local parameter) {
350+ types
351+ .getInferredTypeOfParameter (parameter)
352+ .giveUp (this , clearInputs: false );
353+ });
354+ });
355+ bailedOutOn.addAll (elements);
356+ return ;
357+ }
358+ elements
359+ .where ((e) => ! bailedOutOn.contains (e))
360+ .forEach ((FunctionEntity element) {
348361 types.strategy.forEachParameter (element, (Local parameter) {
349- types
350- .getInferredTypeOfParameter (parameter)
351- .giveUp (this , clearInputs: false );
362+ ParameterTypeInformation info =
363+ types.getInferredTypeOfParameter (parameter);
364+ info.maybeResume ();
365+ _workQueue.add (info);
352366 });
367+ if (tracer.tracedType.mightBePassedToFunctionApply) {
368+ inferredDataBuilder.registerMightBePassedToApply (element);
369+ }
370+ if (debug.VERBOSE ) {
371+ print ("traced closure $element as "
372+ "${inferredDataBuilder .getCurrentlyKnownMightBePassedToApply (element )}" );
373+ }
353374 });
354- bailedOutOn.addAll (elements);
355- return ;
356375 }
357- elements
358- .where ((e) => ! bailedOutOn.contains (e))
359- .forEach ((FunctionEntity element) {
360- types.strategy.forEachParameter (element, (Local parameter) {
361- ParameterTypeInformation info =
362- types.getInferredTypeOfParameter (parameter);
363- info.maybeResume ();
364- _workQueue.add (info);
365- });
366- if (tracer.tracedType.mightBePassedToFunctionApply) {
367- inferredDataBuilder.registerMightBePassedToApply (element);
368- }
369- if (debug.VERBOSE ) {
370- print ("traced closure $element as "
371- "${inferredDataBuilder .getCurrentlyKnownMightBePassedToApply (element )}" );
372- }
373- });
374- }
375376
376- if (info is ClosureTypeInformation ) {
377- Iterable <FunctionEntity > elements = [info.closure];
378- trace (elements, ClosureTracerVisitor (elements, info, this ));
379- } else if (info is CallSiteTypeInformation ) {
380- final selector = info.selector;
381- if (info is StaticCallSiteTypeInformation &&
382- selector != null &&
383- selector.isCall) {
384- // This is a constructor call to a class with a call method. So we
385- // need to trace the call method here.
386- final calledElement = info.calledElement;
387- assert (calledElement is ConstructorEntity &&
388- calledElement.isGenerativeConstructor);
389- final cls = calledElement.enclosingClass! ;
390- final callMethod = _lookupCallMethod (cls)! ;
391- Iterable <FunctionEntity > elements = [callMethod];
392- trace (elements, ClosureTracerVisitor (elements, info, this ));
393- } else {
394- // We only are interested in functions here, as other targets
395- // of this closure call are not a root to trace but an intermediate
396- // for some other function.
397- Iterable <FunctionEntity > elements = List <FunctionEntity >.from (
398- info.callees.where ((e) => e.isFunction));
377+ if (info is ClosureTypeInformation ) {
378+ Iterable <FunctionEntity > elements = [info.closure];
399379 trace (elements, ClosureTracerVisitor (elements, info, this ));
380+ } else if (info is CallSiteTypeInformation ) {
381+ final selector = info.selector;
382+ if (info is StaticCallSiteTypeInformation &&
383+ selector != null &&
384+ selector.isCall) {
385+ // This is a constructor call to a class with a call method. So we
386+ // need to trace the call method here.
387+ final calledElement = info.calledElement;
388+ assert (calledElement is ConstructorEntity &&
389+ calledElement.isGenerativeConstructor);
390+ final cls = calledElement.enclosingClass! ;
391+ final callMethod = _lookupCallMethod (cls)! ;
392+ Iterable <FunctionEntity > elements = [callMethod];
393+ trace (elements, ClosureTracerVisitor (elements, info, this ));
394+ } else {
395+ // We only are interested in functions here, as other targets
396+ // of this closure call are not a root to trace but an intermediate
397+ // for some other function.
398+ Iterable <FunctionEntity > elements = List <FunctionEntity >.from (
399+ info.callees.where ((e) => e.isFunction));
400+ trace (elements, ClosureTracerVisitor (elements, info, this ));
401+ }
402+ } else if (info is MemberTypeInformation ) {
403+ final member = info.member as FunctionEntity ;
404+ trace (
405+ [member], StaticTearOffClosureTracerVisitor (member, info, this ));
406+ } else if (info is ParameterTypeInformation ) {
407+ failedAt (NO_LOCATION_SPANNABLE ,
408+ 'Unexpected closure allocation info $info ' );
400409 }
401- } else if (info is MemberTypeInformation ) {
402- final member = info.member as FunctionEntity ;
403- trace ([member], StaticTearOffClosureTracerVisitor (member, info, this ));
404- } else if (info is ParameterTypeInformation ) {
405- failedAt (
406- NO_LOCATION_SPANNABLE , 'Unexpected closure allocation info $info ' );
407- }
410+ });
408411 });
409412
410413 dump? .beforeTracing ();
@@ -1137,6 +1140,7 @@ class _InferrerEngineMetrics extends MetricsBase {
11371140 final time = DurationMetric ('time' );
11381141 final analyze = DurationMetric ('time.analyze' );
11391142 final refine1 = DurationMetric ('time.refine1' );
1143+ final trace = DurationMetric ('time.trace' );
11401144 final refine2 = DurationMetric ('time.refine2' );
11411145 final elementsInGraph = CountMetric ('count.elementsInGraph' );
11421146 final allTypesCount = CountMetric ('count.allTypes' );
@@ -1148,6 +1152,7 @@ class _InferrerEngineMetrics extends MetricsBase {
11481152 secondary = [
11491153 analyze,
11501154 refine1,
1155+ trace,
11511156 refine2,
11521157 elementsInGraph,
11531158 allTypesCount,
0 commit comments