From: daveb@geac.UUCP (David Collier-Brown)
Subject: Re: Writing upgradable data structures
Date: 8 Mar 88 13:39:14 GMT [thread overview]
Date: Tue Mar 8 08:39:14 1988
Message-ID: <2417@geac.UUCP> (raw)
In-Reply-To: 2767@enea.se
Date: Fri, 4 Mar 88 23:33 EST
From: Barry Margolin <rutgers!think!barmar>
Subject: Re: Writing upgradable data structures
To: David Collier-Brown <uiucdcs!uiucuxc!unicus!geac!daveb>
In-Reply-To: <8803011228.AA18007@geac.UUCP>
Message-Id: <19880305043329.6.BARMAR@OCCAM.THINK.COM>
While I was in the Multics group at Honeywell we did some
investigation of implementing a Multics followon in Ada. I thought
the same thing regarding versioned structures, but I was convinced by
some more experienced Ada people that we could do this using variant
records. When you upgrade the structure you add a new variant. This
does require recompiling users of the structure, but it doesn't force
old, stable programs to be recoded unless they want to take advantage
of the new structure's features.
>from dave:
> Would you consider posting a variant of this? The requirement that
> one update is an important one, and should be faced by the Ada
> community.
Here's an example, but the idea is pretty simple. If you want to post
it to comp.software-eng (I don't think it is appropriate for
comp.lang.c, and I don't subscribe to comp.software-eng), feel free.
type THING is
record
VERSION: constant (THING_VERSION_1, THING_VERSION_2, THING_VERSION_3, ...);
-- first, the components common to all versions
PART1: <type>;
PART2: <type>;
case VERSION of
-- No THING_VERSION_1 case, because it only has the common parts
when THING_VERSION_2 => PART3: <type>;
PART4: <type>;
when THING_VERSION_3 => PART3: <type>;
PART4: <type>;
PART5: <type>;
PART6: <type>;
when ...
end case;
end record;
Unfortunately, Ada requires you to repeat the common prefixes in each
version. One thing I thought of was to use
type THING is
record
VERSION: constant (THING_VERSION_1, THING_VERSION_2, THING_VERSION_3, ...);
-- first, the components common to all versions
PART1: <type>;
PART2: <type>;
case VERSION of
-- No THING_VERSION_1 case, because it only has the common parts
when THING_VERSION_2 => PART3: <type>;
PART4: <type>;
when THING_VERSION_3 => COMMON: THING (VERSION => THING_VERSION_2);
PART5: <type>;
PART6: <type>;
...
when THING_VERSION_n => COMMON: THING (VERSION => THING_VERSION_n-1);
PARTm-1: <type>;
PARTm: <type>;
end case;
end record;
First of all, I don't know whether Ada allows recursive type
declarations like this; if it doesn't, the above becomes:
type THING_V1 is
record
PART1: <type>;
PART2: <type>;
end record;
type THING_V2 is
record
COMMON: THING_V1;
PART3: <type>;
PART4: <type>;
end record;
...
type THING_Vn is
record
COMMON: THING_Vn-1;
PARTm-1: <type>;
PARTm: <type>;
type THING is
record
VERSION: constant (THING_VERSION_1, THING_VERSION_2, THING_VERSION_3, ...);
case VERSION of
when THING_VERSION_1 => CONTENTS: THING_V1;
when THING_VERSION_2 => CONTENTS: THING_V2;
...
when THING_VERSION_n => CONTENTS: THING_Vn;
end case;
end record;
A problem with this, though, is that I think Ada requires the program to
specify all levels of a structure in a reference to a component, so a
program that wants to access PART1 of a THING must use X.CONTENTS.PART1
if it is a version 1 THING, but X.CONTENTS.CONTENTS.CONTENTS.PART1 if it
is a version 3 THING. PL/I permits the program to leave out structure
qualifiers if the reference is unambiguous.
I don't subscribe to comp.software-eng, so if anyone has any comments on
this, reply via mail.
--
Barry Margolin
Thinking Machines Corp.
barmar@think.com
uunet!think!barmar
next parent reply other threads:[~1988-03-08 13:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2307@geac.UUCP>
[not found] ` <2767@enea.se>
1988-03-08 13:39 ` David Collier-Brown [this message]
1988-03-10 14:03 ` Writing upgradable data structures David Collier-Brown
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox