[m-rev.] for review: improve `_init.c' file creation

Simon Taylor stayl at cs.mu.OZ.AU
Wed Nov 28 05:23:41 AEDT 2001


On 27-Nov-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 27-Nov-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:

> This change does the wrong thing when `-x' or `--extra-inits' option
> is included in C2INITFLAGS,

mmake doesn't get that right even without this change.
It does get it right with the new version below.

> I also don't think that this behaviour should be unconditional,
> and right now I don't think it should even be the default.
> I think it should only be enabled when the `--make' option (rebuild
> only those things which are not up-to-date) is set; if that option
> is not set, then things should be rebuilt unconditionally.
> This is needed for consistency with the way we handle all the other
> files.  

I'll do the change to mercury_compile.m as part of the `--make' change.

> Also, I'm not yet convinced that this change is worthwhile from an
> efficiency perspective, at least in the case when c2init is invoked from
> mmake rather than mmc, because I suspect that the overhead of checking
> to see whether the *.cmd file has changed may be similar to the cost
> of running c2init in the first place.

You're right about the efficiency. I've changed the code to call
c2init whenever mmake is working out whether to link the program,
and also to use mercury_update_interface to update the `_init.c' file.
This solves the `--extra-inits' problem (but with an efficiency
cost of grepping through all the C files on every link when
`--extra-inits' is enabled, which should be rare).
 
> > +		% XXX Why does `io__read_file_as_string' return a separate
> > +		% status and result, rather than an `io__res(string)'?
> 
> The reason is to ensure that, in the case when some characters are
> successfully read and then an I/O error occurs, the part of the file
> that was successfully read can be returned.

When is that behaviour useful? If an error occurs in the middle
of a read, can the part that was read be trusted? It also doesn't
force the user to check for errors before using the result like all
the other input predicates do (including `io__read_file'). It might be
better to use a different result type like the one below, but I think
the best solution is just to return an `io__res(string)' and throw away
the partially read data.

:- type io__read_file_result(T)
	--->	ok(T)
	;	error(
			T,		% The partial result.
			io__error
		).

Simon.


Estimated hours taken: 2
Branches: main

compiler/modules.m:
	Always update the `_init.c' file when running an mmake
	which could link the program. With this change the
	user does not need to manually force an update of
	the `_init.c' file when enabling tracing.

	Update the `_init.c' file using mercury_update_interface
	to avoid relinking when the `_init.c' file has not changed.


Index: modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.208
diff -u -u -r1.208 modules.m
--- modules.m	24 Nov 2001 17:52:15 -0000	1.208
+++ modules.m	27 Nov 2001 18:07:26 -0000
@@ -3506,21 +3506,17 @@
 							InitPicObjFileName),
 
 	% Note we have to do some ``interesting'' hacks to get
-	% `$(ALL_MLLIBS_DEP)' and `$(ALL_C2INITARGS)' to work in the
-	% dependency list (and not complain about undefined variables).
+	% `$(ALL_MLLIBS_DEP)' to work in the dependency list
+	% (and not complain about undefined variables).
 	% These hacks rely on features of GNU Make, so should not be used
 	% if we cannot assume we are using GNU Make.
 	globals__io_lookup_bool_option(assume_gmake, Gmake),
 	{ Gmake = yes ->
 		append_list(["\\\n\t\t$(foreach @,", MakeVarName,
 				",$(ALL_MLLIBS_DEP))"],
-				All_MLLibsDepString),
-		append_list(["\\\n\t\t$(foreach @,undefined,$(foreach *,",
-				MakeVarName, ",$(ALL_C2INITARGS)))"],
-				All_C2InitArgsDepString)
+				All_MLLibsDepString)
 	;
-		All_MLLibsDepString = "$(ALL_MLLIBS_DEP)",
-		All_C2InitArgsDepString = "$(ALL_C2INITARGS)"
+		All_MLLibsDepString = "$(ALL_MLLIBS_DEP)"
 	},
 
 	%
@@ -3664,12 +3660,19 @@
 	list__foldl(append_to_init_list(DepStream, InitFileName), Modules),
 	io__write_string(DepStream, "\n"),
 
-	io__write_strings(DepStream, [
-		InitCFileName, " : ", DepFileName, " ", DvFileName, " ",
-			All_C2InitArgsDepString, "\n",
-		"\t$(C2INIT) $(ALL_GRADEFLAGS) $(ALL_C2INITFLAGS) ",
-			"--init-c-file ", InitCFileName,
-			" $(", MakeVarName, ".init_cs) $(ALL_C2INITARGS)\n\n"
+	% The `force-module_init' dependency forces the commands for
+	% the `module_init.c' rule to be run every time the rule
+	% is considered.
+	{ prog_out__sym_name_to_string(ModuleName, ".", ModuleFileName) },
+	{ ForceC2InitTarget = "force-" ++ ModuleFileName ++ "_init" },
+	{ TmpInitCFileName = InitCFileName ++ ".tmp" },
+	io__write_strings(DepStream, [
+		ForceC2InitTarget, " :\n\n",
+		InitCFileName, " : ", ForceC2InitTarget, "\n",
+		"\t@$(C2INIT) $(ALL_GRADEFLAGS) $(ALL_C2INITFLAGS) ",
+			"--init-c-file ", TmpInitCFileName,
+			" $(", MakeVarName, ".init_cs) $(ALL_C2INITARGS)\n",
+		"\t at mercury_update_interface ", InitCFileName, "\n\n"
 	]),
 
 	module_name_to_lib_file_name("lib", ModuleName, ".install_ints", no,
--------------------------------------------------------------------------
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