Files
mercury/compiler/granularity.m
Zoltan Somogyi a19a5f0267 Delete the Erlang backend from the compiler.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_backend.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
compiler/erlang_rtti.m:
compiler/mercury_compile_erl_back_end.m:
    Delete these modules, which together constitute the Erlang backend.

compiler/notes/compiler_design.html:
    Delete references to the deleted modules.

compiler/parse_tree_out_type_repn.m:
    Update the format we use to represent the sets of foreign_type and
    foreign_enum declarations for a type as part of its item_type_repn_info,
    now that Erlang is no longer a target language.

compiler/parse_type_repn.m:
    Accept both the updated version of the item_type_repn_info and the
    immediately previous version, since the installed compiler will
    initially generate that previous version. However, stop accepting
    an even older version that we stopped generating several months ago.

compiler/parse_pragma_foreign.m:
    When the compiler finds a reference to Erlang as a foreign language,
    add a message about support for Erlang being discontinued to the error
    message.

    Make the code parsing foreign_decls handle the term containing
    the foreign language the same way as the codes parsing foreign
    codes, procs, types and enums.

    Add a mechanism to help parse_mutable.m to do the same.

compiler/parse_mutable.m:
    When the compiler finds a reference to Erlang as a foreign language,
    print an error message about support for Erlang being discontinued.

compiler/compute_grade.m:
    When the compiler finds a reference to Erlang as a grade component,
    print an informational message about support for Erlang being discontinued.

compiler/pickle.m:
compiler/make.build.m:
    Delete Erlang foreign procs and types.

compiler/add_foreign_enum.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_type.m:
compiler/check_libgrades.m:
compiler/check_parse_tree_type_defns.m:
compiler/code_gen.m:
compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/const_struct.m:
compiler/convert_parse_tree.m:
compiler/dead_proc_elim.m:
compiler/decide_type_repn.m:
compiler/deps_map.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/foreign.m:
compiler/globals.m:
compiler/granularity.m:
compiler/handle_options.m:
compiler/hlds_code_util.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/int_emu.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/lco.m:
compiler/llds_out_file.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_separate_items.m:
compiler/make_hlds_warn.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/ml_code_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_target_util.m:
compiler/ml_top_gen.m:
compiler/mlds.m:
compiler/mlds_dump.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_cs_type.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_type.m:
compiler/module_imports.m:
compiler/parse_pragma_foreign.m:
compiler/parse_tree_out.m:
compiler/polymorphism.m:
compiler/pragma_c_gen.m:
compiler/prog_data.m:
compiler/prog_data_foreign.m:
compiler/prog_foreign.m:
compiler/prog_item.m:
compiler/simplify_goal_scope.m:
compiler/special_pred.m:
compiler/string_encoding.m:
compiler/top_level.m:
compiler/uint_emu.m:
compiler/write_deps_file.m:
    Remove references to Erlang as a backend or as a target language.

tests/invalid/bad_foreign_code.{m,err_exp}:
tests/invalid/bad_foreign_decl.{m,err_exp}:
tests/invalid/bad_foreign_enum.{m,err_exp}:
tests/invalid/bad_foreign_export.{m,err_exp}:
tests/invalid/bad_foreign_export_enum.{m,err_exp}:
tests/invalid/bad_foreign_import_module.{m,err_exp}:
tests/invalid/bad_foreign_proc.{m,err_exp}:
tests/invalid/bad_foreign_type.{m,err_exp}:
    Add a test for Erlang as an invalid foreign language. Expect both the
    new error message for this new error, and the updated list of now-valid
    foreign languages on all errors.
2020-10-29 13:24:49 +11:00

