Re: The case for transpiled generics
| From: | Matthew Brown | Date: | Thu, 17 Sep 2020 20:17:05 +0000 |
| Subject: | Re: The case for transpiled generics | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111894@lists.php.net to get a copy of this message | ||
> On Sep 17, 2020, at 3:25 PM, Levi Morrison <levi.morrison@datadoghq.com> wrote:
>
>
>>
>> On Thu, Sep 17, 2020 at 1:00 PM Matthew Brown <matthewmatthew@gmail.com> wrote:
>>>> On Sep 17, 2020, at 1:28 PM, Brent Roose <brendt@stitcher.io> wrote:
>>> But I don't want to get stuck on phrasing, if elidiing is the right term as Larry
>>> suggests, let's go with it!
>>
>> No, the correct term is “type erasure”:
>> https://en.m.wikipedia.org/wiki/Type_erasure
>
> "type erasure" with respect to generics means that they are checked at
> compile-time and erased at run-time. For instance, Java does generics
> through type erasure, and you had better believe those get checked at
> compile-time! This isn't what is being proposed, at least not how I
> understood it.
>
> Really these are just "hints", but historically in PHP the term "type
> hints" meant actually type checks.
>
> In summary:
> - Checked at run-time (and probably also compile-time when possible):
> reified generics.
> - Checked only at compile-time and thrown away at run-time: erased generics.
> - Not checked at all: ____?. Maybe we can call them "ignored generics"?
Seems like Python calls this same exact behaviour type erasure:
https://www.python.org/dev/peps/pep-0484/#instantiating-generic-classes-and-type-erasure
The term term type erasure is also used in documentation for an unofficial Python type checker:
https://mypy.readthedocs.io/en/stable/generics.html
Looks like Hack also uses the term in this context:
https://docs.hhvm.com/hack/generics/type-erasure
(Hack’s compiler doesn’t perform any generic type-checking)