[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Accidental clobbering of pnames etc.

As an alternative to current anarchy and my earlier proposal to have
extra runtime types for readonly-string etc., perhaps we could have a way
to declare things readonly. There are two kinds: (1) This function is
guaranteed not to modify this particular argument; (2) This returned value
must not be modified by anyone.  The compiler can then be fixed so that
it's ok to pass (2) data as (1) args, but not as non-(1) args. User functions
can be declared not to ever modify their args, and the compiler can verify
this is indeed true when compiling those functions. Global variables can
be declared (3) this variable may contain data that should never be modified,
then it's permissible to store (2) data in that variable and impermissible
to destructively modify anything stored there. Any time data is picked
out of a readonly variable or a readonly returned value, that sub-data is
also considered to be readonly, and the compiler enforces that nobody
tries to modify it or put it where somebody else would be allowed to
modify. Of course when a total copy (including copying bytes of strings
etc.) of data occurs that resultant data is no longer considered readonly.

This is overkill in the sense that if you have one little piece of readonly
data which you insert into something else, that whole large object is
readonly, and if then a part is extracted from some place unrelated to
the truly readonly data that part is unnecessarily readonly, but the
programmer can avoid that by copying the little readonly piece in the
first place before sticking it into the big structure. Anyway, compiled
code will then never clobber PNAMEs etc. with this proposal implemented.
(Maybe even a super-smart interpretor could respect the declarations??)