pnnl / lamellar-runtime

Lamellar is an asynchronous tasking runtime for HPC systems developed in RUST
Other
43 stars 5 forks source link

Check for lock-acquiring-temporaries unused across function call #37

Open JosephCottam opened 9 months ago

JosephCottam commented 9 months ago

A potentail lamellar-lint: Try to detect when a temporary holds a lock but that temporary is never used again.

async fn do_stuff(table: LocalLockArray) {
   let values = table.read_local_data().await;
   let v = values[0];
   do_other_stuff(table);
}

If do_other_stuff wants to write to table, it will be blocked because the read_lock is held until do_stuff finishes. It would be nice to have a lint that (1) knows what functions grab locks and (2) indicates when those locks probably aren't needed after a certain point (and suggests the temporary be explicitly dropped).

JosephCottam commented 9 months ago

Discussion with @rdfriese , the idea of only suggesting if the locked structure is passed to another context. However, there might be difficulty around alias detection...

async fn do_stuff(table: LocalLockArray) {
   let values = table.read_local_data().await;
   let v = values[0];

   let table2 = table;
   do_other_stuff(table2);
}

Not sure when the linter runs, but if the de-aliasing isn't run yet this case would be harder to catch.