News for hackers. Stuff that matters.
Re:I’m porting the TypeScript type checker tsc to Go by speedgoose on Tuesday January 25, 2022 @02:16PM (#30076575)
I think the point is valid. As a rust beginner I tried to make a graph data structure and it was difficult. Using RefCell is not very nice because it moves the problem from compile time to runtime and you still can’t mutate the same data structure more than once at the same time.
Re:I’m porting the TypeScript type checker tsc to Go by m-hilgendorf on Tuesday January 25, 2022 @05:53PM (#30079278)
Rust encourages you to use an adjacent list/matrix for your graph representation, which is preferable almost all of the time for graph algorithms. It's a little unwieldy if the graph needs to be mutable during the core algorithms, but almost all algorithms in practice assume it will be stable.
Re:I’m porting the TypeScript type checker tsc to Go by tomcam on Tuesday January 25, 2022 @02:35PM (#30076838)
This is interesting but I don't know Rust. Presumably your graph data structure grows dynamically, meaning you have to add nodes at runtime. When. you say you can't mutate the same data structure more than once at runtime, what does it mean? That you can't set both a parent and a child pointer in the same function, or what?
Re:I’m porting the TypeScript type checker tsc to Go by speedgoose on Tuesday January 25, 2022 @04:11PM (#30078089)
I’m very far from being a rust expert but it was difficult to build a bi-directional graph because it’s difficult to connect the nodes together. A simple recursive algorithm will not work. I ended up using a crate.

I found the following article interesting on the topic : https://aminb.gitbooks.io/rust-for-c/content/graphs/

Re:I’m porting the TypeScript type checker tsc to Go by jupp0r on Tuesday January 25, 2022 @05:57PM (#30079316)
It shouldn't be difficult:

1. You have a graph struct that has ownership of all nodes (in Rc containers).

2. Nodes have Weak references to connected nodes

Re:I’m porting the TypeScript type checker tsc to Go by bobbylarrybobby on Tuesday January 25, 2022 @06:00PM (#30079344)
In the case of RefCell, when you begin modifying its data, you’re not allowed to begin modifying its data a second time without declaring “I’m done” with the first modification. This makes doing several modifications in different places that are interspersed with each other tricky because it’s hard to reason about when each spot is actually done so that a modification can be performed elsewhere. (If your program is single threaded it’s possible you don’t even care about mutation happening in multiple places, but Rust cares because in general Rust programs need not be single threaded.)
Re:I’m porting the TypeScript type checker tsc to Go by throw10920 on Thursday January 27, 2022 @09:52AM (#30101254)
Rust doesn't allow you to relax mutation constraints for a single-threaded program?