@@ -1150,6 +1150,61 @@ step4b_identity_version_merge(PrepareState& state, WorklistItemCtx& ctx,
11501150 return {};
11511151}
11521152
1153+ // A LATER EDGE THAT ASKS MORE FEATURES OF A RESOLVED PACKAGE (mcpp#897). The
1154+ // package was walked with the features its first edge asked; the union of its
1155+ // edges is what it is built with, so the feature-deps and the forwards of each
1156+ // feature that only a later edge activates are walked now, as the first walk
1157+ // would have walked them. Measured: `v` selected as a member and reached by
1158+ // `s` with `x` compiled `x`'s sources while `x`'s feature-deps never reached
1159+ // the graph.
1160+ static std::expected<void , std::string>
1161+ step4b_widen_features (PrepareState& state, std::size_t depIndex, const WorkItem& item,
1162+ const mcpp::manifest::DependencySpec& spec) {
1163+ if (depIndex >= state.dep_manifests .size ()) return {};
1164+ auto requested = state.depFeatureRequests .find (depIndex);
1165+ if (requested == state.depFeatureRequests .end ()) return {};
1166+ auto & [features, seeded] = requested->second ;
1167+ std::vector<std::string> wider = features;
1168+ for (auto const & f : spec.features )
1169+ if (std::ranges::find (wider, f) == wider.end ()) wider.push_back (f);
1170+ const bool widerSeed = seeded || spec.defaultFeatures ;
1171+ if (wider == features && widerSeed == seeded) return {};
1172+ auto & dm = *state.dep_manifests [depIndex];
1173+ const auto before = feature_closure (dm, features, seeded);
1174+ const auto after = feature_closure (dm, wider, widerSeed);
1175+ features = std::move (wider);
1176+ seeded = widerSeed;
1177+ if (after == before) return {};
1178+ if (auto fe = validateForwards (state, dm, after, dm.package .name ); !fe)
1179+ return std::unexpected (fe.error ());
1180+ const auto previous = dm.dependencies ;
1181+ if (auto fm = mergeActiveFeatureDeps (dm, features, seeded); !fm)
1182+ return std::unexpected (fm.error ());
1183+ if (depIndex + 1 < state.packages .size ())
1184+ state.packages [depIndex + 1 ].manifest .dependencies = dm.dependencies ;
1185+ std::string label = dm.package .name ;
1186+ for (auto const & [k, r] : state.resolved )
1187+ if (r.depIndex == depIndex) {
1188+ label = std::format (" {}{}{}@{}" , k.ns , k.ns .empty () ? " " : " ." , k.shortName ,
1189+ r.source == " version" ? r.version : r.source );
1190+ break ;
1191+ }
1192+ const auto root = depIndex + 1 < state.packages .size () ? state.packages [depIndex + 1 ].root
1193+ : std::filesystem::path{};
1194+ for (auto const & [childName, childSpec] : dm.dependencies ) {
1195+ auto was = previous.find (childName);
1196+ auto now = childSpec;
1197+ auto then = was == previous.end () ? childSpec : was->second ;
1198+ injectForwards (dm, after, childName, now);
1199+ injectForwards (dm, before, childName, then);
1200+ if (was != previous.end () && now.features == then.features && now.tools == then.tools )
1201+ continue ;
1202+ state.worklist .push_back ({childName, now, label, now.version , depIndex, root,
1203+ item.devOnly , item.buildOnly });
1204+ }
1205+ return {};
1206+ }
1207+
11531208static std::expected<void , std::string>
11541209step4b_handle_already_resolved (PrepareState& state, WorklistItemCtx& ctx,
11551210 std::map<ResolvedKey, ResolvedRecord>::iterator it) {
@@ -1267,7 +1322,7 @@ step4b_handle_already_resolved(PrepareState& state, WorklistItemCtx& ctx,
12671322 it->second .depIndex + 1 ,
12681323 spec, item.fromBuildTable , name);
12691324 }
1270- return {} ;
1325+ return step4b_widen_features (state, it-> second . depIndex , item, spec) ;
12711326 }
12721327 if (sourceKind == " version" && it->second .version != spec.version ) {
12731328 if (auto r = step4b_identity_version_merge (state, ctx, it); !r)
@@ -1343,7 +1398,7 @@ step4b_handle_already_resolved(PrepareState& state, WorklistItemCtx& ctx,
13431398 it->second .depIndex + 1 ,
13441399 spec, item.fromBuildTable , name);
13451400 }
1346- return {} ;
1401+ return step4b_widen_features (state, it-> second . depIndex , item, spec) ;
13471402 return {};
13481403}
13491404
@@ -1924,6 +1979,7 @@ step4b_finalize_dependency(PrepareState& state, WorklistItemCtx& ctx) {
19241979 key.shortName ,
19251980 sourceKind == " version" ? spec.version : sourceKind);
19261981 const std::size_t selfIdx = state.dep_manifests .size () - 1 ;
1982+ state.depFeatureRequests [selfIdx] = {spec.features , spec.defaultFeatures };
19271983 // #243: forward this dep's active features to ITS children before they
19281984 // are pushed (transitive dep->dep forwarding rides the BFS forward
19291985 // edge). Uses the SAME closure inputs as mergeActiveFeatureDeps above
0 commit comments