void LSLocation::reduce(LSLocation &Base, SILModule *M, LSLocationSet &Locs, TypeExpansionAnalysis *TE) { // First, construct the LSLocation by appending the projection path from the // accessed node to the leaf nodes. LSLocationList Nodes; ProjectionPath &BasePath = Base.getPath().getValue(); for (const auto &P : TE->getTypeExpansionProjectionPaths(Base.getType(), M, TEKind::TENode)) { Nodes.push_back(LSLocation(Base.getBase(), P.getValue(), BasePath)); } // Second, go from leaf nodes to their parents. This guarantees that at the // point the parent is processed, its children have been processed already. for (auto I = Nodes.rbegin(), E = Nodes.rend(); I != E; ++I) { LSLocationList FirstLevel; I->getFirstLevelLSLocations(FirstLevel, M); // Reached the end of the projection tree, this is a leaf node. if (FirstLevel.empty()) continue; // If this is a class reference type, we have reached end of the type tree. if (I->getType().getClassOrBoundGenericClass()) continue; // This is NOT a leaf node, check whether all its first level children are // alive. bool Alive = true; for (auto &X : FirstLevel) { Alive &= Locs.find(X) != Locs.end(); } // All first level locations are alive, create the new aggregated location. if (Alive) { for (auto &X : FirstLevel) Locs.erase(X); Locs.insert(*I); } } }