@@ -176,16 +176,14 @@ static std::vector<ModuleDependencyID>
176176computeTopologicalSortOfExplicitDependencies (
177177 const ModuleDependencyIDSetVector &allModules,
178178 const ModuleDependenciesCache &cache) {
179+ std::unordered_set<ModuleDependencyID> visited;
180+ std::vector<ModuleDependencyID> result;
181+ std::stack<ModuleDependencyID> stack;
182+
179183 // Must be explicitly-typed to allow recursion
180- std::function<void (const ModuleDependencyID &,
181- std::stack<ModuleDependencyID> &,
182- std::unordered_set<ModuleDependencyID> &,
183- std::vector<ModuleDependencyID> &)>
184- visit;
185- visit = [&visit, &cache](const ModuleDependencyID &moduleID,
186- std::stack<ModuleDependencyID> &stack,
187- std::unordered_set<ModuleDependencyID> &visited,
188- std::vector<ModuleDependencyID> &result) {
184+ std::function<void (const ModuleDependencyID &)> visit;
185+ visit = [&visit, &cache, &visited, &result,
186+ &stack](const ModuleDependencyID &moduleID) {
189187 // Mark this node as visited -- we are done if it already was.
190188 if (!visited.insert (moduleID).second )
191189 return ;
@@ -196,7 +194,7 @@ computeTopologicalSortOfExplicitDependencies(
196194 // since that would mean we have found a cycle, which should not
197195 // be possible because we checked for cycles earlier.
198196 stack.push (succID);
199- visit (succID, stack, visited, result );
197+ visit (succID);
200198 auto top = stack.top ();
201199 stack.pop ();
202200 assert (top == succID);
@@ -206,13 +204,10 @@ computeTopologicalSortOfExplicitDependencies(
206204 result.push_back (moduleID);
207205 };
208206
209- std::unordered_set<ModuleDependencyID> visited;
210- std::vector<ModuleDependencyID> result;
211- std::stack<ModuleDependencyID> stack;
212207 for (const auto &modID : allModules) {
213208 assert (stack.empty ());
214209 stack.push (modID);
215- visit (modID, stack, visited, result );
210+ visit (modID);
216211 auto top = stack.top ();
217212 stack.pop ();
218213 assert (top == modID);
@@ -222,13 +217,15 @@ computeTopologicalSortOfExplicitDependencies(
222217 return result;
223218}
224219
225- // / For each module in the graph, compute a set of all its dependencies
220+ // / For each module in the graph, compute a set of all its dependencies,
226221// / direct *and* transitive.
227222static std::unordered_map<ModuleDependencyID,
228223 std::set<ModuleDependencyID>>
229224computeTransitiveClosureOfExplicitDependencies (
230225 const std::vector<ModuleDependencyID> &topologicallySortedModuleList,
231226 const ModuleDependenciesCache &cache) {
227+ // The usage of an ordered ::set is important to ensure the
228+ // dependencies are listed in a deterministic order.
232229 std::unordered_map<ModuleDependencyID, std::set<ModuleDependencyID>>
233230 result;
234231 for (const auto &modID : topologicallySortedModuleList)
@@ -286,7 +283,7 @@ resolveExplicitModuleInputs(ModuleDependencyID moduleID,
286283 } break ;
287284 case swift::ModuleDependencyKind::Clang: {
288285 auto clangDepDetails = depInfo->getAsClangModule ();
289- assert (binaryDepDetails && " Expected Clang Module dependency." );
286+ assert (clangDepDetails && " Expected Clang Module dependency." );
290287 commandLine.push_back (" -Xcc" );
291288 commandLine.push_back (" -fmodule-file=" + depModuleID.first + " =" +
292289 clangDepDetails->pcmOutputPath );
0 commit comments