Mercury Bugs - mercury
View Issue Details
0000052mercuryBugpublic2008-03-13 17:072008-03-27 23:42
Assigned Tojuliensf 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000052: rebuilding a program with a mutable in a different grade causes invalid c to be generated
DescriptionCompile the attached program in hlc.gc and then rebuild in asm_fast.gc and the c compiler gives an error:

jupiter:/home/jupiter/maclarty/mut> mmc --make mut --grade hlc.gc
Making Mercury/int3s/mut.int3
Making Mercury/ints/
Making Mercury/cs/mut.c
Making Mercury/os/mut.o
Making mut
jupiter:/home/jupiter/maclarty/mut> ./mut
jupiter:/home/jupiter/maclarty/mut> mmc --make mut --grade asm_fast.gc
Making mut
** Error making `mut'.
Mercury/os/mut_init.o(.text+0x458): In function `mercury_init':
: undefined reference to `<predicate 'main'/2 mode 0>'
Mercury/os/mut.o(.text+0x1a): In function `<predicate 'main'/2 mode 0>':
: undefined reference to `<predicate 'io.write_int'/3 mode 0>'
Mercury/os/mut.o(.text+0x22): In function `<predicate 'main'/2 mode 0>':
: undefined reference to `<predicate ''/2 mode 0>'
collect2: ld returned 1 exit status
TagsNo tags attached.
Attached Files? mut.m (247) 2008-03-13 17:07

2008-03-13 17:30   
That's happening because the .mh file that is built in the hlc.gc grade is not
replaced when the program is re-compiled in asm_fast.gc (since the timestamp
on the .m file won't have changed). The hlc and asm_fast versions of the
program use different C types in the mutable definition which is why it fails
to compile.

The are already two solutions to this:

(1) do a --make mut.realclean before rebuilding the program in a different grade.

or, if you wish to support multiple grades simulatenously

(2) use --use-grade-subdirs
2008-03-14 12:08   
The problem still occurs with --use-grade-subdirs in the original program. The test case I submitted does however work with --use-grade-subdirs. I'll see if I can create another test case that exhibits the problem when --use-grade-subdirs is enabled.
2008-03-15 01:25   
The bug here is that the compiler doesn't consider .mh files to be grade
dependent when in fact they are because the types of the global variables
used to implement mutables will vary depending on whether the high-level
or low-level C backend is being used.

This can be fixed by writing both mutable declarations to the .mh
file and use #ifdef MR_HIGHLEVEL_CODE to conditionally include only
one of them.

(A alternative fix is to make the .mh files grade dependent but this is
more involved as it will invovle chaning the way that libraries
are installed.)
2008-03-27 23:42   
Fix committed. See log message for r1.77 of compiler/make_hlds_passes.m for details.

Issue History
2008-03-13 17:07maclartyNew Issue
2008-03-13 17:07maclartyFile Added: mut.m
2008-03-13 17:30juliensfNote Added: 0000087
2008-03-14 12:08maclartyNote Added: 0000088
2008-03-15 01:25juliensfNote Added: 0000089
2008-03-15 01:25juliensfStatusnew => assigned
2008-03-15 01:25juliensfAssigned To => juliensf
2008-03-27 23:42juliensfStatusassigned => resolved
2008-03-27 23:42juliensfResolutionopen => fixed
2008-03-27 23:42juliensfNote Added: 0000093