mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 14:25:56 +00:00
Estimated hours taken: 18 Branches: main Move the univ, maybe, pair and unit types from std_util into their own modules. std_util still contains the general purpose higher-order programming constructs. library/std_util.m: Move univ, maybe, pair and unit (plus any other related types and procedures) into their own modules. library/maybe.m: New module. This contains the maybe and maybe_error types and the associated procedures. library/pair.m: New module. This contains the pair type and associated procedures. library/unit.m: New module. This contains the types unit/0 and unit/1. library/univ.m: New module. This contains the univ type and associated procedures. library/library.m: Add the new modules. library/private_builtin.m: Update the declaration of the type_ctor_info struct for univ. runtime/mercury.h: Update the declaration for the type_ctor_info struct for univ. runtime/mercury_mcpp.h: runtime/mercury_hlc_types.h: Update the definition of MR_Univ. runtime/mercury_init.h: Fix a comment: ML_type_name is now exported from type_desc.m. compiler/mlds_to_il.m: Update the the name of the module that defines univs (which are handled specially by the il code generator.) library/*.m: compiler/*.m: browser/*.m: mdbcomp/*.m: profiler/*.m: deep_profiler/*.m: Conform to the above changes. Import the new modules where they are needed; don't import std_util where it isn't needed. Fix formatting in lots of modules. Delete duplicate module imports. tests/*: Update the test suite to confrom to the above changes.
134 lines
4.6 KiB
Mathematica
134 lines
4.6 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2000, 2003, 2005-2006 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% File: goal_store.m.
|
|
% Main author: petdr.
|
|
%
|
|
% Define a type goal_store(Key) which allows a hlds_goal to be stored in a
|
|
% dictionary like structure. However, there some operations on this dictionary
|
|
% that are specific to hlds_goals.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module transform_hlds.goal_store.
|
|
:- interface.
|
|
|
|
:- import_module hlds.hlds_goal.
|
|
:- import_module hlds.hlds_module.
|
|
:- import_module hlds.instmap.
|
|
:- import_module parse_tree.prog_data.
|
|
|
|
:- import_module bool.
|
|
:- import_module pair.
|
|
:- import_module set.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- type stored_goal == pair(hlds_goal, instmap).
|
|
:- type goal_store(T).
|
|
|
|
:- pred goal_store_init(goal_store(T)::out) is det.
|
|
:- func goal_store_init = goal_store(T).
|
|
|
|
:- pred goal_store_det_insert(T::in, stored_goal::in,
|
|
goal_store(T)::in, goal_store(T)::out) is det.
|
|
|
|
:- pred goal_store_lookup(goal_store(T)::in, T::in, stored_goal::out) is det.
|
|
|
|
:- pred goal_store_member(goal_store(T)::in, T::out, stored_goal::out)
|
|
is nondet.
|
|
|
|
:- pred goal_store_all_ancestors(goal_store(T)::in, T::in, vartypes::in,
|
|
module_info::in, bool::in, set(T)::out) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module hlds.goal_util.
|
|
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module map.
|
|
:- import_module solutions.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- type goal_store(T) == map.map(T, stored_goal).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
goal_store_init(GS) :-
|
|
map.init(GS).
|
|
|
|
goal_store_init = GS :-
|
|
goal_store_init(GS).
|
|
|
|
goal_store_det_insert(Id, Goal, GS0, GS) :-
|
|
map.det_insert(GS0, Id, Goal, GS).
|
|
|
|
goal_store_lookup(GS, Id, Goal) :-
|
|
map.lookup(GS, Id, Goal).
|
|
|
|
goal_store_member(GoalStore, Key, Goal) :-
|
|
map.member(GoalStore, Key, Goal).
|
|
|
|
goal_store_all_ancestors(GoalStore, StartId, VarTypes, ModuleInfo, FullyStrict,
|
|
AncestorIds) :-
|
|
AncestorIds = ancestors_2(GoalStore, [StartId], set.init,
|
|
VarTypes, ModuleInfo, FullyStrict).
|
|
|
|
:- func ancestors_2(goal_store(T), list(T), set(T), vartypes, module_info,
|
|
bool) = set(T).
|
|
|
|
ancestors_2(_GoalStore, [], _VisitedIds, _VarTypes, _ModuleInfo, _FullyStrict)
|
|
= set.init.
|
|
ancestors_2(GoalStore, [Id|Ids], VisitedIds, VarTypes, ModuleInfo, FullyStrict)
|
|
= AncestorIds :-
|
|
( set.member(Id, VisitedIds) ->
|
|
AncestorIds = ancestors_2(GoalStore, Ids, VisitedIds, VarTypes,
|
|
ModuleInfo, FullyStrict)
|
|
;
|
|
Ancestors = direct_ancestors(GoalStore, Id, VarTypes, ModuleInfo,
|
|
FullyStrict),
|
|
AncestorIds = set.list_to_set(Ancestors) `union`
|
|
ancestors_2(GoalStore, Ancestors `append` Ids,
|
|
set.insert(VisitedIds, Id), VarTypes, ModuleInfo, FullyStrict)
|
|
).
|
|
|
|
:- func direct_ancestors(goal_store(T), T, vartypes, module_info, bool)
|
|
= list(T).
|
|
|
|
direct_ancestors(GoalStore, StartId, VarTypes, ModuleInfo, FullyStrict)
|
|
= Ancestors :-
|
|
solutions.solutions(
|
|
direct_ancestor(GoalStore, StartId, VarTypes, ModuleInfo, FullyStrict),
|
|
Ancestors).
|
|
|
|
:- pred direct_ancestor(goal_store(T)::in, T::in, vartypes::in,
|
|
module_info::in, bool::in, T::out) is nondet.
|
|
|
|
direct_ancestor(GoalStore, StartId, VarTypes, ModuleInfo, FullyStrict,
|
|
EarlierId) :-
|
|
goal_store_lookup(GoalStore, StartId, LaterGoal - LaterInstMap),
|
|
goal_store_member(GoalStore, EarlierId, EarlierGoal - EarlierInstMap),
|
|
compare((<), EarlierId, StartId),
|
|
not goal_util.can_reorder_goals(ModuleInfo, VarTypes, FullyStrict,
|
|
EarlierInstMap, EarlierGoal, LaterInstMap, LaterGoal).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- func this_file = string.
|
|
|
|
this_file = "goal_store.m".
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module goal_store.
|
|
%-----------------------------------------------------------------------------%
|