Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site decwrl.UUCP Path: utzoo!linus!decvax!decwrl!powell From: powell@decwrl.UUCP Newsgroups: net.lang.mod2 Subject: id AA11814; Sun, 19 Feb 84 21:02:32 pst Message-ID: <5697@decwrl.UUCP> Date: Sun, 26-Feb-84 00:02:45 EST Article-I.D.: decwrl.5697 Posted: Sun Feb 26 00:02:45 1984 Date-Received: Mon, 20-Feb-84 08:40:42 EST Sender: powell@decwrl.UUCP Organization: DEC Western Research Lab, Los Altos, CA Lines: 76 Date: Sun, 19 Feb 84 21:02:32 pst From: powell (Mike Powell) Message-Id: <8402200502.AA11814@decwrl.arpa> To: net.lang.mod2 Subject: Circularity Peculiarity As an implementer of a Modula-2 compiler, I would be interested to know exactly what sort of "cyclic dependency" is permitted by the Volition (or any other) compiler. A reference to Wirth's book indicating where it says it's legal would also be helpful. It seems to me that allowing the following is hard: definition module a; from b import BType; export qualified AType; type AType = pointer to record b : BType; end; end a; definition module b; from a import AType; export qualified BType; type BType = record a : AType; end; end b; I've supported a compiler (for the Model programming language) which allowed such things, and the type resolution procedures were the largest single source of bugs. The problem is that an additional pass is required to resolve types. The walk over the type graph is complicated because there may be recursions (as above). If there is a loop, there must be a pointer (otherwise, it's an error), and the loop must be broken at that point. Anyhow, it turned out to be expensive to do it right (if the fact that we don't know of any bugs at the moment means it does it right). Moreover, if Wirth's intent were to allow such circularity, there would be no need for rule 1 in section 4 of the report, since forward references to types would be handled by the same mechanism. What I think is easy to do is to allow the following: definition module a; (* no imports from b *) ... end a; implementation module a; from b import WhateverYouLike; ... end a; definition module b; from a import Anything; ... end b; implementation module b; ... end b; In this case, the only potential question is about which initialization routine is executed first. Again, if anyone has a concrete answer, I'd be interested. For local modules, they are supposed to be initialized in declaration order (Report section 11), not dependency order, which could allow a procedure in a local module to be called before its initialization is executed! Anyhow, opinions or citations would be appreciated. Michael L. Powell Western Research Laboratory Digital Equipment Corporation Los Altos, CA {ucbvax,decvax}!decwrl!powell