Up to top level
compiler bugs   dustin's bugs   fixed   incoming   nonproblems   tests   website bugs  

Logged in as guest

Viewing nonproblems/31
Full headers

From: louised@dai.ed.ac.uk
Subject: Confused about useonly
Compose reply
Download message
Move To:
2 replies: 1 2
1 followups: 1

Private message: yes  no

Notes:

Notification:


Date: Fri, 15 Sep 2000 08:56:06 -0500 (CDT)
From: louised@dai.ed.ac.uk
To: teyjus@cs.umn.edu
Subject: Confused about useonly
Full_Name: Louise Dennis
Version: 1.0-b29
OS: Solaris
Submission from: (NULL) (194.83.240.18)


If I'm importing or accumulating a module and I wish to mark some predicate in
that 
module as useonly the compiler complains that it is not so marked in the parent
module.

If I mark it useonly in the parent module where it is defined then the compiler,
as I
expected, complains because it _isn't_ useonly in that module.

How do I get the compiler to accept a use only declaration?

Reply 1

Resend
From: Gopalan Nadathur <teyjus@cs.umn.edu>
To: louised@dai.ed.ac.uk
Subject: Re: Confused about useonly (PR#31)
Date: Thu Nov  2 14:19:08 2000
CC: teyjus@cs.uchicago.edu
Hi Louise,

It has taken a while for me to respond to this report---hopefully things will be
faster here on out. 

You had asked

> Full_Name: Louise Dennis
> Version: 1.0-b29
> OS: Solaris
> Submission from: (NULL) (194.83.240.18)
> 
> 
> If I'm importing or accumulating a module and I wish to mark some predicate
in
> that 
> module as useonly the compiler complains that it is not so marked in the
parent
> module.
> 
> If I mark it useonly in the parent module where it is defined then the
compiler,
> as I
> expected, complains because it _isn't_ useonly in that module.
> 
> How do I get the compiler to accept a use only declaration?
> 

I am not sure I understand the problem.  Here are a collection of modules and
associated signatures that seem to do exactly what you want and they do not
cause 
any complaints from the compiler:

-----------------------------
sig test1.

useonly foo o.
-----------------------------
module test1.

-----------------------------
sig test2.

type foo o.

type bar o.
-----------------------------
module test2.

accumulate test1.

foo :- bar.
-----------------------------

I can replace the accumulate in test2 with an import and this is still okay.
Am I missing something?

-Gopalan


Followup 1

Compose reply
Download message
Date: Fri, 03 Nov 2000 11:38:33 +0000
From: Louise Dennis <louised@dai.ed.ac.uk>
To: Gopalan Nadathur <teyjus@cs.umn.edu>
Subject: Re: Confused about useonly (PR#31)
I think, looking at your example that I must be confused over what
useonly is for.  What function is it serving here?  You can't define any
clauses for foo in test1 so what's the point of defining it at all? 
However you import it into test2 which can define clauses for it?  It
seems to me that this is for a relatively specialised case where you
want to use a predicate in a module which won't have any clauses defined
until some module later in the compile process is built.  Is this
right?  If so then I asked the wrong question.

The problem I was trying to use useonly to solve is as follows:  I
originally built the teyjus version of lclam with a fairly complex
module dependency structure (e.g. the built-in lists module was
imported/accumulated into a number of other modules all of which were
eventually accumulated/imported into the top level lclam module).

Orginally I used import for all modules which contained only predicates
I didn't want to extend believing that (with care) this would avoid the
problem where such predicate's clauses would appear multiple times and
so I would get duplicated successes.  This didn't work because once a
chain of imports was more that 2 long the final module couldn't "see"
predicates in earlier modules.  This meant that I was frequently
importing a module like lists into every module that wanted to use list
predicates even if that module was importing modules that also used
lists.  In this case some predicates would still be seeing the list
predicates twice.  An example is the following test set of files I set
up to try and solve the problem of what import/accumulate statement I
should use where.  The object is that with 
tjsim final I want atest, btest and testing all to succeed once only.

The solutions I have found are to impose a strict compilation order the
modules by which each module accumulates one and only one module and
each module is accumulated by one and only one module.  The disadvantage
of this is that when you create a new module you have to insert it into
this chain in an (often) rather unituitive way.

The other seems to be to use accum_sig only except in the very last
module where you import/accumulate everything as appropriate.  This is
less fiddly but seems to go against the idea of modules as working
pieces of code in their own right.

I feel there should be a better way to do this but I've not been able to
work it out.

Louise

---
sig test.

kind greeting type.

type hello greeting.

type test greeting -> o.
end
---
module test.

test hello.

end
---
sig routea.

accum_sig test.

type routea greeting -> o.

end
---
module routea.

import test.

routea X:-
	test X.

end
---
sig routeb.

accum_sig test.

kind greeting type.

type routeb greeting -> o.

end
---
module routeb.

import test.

routeb X:-
	test X.

end
---
sig final.

accum_sig routea, routeb, test.

type atest greeting -> o.
type btest greeting -> o.
type testing greeting -> o.

end
---
module final.

import routea, routeb, test.

atest A :-
	routea A.

btest B :-
	routeb B.

testing C :-
	test C.

end
---


Reply 2

Resend
From: Gopalan Nadathur <teyjus@cs.umn.edu>
To: louised@dai.ed.ac.uk
Subject: Re: Confused about useonly (PR#31)
Date: Tue Dec 12 21:34:44 2000
CC: teyjus@cs.uchicago.edu
Hi Louise, 

For some reason, this posting was not forwarded to me and I am seeing it only
now, when explicitly browsing through the bug report page. While I check on why
this
happened, perhaps it is a good idea to CC the message explicitly to
teyjus@cs.uchicago.edu. 

> I think, looking at your example that I must be confused over what
> useonly is for.  What function is it serving here?  You can't define any
> clauses for foo in test1 so what's the point of defining it at all? 

The purpose of useonly here is to allow foo to be recognized as a predicate in 
test1 (and thus be used in the bodies of clauses) but to signal at the same
time
that no new clauses can be added for it in test1. This does have a
documentation
value and it has an effect also on the code that is generated---this code can 
be more efficient. 

With regard to the problem you want to solve. First, if a module testa is
imported 
or accumulated into two different modules testb and testc that are then
imported
or accumulated into a common module testd, you will simply get two copies of
testa. 
There is not much to be done about this---consider the fact that you can hide
things 
from testa inside testb or testc and you will begin to see why this must be the

case. 

Now, the effect you want to achieve is that of having exactly one version of the

predicates in testa visible in each of testb, testc and testd. There are two
ways 
to have this. One way is what you suggest: accumulate the signature of testa in
testb and testc and accumulate the code of testa in only testd. The other way
to
achieve this effect is to accumulate testa into testb, testc and testd but to
*not* 
accumulate the signature of testa into the signature of testb and testc. Thus,
the versions of testa that are accumulated into testb, testc and testd are kept

*distinct* and so there is only one version visible within each. 

The second solution gives you the effect of `independent' modules but there is
also
a larger bytecode. Actually, I do not see the first solution as that far away
from
the idea of independent modules as your message seems to suggest. One way to 
thing of testb without the code for the predicates in testa but with the
signature 
of testa accumulated into its signature is as a module that is parameterised by

the signature testa: when it is accumulated into a context that has a
definition
for the predicates in testa, then it obtains a particular, executable, meaning.


I append a version of the code you included modified to reflect the second
solution 
below. 

-Gopalan

P.S. Import is a costly operation; I would use accumulate instead whereever it
makes
sense. Right now accumulate does not support separate compilation but I hope
that
this will change in the future. 

---------------------------
sig test.

kind greeting type.

type hello greeting.

type test greeting -> o.
end
---
module test.

test hello.

end
---
sig routea.

type routea greeting -> o.

end
---
module routea.

import test.

routea X:-
        test X.

end
---
sig routeb.

kind greeting type.

type routeb greeting -> o.

end
---
module routeb.

import test.

routeb X:-
        test X.

end
---
sig final.

accum_sig routea, routeb, test.

type atest greeting -> o.
type btest greeting -> o.
type testing greeting -> o.

end
---
module final.

import routea, routeb, test.

atest A :-
        routea A.

btest B :-
        routeb B.

testing C :-
        test C.

end
---

Up to top level
compiler bugs   dustin's bugs   fixed   incoming   nonproblems   tests   website bugs  

Logged in as guest


[ Home | Overview | Download | Language Documentation | Bug Tracking | Implementation Documentation | Links ]