[m-dev.] for review: fix block nesting hits fixed limit in MSVC

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jul 19 07:07:13 AEST 2000


On 07-Jul-2000, Peter Ross <petdr at cs.mu.OZ.AU> wrote:
> 
> Avoid a fixed limit problem where only N levels of block nesting is
> allowed in the MSVC compiler.
> 
> compiler/ml_code_gen.m:
>     ml_join_decls creates block nesting proportional to the size of the
>     disjunction when generating disjunctions in a model_non context.
>     Now we always create a block for each arm of the disjunction.  This
>     allows us to safely concatenate blocks together, and hence only nest
>     blocks one level deeper.

That change looks fine.  But I do have a couple of suggestions.

> Index: ml_code_gen.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
> retrieving revision 1.52
> diff -u -r1.52 ml_code_gen.m
> --- ml_code_gen.m	2000/06/06 06:21:22	1.52
> +++ ml_code_gen.m	2000/07/07 16:01:31
> @@ -2411,8 +2411,10 @@
>  	% (the HLDS should not contain singleton disjunctions,
>  	% but this code is needed to handle recursive calls to ml_gen_disj)
>  	%
> -ml_gen_disj([SingleGoal], CodeModel, _, MLDS_Decls, MLDS_Statements) -->
> -	ml_gen_goal(CodeModel, SingleGoal, MLDS_Decls, MLDS_Statements).
> +ml_gen_disj([SingleGoal], CodeModel, Context, [], [MLDS_Statement]) -->
> +	ml_gen_goal(CodeModel, SingleGoal, Goal_Decls, Goal_Statements),
> +	{ MLDS_Statement = ml_gen_block(Goal_Decls, Goal_Statements,
> +			Context) }.

It would be more concise to write that as

ml_gen_disj([SingleGoal], CodeModel, _Context, [], [MLDS_Statement]) -->
	ml_gen_goal(CodeModel, SingleGoal, MLDS_Statement).

Either way, though, I think it would be helpful to have a comment
here explaining why the goal was being generated as a block.

>  ml_gen_disj([First | Rest], CodeModel, Context,
>  		MLDS_Decls, MLDS_Statements) -->
> @@ -2429,9 +2431,18 @@
>  		ml_gen_goal(model_non, First, FirstDecls, FirstStatements),
>  		ml_gen_disj(Rest, model_non, Context,
>  			RestDecls, RestStatements),
> -		{ ml_join_decls(FirstDecls, FirstStatements,
> -			RestDecls, RestStatements, Context,
> -			MLDS_Decls, MLDS_Statements) }
> +
> +		(
> +			{ RestDecls = [] }
> +		->
> +			{ FirstBlock = ml_gen_block(FirstDecls,
> +					FirstStatements, Context) },
> +			{ MLDS_Decls = [] },
> +			{ MLDS_Statements = [FirstBlock | RestStatements] }
> +		;
> +			{ error("ml_gen_disj: RestDecls not empty.") }
> +		)
> +

It would be more concise to write that as

  		ml_gen_goal(model_non, First, FirstBlock),
  		ml_gen_disj(Rest, model_non, Context,
  			RestDecls, RestStatements),

		(
			{ RestDecls = [] }
		->
			{ MLDS_Decls = [] },
			{ MLDS_Statements = [FirstBlock | RestStatements] }
		;
			{ error("ml_gen_disj: RestDecls not empty.") }
		)

or as

  		ml_gen_goal(model_non, First, FirstBlock),
  		ml_gen_disj(Rest, model_non, Context,
  			RestDecls, RestStatements),
		{ ml_join_decls([], FirstBlock,
			RestDecls, RestStatements, Context,
			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