codefrau / SqueakJS

A Squeak Smalltalk VM in Javascript
https://squeak.js.org
MIT License
364 stars 75 forks source link

Error: Class not in class table #132

Closed codefrau closed 9 months ago

codefrau commented 2 years ago

Bug report from Dan Ingalls:

I just tried out Squeak 5.0 (2015) and filed in most of my St72 stuff, but found i could not save.

This happens consistently - I start over, fileIn and cannot save, even if I saveAs as my first act after starting up the 5.0.

The error is "Class not in class table"

codefrau commented 2 years ago

With a Spur object memory, classes are supposed to be entered into the global class table. Their identity hash is the index into that class table. The identity hash primitive is supposed to put them there. That index is used instead of a class pointer in object headers.

SqueakJS doesn’t actually use the index or class table at runtime, it just tries to keep track of it. It’s quite possible I never tested that properly.

codefrau commented 1 year ago

Workaround from Dan:

First I filed out the class in question (would help if the error told me which it was, but I figured it was the one to which I had added an instvar).

Then I removed the class. Might have to nil its value in Undeclared (I didn’t)

Then I saved and it worked.

Then I filed the class back in from its filout (could add the instvar in the file if desired).

All seems fine.

fniephaus commented 1 year ago

FWIW, I've implemented this some time ago in TruffleSqueak. :wink:

codefrau commented 9 months ago

Yeah I implemented it 7 years ago too (35a209bc649419465a81f9e19c28b749faafab7c and 93827e81df93955341b08eee7b12eb825b9305aa) and it normally works fine, but for some reason not after adding an inst var to the class...

codefrau commented 9 months ago

Found the bug: when the class was become'd (e.g. when adding an inst var) then the class table entry would still point to the obsolete class. That's why the check failed when saving the class table.