Forráskód Böngészése

Avoid default captures in lambda expressions

That way we're intentional about each capture by reference or value
Ian Goldberg 1 éve
szülő
commit
1216a94599
5 módosított fájl, 34 hozzáadás és 33 törlés
  1. 13 12
      duoram.tcc
  2. 1 1
      mpcops.cpp
  3. 6 6
      online.cpp
  4. 10 10
      preproc.cpp
  5. 4 4
      rdpf.cpp

+ 13 - 12
duoram.tcc

@@ -175,11 +175,11 @@ void Duoram<T>::Flat::bitonic_sort(address_t start, nbits_t depth, bool dir)
     // Recurse on the first half (increasing order) and the second half
     // (decreasing order) in parallel
     run_coroutines(this->yield,
-        [&](yield_t &yield) {
+        [this, start, depth](yield_t &yield) {
             Flat Acoro = context(yield);
             Acoro.bitonic_sort(start, depth-1, 0);
         },
-        [&](yield_t &yield) {
+        [this, start, depth](yield_t &yield) {
             Flat Acoro = context(yield);
             Acoro.bitonic_sort(start+(1<<(depth-1)), depth-1, 1);
         });
@@ -200,19 +200,20 @@ void Duoram<T>::Flat::butterfly(address_t start, nbits_t depth, bool dir)
     address_t halfwidth = address_t(1)<<(depth-1);
     std::vector<coro_t> coroutines;
     for (address_t i=0; i<halfwidth;++i) {
-        coroutines.emplace_back([&, i](yield_t &yield) {
-            Flat Acoro = context(yield);
-            Acoro.osort(start+i, start+i+halfwidth, dir);
-        });
+        coroutines.emplace_back(
+            [this, start, halfwidth, dir, i](yield_t &yield) {
+                Flat Acoro = context(yield);
+                Acoro.osort(start+i, start+i+halfwidth, dir);
+            });
     }
     run_coroutines(this->yield, coroutines);
     // Recurse on each half in parallel
     run_coroutines(this->yield,
-        [&](yield_t &yield) {
+        [this, start, depth, dir](yield_t &yield) {
             Flat Acoro = context(yield);
             Acoro.butterfly(start, depth-1, dir);
         },
-        [&](yield_t &yield) {
+        [this, start, halfwidth, depth, dir](yield_t &yield) {
             Flat Acoro = context(yield);
             Acoro.butterfly(start+halfwidth, depth-1, dir);
         });
@@ -470,11 +471,11 @@ void Duoram<RegAS>::Flat::osort(const U &idx1, const V &idx2, bool dir)
     // Load the values in parallel
     RegAS val1, val2;
     run_coroutines(yield,
-        [&](yield_t &yield) {
+        [this, &idx1, &val1](yield_t &yield) {
             Flat Acoro = context(yield);
             val1 = Acoro[idx1];
         },
-        [&](yield_t &yield) {
+        [this, &idx2, &val2](yield_t &yield) {
             Flat Acoro = context(yield);
             val2 = Acoro[idx2];
         });
@@ -489,11 +490,11 @@ void Duoram<RegAS>::Flat::osort(const U &idx1, const V &idx2, bool dir)
     mpc_flagmult(tio, yield, cmp_diff, cmp, diff);
     // Update the two locations in parallel
     run_coroutines(yield,
-        [&](yield_t &yield) {
+        [this, &idx1, &cmp_diff](yield_t &yield) {
             Flat Acoro = context(yield);
             Acoro[idx1] -= cmp_diff;
         },
-        [&](yield_t &yield) {
+        [this, &idx2, &cmp_diff](yield_t &yield) {
             Flat Acoro = context(yield);
             Acoro[idx2] += cmp_diff;
         });

+ 1 - 1
mpcops.cpp

@@ -190,7 +190,7 @@ void mpc_xs_to_as(MPCTIO &tio, yield_t &yield,
     std::vector<coro_t> coroutines;
     for (nbits_t i=0; i<nbits-1; ++i) {
         coroutines.emplace_back(
-            [&, i](yield_t &yield) {
+            [&tio, &as_bitand, &xs_x, i, nbits](yield_t &yield) {
                 mpc_valuemul(tio, yield, as_bitand[i], (xs_x.xshare>>i)&1, nbits);
             });
     }

+ 6 - 6
online.cpp

@@ -44,23 +44,23 @@ static void online_test(MPCIO &mpcio, yield_t &yield,
     }
     std::vector<coro_t> coroutines;
     coroutines.emplace_back(
-        [&](yield_t &yield) {
+        [&tio, &A, nbits](yield_t &yield) {
             mpc_mul(tio, yield, A[2], A[0], A[1], nbits);
         });
     coroutines.emplace_back(
-        [&](yield_t &yield) {
+        [&tio, &A, V, nbits](yield_t &yield) {
             mpc_valuemul(tio, yield, A[3], V, nbits);
         });
     coroutines.emplace_back(
-        [&](yield_t &yield) {
+        [&tio, &A, &F0, nbits](yield_t &yield) {
             mpc_flagmult(tio, yield, A[5], F0, A[4], nbits);
         });
     coroutines.emplace_back(
-        [&](yield_t &yield) {
+        [&tio, &A, &F1, nbits](yield_t &yield) {
             mpc_oswap(tio, yield, A[6], A[7], F1, nbits);
         });
     coroutines.emplace_back(
-        [&](yield_t &yield) {
+        [&tio, &A, &X, nbits](yield_t &yield) {
             mpc_xs_to_as(tio, yield, A[8], X, nbits);
         });
     run_coroutines(yield, coroutines);
@@ -828,7 +828,7 @@ void online_main(MPCIO &mpcio, const PRACOptions &opts, char **args)
     // to start one themselves
     MPCTIO tio(mpcio, 0);
     run_coroutines(tio,
-        [&](yield_t &yield) {
+        [&mpcio, &opts, &args](yield_t &yield) {
             if (!*args) {
                 std::cerr << "Mode is required as the first argument when not preprocessing.\n";
                 return;

+ 10 - 10
preproc.cpp

@@ -98,7 +98,7 @@ void preprocessing_comp(MPCIO &mpcio, const PRACOptions &opts, char **args)
 
                     for (unsigned int i=0; i<num; ++i) {
                         coroutines.emplace_back(
-                            [&, tripfile](yield_t &yield) {
+                            [&tio, tripfile](yield_t &yield) {
                                 yield();
                                 MultTriple T = tio.triple(yield);
                                 tripfile.os() << T;
@@ -111,7 +111,7 @@ void preprocessing_comp(MPCIO &mpcio, const PRACOptions &opts, char **args)
 
                     for (unsigned int i=0; i<num; ++i) {
                         coroutines.emplace_back(
-                            [&, halffile](yield_t &yield) {
+                            [&tio, halffile](yield_t &yield) {
                                 yield();
                                 HalfTriple H = tio.halftriple(yield);
                                 halffile.os() << H;
@@ -123,7 +123,7 @@ void preprocessing_comp(MPCIO &mpcio, const PRACOptions &opts, char **args)
                         mpcio.player, thread_num, type);
                     for (unsigned int i=0; i<num; ++i) {
                         coroutines.emplace_back(
-                            [&, tripfile, type](yield_t &yield) {
+                            [&tio, &opts, tripfile, type](yield_t &yield) {
                                 yield();
                                 RDPFTriple rdpftrip =
                                     tio.rdpftriple(yield, type, opts.expand_rdpfs);
@@ -144,7 +144,7 @@ void preprocessing_comp(MPCIO &mpcio, const PRACOptions &opts, char **args)
 
                     for (unsigned int i=0; i<num; ++i) {
                         coroutines.emplace_back(
-                            [&, cdpffile](yield_t &yield) {
+                            [&tio, cdpffile](yield_t &yield) {
                                 yield();
                                 CDPF C = tio.cdpf(yield);
                                 cdpffile.os() << C;
@@ -152,7 +152,7 @@ void preprocessing_comp(MPCIO &mpcio, const PRACOptions &opts, char **args)
                     }
                 } else if (type == 0x82) {
                     coroutines.emplace_back(
-                        [&, num](yield_t &yield) {
+                        [&tio, num](yield_t &yield) {
                             yield();
                             unsigned int istart = 0x31415080;
                             for (unsigned int i=istart; i<istart+num; ++i) {
@@ -226,7 +226,7 @@ void preprocessing_server(MPCServerIO &mpcsrvio, const PRACOptions &opts, char *
 
                     for (unsigned int i=0; i<num; ++i) {
                         coroutines.emplace_back(
-                            [&](yield_t &yield) {
+                            [&stio](yield_t &yield) {
                                 yield();
                                 stio.triple(yield);
                             });
@@ -240,7 +240,7 @@ void preprocessing_server(MPCServerIO &mpcsrvio, const PRACOptions &opts, char *
 
                     for (unsigned int i=0; i<num; ++i) {
                         coroutines.emplace_back(
-                            [&](yield_t &yield) {
+                            [&stio](yield_t &yield) {
                                 yield();
                                 stio.halftriple(yield);
                             });
@@ -260,7 +260,7 @@ void preprocessing_server(MPCServerIO &mpcsrvio, const PRACOptions &opts, char *
                             mpcsrvio.player, thread_num, depth);
                         for (unsigned int i=0; i<num; ++i) {
                             coroutines.emplace_back(
-                                [&, pairfile, depth](yield_t &yield) {
+                                [&stio, &opts, pairfile, depth](yield_t &yield) {
                                     yield();
                                     RDPFPair rdpfpair = stio.rdpfpair(yield, depth);
                                 printf("usi0 = %016lx\n", rdpfpair.dpf[0].unit_sum_inverse);
@@ -286,7 +286,7 @@ void preprocessing_server(MPCServerIO &mpcsrvio, const PRACOptions &opts, char *
 
                     for (unsigned int i=0; i<num; ++i) {
                         coroutines.emplace_back(
-                            [&](yield_t &yield) {
+                            [&stio](yield_t &yield) {
                                 yield();
                                 stio.cdpf(yield);
                             });
@@ -299,7 +299,7 @@ void preprocessing_server(MPCServerIO &mpcsrvio, const PRACOptions &opts, char *
                     stio.queue_p1(&num, 4);
 
                     coroutines.emplace_back(
-                        [&, num] (yield_t &yield) {
+                        [&stio, num] (yield_t &yield) {
                             unsigned int istart = 0x31415080;
                             yield();
                             for (unsigned int i=istart; i<istart+num; ++i) {

+ 4 - 4
rdpf.cpp

@@ -133,14 +133,14 @@ RDPF::RDPF(MPCTIO &tio, yield_t &yield,
         // Exchange the parities and do mpc_reconstruct_choice at the
         // same time (bundled into the same rounds)
         run_coroutines(yield,
-            [&](yield_t &yield) {
+            [this, &tio, &our_parity_bit, &peer_parity_bit](yield_t &yield) {
                 tio.queue_peer(&our_parity_bit, 1);
                 yield();
                 uint8_t peer_parity_byte;
                 tio.recv_peer(&peer_parity_byte, 1);
                 peer_parity_bit = peer_parity_byte & 1;
             },
-            [&](yield_t &yield) {
+            [this, &tio, &CW, &L, &R, &bs_choice, &our_parity](yield_t &yield) {
                 mpc_reconstruct_choice(tio, yield, CW, bs_choice,
                     (R ^ our_parity), L);
             });
@@ -319,13 +319,13 @@ RDPFTriple::RDPFTriple(MPCTIO &tio, yield_t &yield,
     std::vector<coro_t> coroutines;
     for (int i=0;i<3;++i) {
         coroutines.emplace_back(
-            [&, i](yield_t &yield) {
+            [this, &tio, depth, i, save_expansion](yield_t &yield) {
                 dpf[i] = RDPF(tio, yield, xs_target, depth,
                     save_expansion);
             });
     }
     coroutines.emplace_back(
-        [&](yield_t &yield) {
+        [this, &tio, depth](yield_t &yield) {
             mpc_xs_to_as(tio, yield, as_target, xs_target, depth);
         });
     run_coroutines(yield, coroutines);