Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] [HHVM] better reified generics support #8772

Closed
azjezz opened this issue Dec 2, 2020 · 2 comments
Closed

[RFC] [HHVM] better reified generics support #8772

azjezz opened this issue Dec 2, 2020 · 2 comments

Comments

@azjezz
Copy link
Contributor

azjezz commented Dec 2, 2020

Standalone code, or other way to reproduce the problem

<<__ConsistentConstruct>>
final class A<<<__Newable>> reify T> {
  public function __construct(
    public classname<T> $class_name = T::class
  ) {}
}

<<__ConsistentConstruct>>
class B<reify T> {}
<<__ConsistentConstruct>>
final class C<reify Ti, reify To> extends B<Ti> {}

<<__EntryPoint>>
function main(): void {
  $a = create<A<C<B<float>, string>>>();

  print $a->class_name; // result: C | expected: C<B<float>, string>>
}

function create<<<__Enforcable, __Newable>> reify T>(): T {
  var_dump(T::class); // result: A | expected: A<C<B<float>, string>>>

  return new T();
}

Steps to reproduce the behavior:

  1. write down the previous code in a .hack file
  2. execute the file noramlly using hhvm

Expected behavior

output:

string(23) "A<C<B<float>, string>>>"
C<B<float>, string>>

Actual behavior

string(1) "A"
C

Environment

  • Operating system irrevelent
  • Installation method irrevelent
  • HHVM Version - latest

Please include the output of hhvm --version and hh_client --version

Additional context

currently T::class returns classname<T>, hack has both typename<T> and classname<T> types, both these types are nothing more of a string at runtime, what would be a great solution is to make them not string, but rather something else ( e.g: simiar to function reference: class reference and type reference - which class reference being a subtype of type reference ), which can be used as is now, but cannot be used as a string, this new type can hold all generic parameter types, and optionally convereted to a string representation.

@lexidor
Copy link
Collaborator

lexidor commented Dec 4, 2020

Just adding to the pool of knowledge. The runtime representation of classname is currently a plain string indeed. LazyClass might become a new runtime representation of a classname. But afaik this does not intend to include reifyied generics.

856057b is where LazyClass was first mentioned.

It might be worth asking around what the idea is behind this type.


Could you please update your issue text with the hhvm version?

Your issue title is a bit generic. Would a variation of: "Can't retrieve reifyied generics from a classname<T>" describe your issue?

What happens when you use the new operator on a classname of a class with a reifyied generic?

@lexidor
Copy link
Collaborator

lexidor commented Aug 30, 2023

I am going over old issues on this repository, to see which ones apply to the current versions of hhvm.

classname<T> string forms do not contain generic information. The HH\ReifiedGenerics\get_typestructure<T>() function exposes information about inner generics. You are able to reconstruct the string name fully from the type structure.

@lexidor lexidor closed this as completed Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants