[m-rev.] for review: allow execution of incomplete programs

Simon Taylor stayl at cs.mu.OZ.AU
Fri Feb 21 11:22:25 AEDT 2003


On 21-Feb-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Estimated hours taken: 7
> Branches: main
> 
> Add support for two new compiler options,
> `--allow-stubs' and `--no-warn-stubs',
> to allow execution of programs which are incomplete.
> 
> `--allow-stubs' delays the reporting of errors for procedures with no
> clauses until run-time, instead issuing only a warning at compile.
> `--no-warn-stubs' allows even that warning to be supressed.

> Index: compiler/typecheck.m
> ===================================================================
> +
> +	%
> +	% Generate `PredName = "<PredName>"'
> +	%
> +	varset__new_named_var(VarSet0, "PredName", PredNameVar, VarSet),
> +	pred_info_context(PredInfo, Context),
> +	create_atomic_unification(PredNameVar,
> +		functor(string_const(PredName), no, []),
> +		Context, explicit, [], Unify - UnifyGoalInfo0),
> +	goal_info_set_nonlocals(UnifyGoalInfo0,
> +		set__make_singleton_set(PredNameVar), UnifyGoalInfo),

Use hlds_goal__make_string_const_construction.

> +	%
> +	% Generate `private_builtin.no_clauses(PredName)'
> +	% or `private_builtin.sorry(PredName)'
> +	%
> +	mercury_private_builtin_module(PrivateBuiltin),
> +	pred_info_module(PredInfo, ModuleName),
> +	( mercury_std_library_module_name(ModuleName) ->
> +		CalleeName = "sorry"
> +	;
> +		CalleeName = "no_clauses"
> +	),
> +	CalleeSymName = qualified(PrivateBuiltin, CalleeName),
> +	module_info_get_predicate_table(ModuleInfo, PredicateTable),
> +	(
> +		predicate_table_search_pred_m_n_a(PredicateTable,
> +			PrivateBuiltin, CalleeName, 1, [CalleePredId0])
> +	->
> +		CalleePredId = CalleePredId0
> +	;
> +		error("generate_stub_clauses: cannot find private_builtin."
> +			++ CalleeName ++ "/1")
> +	),
> +	hlds_pred__initial_proc_id(CalleeProcId),
> +	Call = call(CalleePredId, CalleeProcId, [PredNameVar],
> +			not_builtin, no, CalleeSymName),
> +	goal_info_init(Context, GoalInfo),
> +	goal_info_set_nonlocals(GoalInfo,
> +		set__make_singleton_set(PredNameVar), CallGoalInfo),

Use goal_util__generate_simple_call.

> Index: compiler/unused_args.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/unused_args.m,v
> retrieving revision 1.80
> diff -u -d -r1.80 unused_args.m
> --- compiler/unused_args.m	17 Jan 2003 05:56:48 -0000	1.80
> +++ compiler/unused_args.m	20 Feb 2003 17:52:54 -0000
> @@ -1541,6 +1541,12 @@
>  				% that have unused arguments.
>  			\+ code_util__predinfo_is_builtin(PredInfo),
>  			\+ code_util__compiler_generated(PredInfo),
> +				% Don't warn about stubs for procedures
> +				% with no clauses -- in that case,
> +				% we *expect* that none of the arguments
> +				% will be used,
> +			pred_info_get_markers(PredInfo, Markers),
> +			\+ check_marker(Markers, stub),
>  				% Don't warn about lambda expressions
>  				% not using arguments. (The warning
>  				% message for these doesn't contain

You'll also need to make unused_args assume all the arguments of stubs are
used in unused_args__setup_local_var_usage to avoid spurious warnings in
callers. Just handle them as for builtins.

> Index: tests/hard_coded/allow_stubs.exp
> ===================================================================
> RCS file: tests/hard_coded/allow_stubs.exp
> diff -N tests/hard_coded/allow_stubs.exp
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ tests/hard_coded/allow_stubs.exp	20 Feb 2003 19:32:58 -0000
> @@ -0,0 +1,2 @@
> +hello world
> +going goodbye
> Index: tests/hard_coded/allow_stubs.m
> ===================================================================
> +:- mode trap_exceptions(pred(di, uo) is det, di, uo) is cc_multi.
> +trap_exceptions(IOGoal) -->
> +	try_io((pred({}::out, di, uo) is det --> IOGoal), Res),
> +	( { Res = succeeded({}) }
> +	; { Res = exception(Exception) },
> +	  print("[caught exception: "),
> +	  print(univ_value(Exception)),
> +	  print("]\n")
> +	).

Does the expected output match the test case here?
Shouldn't `[caught exception: ...]' occur somewhere?

Otherwise, this change is fine.

Simon.
--------------------------------------------------------------------------
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