Why does Ḫattušumna Laḫḫa crash, and, what can be done about it?

If you got partway through Ḫattušumna Laḫḫa and saw a dreaded “Technical trouble: Heap space exhausted” error, that’s hopefully fixed now. So feel free to give it another shot!

But, why does this happen in Hittite when it doesn’t in English?

The problem is that Hittite allows multiple nouns in a row without any separator in between. In English IF commands, this is rare: generally you TAKE BELL AND BOOK or GIVE BOOK TO MAN. There’s the occasional GIVE MAN BOOK, but those are rare enough that they can generally be handled as special cases.

In Hittite, though, multiple nouns in a row are standard. So the parser needs to cope with that. The obvious solution is this:

(parse $Words into noun list $Nouns)
	*(split $Words anywhere into $Left and $Right)
	*(parse $Left into single noun $LNoun)
	*(parse $Right into noun list $RNouns)
	($Nouns = [$LNoun | $RNouns])

And for the most part, this works fine! But what if we have a multi-word noun, like a ḫattaluwantan aškan (barred door)? Now we have an ambiguity! Because either word can be used to refer to this object, the two-word phrase could parse as either:

  • One object: the ḫattaluwantan aškan
  • Two objects: the ḫattaluwantan aškan and the ḫattaluwantan aškan

Well, we can fix this without too much trouble:

(parse $Words into noun list $Nouns)
	*(split $Words anywhere into $Left and $Right)
	*(parse $Left into single noun $LNoun)
	*(parse $Right into noun list [$RFirst | $RNouns]) %% We split off $First to make sure we’re not breaking a single noun phrase in half, but this also guarantees that the right noun list is nonempty
	~($LNoun = $RFirst)
	($Nouns = [$LNoun $RFirst | $RNouns])

This works fine for our barred door, but what about some cheese: GA.KIN.AG? For historical reasons going back to the Z-machine, periods are treated as “word separators” here: GA.KIN.AG is actually read as five words, GA . KIN . AG, not a single combined word. And in Ḫattušumna Laḫḫa specifically, the determiner separator ^ is treated as a “word separator” too.

Now, if there’s any other noun with a period in its name (perhaps a dog, UR.GI₇), GA . KIN . AG could potentially parse as a list of five nouns: cheese, dog, cheese, dog, cheese. Or it could parse as cheese, dog, cheese, or simply cheese—clearly we don’t want a period on its own to be recognized as the name of anything!

So in the original IFComp build of Ḫattušumna Laḫḫa, periods and carets are simply stripped out of the command before parsing. This…mostly works. That original build also says, if there’s any ambiguity, prefer the one with fewer objects, which handles any remaining cases that slip through.

But, that “prefer the one with fewer objects” principle only works if parsing can actually finish! If the game runs out of memory and crashes before that, then it’s no help at all!

The solution came to me in a dream. We say that a grouping of words “breaks a compound” if it starts or ends with a period (or a caret). Then we simply reject any parses that break a compound:

(compound boundary @./@^)

([(compound boundary $) | $] breaks a compound)
($Words breaks a compound)
	(split last element from $Words into $Last and $)
	(compound boundary $Last)

(parse $Words into noun list $)
	($Words breaks a compound)
	(just) (fail)

And now all those ambiguities don’t consume a ton of memory just to get rejected at the end anyway. GA.KIN.AG can only mean a single object, “cheese”, because any attempt to break it up will “break a compound”.

Hopefully this cleans up the problem for good!

Someone reported that with the new update, the following command on tablet 3:

dub 1 kam u3 dub 2 kam u3 dub 3 kam u3 dub 4 kam u3 dub 5 kam u3 dub 6 kam u3 dub 7 kam u3 dub 8 kam u3 dub 9 kam ohhun

…would still crash. Oops! I have some special logic to short-circuit the parser when looking at the pattern “DUB [number]^KAM” (“tablet number N”), but the change to the preprocessing mentioned above broke it.

I have a new build that fixes this, but I don’t want to break saves again on the day before the comp ends. So for now, you can just use “1 2 3 4 5 6 7 8 9 ohhun” if you want to examine nine tablets at once.

I get how this might appear in actual play, but I can’t help thinking of my favorite changelog message of all time, from Inform 7 6M62:

Many users gave up their time to report bugs in 2014/15, and we’re grateful to all of them, but a particular tip of the hat goes to Daniel Fremont, who not only tested many obscure corners of the language but also combed through the documentation for out-of-date usages. It is thanks to Daniel that we learned that repeating the sentence “Foo is a room.” 117030 times would crash the compiler, and that the documentation made what he called “a 300 sextillion kg error in the mass of Jupiter” (in our defence, that makes less difference than you might expect); and, at Daniel’s urging, we did indeed “pick a consistent spelling for ‘discombobulate’”. [1]

Here’s to testers. :clinking_glasses: