PreviousUpNext

15.4.57  src/app/makelib/depend/check-sharing.pkg

## check-sharing.pkg
## (C) 1999 Lucent Technologies, Bell Laboratories
## Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)

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


# Check for consistency of "private" and "shared" annotations.


stipulate
    package lg  =  inter_library_dependency_graph;              # inter_library_dependency_graph        is from   src/app/makelib/depend/inter-library-dependency-graph.pkg
    package sym =  symbol_map;                                  # symbol_map                            is from   src/app/makelib/stuff/symbol-map.pkg
herein

    api Check_Sharing {
        #
         check:  (sym::Map( lg::Fat_Tome )
                  , makelib_state::Makelib_State)
                 -> Void;
    };
end;



stipulate
    package err =  error_message;                               # error_message                         is from   src/lib/compiler/front/basics/errormsg/error-message.pkg
    package flt =  frozenlib_tome;                              # frozenlib_tome                        is from   src/app/makelib/freezefile/frozenlib-tome.pkg
    package lg  =  inter_library_dependency_graph;              # inter_library_dependency_graph        is from   src/app/makelib/depend/inter-library-dependency-graph.pkg
    package pp  =  prettyprint;                                 # prettyprint                           is from   src/lib/prettyprint/big/src/prettyprint.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 tlt =  thawedlib_tome;                              # thawedlib_tome                        is from   src/app/makelib/compilable/thawedlib-tome.pkg
    package ttm =  thawedlib_tome_map;                          # thawedlib_tome_map                    is from   src/app/makelib/compilable/thawedlib-tome-map.pkg
herein

    package   check_sharing
    :         Check_Sharing                                     # Check_Sharing                         is from   src/app/makelib/depend/check-sharing.pkg
    {
        fun check (exports, makelib_state)
            =
            {   fun check (sharing_mode::DONT_CARE, _, s, _)
                        =>
                        (s, if (string_set::is_empty s ) sharing_mode::SHARE FALSE;
                            else sharing_mode::DO_NOT_SHARE;fi);

                    check (sharing_mode::PRIVATE, x, _, _)
                        =>
                        (string_set::singleton x, sharing_mode::DO_NOT_SHARE);

                    check (sharing_mode::SHARED, x, s, err)
                        =>
                        {
                            fun ppb pps
                                =
                                {   fun loop [] =>  ();
                                        #
                                        loop (h ! t)
                                            =>
                                            {   pp::string pps h;
                                                pp::newline pps;
                                                loop t;
                                            };
                                    end;

                                    pp::newline pps;
                                    pp::string pps "because of dependence on non-shareable state in:";
                                    pp::newline pps;
                                    loop (string_set::vals_list s);
                                };

                            if (string_set::is_empty s)
                                #                               
                                (s, sharing_mode::SHARE TRUE);
                            else
                                err err::ERROR ("cannot share state of " + x) ppb;
                                (s, sharing_mode::DO_NOT_SHARE);
                            fi;
                        };
                end;

                smlmap = REF ttm::empty;


                fun do_frozenlib_tome_tin (sg::FROZENLIB_TOME_TIN { frozenlib_tome, ... } )
                    =
                    case frozenlib_tome.sharing_mode
                        #                                   
                        sharing_mode::DO_NOT_SHARE =>  string_set::singleton (flt::describe_frozenlib_tome  frozenlib_tome);
                        _                          =>  string_set::empty;
                    esac;


                fun do_thawedlib_tome_tin (sg::THAWEDLIB_TOME_TIN tin)
                    =
                    {   tin ->  { thawedlib_tome =>   i,
                                  near_imports   =>  li,
                                  far_imports    =>  gi,
                                  ...
                                };


                        fun acc f (arg, s)
                            =
                            string_set::union (f arg, s);


                        case (ttm::get (*smlmap, i))
                            #                   
                             THE s => s;

                             NULL => {
                                  gs = fold_forward (acc do_masked_tome) string_set::empty gi;
                                  ls = fold_forward (acc do_thawedlib_tome_tin) gs li;

                                  my (s, m) = check (   tlt::sharing_request_of i,
                                                        tlt::describe_thawedlib_tome i,
                                                        ls,
                                                        tlt::error makelib_state i
                                                     );

                                  smlmap := ttm::set (*smlmap, i, s);
                                  tlt::set_sharing_mode (i, m);
                                  s;
                              };
                        esac;
                    }

                also
                fun do_tome_tin (sg::TOME_IN_FROZENLIB tome_in_frozenlib ) =>   do_frozenlib_tome_tin  tome_in_frozenlib.frozenlib_tome_tin;
                    do_tome_tin (sg::TOME_IN_THAWEDLIB thawedlib_tome_tin) =>   do_thawedlib_tome_tin  thawedlib_tome_tin;
                end 

                also
                fun do_masked_tome { exports_mask, tome_tin }
                    =
                    do_tome_tin  tome_tin;

                fun import_export  (fat_tome: lg::Fat_Tome)
                    =
                    ignore (do_masked_tome (fat_tome.masked_tome_thunk ()));

                sym::apply  import_export  exports;
            };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext