@@ -17,7 +17,7 @@ inline void hash_combine(std::size_t& hash, const T& v) {
1717}
1818
1919uint64_t RequestHasher::operator ()(capnproto::Request::Reader reader_) const {
20- size_t hash = 0 ;
20+ size_t hash = reader_. getProcesses (). size () ;
2121 for (auto reader : reader_.getProcesses ()) {
2222 hash_combine (hash, reader.getExecutable ().which ());
2323 switch (reader.getExecutable ().which ()) {
@@ -35,7 +35,18 @@ uint64_t RequestHasher::operator()(capnproto::Request::Reader reader_) const {
3535 for (std::string arg : reader.getArgs ()) {
3636 hash_combine (hash, arg);
3737 }
38- hash_combine (hash, util::SHA256_t (reader.getStdin ()).Hex ());
38+ hash_combine (hash, reader.getStdin ().which ());
39+ switch (reader.getStdin ().which ()) {
40+ case capnproto::ProcessRequest::Stdin::FIFO:
41+ hash_combine (hash, reader.getStdin ().getFifo ());
42+ break ;
43+ case capnproto::ProcessRequest::Stdin::HASH:
44+ hash_combine (hash, util::SHA256_t (reader.getStdin ().getHash ()).Hex ());
45+ break ;
46+ }
47+ hash_combine (hash, reader.getStdout ());
48+ hash_combine (hash, reader.getStderr ());
49+ // TODO: be consistent if the files are permuted.
3950 for (auto in : reader.getInputFiles ()) {
4051 hash_combine (hash, std::string (in.getName ()));
4152 hash_combine (hash, util::SHA256_t (in.getHash ()).Hex ());
@@ -44,6 +55,10 @@ uint64_t RequestHasher::operator()(capnproto::Request::Reader reader_) const {
4455 for (std::string out : reader.getOutputFiles ()) {
4556 hash_combine (hash, out);
4657 }
58+ for (auto in : reader.getFifos ()) {
59+ hash_combine (hash, std::string (in.getName ()));
60+ hash_combine (hash, in.getId ());
61+ }
4762 hash_combine (hash, reader.getLimits ().getCpuTime ());
4863 hash_combine (hash, reader.getLimits ().getWallTime ());
4964 hash_combine (hash, reader.getLimits ().getMemory ());
@@ -84,9 +99,19 @@ bool RequestComparator::operator()(capnproto::Request::Reader a_,
8499 for (size_t i = 0 ; i < aargs.size (); i++) {
85100 if (aargs[i] != bargs[i]) return false ;
86101 }
87- if (util::SHA256_t (a.getStdin ()).Hex () !=
88- util::SHA256_t (b.getStdin ()).Hex ())
89- return false ;
102+ if (a.getStdin ().which () != b.getStdin ().which ()) return false ;
103+ switch (a.getStdin ().which ()) {
104+ case capnproto::ProcessRequest::Stdin::FIFO:
105+ if (a.getStdin ().getFifo () != b.getStdin ().getFifo ()) return false ;
106+ break ;
107+ case capnproto::ProcessRequest::Stdin::HASH:
108+ if (util::SHA256_t (a.getStdin ().getHash ()).Hex () !=
109+ util::SHA256_t (b.getStdin ().getHash ()).Hex ())
110+ return false ;
111+ break ;
112+ }
113+ if (a.getStdout () != b.getStdout ()) return false ;
114+ if (a.getStderr () != b.getStderr ()) return false ;
90115 std::vector<std::tuple<std::string, std::string, bool >> ainput;
91116 std::vector<std::tuple<std::string, std::string, bool >> binput;
92117 for (auto in : a.getInputFiles ()) {
@@ -100,6 +125,17 @@ bool RequestComparator::operator()(capnproto::Request::Reader a_,
100125 std::sort (ainput.begin (), ainput.end ());
101126 std::sort (binput.begin (), binput.end ());
102127 if (ainput != binput) return false ;
128+ std::vector<std::tuple<std::string, uint32_t >> afifo;
129+ std::vector<std::tuple<std::string, uint32_t >> bfifo;
130+ for (auto f : a.getFifos ()) {
131+ afifo.emplace_back (f.getName (), f.getId ());
132+ }
133+ for (auto f : b.getFifos ()) {
134+ bfifo.emplace_back (f.getName (), f.getId ());
135+ }
136+ std::sort (afifo.begin (), afifo.end ());
137+ std::sort (bfifo.begin (), bfifo.end ());
138+ if (afifo != bfifo) return false ;
103139 std::vector<std::string> aoutput;
104140 std::vector<std::string> boutput;
105141 for (auto out : a.getOutputFiles ()) {
@@ -132,7 +168,9 @@ std::vector<util::SHA256_t> Hashes(capnproto::Request::Reader req_,
132168 if (!hash.isZero ()) ans.push_back (hash);
133169 };
134170 for (auto req : req_.getProcesses ()) {
135- add (req.getStdin ());
171+ if (req.getStdin ().isHash ()) {
172+ add (req.getStdin ().getHash ());
173+ }
136174 if (req.getExecutable ().isLocalFile ())
137175 add (req.getExecutable ().getLocalFile ().getHash ());
138176 for (auto f : req.getInputFiles ()) add (f.getHash ());
0 commit comments