comp.lang.ada
 help / color / mirror / Atom feed
* elaboration circularity detected problem, How to fix?
@ 2004-09-20 14:51 Scott Travak
  2004-09-20 15:52 ` Martin Dowie
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Scott Travak @ 2004-09-20 14:51 UTC (permalink / raw)


Hi everyone, I was hoping to obtain some assistance with a program I am 
constructing. Essentially my program is made up as follows:

1) Two packages (one of which is a generic package).
2) Each package essentially contains a task
3) Each task contains a reference to (operates on) the other task

I am encountering a "elaboration circularity detected" error (see below).

-----------------
Error received:
-----------------

error: elaboration circularity detected
info:    "main (body)" must be elaborated before "main (body)"
info:       reason: Elaborate_All probably needed in unit "main (body)"
info:       recompile "main (body)" with -gnatwl for full details
info:          "main (body)"
info:             must be elaborated along with its spec:
info:          "main (spec)"
info:             which is withed by:
info:          "location (body)"
info:             which must be elaborated along with its spec:
info:          "location (spec)"
info:             which is withed by:
info:          "main (body)"

gnatmake: *** bind failed.

I do not know how to get myself out of this one. I think it has something to 
do with the way I have placed the instantiated package within the context of 
the code. There are two places where I have defined the same instantiated 
package. I think I should only define it once. But I don't know how to get 
around the dependency loop.

Any help would be greatly appreciated!

Thanks
Scott.


-----------
entry.adb
-----------

with Location;

procedure entry is

  package Chicago_Ptr is new Location (Chicago);

begin

  Chicago_Ptr.TaskA_Ptr := new Chicago_Ptr.TaskA_Type;

end;

------------
location.ads
------------

generic
  ..

package Location is

  task type taskA_Type is
  begin
  ..
  end taskA_Type;

  type taskA_Ptr_Type is access taskA_Type;
  taskA_Ptr : taskA_Ptr_Type;

end Location;

------------
location.adb
------------

with Main;
use  Main;

package body Location

  task body taskA_Type is
  begin
  ..
  taskB.Some_ChannelB();
  end taskA_Type;

end Location;

-----------------
main.ads
-----------------

package Main is

  task taskB is
  begin
  ..
  end taskB;

end Main;

-----------------
main.adb
-----------------

with Location

package body Main is

  package Chicago_Ptr is new Location (Chicago);

  task body taskB is
  begin
  ..
  Chicago_ptr.Some_ChannelA();
  end taskB;

end Main;






^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: elaboration circularity detected problem, How to fix?
  2004-09-20 14:51 elaboration circularity detected problem, How to fix? Scott Travak
@ 2004-09-20 15:52 ` Martin Dowie
  2004-09-20 17:11   ` Florian Weimer
  2004-09-21  6:32   ` Scott Travak
       [not found] ` <7e7vk0dv2qhpqbdd58c0bvpesitapijr8v@4ax.com>
  2004-09-22 21:08 ` Simon Wright
  2 siblings, 2 replies; 14+ messages in thread
From: Martin Dowie @ 2004-09-20 15:52 UTC (permalink / raw)


Scott Travak wrote:
> Hi everyone, I was hoping to obtain some assistance with a program I
> am constructing. Essentially my program is made up as follows:
>
> 1) Two packages (one of which is a generic package).
> 2) Each package essentially contains a task
> 3) Each task contains a reference to (operates on) the other task
>
> I am encountering a "elaboration circularity detected" error (see
> below).

try building using the " -gnatE " option.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: elaboration circularity detected problem, How to fix?
  2004-09-20 15:52 ` Martin Dowie
@ 2004-09-20 17:11   ` Florian Weimer
  2004-09-20 21:19     ` Randy Brukardt
  2004-09-21  6:32   ` Scott Travak
  1 sibling, 1 reply; 14+ messages in thread
From: Florian Weimer @ 2004-09-20 17:11 UTC (permalink / raw)


* Martin Dowie:

> Scott Travak wrote:
>> Hi everyone, I was hoping to obtain some assistance with a program I
>> am constructing. Essentially my program is made up as follows:
>>
>> 1) Two packages (one of which is a generic package).
>> 2) Each package essentially contains a task
>> 3) Each task contains a reference to (operates on) the other task
>>
>> I am encountering a "elaboration circularity detected" error (see
>> below).
>
> try building using the " -gnatE " option.

