[m-rev.] diff: fix typeclass inlining bug
Simon Taylor
stayl at cs.mu.OZ.AU
Sun Jul 21 18:00:22 AEST 2002
Estimated hours taken: 3
Branches: main
compiler/inlining.m:
Fix a bug in inlining of procedures with typeclass constraints.
The type_info location for the callee overwrote the location
in the caller, but the location in the callee may have been
computed by extracting type_infos from typeclass_infos in the
caller, so it wouldn't be valid when computing the locations of
the type variables in the head of the caller.
Remove a partial work-around for this bug, which disabled
inlining of procedures with class constraints when tracing
is enabled. The work-around didn't prevent the code generator
abort occurring when constructing closure layouts.
tests/valid/Mmakefile:
tests/valid/typeclass_inlining_bug.m:
Test case.
Index: compiler/inlining.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/inlining.m,v
retrieving revision 1.107
diff -u -u -r1.107 inlining.m
--- compiler/inlining.m 28 Mar 2002 03:43:05 -0000 1.107
+++ compiler/inlining.m 19 Jul 2002 14:07:53 -0000
@@ -727,7 +727,13 @@
apply_substitutions_to_var_map(CalleeTypeInfoVarMap0,
TypeRenaming, TypeSubn, Subn, CalleeTypeInfoVarMap1),
- map__merge(TypeInfoVarMap0, CalleeTypeInfoVarMap1,
+
+ % Prefer the type_info_locn from the caller.
+ % The type_infos or typeclass_infos passed to the callee may
+ % have been produced by extracting type_infos or typeclass_infos
+ % from typeclass_infos in the caller, so they won't necessarily
+ % be the same.
+ map__overlay(CalleeTypeInfoVarMap1, TypeInfoVarMap0,
TypeInfoVarMap).
inlining__get_type_substitution(HeadTypes, ArgTypes,
@@ -835,10 +841,10 @@
is semidet.
inlining__should_inline_proc(PredId, ProcId, BuiltinState, HighLevelCode,
- Tracing, InlinedProcs, CallingPredMarkers, ModuleInfo) :-
+ _Tracing, InlinedProcs, CallingPredMarkers, ModuleInfo) :-
InlinePromisedPure = yes,
inlining__can_inline_proc(PredId, ProcId, BuiltinState,
- HighLevelCode, Tracing, InlinePromisedPure,
+ HighLevelCode, InlinePromisedPure,
CallingPredMarkers, ModuleInfo),
% OK, we could inline it - but should we? Apply our heuristic.
@@ -854,18 +860,16 @@
CallingPredMarkers, ModuleInfo) :-
module_info_globals(ModuleInfo, Globals),
globals__lookup_bool_option(Globals, highlevel_code, HighLevelCode),
- globals__get_trace_level(Globals, TraceLevel),
- Tracing = bool__not(trace_level_is_none(TraceLevel)),
inlining__can_inline_proc(PredId, ProcId, BuiltinState,
- HighLevelCode, Tracing, InlinePromisedPure,
+ HighLevelCode, InlinePromisedPure,
CallingPredMarkers, ModuleInfo).
:- pred inlining__can_inline_proc(pred_id, proc_id, builtin_state, bool,
- bool, bool, pred_markers, module_info).
-:- mode inlining__can_inline_proc(in, in, in, in, in, in, in, in) is semidet.
+ bool, pred_markers, module_info).
+:- mode inlining__can_inline_proc(in, in, in, in, in, in, in) is semidet.
inlining__can_inline_proc(PredId, ProcId, BuiltinState, HighLevelCode,
- Tracing, InlinePromisedPure, CallingPredMarkers, ModuleInfo) :-
+ InlinePromisedPure, CallingPredMarkers, ModuleInfo) :-
% don't inline builtins, the code generator will handle them
BuiltinState = not_builtin,
@@ -904,22 +908,6 @@
CalledGoal = foreign_proc(_,_,_,_,_,_,_) - _,
proc_info_interface_determinism(ProcInfo, Detism),
( Detism = nondet ; Detism = multidet )
- ),
-
- % XXX:
- % If tracing is enabled, then the code generator will need to figure
- % out the locations of typeinfos inside typeclass_infos. At the moment,
- % due to a bug, the algorithm for doing this figuring can cause a
- % compiler abort if we inline calls that have typeclass constraints.
- (
- Tracing = yes
- =>
- (
- pred_info_clauses_info(PredInfo, ClausesInfo),
- TypeClassInfoVarMap = ClausesInfo ^
- clause_typeclass_info_varmap,
- map__is_empty(TypeClassInfoVarMap)
- )
),
% Only inline foreign_code if it is appropriate for
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.107
diff -u -u -r1.107 Mmakefile
--- tests/valid/Mmakefile 14 Jul 2002 15:12:41 -0000 1.107
+++ tests/valid/Mmakefile 19 Jul 2002 06:09:12 -0000
@@ -166,6 +166,7 @@
tricky_ite.m \
two_pragma_c_codes.m \
two_way_unif.m \
+ typeclass_inlining_bug.m \
type_inf_ambig_test.m \
unbound_inst_var.m \
unbound_tvar_in_lambda.m \
Index: tests/valid/typeclass_inlining_bug.m
===================================================================
RCS file: tests/valid/typeclass_inlining_bug.m
diff -N tests/valid/typeclass_inlining_bug.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/valid/typeclass_inlining_bug.m 19 Jul 2002 06:09:33 -0000
@@ -0,0 +1,40 @@
+:- module typeclass_inlining_bug.
+
+:- interface.
+
+:- import_module list.
+
+:- type analysis
+ ---> some [Call, Answer] analysis(Call, Answer)
+ => analysis(Call, Answer).
+
+:- typeclass analysis(Call, Answer) <=
+ (call_pattern(Call), answer_pattern(Answer))
+ where
+[].
+
+:- type analysis_name == string.
+
+:- typeclass call_pattern(Call) where [].
+
+:- typeclass answer_pattern(Answer) where [].
+
+:- type analysis_info.
+
+:- pred lookup_call_pattern(Call::in, list(analysis)::in,
+ list(Answer)::out) is det <= analysis(Call, Answer).
+
+:- implementation.
+
+:- import_module map, require, set, std_util.
+
+lookup_call_pattern(CallPattern, Results, AnswerPatterns) :-
+ AnswerPatterns = list__filter_map(filter_results(CallPattern),
+ Results).
+
+:- func filter_results(Call, analysis) = Answer is semidet
+ <= (call_pattern(Call), answer_pattern(Answer)).
+
+filter_results(_, analysis(_, Answer0)) = Answer :-
+ univ(Answer0) = univ(Answer).
+
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list