ta0kira / zeolite

Zeolite is a statically-typed, general-purpose programming language.
Apache License 2.0
18 stars 0 forks source link

Remove `parent` members from `@type` and `@value` instances where possible. #199

Open ta0kira opened 2 years ago

ta0kira commented 2 years ago

We can probably define an inline parent() for use in codegen so that the erasure is transparent.

  1. This should be easy for categories without params. The main issue will be that we'll need to get the type every time we need it. Maybe we can change CreateType_Foo to return const S<const Type_Foo>& so that it doesn't update reference counts when we're not storing a reference.

  2. For categories with params, we can't return const S<const Type_Foo>& because the reference count could go to zero during the return process. (For categories without params, the reference is static.)

    But, assuming that problem is solved, we'd need to add a flag to CompiledData to indicate if the generated @value code ever refers to the @type parent. (We should still be able to eliminate the @category parent in @type instances.)

    Note that this could still be a bad idea, since it would potentially require constructing and then destructing a Type_Foo every time a @value is created. So, I think we'd actually need to update the constructor for Value_Foo to not require a parent arg.

  3. We'd potentially need to treat extensions differently, e.g., skip removing parent if it has params.