aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-15 21:19:38 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-15 21:19:38 +0100
commitd76f838b1a492c9bd973c5917309391c23bf2ef8 (patch)
tree6ac75ce6cdfe6c3902781989b52c6494d48db197
parent57a5ecb744348698b3781bdbcd4aacd7014b7a70 (diff)
downloadpaludis-d76f838b1a492c9bd973c5917309391c23bf2ef8.tar.gz
paludis-d76f838b1a492c9bd973c5917309391c23bf2ef8.tar.xz
Serialise and export the NAG
-rw-r--r--paludis/resolver/lineariser.cc24
-rw-r--r--paludis/resolver/nag.cc71
-rw-r--r--paludis/resolver/nag.hh7
-rw-r--r--paludis/resolver/resolved.cc4
-rw-r--r--paludis/resolver/resolved.hh3
-rw-r--r--paludis/resolver/resolver.cc2
6 files changed, 96 insertions, 15 deletions
diff --git a/paludis/resolver/lineariser.cc b/paludis/resolver/lineariser.cc
index 101bb1c..daa9399 100644
--- a/paludis/resolver/lineariser.cc
+++ b/paludis/resolver/lineariser.cc
@@ -58,15 +58,13 @@ namespace paludis
{
const Environment * const env;
const std::tr1::shared_ptr<Resolved> resolved;
- const std::tr1::shared_ptr<NAG> nag;
ChangeOrRemoveResolvents change_or_remove_resolvents;
Implementation(
const Environment * const e,
const std::tr1::shared_ptr<Resolved> & r) :
env(e),
- resolved(r),
- nag(new NAG)
+ resolved(r)
{
}
};
@@ -90,7 +88,6 @@ namespace
struct DecisionDispatcher
{
const std::tr1::shared_ptr<Resolved> resolved;
- const std::tr1::shared_ptr<NAG> nag;
ResolventsSet & ignore_dependencies_from_resolvents;
ChangeOrRemoveResolvents & change_or_remove_resolvents;
const Resolvent resolvent;
@@ -98,13 +95,11 @@ namespace
DecisionDispatcher(
const std::tr1::shared_ptr<Resolved> & r,
- const std::tr1::shared_ptr<NAG> & n,
ResolventsSet & i,
ChangeOrRemoveResolvents & c,
const Resolvent & v,
const std::tr1::shared_ptr<const Decision> & d) :
resolved(r),
- nag(n),
ignore_dependencies_from_resolvents(i),
change_or_remove_resolvents(c),
resolvent(v),
@@ -126,13 +121,13 @@ namespace
bool visit(const NothingNoChangeDecision &)
{
- nag->add_node(resolvent);
+ resolved->nag()->add_node(resolvent);
return true;
}
bool visit(const ExistingNoChangeDecision &)
{
- nag->add_node(resolvent);
+ resolved->nag()->add_node(resolvent);
return true;
}
@@ -140,7 +135,7 @@ namespace
{
if (decision->taken())
{
- nag->add_node(resolvent);
+ resolved->nag()->add_node(resolvent);
change_or_remove_resolvents.insert(std::make_pair(resolvent,
std::tr1::static_pointer_cast<const ChangeOrRemoveDecision>(decision)));
return true;
@@ -156,7 +151,7 @@ namespace
{
if (decision->taken())
{
- nag->add_node(resolvent);
+ resolved->nag()->add_node(resolvent);
change_or_remove_resolvents.insert(std::make_pair(resolvent,
std::tr1::static_pointer_cast<const ChangeOrRemoveDecision>(decision)));
return true;
@@ -326,7 +321,6 @@ Lineariser::resolve()
{
DecisionDispatcher decision_dispatcher(
_imp->resolved,
- _imp->nag,
ignore_dependencies_from_resolvents,
_imp->change_or_remove_resolvents,
(*r)->resolvent(),
@@ -344,17 +338,17 @@ Lineariser::resolve()
if (ignore_dependencies_from_resolvents.end() != ignore_edges_from_resolvents.find((*r)->resolvent()))
continue;
- EdgesFromReasonVisitor edges_from_reason_visitor(_imp->nag, ignore_dependencies_from_resolvents, (*r)->resolvent());
+ EdgesFromReasonVisitor edges_from_reason_visitor(_imp->resolved->nag(), ignore_dependencies_from_resolvents, (*r)->resolvent());
for (Constraints::ConstIterator c((*r)->constraints()->begin()),
c_end((*r)->constraints()->end()) ;
c != c_end ; ++c)
(*c)->reason()->accept(edges_from_reason_visitor);
}
- _imp->nag->verify_edges();
+ _imp->resolved->nag()->verify_edges();
_imp->env->trigger_notifier_callback(NotifierCallbackResolverStageEvent("Finding NAG SCCs"));
- const std::tr1::shared_ptr<const SortedStronglyConnectedComponents> ssccs(_imp->nag->sorted_strongly_connected_components());
+ const std::tr1::shared_ptr<const SortedStronglyConnectedComponents> ssccs(_imp->resolved->nag()->sorted_strongly_connected_components());
_imp->env->trigger_notifier_callback(NotifierCallbackResolverStageEvent("Linearising SCCs"));
for (SortedStronglyConnectedComponents::ConstIterator scc(ssccs->begin()), scc_end(ssccs->end()) ;
@@ -397,7 +391,7 @@ Lineariser::resolve()
scc_nag.add_node(*r);
/* we only need edges inside our SCC, and only those to other
* change or remove nodes */
- for (NAG::EdgesFromConstIterator e(_imp->nag->begin_edges_from(*r)), e_end(_imp->nag->end_edges_from(*r)) ;
+ for (NAG::EdgesFromConstIterator e(_imp->resolved->nag()->begin_edges_from(*r)), e_end(_imp->resolved->nag()->end_edges_from(*r)) ;
e != e_end ; ++e)
if (changes_in_scc.end() != changes_in_scc.find(e->first))
scc_nag.add_edge(*r, e->first, e->second);
diff --git a/paludis/resolver/nag.cc b/paludis/resolver/nag.cc
index 50dd250..04a48a5 100644
--- a/paludis/resolver/nag.cc
+++ b/paludis/resolver/nag.cc
@@ -30,6 +30,7 @@
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/member_iterator-impl.hh>
+#include <paludis/serialise-impl.hh>
#include <tr1/unordered_set>
#include <tr1/unordered_map>
#include <algorithm>
@@ -268,6 +269,52 @@ NAG::end_edges_from(const Resolvent & r) const
return EdgesFromConstIterator(e->second.end());
}
+void
+NAG::serialise(Serialiser & s) const
+{
+ SerialiserObjectWriter w(s.object("NAG"));
+ w.member(SerialiserFlags<serialise::container>(), "nodes", _imp->nodes);
+
+ int c(0);
+ for (Edges::const_iterator e(_imp->edges.begin()), e_end(_imp->edges.end()) ;
+ e != e_end ; ++e)
+ {
+ for (NodesWithProperties::const_iterator n(e->second.begin()), n_end(e->second.end()) ;
+ n != n_end ; ++n)
+ {
+ ++c;
+ w.member(SerialiserFlags<>(), "edge." + stringify(c) + ".f", e->first);
+ w.member(SerialiserFlags<>(), "edge." + stringify(c) + ".t", n->first);
+ w.member(SerialiserFlags<>(), "edge." + stringify(c) + ".p", n->second);
+ }
+ }
+
+ w.member(SerialiserFlags<>(), "edge.count", stringify(c));
+}
+
+const std::tr1::shared_ptr<NAG>
+NAG::deserialise(Deserialisation & d)
+{
+ Deserialisator v(d, "NAG");
+ std::tr1::shared_ptr<NAG> result(new NAG);
+
+ {
+ Deserialisator vv(*v.find_remove_member("nodes"), "c");
+ for (int n(1), n_end(vv.member<int>("count") + 1) ; n != n_end ; ++n)
+ result->add_node(vv.member<Resolvent>(stringify(n)));
+ }
+
+ for (int n(1), n_end(v.member<int>("edge.count") + 1) ; n != n_end ; ++n)
+ result->add_edge(
+ v.member<Resolvent>("edge." + stringify(n) + ".f"),
+ v.member<Resolvent>("edge." + stringify(n) + ".t"),
+ v.member<NAGEdgeProperties>("edge." + stringify(n) + ".p")
+ );
+
+ result->verify_edges();
+ return result;
+}
+
NAGEdgeProperties &
NAGEdgeProperties::operator|= (const NAGEdgeProperties & other)
{
@@ -276,5 +323,29 @@ NAGEdgeProperties::operator|= (const NAGEdgeProperties & other)
return *this;
}
+void
+NAGEdgeProperties::serialise(Serialiser & s) const
+{
+ s.object("NAGEdgeProperties")
+ .member(SerialiserFlags<>(), "build", build())
+ .member(SerialiserFlags<>(), "build_all_met", build_all_met())
+ .member(SerialiserFlags<>(), "run", run())
+ .member(SerialiserFlags<>(), "run_all_met", run_all_met())
+ ;
+}
+
+const NAGEdgeProperties
+NAGEdgeProperties::deserialise(Deserialisation & d)
+{
+ Deserialisator v(d, "NAGEdgeProperties");
+
+ return make_named_values<NAGEdgeProperties>(
+ n::build() = v.member<bool>("build"),
+ n::build_all_met() = v.member<bool>("build_all_met"),
+ n::run() = v.member<bool>("run"),
+ n::run_all_met() = v.member<bool>("run_all_met")
+ );
+}
+
template class WrappedForwardIterator<NAG::EdgesFromConstIteratorTag, const std::pair<const Resolvent, NAGEdgeProperties> >;
diff --git a/paludis/resolver/nag.hh b/paludis/resolver/nag.hh
index 5639856..f9f0ea8 100644
--- a/paludis/resolver/nag.hh
+++ b/paludis/resolver/nag.hh
@@ -26,6 +26,7 @@
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/named_value.hh>
+#include <paludis/serialise-fwd.hh>
#include <tr1/memory>
namespace paludis
@@ -48,6 +49,9 @@ namespace paludis
NamedValue<n::run_all_met, bool> run_all_met;
NAGEdgeProperties & operator|= (const NAGEdgeProperties &);
+
+ void serialise(Serialiser &) const;
+ static const NAGEdgeProperties deserialise(Deserialisation & d) PALUDIS_ATTRIBUTE((warn_unused_result));
};
class NAG :
@@ -69,6 +73,9 @@ namespace paludis
typedef WrappedForwardIterator<EdgesFromConstIteratorTag, const std::pair<const Resolvent, NAGEdgeProperties> > EdgesFromConstIterator;
EdgesFromConstIterator begin_edges_from(const Resolvent &) const PALUDIS_ATTRIBUTE((warn_unused_result));
EdgesFromConstIterator end_edges_from(const Resolvent &) const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ void serialise(Serialiser &) const;
+ static const std::tr1::shared_ptr<NAG> deserialise(Deserialisation & d) PALUDIS_ATTRIBUTE((warn_unused_result));
};
}
diff --git a/paludis/resolver/resolved.cc b/paludis/resolver/resolved.cc
index dcf8a48..9609899 100644
--- a/paludis/resolver/resolved.cc
+++ b/paludis/resolver/resolved.cc
@@ -22,6 +22,7 @@
#include <paludis/resolver/decision.hh>
#include <paludis/resolver/resolutions_by_resolvent.hh>
#include <paludis/resolver/work_lists.hh>
+#include <paludis/resolver/nag.hh>
#include <paludis/util/make_named_values.hh>
#include <paludis/serialise-impl.hh>
@@ -32,6 +33,7 @@ void
Resolved::serialise(Serialiser & s) const
{
s.object("Resolved")
+ .member(SerialiserFlags<serialise::might_be_null>(), "nag", nag())
.member(SerialiserFlags<serialise::might_be_null>(), "resolutions_by_resolvent", resolutions_by_resolvent())
.member(SerialiserFlags<serialise::might_be_null>(), "taken_change_or_remove_decisions", taken_change_or_remove_decisions())
.member(SerialiserFlags<serialise::might_be_null>(), "taken_unable_to_make_decisions", taken_unable_to_make_decisions())
@@ -48,6 +50,8 @@ Resolved::deserialise(Deserialisation & d)
Deserialisator v(d, "Resolved");
return make_named_values<Resolved>(
+ n::nag() =
+ v.member<std::tr1::shared_ptr<NAG> >("nag"),
n::resolutions_by_resolvent() =
v.member<std::tr1::shared_ptr<ResolutionsByResolvent> >("resolutions_by_resolvent"),
n::taken_change_or_remove_decisions() =
diff --git a/paludis/resolver/resolved.hh b/paludis/resolver/resolved.hh
index 54a7dac..60e4454 100644
--- a/paludis/resolver/resolved.hh
+++ b/paludis/resolver/resolved.hh
@@ -25,6 +25,7 @@
#include <paludis/resolver/resolutions_by_resolvent-fwd.hh>
#include <paludis/resolver/decision-fwd.hh>
#include <paludis/resolver/work_lists-fwd.hh>
+#include <paludis/resolver/nag-fwd.hh>
#include <paludis/util/named_value.hh>
#include <paludis/serialise-fwd.hh>
#include <tr1/memory>
@@ -33,6 +34,7 @@ namespace paludis
{
namespace n
{
+ typedef Name<struct nag_name> nag;
typedef Name<struct resolutions_by_resolvent_name> resolutions_by_resolvent;
typedef Name<struct taken_change_or_remove_decisions_name> taken_change_or_remove_decisions;
typedef Name<struct taken_unable_to_make_decisions_name> taken_unable_to_make_decisions;
@@ -46,6 +48,7 @@ namespace paludis
{
struct Resolved
{
+ NamedValue<n::nag, std::tr1::shared_ptr<NAG> > nag;
NamedValue<n::resolutions_by_resolvent, std::tr1::shared_ptr<ResolutionsByResolvent> > resolutions_by_resolvent;
NamedValue<n::taken_change_or_remove_decisions, std::tr1::shared_ptr<ChangeOrRemoveDecisionsWithNotes> > taken_change_or_remove_decisions;
NamedValue<n::taken_unable_to_make_decisions, std::tr1::shared_ptr<Decisions<UnableToMakeDecision> > > taken_unable_to_make_decisions;
diff --git a/paludis/resolver/resolver.cc b/paludis/resolver/resolver.cc
index b52fe7e..3706476 100644
--- a/paludis/resolver/resolver.cc
+++ b/paludis/resolver/resolver.cc
@@ -28,6 +28,7 @@
#include <paludis/resolver/decisions.hh>
#include <paludis/resolver/work_list.hh>
#include <paludis/resolver/work_lists.hh>
+#include <paludis/resolver/nag.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/sequence.hh>
@@ -63,6 +64,7 @@ namespace paludis
env(e),
fns(f),
resolved(new Resolved(make_named_values<Resolved>(
+ n::nag() = make_shared_ptr(new NAG),
n::resolutions_by_resolvent() = make_shared_ptr(new ResolutionsByResolvent),
n::taken_change_or_remove_decisions() = make_shared_ptr(new ChangeOrRemoveDecisionsWithNotes),
n::taken_unable_to_make_decisions() = make_shared_ptr(new Decisions<UnableToMakeDecision>),