PreviousUpNext

15.4.59  src/app/makelib/depend/indegrees-of-library-dependency-graph.pkg

## indegrees-of-library-dependency-graph.pkg

# Compiled by:
#     src/app/makelib/makelib.sublib



# Calculate a map of in-degrees
# (that is, the number of SML_NODEs
# that depend on it) for each THAWEDLIB_TOME.
#
# The in-degree of a node can serve
# as a hint for prioritizing
# compilations during parallel make.



###                 "Easy writing makes damned hard reading."
###
###                              -- Richard Brinsley Sheridan 



stipulate
    package lg  =  inter_library_dependency_graph;              # inter_library_dependency_graph        is from   src/app/makelib/depend/inter-library-dependency-graph.pkg
    package ttm =  thawedlib_tome_map;                          # thawedlib_tome_map                    is from   src/app/makelib/compilable/thawedlib-tome-map.pkg
herein

    api Indegrees_Of_Library_Dependency_Graph {
        #
        compute__node_to_indegree__map_of                       # Compute, for each node in graph, number of directed edges entering it, return as a node-to-indegree map.
            :
            lg::Inter_Library_Dependency_Graph                  # Dependency graph to analyze.
            ->
            ttm::Map(Int);                                      # Result map from thawedlib_tome nodes to in-degree counts.
    };
end;



stipulate
    package lg  =  inter_library_dependency_graph;              # inter_library_dependency_graph        is from   src/app/makelib/depend/inter-library-dependency-graph.pkg
    package sg  =  intra_library_dependency_graph;              # intra_library_dependency_graph        is from   src/app/makelib/depend/intra-library-dependency-graph.pkg
    package sym =  symbol_map;                                  # symbol_map                            is from   src/app/makelib/stuff/symbol-map.pkg
    package ttm =  thawedlib_tome_map;                          # thawedlib_tome_map                    is from   src/app/makelib/compilable/thawedlib-tome-map.pkg
herein

    package   indegrees_of_library_dependency_graph
    :         Indegrees_Of_Library_Dependency_Graph
    {
        # This is (only) called once in:
        #
        #     src/app/makelib/compile/compile-in-dependency-order-g.pkg
        #
        fun compute__node_to_indegree__map_of (lg::LIBRARY { catalog, ... } )
                =>
                {   fun do_masked_tome sn ({ exports_mask, tome_tin => sg::TOME_IN_THAWEDLIB tome }: sg::Masked_Tome, indegree_map)
                            =>
                            sn (tome, indegree_map);

                        do_masked_tome _ (_, indegree_map)
                            =>
                            indegree_map;
                    end;


                    fun increment_thawedlib_tome (sg::THAWEDLIB_TOME_TIN { thawedlib_tome, ... }, indegree_map)
                        =
                        ttm::set (indegree_map, thawedlib_tome, 1 + the_else (ttm::get (indegree_map, thawedlib_tome), 0));


                    fun do_thawedlib_tome_tin  (sg::THAWEDLIB_TOME_TIN  thawedlib_tome,  indegree_map)
                        =
                        {   thawedlib_tome
                              ->
                              { thawedlib_tome,
                                near_imports,
                                far_imports
                              };


                            indegree_map
                                =
                                case (ttm::get (indegree_map, thawedlib_tome))
                                    #
                                    THE _ =>   indegree_map;
                                    #
                                    NULL  =>
                                        fold_forward
                                            do_thawedlib_tome_tin
                                            (   fold_forward (do_masked_tome  do_thawedlib_tome_tin)
                                                      (ttm::set (indegree_map, thawedlib_tome, 0))
                                                      far_imports
                                            )
                                            near_imports;
                                esac;

                            fold_forward
                                increment_thawedlib_tome
                                (fold_forward  (do_masked_tome  increment_thawedlib_tome)  indegree_map  far_imports)
                                near_imports;
                        };


                    fun do_fat_tome   (fat_tome: lg::Fat_Tome,   indegree_map)
                        =
                        do_masked_tome  do_thawedlib_tome_tin  (fat_tome.masked_tome_thunk(),  indegree_map);


                    sym::fold_forward
                        do_fat_tome
                        ttm::empty
                        catalog;
                };


            compute__node_to_indegree__map_of  lg::BAD_LIBRARY
                =>
                ttm::empty;
        end;                                                                            # fun indegrees
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext