[m-rev.] diff: misc fixes for erlang
Peter Wang
wangp at students.csse.unimelb.edu.au
Thu Jun 14 14:43:24 AEST 2007
Estimated hours taken: 1
Branches: main
compiler/elds_to_erlang.m:
Keep Erlang function names a fair bit shorter than the maximum length,
as the Erlang compiler can derive other function names from them, which
then exceed the maximum length.
compiler/erl_rtti.m:
Fix a bug in generating method wrappers for non-special preds. We were
using the proc_arity field from the rtti_proc_label but that is the
original arity, whereas we need to include inserted type_info arguments
in our calculation.
Work around a problem in which the Erlang compiler aborts on a term we
generate for the details of type constructors, because the term is too
big (it happens on the libs.option type).
Index: compiler/elds_to_erlang.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/elds_to_erlang.m,v
retrieving revision 1.17
diff -u -r1.17 elds_to_erlang.m
--- compiler/elds_to_erlang.m 14 Jun 2007 01:50:28 -0000 1.17
+++ compiler/elds_to_erlang.m 14 Jun 2007 04:41:50 -0000
@@ -782,14 +782,17 @@
),
output_atom(Atom, !IO).
- % Some RTTI function names can be longer than the 255 character limit on
+ % Some RTTI function names can be longer than the character limit on
% atom names. To shorten long names, we take the left and right parts
% of the string and stick the hash of the string in the middle.
%
:- func shorten_long_atom_name(string) = string.
shorten_long_atom_name(Name0) = Name :-
- (if string.length(Name0) =< 255 then
+ % Erlang atom names can be up to 255 characters long, but the Erlang
+ % compiler may mangle it (e.g. to derive the names of anonymous functions)
+ % which would then exceed the limit.
+ (if string.length(Name0) =< 200 then
Name = Name0
else
% Use only lower 32 bits of the hash value so that the result is the
Index: compiler/erl_rtti.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/erl_rtti.m,v
retrieving revision 1.12
diff -u -r1.12 erl_rtti.m
--- compiler/erl_rtti.m 7 Jun 2007 07:53:05 -0000 1.12
+++ compiler/erl_rtti.m 14 Jun 2007 04:41:50 -0000
@@ -54,6 +54,7 @@
:- import_module libs.compiler_util.
:- import_module mdbcomp.prim_data.
:- import_module parse_tree.prog_data.
+:- import_module parse_tree.prog_util.
:- import_module bool.
:- import_module int.
@@ -267,7 +268,6 @@
!VarSet) :-
PredId = RttiProcId ^ pred_id,
ProcId = RttiProcId ^ proc_id,
- Arity = RttiProcId ^ proc_arity,
ArgTypes = RttiProcId ^ proc_arg_types,
ArgModes = RttiProcId ^ proc_arg_modes,
Detism = RttiProcId ^ proc_interface_detism,
@@ -296,7 +296,7 @@
%
svvarset.new_named_var("TypeClassInfo", TCIVar, !VarSet),
- svvarset.new_vars(Arity, Ws, !VarSet),
+ svvarset.new_vars(list.length(ArgTypes) - NumExtra, Ws, !VarSet),
% Make the ``E<n> = element(<n>, TypeClassInfo)'' expressions.
list.map2_foldl(extract_extra_arg(TCIVar), 1 .. NumExtra,
@@ -544,11 +544,14 @@
gen_init_special_pred(ModuleInfo, UnifyProcLabel, UnifyExpr, !VarSet),
gen_init_special_pred(ModuleInfo,
CompareProcLabel, CompareExpr, !VarSet),
+
+ erlang_type_ctor_details(ModuleInfo, Details, ELDSDetails0, RttiDefns0),
+ reduce_list_term_complexity(ELDSDetails0, ELDSDetails,
+ [], RevAssignments, !VarSet),
+
VarSet = !.VarSet
),
- erlang_type_ctor_details(ModuleInfo, Details, ELDSDetails, RttiDefns0),
-
ELDSTypeCtorData = elds_tuple([
elds_term(elds_int(Arity)),
elds_term(elds_int(Version)),
@@ -559,11 +562,14 @@
erlang_type_ctor_rep(Details),
ELDSDetails
]),
+ ClauseBody = elds_block(list.reverse(RevAssignments) ++
+ [elds_term(ELDSTypeCtorData)]),
+
TypeCtor = rtti_type_ctor(ModuleName, TypeName, Arity),
RttiId = elds_rtti_type_ctor_id(TypeCtor),
IsExported = yes,
RttiDefn = elds_rtti_defn(RttiId, IsExported, VarSet,
- elds_clause([], elds_term(ELDSTypeCtorData))),
+ elds_clause([], ClauseBody)),
RttiDefns = [RttiDefn | RttiDefns0].
:- func erlang_type_ctor_rep(erlang_type_ctor_details) = elds_expr.
@@ -733,6 +739,32 @@
Defns = []
).
+ % For some types we can generate a very long list for the type ctor
+ % details, such that the Erlang compiler aborts with a message "An
+ % implementation limit was reached. Try reducing the complexity of this
+ % function."
+ %
+ % Work around this problem by lifting the tail expression of each cons cell
+ % out and assigning it to a fresh variable.
+ %
+:- pred reduce_list_term_complexity(elds_expr::in, elds_expr::out,
+ list(elds_expr)::in, list(elds_expr)::out,
+ prog_varset::in, prog_varset::out) is det.
+
+reduce_list_term_complexity(Expr0, Expr, !RevAssignments, !VarSet) :-
+ (if
+ Expr0 = elds_term(elds_tuple([Functor, Head, Tail0])),
+ Functor = elds_term(elds_atom(SymName)),
+ unqualify_name(SymName) = "[|]"
+ then
+ reduce_list_term_complexity(Tail0, Tail, !RevAssignments, !VarSet),
+ svvarset.new_var(V, !VarSet),
+ Assign = elds_eq(expr_from_var(V), Tail),
+ Expr = elds_term(elds_tuple([Functor, Head, expr_from_var(V)])),
+ list.cons(Assign, !RevAssignments)
+ else
+ Expr = Expr0
+ ).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list