newspeaklanguage / newspeak

Newspeak is a live object-capability language in the Smalltalk tradition
https://newspeaklanguage.org/
Other
136 stars 11 forks source link

Implement transient slots. #90

Closed gbracha closed 6 months ago

gbracha commented 3 years ago

As the old Squeak version did. They are needed long term of orthogonal sync, but also for implementing images and most immediately, for improved liveness. Every cached slot should become a transient one, and every time it's code is redefined, the slot should be nil'ed (as with sync) and the data will be be recomputed - ensuring instant live update.

gbracha commented 2 years ago

My latest thinking on this is that rather than define transient as a language feature, it may be better to define a concept of lazy slots, and use metadata to describe transient slots.

A lazy slot would be defined by prefixing it with lazy. It would require an initializer, but would be initialized to nil, and at first access, the initializer would be evaluated and the slot would be set to the result. In other words,

lazy slot = e.

would be roughly equivalent to

slot_x, where slot_x is an invalid identifier, and method

slot = ( slot_x isNil ifTrue: [slot_x:: e]. ^slot_x )

Note that lazy slots are not defined in the scope of the factory method.

If we actually want a transient slot, we'd write

( :transient: ) lazy slot = e.

The metadata would describe the following slot declaration, which would be treated as transient by the persistence/sync mechanism. It would warn if the slot was not lazy, since that would cause failure upon sync, since it would not be initialized. We should resist any temptation to have the metadata induce laziness, as this conflates metadata and runtime semantics.

The advantage of this design is that there are many cases where lazy initialization is needed, irrespective of persistence, and we are currently forced to implement it manually. This makes laziness independent of transience (but not vice versa, as transient slots must be lazy).

gbracha commented 2 years ago

Looking further into the transient/lazy question, I see that the grammar, parser & compiler code for transient slots is already in the Psoup version. Mirror & IDE support is missing, and of course NewspeakPredictiveParsing needs to support it as well - and everything would have to be renamed form T/transient to L/lazy. Still, it's actually better than I thought.  One would need branches for both https://github.com/newspeaklanguage/newspeak and https://github.com/newspeaklanguage/primordialsoup (the latter containing the compiler & mirror code). I'll start by updating the spec.

gbracha commented 2 years ago

Update. Revised spec. Compiler/parser support is put back and passes the relevant tests. Mirror support is in progress but still not ready. No work on IDE yet.

gbracha commented 6 months ago

We have a IDE support, but it's not quite solid yet. Need to test it further so we can close this.

gbracha commented 6 months ago

I'm going to close this, as the IDE support seems to work with the latest mirror changes.