|
From: Peter C. Chapin on 13 Apr 2008 18:49 Robert A Duff wrote: > The stricter rules are conservative, and modular -- when compiling > Parent, it sees that you're calling Parent.Child, and assumes the worst > WITHOUT looking at Parent.Child body. For example, it assumes that > Parent.Child might call Dummy, causing a real cycle. Thanks to you and Samuel Tardieu for your replies. They do help to clarify things for me somewhat. It is easy for me to understand how Parent.Child's body would have an elaboration dependency on Parent's spec, but I did not expect Parent.Child's body to necessarily have an elaboration dependency on Parent's body. Are you saying that it doesn't (necessarily) have such a dependency in standard Ada, but that I'm experiencing an example of GNAT's stricter rules? In any event I got my example to work with an appropriate application of pragma Elaborate. I guess I didn't stumble into the right combination in my earlier tinkering. It helps to have a better idea of what is happening. :-) > I suggest you read the section in the GNAT docs about elaboration. > It explains all this stuff in great detail. Yes, actually I read that stuff, but I didn't see anything in particular about elaboration dependencies between parent and child packages. >> Note my actual program involves a task in the parent that is trying to >> use subprograms in the child. However, the difficulties I'm having >> appear to be unrelated to tasking. > > Don't be too sure. Tasks get activated "early", and can easily cause > elab cycles. Look at the docs for details. I'm not saying that the errors in the tasking example (my real program) are wrong. Indeed, I assumed there was some non-trivial stuff going on during elaboration that was stimulating the error. I was just glad when I could (apparently) reproduce the problem with a simpler example. That makes it easier to study, of course. Peter
From: Robert A Duff on 14 Apr 2008 09:56 "Peter C. Chapin" <pchapin(a)sover.net> writes: > Thanks to you and Samuel Tardieu for your replies. You're welcome. >...They do help to > clarify things for me somewhat. It is easy for me to understand how > Parent.Child's body would have an elaboration dependency on Parent's > spec, but I did not expect Parent.Child's body to necessarily have an > elaboration dependency on Parent's body. Are you saying that it doesn't > (necessarily) have such a dependency in standard Ada, but that I'm > experiencing an example of GNAT's stricter rules? Yes. Your original example (with no pragmas added) is legal, and a valid Ada compiler (such as GNAT with -gnatE) will compile and link it just fine. However, it might fail at run time. Worst case: it works fine, but 2 years later, you port it to a new compiler (new machine, or even a new version of the same compiler), and you get a mysterious Program_Error. If you get an elab cycle when you modify your program (e.g., you add a with_clause), it's easy to deal with -- your change is small, and you know it caused the cycle. But if you get a Program_Error when porting a giant program to a new compiler, it can easily take several hours to figure out the problem. - Bob
From: Jeffrey R. Carter on 14 Apr 2008 13:33 Peter C. Chapin wrote: > > package Parent is > -- Needed so this package requires/allows a body. > procedure Dummy; > end Parent; Not related to your question, but perhaps of interest to you: Dummy is not needed so the pkg allows a body. Pragma Elaborate_Body is a better way to achieve that: package Parent is pragma Elaborate_Body; end Parent; -- Jeff Carter "My name is Jim, but most people call me ... Jim." Blazing Saddles 39
From: Robert A Duff on 14 Apr 2008 13:52 "Jeffrey R. Carter" <spam.jrcarter.not(a)spam.acm.org> writes: > Peter C. Chapin wrote: >> package Parent is >> -- Needed so this package requires/allows a body. >> procedure Dummy; >> end Parent; > > Not related to your question, but perhaps of interest to you: Dummy is > not needed so the pkg allows a body. Pragma Elaborate_Body is a better > way to achieve that: It's better in many cases, but in this particular case, it would make the program illegal. ;-) > package Parent is > pragma Elaborate_Body; > end Parent; - Bob
From: Robert A Duff on 14 Apr 2008 16:21 Samuel Tardieu <sam(a)rfc1149.net> writes: >>>>>> "Robert" == Robert A Duff <bobduff(a)shell01.TheWorld.com> writes: > > Robert> Samuel Tardieu <sam(a)rfc1149.net> writes: >>> No. pragma Elaborate_All is transitive, and forces the elaboration >>> of Parent body (since Parent.Child has an implicit dependency on >>> Parent) > > Robert> Yes, it has a dependence. But why do you call it "implicit"? > > Because it is not spelt explicitely using a with clause or an > Elaborate/Elaborate_All pragma. And if it's not explicit, it must be > implicit. OK. To me, the primary purpose of a with clause, and the primary purpose of a parent name, is their effect on visibility. Both appear explicitly in the code. Secondary issues are semantic dependences, compilation dependences, and elaboration-order dependences. So I don't see one as more "implicit" than the other. The reason I asked is that "implicit" is often a matter of opinion, and I'm curious about what it means to people in cases like this. There was some argument at AdaCore recently about what pragma Restrictions (No_Implicit_Heap_Allocations); means in a certain obscure case. > One could say that when you write "package Parent.Child", you > explicitely spell "Parent" so this is an explicit dependency > declaration. Yes, one could, and I do. ;-) >...However, for me it is a declaration of the "Parent.Child" > package, which implicitely creates a semantic dependency on Parent. > > Now, I think we are both nitpicking here,... Nitpicking? Yes, I plead guilty as charged. ;-) >... as I don't think the RM says > anything about "explicit" vs. "implicit" dependencies, it only > consider "static dependences" and "elaboration dependences". > > Btw, I never noticed the use of "dependence" vs. "dependency" > before. Is there a difference in English? I don't know. Most people say "dependency". But the Ada 83 RM used "dependence", and we didn't change it for Ada 95 (or 2005), and I've gotten used to typing that. Note that the primary author of Ada 83 was a Frenchman. ;-) - Bob
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Announcement: GNAT ported to LLVM Next: SIGAda coverage in GCN |