Dynamic elaboration checks are never the best solution.  If the
elaboration order can't be determined at compile-time, there is some
significant design problem in the code.

Scott, you should try to determine what's causing the circularity and
try to work around it (for example, by putting initialization code
into a different package).



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: elaboration circularity detected problem, How to fix?
  2004-09-20 17:11   ` Florian Weimer
@ 2004-09-20 21:19     ` Randy Brukardt
  2004-09-21 10:09       ` Martin Dowie
  0 siblings, 1 reply; 14+ messages in thread
From: Randy Brukardt @ 2004-09-20 21:19 UTC (permalink / raw)


"Florian Weimer" <fw@deneb.enyo.de> wrote in message
news:87oek027dd.fsf@deneb.enyo.de...
...
> > try building using the " -gnatE " option.
>
> Dynamic elaboration checks are never the best solution.  If the
> elaboration order can't be determined at compile-time, there is some
> significant design problem in the code.

I'd disagree with that. We had problems with static elaboration checks in
Claw, and the design of Claw is great. :-) :-) As I recall, the problems had
to do with operator symbols that would get used in default expressions
before the package could be elaborated. We had to put in a bunch of
Gnat-specific pragmas to eliminate the problems. Program_Error would never
be raised at runtime, and remember that you need -gnatE to conform to the
standard (dynamic elaboration checks is what the Standard requires).

Still, it's probably better to reorganize the code, because otherwise,
you'll forever have to tell people to use -gnatE (and that isn't fun,
especially as lots of people never read the documentation...)

                          Randy.







^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: elaboration circularity detected problem, How to fix?
  2004-09-20 15:52 ` Martin Dowie
  2004-09-20 17:11   ` Florian Weimer
@ 2004-09-21  6:32   ` Scott Travak
  2004-09-21  7:30     ` gnat options (Re: " Peter Hermann
  1 sibling, 1 reply; 14+ messages in thread
From: Scott Travak @ 2004-09-21  6:32 UTC (permalink / raw)


>
> try building using the " -gnatE " option.
>

Thanks, Yep my error is based upon a compilation using the -gnatE option. 
Infact i get the same error if i do/don't use that option.

Cheers, Scott 





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: elaboration circularity detected problem, How to fix?
       [not found] ` <7e7vk0dv2qhpqbdd58c0bvpesitapijr8v@4ax.com>
@ 2004-09-21  6:44   ` Scott Travak
  2004-09-21 18:40     ` Ludovic Brenta
  0 siblings, 1 reply; 14+ messages in thread
From: Scott Travak @ 2004-09-21  6:44 UTC (permalink / raw)


Hi Dennis, yes you are right, there are a few inconsistencies there. Sorry 
about that. My scaled-down workable code (which produces the same error) is 
as follows:

Essentially what the example code is trying to do is:

1) create a remote location (i.e. chicago) with a 'send' and 'receive' task
2) the 'send task' sends a signal to some Destination station
3) the Destination station sends an acknowledgement signal back to chicago's 
'receive task'

The code worked fine prior to changing the location package into a generic 
package.

All I want is to get rid of this "error: elaboration circularity detected" 
compilation error.

Thanks for any help!

Cheers, Scott

-----------------
main.adb
-----------------

with Definitions;
use  Definitions;

with Location;

procedure main is

   package Chicago_Ptr is new Location (Chicago);

begin

   Chicago_Ptr.Send_Ptr    := new Chicago_Ptr.Send_Type;
   Chicago_Ptr.Receive_Ptr := new Chicago_Ptr.Receive_Type;

end main;


-----------------
definitions.adb
-----------------

package Definitions is

   type Location_Type is
         (Chicago,
          Paris,
          London);

end Definitions;


-----------------
location.ads
-----------------

with Definitions;
use  Definitions;

generic
   Centre : Location_Type;

package Location is

   task type Send_Type is
   end  Send_Type;

   task type Receive_Type is
      entry Ack_Channel;
   end Receive_Type;

   type Send_Ptr_Type is access Send_Type;
   type Receive_Ptr_Type is access Receive_Type;

   Send_Ptr    : Send_Ptr_Type;
   Receive_Ptr : Receive_Ptr_Type;

