1 // Copyright (c) Facebook, Inc. and its affiliates.
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
6 use dashmap::{mapref::entry::Entry, DashMap};
7 use depgraph_api::{DeclName, DepGraphWriter, DependencyName, Result};
8 use std::collections::HashSet;
10 pub type DeclNameSet = HashSet<DeclName>;
12 #[derive(Debug, Clone)]
13 pub struct DependencyGraph {
14 // We store the dependency edges in "reverse dependency" fashion (rdeps)
18 // class B extends A {}
21 // Extends(A) : {Type(B)}
22 pub rdeps: DashMap<DependencyName, DeclNameSet>,
25 impl DependencyGraph {
26 pub fn new() -> Self {
28 rdeps: DashMap::new(),
33 impl DepGraphWriter for DependencyGraph {
34 fn add_dependency(&self, dependent: DeclName, dependency: DependencyName) -> Result<()> {
35 match self.rdeps.entry(dependency) {
37 let mut dependents: DeclNameSet = DeclNameSet::new();
38 dependents.insert(dependent);
41 Entry::Occupied(mut e) => {
42 e.get_mut().insert(dependent);