257 lines
10 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
% Copyright (C) 2006-2012 The University of Melbourne.
% Copyright (C) 2017 The Mercury Team.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
%
% File: granularity.m.
% Author: zs.
%
% Find every parallel conjunction G1 & G2 & G3 & ... & Gn in the given module,
% and replace it with a goal that tests at runtime whether there are enough
% free CPUs to make parallel execution worthwhile, and if not, executes
% the conjunction sequentially instead.
%
%-----------------------------------------------------------------------------%
:- module transform_hlds.granularity.
:- interface.
:- import_module hlds.
:- import_module hlds.hlds_module.
%-----------------------------------------------------------------------------%
:- pred control_granularity(module_info::in, module_info::out) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module hlds.goal_util.
:- import_module hlds.hlds_dependency_graph.
:- import_module hlds.hlds_pred.
:- import_module hlds.hlds_goal.
:- import_module hlds.instmap.
:- import_module hlds.pred_table.
:- import_module hlds.quantification.
:- import_module libs.
:- import_module libs.dependency_graph.
:- import_module libs.globals.
:- import_module mdbcomp.
:- import_module mdbcomp.builtin_modules.
:- import_module mdbcomp.prim_data.
:- import_module parse_tree.
:- import_module parse_tree.prog_data.
:- import_module parse_tree.prog_data_foreign.
:- import_module bool.
:- import_module list.
:- import_module map.
:- import_module maybe.
:- import_module require.
:- import_module set.
:- import_module string.
%-----------------------------------------------------------------------------%
control_granularity(!ModuleInfo) :-
module_info_rebuild_dependency_info(!ModuleInfo, DepInfo),
SCCs = dependency_info_get_bottom_up_sccs(DepInfo),
list.foldl(runtime_granularity_test_in_scc, SCCs, !ModuleInfo).
:- pred runtime_granularity_test_in_scc(set(pred_proc_id)::in,
module_info::in, module_info::out) is det.
runtime_granularity_test_in_scc(SCC, !ModuleInfo) :-
set.foldl(runtime_granularity_test_in_proc(SCC), SCC, !ModuleInfo).
:- pred runtime_granularity_test_in_proc(scc::in, pred_proc_id::in,
module_info::in, module_info::out) is det.
runtime_granularity_test_in_proc(SCC, proc(PredId, ProcId), !ModuleInfo) :-
module_info_get_preds(!.ModuleInfo, PredTable0),
map.lookup(PredTable0, PredId, PredInfo0),
pred_info_get_proc_table(PredInfo0, ProcTable0),
map.lookup(ProcTable0, ProcId, ProcInfo0),
proc_info_get_has_parallel_conj(ProcInfo0, HasParallelConj),
(
HasParallelConj = has_parallel_conj,
proc_info_get_goal(ProcInfo0, Goal0),
runtime_granularity_test_in_goal(Goal0, Goal, no, Changed,
SCC, !.ModuleInfo),
(
Changed = no
;
Changed = yes,
proc_info_set_goal(Goal, ProcInfo0, ProcInfo1),
requantify_proc_general(ordinary_nonlocals_no_lambda,
ProcInfo1, ProcInfo),
map.det_update(ProcId, ProcInfo, ProcTable0, ProcTable),
pred_info_set_proc_table(ProcTable, PredInfo0, PredInfo),
map.det_update(PredId, PredInfo, PredTable0, PredTable),
module_info_set_preds(PredTable, !ModuleInfo)
)
;
HasParallelConj = has_no_parallel_conj
% There is no parallelism in this procedure, so there is no granularity
% to control.
).
:- pred runtime_granularity_test_in_goal(hlds_goal::in, hlds_goal::out,
bool::in, bool::out, scc::in, module_info::in) is det.
runtime_granularity_test_in_goal(Goal0, Goal, !Changed, SCC, ModuleInfo) :-
Goal0 = hlds_goal(GoalExpr0, GoalInfo),
(
GoalExpr0 = conj(parallel_conj, Goals0),
runtime_granularity_test_in_goals(Goals0, Goals, !Changed, SCC,
ModuleInfo),
module_info_get_globals(ModuleInfo, Globals),
globals.get_target(Globals, Target),
(
Target = target_c,
ModuleName = mercury_par_builtin_module,
CalledSCCPredProcIds = goal_list_calls_proc_in_set(Goals, SCC),
( if set.is_empty(CalledSCCPredProcIds) then
GoalExpr = conj(parallel_conj, Goals)
else
ProcName = "evaluate_parallelism_condition",
Args = [],
ExtraArgs = [],
MaybeRuntimeCond = no,
Features = [],
Context = goal_info_get_context(GoalInfo),
some [!Attributes] (
!:Attributes = default_attributes(lang_c),
set_thread_safe(proc_thread_safe, !Attributes),
set_purity(purity_impure, !Attributes),
set_may_call_mercury(proc_will_not_call_mercury,
!Attributes),
set_terminates(proc_terminates, !Attributes),
set_may_throw_exception(proc_will_not_throw_exception,
!Attributes),
set_may_call_mm_tabled(proc_will_not_call_mm_tabled,
!Attributes),
set_may_modify_trail(proc_will_not_modify_trail,
!Attributes),
Attributes = !.Attributes
),
generate_foreign_proc(ModuleInfo, ModuleName, ProcName,
pf_predicate, only_mode, detism_semi, purity_impure,
Attributes, Args, ExtraArgs, MaybeRuntimeCond,
runtime_test_code, Features, instmap_delta_bind_no_var,
Context, Cond),
Then = hlds_goal(conj(parallel_conj, Goals), GoalInfo),
Else = hlds_goal(conj(plain_conj, Goals), GoalInfo),
IfThenElse = hlds_goal(if_then_else([], Cond, Then, Else),
GoalInfo),
Reason = promise_purity(purity_pure),
GoalExpr = scope(Reason, IfThenElse),
!:Changed = yes
)
;
( Target = target_csharp
; Target = target_java
),
% This should have caught by mercury_compile.m.
unexpected($pred, "unsupported target language")
)
;
GoalExpr0 = conj(plain_conj, Goals0),
runtime_granularity_test_in_goals(Goals0, Goals, !Changed, SCC,
ModuleInfo),
GoalExpr = conj(plain_conj, Goals)
;
GoalExpr0 = disj(Goals0),
runtime_granularity_test_in_goals(Goals0, Goals, !Changed, SCC,
ModuleInfo),
GoalExpr = disj(Goals)
;
GoalExpr0 = switch(Var, CanFail, Cases0),
runtime_granularity_test_in_cases(Cases0, Cases, !Changed, SCC,
ModuleInfo),
GoalExpr = switch(Var, CanFail, Cases)
;
GoalExpr0 = if_then_else(Vars, Cond0, Then0, Else0),
runtime_granularity_test_in_goal(Cond0, Cond, !Changed, SCC,
ModuleInfo),
runtime_granularity_test_in_goal(Then0, Then, !Changed, SCC,
ModuleInfo),
runtime_granularity_test_in_goal(Else0, Else, !Changed, SCC,
ModuleInfo),
GoalExpr = if_then_else(Vars, Cond, Then, Else)
;
GoalExpr0 = negation(SubGoal0),
runtime_granularity_test_in_goal(SubGoal0, SubGoal, !Changed, SCC,
ModuleInfo),
GoalExpr = negation(SubGoal)
;
GoalExpr0 = scope(Reason, SubGoal0),
( if
Reason = from_ground_term(_, FGT),
( FGT = from_ground_term_construct
; FGT = from_ground_term_deconstruct
)
then
GoalExpr = GoalExpr0
else
runtime_granularity_test_in_goal(SubGoal0, SubGoal, !Changed, SCC,
ModuleInfo),
GoalExpr = scope(Reason, SubGoal)
)
;
( GoalExpr0 = plain_call(_, _, _, _, _, _)
; GoalExpr0 = generic_call(_, _, _, _, _)
; GoalExpr0 = call_foreign_proc(_, _, _, _, _, _, _)
; GoalExpr0 = unify(_, _, _, _, _)
),
GoalExpr = GoalExpr0
;
GoalExpr0 = shorthand(_),
unexpected($pred, "shorthand")
),
Goal = hlds_goal(GoalExpr, GoalInfo).
:- pred runtime_granularity_test_in_goals(
list(hlds_goal)::in, list(hlds_goal)::out, bool::in, bool::out,
scc::in, module_info::in) is det.
runtime_granularity_test_in_goals([], [], !Changed, _, _).
runtime_granularity_test_in_goals([Goal0 | Goals0], [Goal | Goals], !Changed,
SCC, ModuleInfo) :-
runtime_granularity_test_in_goal(Goal0, Goal, !Changed, SCC, ModuleInfo),
runtime_granularity_test_in_goals(Goals0, Goals, !Changed, SCC,
ModuleInfo).
:- pred runtime_granularity_test_in_cases( list(case)::in, list(case)::out,
bool::in, bool::out, scc::in, module_info::in) is det.
runtime_granularity_test_in_cases([], [], !Changed, _, _).
runtime_granularity_test_in_cases([Case0 | Cases0], [Case | Cases], !Changed,
SCC, ModuleInfo) :-
Case0 = case(MainConsId, OtherConsIds, Goal0),
runtime_granularity_test_in_goal(Goal0, Goal, !Changed, SCC, ModuleInfo),
Case = case(MainConsId, OtherConsIds, Goal),
runtime_granularity_test_in_cases(Cases0, Cases, !Changed, SCC,
ModuleInfo).
%-----------------------------------------------------------------------------%
:- func runtime_test_code = string.
runtime_test_code =
"SUCCESS_INDICATOR = MR_par_cond_local_wsdeque_length;\n" ++
"#ifdef MR_DEBUG_RUNTIME_GRANULARITY_CONTROL\n" ++
"MR_record_conditional_parallelism_decision(SUCCESS_INDICATOR);\n" ++
"#endif\n".
%-----------------------------------------------------------------------------%
:- end_module transform_hlds.granularity.
%-----------------------------------------------------------------------------%