end Location;


-----------------
location.adb
-----------------

with Text_Io;
use  Text_Io;

with Station;
use  Station;

package body Location is

   task body Send_Type is
      Calls : Integer := 2;
      Done  : Boolean := False;
   begin

      Put_Line(Location_Type'Image(Centre) & "_SEND alive");

      while Calls > 0 loop
         delay 0.1;
         Destination.Signal;
         Calls := Calls - 1;
      end loop;

      Put_Line(Location_Type'Image(Centre) & "_SEND dead");

   end Send_Type;

   ------------

   task body Receive_Type is
      Done : Boolean := False;
   begin

      Put_Line(Location_Type'Image(Centre) & "_RECEIVE alive");

      while not Done loop

         select
            accept Ack_Channel do
               Put_Line("Signal received by DESTINATION");
            end Ack_Channel;
         else
            delay 0.1;
         end select;

      end loop;

      Put_Line(Location_Type'Image(Centre) & "_RECEIVE dead");

   end Receive_Type;

end Location;


-----------------
station.ads
-----------------

package Station is

   task Destination is
      entry Signal;
   end Destination;

end Station;


-----------------
station.adb
-----------------

with Text_Io;
use  Text_Io;

with Definitions;
use  Definitions;

with Location;

package body Station is

   package Chicago_Ptr is new Location (Chicago);

   task body Destination is
      Done : Boolean := False;
   begin

      Put_Line("DESTINATION alive");

      while not Done loop

         select
            accept Signal do
               Put_Line("DESTINATION: Received signal");
               Chicago_Ptr.Receive_Ptr.Ack_Channel;
            end Signal;
         else
            delay 0.1;
         end select;

      end loop;

      Put_Line("DESTINATION dead");

   end Destination;

end Station; 





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: gnat options (Re: elaboration circularity detected problem, How to fix?
  2004-09-21  6:32   ` Scott Travak
@ 2004-09-21  7:30     ` Peter Hermann
  2004-09-21  8:00       ` Scott Travak
  2004-09-21  8:09       ` Alex R. Mosteo
  0 siblings, 2 replies; 14+ messages in thread
From: Peter Hermann @ 2004-09-21  7:30 UTC (permalink / raw)


Scott Travak <s.travak@j-inet.com> wrote:
> Thanks, Yep my error is based upon a compilation using the -gnatE option. 

apropos:
I would like to have a summary of all options a,b,c,...,A,B,C...
for gnat, gnatmake, gcc, etc... in one place.
Does this exist somewhere?
The gnat documentation is poor in this respect, spreading that info,
which always leads to a waste of time when searching for the meaning
of an option, e.g. -gnatE.

-- 
--Peter Hermann(49)0711-685-3611 fax3758 ica2ph@csv.ica.uni-stuttgart.de
--Pfaffenwaldring 27 Raum 114, D-70569 Stuttgart Uni Computeranwendungen
--http://www.csv.ica.uni-stuttgart.de/homes/ph/
--Team Ada: "C'mon people let the world begin" (Paul McCartney)



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: gnat options (Re: elaboration circularity detected problem, How to fix?
  2004-09-21  7:30     ` gnat options (Re: " Peter Hermann
@ 2004-09-21  8:00       ` Scott Travak
  2004-09-21  8:09       ` Alex R. Mosteo
  1 sibling, 0 replies; 14+ messages in thread
From: Scott Travak @ 2004-09-21  8:00 UTC (permalink / raw)


well executing gnatmake gives a summary of the options. Or did you want 
something more indepth?

C:\>gnatmake

Usage: gnatmake  opts  name  {[-cargs opts] [-bargs opts] [-largs opts]}

  name  is a file name from which you can omit the .adb or .ads suffix

gnatmake switches:
  -a       Consider all files, even readonly ali files
  -b       Bind only
  -c       Compile only
  -C       Cache source mappings: invoke the compiler with a mapping file
  -f       Force recompilations of non predefined units
  -i       In place. Replace existing ali file, or put it with source
  -jnum    Use nnn processes to compile
  -k       Keep going after compilation errors
  -l       Link only
  -m       Minimal recompilation
  -M       List object file dependences for Makefile
  -n       Check objects up to date, output next file to compile if not
  -o name  Choose an alternate executable name
  -Pproj   Use GNAT Project File proj
  -q       Be quiet/terse
  -s       Recompile if compiler switches have changed
  -u       Unique compilation. Only compile the given file.
  -v       Display reasons for all (re)compilations
  -vPx     Specify verbosity when parsing GNAT Project Files
  -Xnm=val Specify an external reference for GNAT Project Files
  -z       No main subprogram (zero main)

  --GCC=command       Use this gcc command
  --GNATBIND=command  Use this gnatbind command
  --GNATLINK=command  Use this gnatlink command

Source and Library search path switches:
  -aLdir    Skip missing library sources if ali in dir
  -Adir     like -aLdir -aIdir
  -aOdir    Specify library/object files search path
  -aIdir    Specify source files search path
  -Idir     Like -aIdir -aOdir
  -I-       Don't look for sources & library files in the default directory
  -Ldir     Look for program libraries also in dir
  -nostdinc Don't look for sources in the system default directory
  -nostdlib Don't look for library files in the system default directory
  --RTS=dir specify the default source and object search path

To pass an arbitrary switch to the Compiler, Binder or Linker:
  -cargs opts   opts are passed to the compiler
  -bargs opts   opts are passed to the binder
  -largs opts   opts are passed to the linker

Compiler switches (passed to the compiler by gnatmake):

  -fstack-check Generate stack checking code
  -fno-inline   Inhibit all inlining (makes executable smaller)
  -g            Generate debugging information
  -Idir         Specify source files search path
  -I-           Do not look for sources in current directory
  -O[0123]      Control the optimization level

  -gnata    Assertions enabled. Pragma Assert/Debug to be activated
  -gnatA    Avoid processing gnat.adc, if present file will be ignored
  -gnatb    Generate brief messages to stderr even if verbose mode set
  -gnatc    Check syntax and semantics only (no code generation)
  -gnatC    Compress names in external names and debug info tables
  -gnatd?   Compiler debug option ? (a-z,A-Z,0-9), see debug.adb
  -gnatD    Debug expanded generated code rather than source code
  -gnatec?  Specify configuration pragmas file, e.g. -gnatec/x/f.adc
  -gnatem?  Specify mapping file, e.g. -gnatemmapping
  -gnatE    Dynamic elaboration checking mode enabled
  -gnatf    Full errors. Verbose details, all undefined references
  -gnatF    Force all import/export external names to all uppercase
  -gnatg    GNAT implementation mode (used for compiling GNAT units)
  -gnatG    Output generated expanded code in source form
  -gnath    Output this usage (help) information
  -gnati?   Identifier char set (?=1/2/3/4/5/8/9/p/f/n/w)
  -gnatk    Limit file names to nnn characters (k = krunch)
  -gnatl    Output full source listing with embedded error messages
  -gnatL    Use longjmp/setjmp for exception handling
  -gnatmnnn Limit number of detected errors to nnn (1-999)
  -gnatn    Inlining of subprograms (apply pragma Inline across units)
  -gnatN    Full (frontend) inlining of subprograqms
  -gnato    Enable overflow checking (off by default)
  -gnatO nm Set name of output ali file (internal switch)
  -gnatp    Suppress all checks
  -gnatP    Generate periodic calls to System.Polling.Poll
  -gnatq    Don't quit, try semantics, even if parse errors
  -gnatQ    Don't quit, write ali/tree file even if compile errors
  -gnatR?   List rep inf (?=0/1/2/3 for none/types/all/variable)
  -gnats    Syntax check only
  -gnatt    Tree output file to be generated
  -gnatTnnn All compiler tables start at nnn times usual starting size
  -gnatu    List units for this compilation
  -gnatU    Enable unique tag for error messages
  -gnatv    Verbose mode. Full error output with source lines to stdout
  -gnatVxx  Enable selected validity checking mode, xx = list of parameters:
        a    turn on all validity checking options
        c    turn on checking for copies
        C    turn off checking for copies
        d    turn on default (RM) checking
        D    turn off default (RM) checking
        f    turn on checking for floating-point
        F    turn off checking for floating-point
        i    turn on checking for in params
        I    turn off checking for in params
        m    turn on checking for in out params
        M    turn off checking for in out params
        o    turn on checking for operators/attributes
        O    turn off checking for operators/attributes
        r    turn on checking for returns
        R    turn off checking for returns
        s    turn on checking for subscripts
        S    turn off checking for subscripts
        t    turn on checking for tests
        T    turn off checking for tests
        n    turn off all validity checks (including RM)
  -gnatwxx  Enable selected warning modes, xx = list of parameters:
        a    turn on all optional warnings (except b,h)
        A    turn off all optional warnings
        b    turn on biased rounding warnings
        B    turn off biased rounding warnings
        c    turn on constant conditional warnings
        C*   turn off constant conditional warnings
        e    treat all warnings as errors
        f    turn on unreferenced formal warnings
        F*   turn off unreferenced formal warnings
        h    turn on warnings for hiding variables
        H*   turn off warnings for hiding variables
        i*   turn on warnings for implementation units
        I    turn off warnings for implementation units
        l    turn on elaboration warnings
        L*   turn off elaboration warnings
        o*   turn on address clause overlay warnings
        O    turn off address clause overlay warnings
        p    turn on warnings for ineffective pragma inline
        P*   turn off warnings for ineffective pragma inline
        r    turn on redundant construct warnings
        R*   turn off redundant construct warnings
        s    suppress all warnings
        u    turn on warnings for unused entities
        U*   turn off warnings for unused entities
        *    indicates default in above list
  -gnatW    Wide character encoding method (h/u/s/e/8/b)
  -gnatx    Suppress output of cross-reference information
  -gnatX    Language extensions permitted
  -gnaty    Enable all style checks except 'o', indent=3
  -gnatyxx  Enable selected style checks xx = list of parameters:
        1-9  check indentation
        a    check attribute casing
        b    check no blanks at end of lines
        c    check comment format
        e    check end/exit labels present
        f    check no form feeds/vertical tabs in source
        h    check no horizontal tabs in source
        i    check if-then layout
        k    check casing rules for keywords, identifiers
        l    check reference manual layout
        m    check line length <= 79 characters
        n    check casing of package Standard identifiers
        Mnnn check line length <= nnn characters
        o    check subprogram bodies in alphabetical order
        p    check pragma casing
        r    check RM column layout
        s    check separate subprogram specs present
        t    check token separation rules
  -gnatz    Distribution stub generation (r/s for receiver/sender stubs)
  -gnatZ    Use zero cost exception handling
  -gnat83   Enforce Ada 83 restrictions 





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: gnat options (Re: elaboration circularity detected problem, How to fix?
  2004-09-21  7:30     ` gnat options (Re: " Peter Hermann
  2004-09-21  8:00       ` Scott Travak
@ 2004-09-21  8:09       ` Alex R. Mosteo
  1 sibling, 0 replies; 14+ messages in thread
From: Alex R. Mosteo @ 2004-09-21  8:09 UTC (permalink / raw)


Peter Hermann wrote:
> Scott Travak <s.travak@j-inet.com> wrote:
> 
>>Thanks, Yep my error is based upon a compilation using the -gnatE option. 
> 
> 
> apropos:
> I would like to have a summary of all options a,b,c,...,A,B,C...
> for gnat, gnatmake, gcc, etc... in one place.
> Does this exist somewhere?
> The gnat documentation is poor in this respect, spreading that info,
> which always leads to a waste of time when searching for the meaning
> of an option, e.g. -gnatE.

Either the user guide or the reference manual has a list of options that 
I'd say is comprehensive and non-spreaded. I suggest a top-down read at 
least once.

Then if you're interested in a particular option it's easy to use the 
search function of the browser.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: elaboration circularity detected problem, How to fix?
  2004-09-20 21:19     ` Randy Brukardt
@ 2004-09-21 10:09       ` Martin Dowie
  2004-09-21 17:53         ` Randy Brukardt
  0 siblings, 1 reply; 14+ messages in thread
From: Martin Dowie @ 2004-09-21 10:09 UTC (permalink / raw)


Randy Brukardt wrote:
> We had to put in a bunch of Gnat-specific pragmas to eliminate the
problems.
> Program_Error would never be raised at runtime, and remember that you
> need -gnatE to conform to the standard (dynamic elaboration checks is
> what the Standard requires).

So to change from "GNAT" to "Ada" the list of options is
"-gnato -gnatE -fstack-check"? Anyone got any more?..






^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: elaboration circularity detected problem, How to fix?
  2004-09-21 10:09       ` Martin Dowie
@ 2004-09-21 17:53         ` Randy Brukardt
  0 siblings, 0 replies; 14+ messages in thread
From: Randy Brukardt @ 2004-09-21 17:53 UTC (permalink / raw)


"Martin Dowie" <martin.dowie@baesystems.com> wrote in message
news:414ffc57$1_1@baen1673807.greenlnk.net...
> Randy Brukardt wrote:
> > We had to put in a bunch of Gnat-specific pragmas to eliminate the
> problems.
> > Program_Error would never be raised at runtime, and remember that you
> > need -gnatE to conform to the standard (dynamic elaboration checks is
> > what the Standard requires).
>
> So to change from "GNAT" to "Ada" the list of options is
> "-gnato -gnatE -fstack-check"? Anyone got any more?..

The options used for running the ACATS the last time that GNAT was tested
for conformity were:

     -O0 -gnatE -gnato -gnatv -gnatws -gnatd7

(You can find this information in the conformity assessment report, which
you can find on-line at www.adaic.com under the "Compilers and Conformity"
section, look in the CPL.)

-gnatv gives verbose messages, -gnatd7 suppresses time stamps in those
messages (presumably to make them easier to compare), and -gnatws is to
suppress warnings.

Of course, this is fairly old (it was done in late 1998) and possibly some
things have changed in the interim.

              Randy.






^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: elaboration circularity detected problem, How to fix?
  2004-09-21  6:44   ` Scott Travak
@ 2004-09-21 18:40     ` Ludovic Brenta
  2004-09-21 20:15       ` Scott Travak
  0 siblings, 1 reply; 14+ messages in thread
From: Ludovic Brenta @ 2004-09-21 18:40 UTC (permalink / raw)


I had to modify Scott's code just a wee bit and I tried it on two
compilers, one being GNAT 3.15p on Debian.  None of the compilers gave
any error message, and the program runs as expected.  Here is my
slightly amended version.  The changes are:

- place everything into one procedure, with nested packages

- remove Station.Chicago_Ptr, which hides the top-level Chicago_Ptr
  but is different, since its pointers are left uninitialised.  In
  fact, this may well be the source of the problem.

Enjoy:

with Ada.Text_Io;
use Ada.Text_Io;

procedure Circularity is

    type Location_Type is (Chicago, Paris, London);

    generic
        Centre : Location_Type;
    package Location is
        task type Send_Type is
        end Send_Type;

        task type Receive_Type is
            entry Ack_Channel;
        end Receive_Type;

        type Send_Ptr_Type is access Send_Type;
        type Receive_Ptr_Type is access Receive_Type;

        Send_Ptr : Send_Ptr_Type;
        Receive_Ptr : Receive_Ptr_Type;
    end Location;


    package Station is
        task Destination is
            entry Signal;
        end Destination;
    end Station;


    package body Location is
        task body Send_Type is
            Calls : Integer := 2;
            Done : Boolean := False;
        begin
            Put_Line (Location_Type'Image (Centre) & "_SEND alive");
            while Calls > 0 loop
                delay 0.1;
                Put_Line (Location_Type'Image (Centre) &
                          " pings the Destination");
                Station.Destination.Signal;
                Calls := Calls - 1;
            end loop;
            Put_Line (Location_Type'Image (Centre) & "_SEND dead");
        end Send_Type;


        task body Receive_Type is
            Done : Boolean := False;
        begin
            Put_Line (Location_Type'Image (Centre) & "_RECEIVE alive");
            while not Done loop
                select
                    accept Ack_Channel do
                        Put_Line (Location_Type'Image (Centre) &
                                  " received an acknowledgement");
                    end Ack_Channel;
                else
                    delay 0.1;
                end select;
            end loop;
            Put_Line (Location_Type'Image (Centre) & "_RECEIVE dead");
        end Receive_Type;
    end Location;


    package Chicago_Ptr is new Location (Chicago);


    package body Station is
        task body Destination is
            Done : Boolean := False;
        begin
            Put_Line ("DESTINATION alive");
            while not Done loop
                select
                    accept Signal do
                        Put_Line ("DESTINATION: Received signal");
                        Chicago_Ptr.Receive_Ptr.Ack_Channel;
                    end Signal;
                else
                    delay 0.1;
                end select;
            end loop;
            Put_Line ("DESTINATION dead");
        end Destination;
    end Station;

begin
    Chicago_Ptr.Send_Ptr := new Chicago_Ptr.Send_Type;
    Chicago_Ptr.Receive_Ptr := new Chicago_Ptr.Receive_Type;
end Circularity;


The output is:
./circularity
DESTINATION alive
CHICAGO_SEND alive
CHICAGO_RECEIVE alive
CHICAGO pings the Destination
DESTINATION: Received signal
CHICAGO received an acknowledgement
CHICAGO pings the Destination
DESTINATION: Received signal
CHICAGO received an acknowledgement
CHICAGO_SEND dead

The program does not exit; of course, the tasks CHICAGO_RECEIVE and
DESTINATION are still waiting for input.  Hence the program behaves as
expected, at least for me.

-- 
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: elaboration circularity detected problem, How to fix?
  2004-09-21 18:40     ` Ludovic Brenta
@ 2004-09-21 20:15       ` Scott Travak
  0 siblings, 0 replies; 14+ messages in thread
From: Scott Travak @ 2004-09-21 20:15 UTC (permalink / raw)


Thanks for that Dennis and Ludovic! The both of you helped me out a lot on 
this. From Dennis I realised that I could be splitting the 'Location' 
package into two seperate packages "Location_Send' and 'Location_Receive'. 
In that case circularity is removed. Ludovic pointed me towards a problem 
being in Station.Chicago_Ptr not being initialised. The program works great 
now.

Yep the tasks CHICAGO_RECEIVE and DESTINATION are still waiting for input. I 
removed some code to make my posted code smaller. My original code controls 
all shutdowns to all tasks.

Thanks so much again!

Cheers, Scott



"Ludovic Brenta" <ludovic.brenta@insalien.org> wrote in message 
news:87y8j3foto.fsf@insalien.org...
>I had to modify Scott's code just a wee bit and I tried it on two
> compilers, one being GNAT 3.15p on Debian.  None of the compilers gave
> any error message, and the program runs as expected.  Here is my
> slightly amended version.  The changes are:
>
> - place everything into one procedure, with nested packages
>
> - remove Station.Chicago_Ptr, which hides the top-level Chicago_Ptr
>  but is different, since its pointers are left uninitialised.  In
>  fact, this may well be the source of the problem.
>
> Enjoy:
>
> with Ada.Text_Io;
> use Ada.Text_Io;
>
> procedure Circularity is
>
>    type Location_Type is (Chicago, Paris, London);
>
>    generic
>        Centre : Location_Type;
>    package Location is
>        task type Send_Type is
>        end Send_Type;
>
>        task type Receive_Type is
>            entry Ack_Channel;
>        end Receive_Type;
>
>        type Send_Ptr_Type is access Send_Type;
>        type Receive_Ptr_Type is access Receive_Type;
>
>        Send_Ptr : Send_Ptr_Type;
>        Receive_Ptr : Receive_Ptr_Type;
>    end Location;
>
>
>    package Station is
>        task Destination is
>            entry Signal;
>        end Destination;
>    end Station;
>
>
>    package body Location is
>        task body Send_Type is
>            Calls : Integer := 2;
>            Done : Boolean := False;
>        begin
>            Put_Line (Location_Type'Image (Centre) & "_SEND alive");
>            while Calls > 0 loop
>                delay 0.1;
>                Put_Line (Location_Type'Image (Centre) &
>                          " pings the Destination");
>                Station.Destination.Signal;
>                Calls := Calls - 1;
>            end loop;
>            Put_Line (Location_Type'Image (Centre) & "_SEND dead");
>        end Send_Type;
>
>
>        task body Receive_Type is
>            Done : Boolean := False;
>        begin
>            Put_Line (Location_Type'Image (Centre) & "_RECEIVE alive");
>            while not Done loop
>                select
>                    accept Ack_Channel do
>                        Put_Line (Location_Type'Image (Centre) &
>                                  " received an acknowledgement");
>                    end Ack_Channel;
>                else
>                    delay 0.1;
>                end select;
>            end loop;
>            Put_Line (Location_Type'Image (Centre) & "_RECEIVE dead");
>        end Receive_Type;
>    end Location;
>
>
>    package Chicago_Ptr is new Location (Chicago);
>
>
>    package body Station is
>        task body Destination is
>            Done : Boolean := False;
>        begin
>            Put_Line ("DESTINATION alive");
>            while not Done loop
>                select
>                    accept Signal do
>                        Put_Line ("DESTINATION: Received signal");
>                        Chicago_Ptr.Receive_Ptr.Ack_Channel;
>                    end Signal;
>                else
>                    delay 0.1;
>                end select;
>            end loop;
>            Put_Line ("DESTINATION dead");
>        end Destination;
>    end Station;
>
> begin
>    Chicago_Ptr.Send_Ptr := new Chicago_Ptr.Send_Type;
>    Chicago_Ptr.Receive_Ptr := new Chicago_Ptr.Receive_Type;
> end Circularity;
>
>
> The output is:
> ./circularity
> DESTINATION alive
> CHICAGO_SEND alive
> CHICAGO_RECEIVE alive
> CHICAGO pings the Destination
> DESTINATION: Received signal
> CHICAGO received an acknowledgement
> CHICAGO pings the Destination
> DESTINATION: Received signal
> CHICAGO received an acknowledgement
> CHICAGO_SEND dead
>
> The program does not exit; of course, the tasks CHICAGO_RECEIVE and
> DESTINATION are still waiting for input.  Hence the program behaves as
> expected, at least for me.
>
> -- 
> Ludovic Brenta. 





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: elaboration circularity detected problem, How to fix?
  2004-09-20 14:51 elaboration circularity detected problem, How to fix? Scott Travak
  2004-09-20 15:52 ` Martin Dowie
       [not found] ` <7e7vk0dv2qhpqbdd58c0bvpesitapijr8v@4ax.com>
@ 2004-09-22 21:08 ` Simon Wright
  2 siblings, 0 replies; 14+ messages in thread
From: Simon Wright @ 2004-09-22 21:08 UTC (permalink / raw)


"Scott Travak" <s.travak@j-inet.com> writes:

> Hi everyone, I was hoping to obtain some assistance with a program I am 
> constructing. Essentially my program is made up as follows:
> 
> 1) Two packages (one of which is a generic package).
> 2) Each package essentially contains a task
> 3) Each task contains a reference to (operates on) the other task
> 
> I am encountering a "elaboration circularity detected" error (see
> below).

The thing to do is to avoid having library level tasks.

The tasks start up as they are elaborated and, since they reference
each other, the compiler can't tell that there isn't a problem (even
if you use the

  task body ...
  begin
     accept Start;

idiom to stop things happening until you are ready).

One way round this is to use access-to-task-type's and only actually
allocate the tasks when you are ready.


Of course there are other ways of getting a circularity (our record
was a loop of 534 in a program with only 530 packages!! I think there
may have been a bug somewhere .. but that was GNAT 3.11 or
thereabouts), but the task way is a winner.


-- 
Simon Wright                               100% Ada, no bugs.



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2004-09-22 21:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-20 14:51 elaboration circularity detected problem, How to fix? Scott Travak
2004-09-20 15:52 ` Martin Dowie
2004-09-20 17:11   ` Florian Weimer
2004-09-20 21:19     ` Randy Brukardt
2004-09-21 10:09       ` Martin Dowie
2004-09-21 17:53         ` Randy Brukardt
2004-09-21  6:32   ` Scott Travak
2004-09-21  7:30     ` gnat options (Re: " Peter Hermann
2004-09-21  8:00       ` Scott Travak
2004-09-21  8:09       ` Alex R. Mosteo
     [not found] ` <7e7vk0dv2qhpqbdd58c0bvpesitapijr8v@4ax.com>
2004-09-21  6:44   ` Scott Travak
2004-09-21 18:40     ` Ludovic Brenta
2004-09-21 20:15       ` Scott Travak
2004-09-22 21:08 ` Simon Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox