Charles-Johnson / zia_programming

A language that can program itself
https://zia-lang.org
GNU General Public License v3.0
3 stars 0 forks source link

Generalise SyntaxTree to use Rc or Arc #38

Closed Charles-Johnson closed 3 years ago

Charles-Johnson commented 3 years ago

Problem

Currently SyntaxTree stores subtrees in a std::sync::Arc so that rayon traits can be used to iterate inside ContextSearch methods in parallel.

Solution

  1. Promote SyntaxTree to a trait with an associated type SharedSyntax that can be implemented as Rc<Self> or Arc<Self> and an associated ConceptId that can match SnapShot's associated type.
  2. Use macro_rules! to define a macro to implement SyntaxTree for multiple types of reference counted smart pointers without having to repeat yourself
  3. A type parameter that impl SyntaxTree can be used to parameterise ContextSearch and Context to generalise over syntax tree types.
  4. Define a trait that ContextSearch implements that has methods that iterate on a single thread for Rc syntax trees and multiple threads for Arc syntax trees.
  5. Define convenient type aliases for Context with Arc and Rc so that consumers understand the difference.
  6. Put use of rayon behind a feature gate so that consumers don't have to compile rayon if they only want a single threaded implementation
  7. Repeat steps 1 and 2 for other recursively Arced data structures