rustc shared state audit

categories

  • remove the shared state
  • seems fine, just document the invariants
  • requires careful examination

for follow-up

  • How much does determinism matter? E.g. for allocating IDs?
  • Document concurrency primitives that are more restrictive than locks, with guidance on how o use them, to help guide audit/refactor process

list

  • Attribute ID generation
  • mk_attr_id in libsyntax::attr (source)
  • Atomic increment
  • SEEMS FINE
  • Error handling librustc_errors::Handler (source)
  • NEEDS AUDIT AND/OR REFACTOR
  • Or… could pull the lock out to the top of the struct, to avoid the need for fine-grained invariants
  • Possibly drop lock in favor of thread-local error handler with end-of-compilation sync
  • librustc_data_structures::TransitiveRelation
  • State used for lazy caching
  • where ‘a: ‘b, ‘c: ‘d, ‘b: ‘c ‘a: ‘c
  • Unclear whether this is ever mutated across threads
  • REFACTOR
  • Lets see if we can change this back to a RefCell, or otherwise eliminate the need for a lock
  • Session
  • profile_channel field (for -Z profile-queries)
  • Uses a Lock around an Option<mpsc::Sender>
  • Could probably be simprlified
  • one_time_diagnostics ensuring that redundant diagnostics aren’t emitted
  • fuel fields using LockCell, not clear whether this actually makes sense
  • later changed to use a Lock around multiple values
  • trait_methods_not_found uses a Lock
  • Ultimately want to get rid of this structure as part of end-to-end queries
  • AUDIT AND DOCUMENT
  • Ideal refactor is to move the shared state into queries, but the session data is populated prior to the query system being available
  • Probably lots  of opportunities to refactor
  • ParseSess
  • registered_diagnostics, a locked map
  • AUDIT AND DOCUMENT (same as above)
  • “Globals” in libsyntax and libsyntax_pos
  • GLOBALS, scoped TLS holding lock-protected data structures
  • Not clear how these “globals” are shared with worker threads…
  • Keep span interning and some of the hygiene data
  • Used pretty much anywhere you work with spans
  • This could probably be improved with an updated version of Rayon
  • SHOULD REFACTOR TO USE NEW RAYON MECHANISM FOR PASSING TO  CHILD THREADS
  • AUDIT AND DOCUMENT LOCKS WITHIN Globals
  • CrateMetadata and CStore
  • Locks around individual fields
  • Gets created early and lives a long time
  • AUDIT AND DOCUMENT