mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 15:26:31 +00:00
Make closures always include layout information, not just in grades in which
Estimated hours taken: 51 Make closures always include layout information, not just in grades in which typeinfo liveness is turned on. This requires separating two notions, which were previously combined: - Body typeinfo liveness means that when a variable X is live, any typeinfo variables describing type variables that occur in the type of X must also be live. - Interface typeinfo liveness means that when the input arguments of a procedure include a polymorphically typed variable (e.g. X), typeinfo variables describing type variables that occur in the type of X must also be among the arguments. This change turns on interface typeinfo liveness for procedures that either have their address taken in the current module, or are exported and thus may have their address taken in some other module. compiler/hlds_pred.m: Centralize decisions wrt whether procedure interfaces and bodies use typeinfo liveness here. compiler/options.m: Rename the typeinfo_liveness option as body_typeinfo_liveness, since this reflects its new function. compiler/call_gen.m: compiler/higher_order.m: compiler/live_vars.m: compiler/liveness.m: compiler/unused_args.m: Use hlds_pred.m to make decisions about liveness. compiler/lambda.m: Always include the relevant typeinfos in the interfaces of procedures created for lambdas. compiler/continuation_info.m: compiler/stack_layout.m: compiler/unify_gen.m: Modify the predicates that record and use layout information about closures to always do so, since the necessary information is now always available about the interfaces of procedures which can be put into closures. Previously, they only did so if typeinfo_liveness was set. Also, generate information about the types of the variables in a closure from the pred_info's arg types field, not from the proc_info's var types field, because unlike the latter, it is valid even for imported predicates. compiler/hlds_out.m: Print the non-clause-related information in the clauses_info part of a pred_info (e.g. the type parameters) even if the predicate has no actual clauses. Simplify the code a bit by getting rid of a duplicate test. compiler/middle_rec.m: Require that the code generated for the base case not refer to any stack slots if this way of generating code is to be used. This is necessary because the base case is executed when the current procedure has no stack frame, and thus any references to stack slots would refer to and possibly overwrite the data in another procedure's frame. In the absence of requiring body typeinfo liveness for exported procedures, such references were not generated; in its presence, they were. However, we now require only interface liveness for exported procedures, so we can still use middle recursion for them. compiler/handle_options.m: Do not turn off middle_rec if (body) typeinfo liveness is turned on, now that the bug has been fixed. For polymorphic predicates, the base case will still contain references to stack slots, and thus the middle-rec optimization will not applied for them, but the optimization may apply to monomorphic predicates. compiler/passes_aux.m: Add the ability to call compiler passes with the procedure id as well as the predicate id of the procedure they are passed. tests/hard_coded/typeclasses/Mmakefile: Refer to --body-typeinfo-liveness instead of --typeinfo-liveness.
This commit is contained in:
@@ -235,7 +235,7 @@
|
||||
set_bbbtree(label)::out) is det.
|
||||
|
||||
:- pred stack_layout__construct_closure_layout(proc_label::in,
|
||||
maybe(closure_layout_info)::in, list(maybe(rval))::out,
|
||||
closure_layout_info::in, list(maybe(rval))::out,
|
||||
create_arg_types::out, int::in, int::out) is det.
|
||||
|
||||
:- implementation.
|
||||
@@ -936,26 +936,20 @@ stack_layout__construct_liveval_name_rvals(var_info(_, LiveValueType),
|
||||
% with runtime/mercury_ho_call.h, which contains macros to access
|
||||
% the data structures we build here.
|
||||
|
||||
stack_layout__construct_closure_layout(ProcLabel, MaybeClosureLayoutInfo,
|
||||
stack_layout__construct_closure_layout(ProcLabel, ClosureLayoutInfo,
|
||||
Rvals, ArgTypes, CNum0, CNum) :-
|
||||
stack_layout__construct_procid_rvals(ProcLabel, ProcIdRvals,
|
||||
ProcIdTypes),
|
||||
( MaybeClosureLayoutInfo = yes(ClosureLayoutInfo) ->
|
||||
ClosureLayoutInfo = closure_layout_info(ClosureArgs,
|
||||
TVarLocnMap),
|
||||
stack_layout__construct_closure_arg_rvals(ClosureArgs,
|
||||
ClosureArgRvals, ClosureArgTypes, CNum0, CNum),
|
||||
stack_layout__construct_tvar_rvals(TVarLocnMap, TVarRvals,
|
||||
TvarRvalTypes),
|
||||
list__append(ClosureArgRvals, TVarRvals, LayoutRvals),
|
||||
LayoutTypes = initial(ClosureArgTypes, TvarRvalTypes)
|
||||
;
|
||||
LayoutRvals = [yes(const(int_const(-1)))],
|
||||
LayoutTypes = initial([1 - yes(integer)], none),
|
||||
CNum = CNum0
|
||||
),
|
||||
ClosureLayoutInfo = closure_layout_info(ClosureArgs,
|
||||
TVarLocnMap),
|
||||
stack_layout__construct_closure_arg_rvals(ClosureArgs,
|
||||
ClosureArgRvals, ClosureArgTypes, CNum0, CNum),
|
||||
stack_layout__construct_tvar_rvals(TVarLocnMap, TVarRvals,
|
||||
TVarRvalTypes),
|
||||
list__append(ClosureArgRvals, TVarRvals, LayoutRvals),
|
||||
list__append(ProcIdRvals, LayoutRvals, Rvals),
|
||||
ArgTypes = initial(ProcIdTypes, LayoutTypes).
|
||||
ArgTypes = initial(ProcIdTypes, initial(ClosureArgTypes,
|
||||
TVarRvalTypes)).
|
||||
|
||||
:- pred stack_layout__construct_closure_arg_rvals(list(closure_arg_info)::in,
|
||||
list(maybe(rval))::out, initial_arg_types::out, int::in, int::out)
|
||||
|
||||
Reference in New Issue
Block a user