HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.03k stars 648 forks source link

[hxb] Add OFD and OBD chunks #11564

Closed Simn closed 5 months ago

Simn commented 5 months ago

We've come across a problem with the current way we handle anon fields and anons. Those are encoded on first use, which is convenient because in the general case anon fields might need type parameters from the local context. This works fine if the reader reads everything in order, but with delayed expression reading there can be the following situation:

  1. An anon is first seen, and thus written, inside an expression
  2. It is later seen in a different place, and written as a reference
  3. The reader delays the expression reading, and then comes across the reference place before the definition place

It would be good to have an isolated test case for this, but it's not very easy to find one because this only occurred in a substantial codebase and is affected by the intricacies of type loading.

With this PR we now distinguish between anon fields that require a local context and those that don't. The former are still written immediately, which should work fine because such abstracts cannot appear elsewhere anyway. The latter are stored in the OFD chunk which is then read separately, which should always work because no local context is required. By extension, this applies to anons and the OBD chunk.