[m-dev.] diff: MLDS back-end: fix bug with unreachable code

Fergus Henderson fjh at cs.mu.OZ.AU
Tue May 9 20:05:17 AEST 2000


Estimated hours taken: 0.5

Fix a bug in the MLDS back-end that broke tests/valid/same_length_2.m.

compiler/ml_code_gen.m:
	When generating code for conjunctions, ensure that we stop
	code generation once we reach a goal with at_most_zero
	solutions.  This is necessary to avoid getting internal
	errors when generating code for the `fail' goals
	that simplify__conj inserts after unreachable code,
	which can happen when the conjunction is model_det.

	Also update some of the documentation.

Workspace: /home/pgrad/fjh/ws/hg
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.36
diff -u -d -r1.36 ml_code_gen.m
--- compiler/ml_code_gen.m	2000/05/08 13:48:05	1.36
+++ compiler/ml_code_gen.m	2000/05/09 09:56:44
@@ -149,8 +149,6 @@
 %		}, {
 %			succeeded = TRUE;
 %		})
-%
-%	done:
 
 %	model_non in semi context: (using catch/throw)
 %		<succeeded = Goal>
@@ -272,6 +270,13 @@
 % Code for non-empty conjunctions
 %
 
+% We need to handle the case where the first goal cannot succeed
+% specially:
+%	at_most_zero Goal:
+%		<Goal, Goals>
+%	===>
+%		<Goal>
+
 %	model_det Goal:
 %		<Goal, Goals>
 % 	===>
@@ -545,7 +550,7 @@
 %-----------------------------------------------------------------------------%
 
 
-% XXX This is still very incomplete!!!
+% XXX This is still not yet complete.
 %
 % Done:
 %	- function prototypes
@@ -563,9 +568,11 @@
 %			- deconstructions
 %		- switches
 %		- commits
+%		- most cases of `pragma c_code'
+%	- RTTI
 % TODO:
 %	- `pragma export'
-%	- RTTI (base_type_functors, base_type_layout)
+%	- complicated `pragma c_code'
 %	- typeclass_infos and class method calls
 %	- high level data representation
 %	  (i.e. generate MLDS type declarations for user-defined types)
@@ -2151,11 +2158,17 @@
 		MLDS_Decls, MLDS_Statements) -->
 	{ Rest = [_ | _] },
 	{ First = _ - FirstGoalInfo },
-	{ goal_info_get_code_model(FirstGoalInfo, FirstCodeModel) },
-	{ DoGenFirst = ml_gen_goal(FirstCodeModel, First) },
-	{ DoGenRest = ml_gen_conj(Rest, CodeModel, Context) },
-	ml_combine_conj(FirstCodeModel, Context, DoGenFirst, DoGenRest,
-		MLDS_Decls, MLDS_Statements).
+	{ goal_info_get_determinism(FirstGoalInfo, FirstDeterminism) },
+	( { determinism_components(FirstDeterminism, _, at_most_zero) } ->
+		% the `Rest' code is unreachable
+		ml_gen_goal(CodeModel, First, MLDS_Decls, MLDS_Statements)
+	;
+		{ determinism_to_code_model(FirstDeterminism, FirstCodeModel) },
+		{ DoGenFirst = ml_gen_goal(FirstCodeModel, First) },
+		{ DoGenRest = ml_gen_conj(Rest, CodeModel, Context) },
+		ml_combine_conj(FirstCodeModel, Context,
+			DoGenFirst, DoGenRest, MLDS_Decls, MLDS_Statements)
+	).
 
 %-----------------------------------------------------------------------------%
 %

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list