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

Support calling generic methods #679

Open
5 of 6 tasks
degory opened this issue Dec 29, 2020 · 0 comments
Open
5 of 6 tasks

Support calling generic methods #679

degory opened this issue Dec 29, 2020 · 0 comments
Assignees

Comments

@degory
Copy link
Owner

degory commented Dec 29, 2020

Generic methods are quite common in the .NET libraries, and not being able to call them renders significant useful functionality inaccessible to ghūl code - it should be possible to call these methods.

Providing support for explicit actual type arguments when calling generic functions is a bit awkward because ghūl generic type expressions cannot be parsed from an expression context without either some syntax to introduce the type expression (e.g. as in new or cast) or else adding more sophisticated backtracking to the parser.

However, it actually looks relatively simple to infer correct types for generic type arguments (at least whilst we don't yet have type inference for anonymous functions see #497 #498)

The process is:

  • Attempt to pattern match the shape of each of the function's actual argument types to the function's formal argument types, treating the function's formal generic type arguments as wild cards, and binding types that match: so a formal function argument of type Iterable[T] ref matches an actual function argument type of Iterable[int[]] ref, binding actual type int[] to type variable T
  • If we can't match every actual argument's type to the corresponding formal argument, then assign the overload a no-match score
  • Where a formal type argument appears multiple times in a function's signature, the actual generic parameter type bound is the most derived common ancestor type of all matches across all actual arguments.
  • If the most derived common ancestor type is object then assign a low match score for that argument
  • Check all type constraints are met - i.e. the actual argument is assignable to or from the constraint type depending on direction of variance - if any type constraint isn't met then assign that function argument a no-match score
  • To emit correct IL assembler we need to refer to any types in the method signature via !!N positional notation
@degory degory self-assigned this Dec 29, 2020
degory added a commit that referenced this issue Dec 30, 2020
- Support calling generic methods (see #679)

Bug fixes:
- Anonymous functions defined in for loop expressions generate invalid IL (closes #683)

Technical:
- Migrate references to concrete NAMED type to base Type where possible
- Split type classes out into separate files
- Remove dead code for looking up built in types
degory added a commit that referenced this issue Dec 30, 2020
Enhancements:
- Support calling generic methods (see #679)

Bug fixes:
- Anonymous functions defined in for loop expressions generate invalid IL (closes #683)

Technical:
- Migrate references to concrete NAMED type to base Type where possible
- Split type classes out into separate files
- Remove dead code for looking up built in types
degory added a commit that referenced this issue Dec 30, 2020
Enhancements:
- Support calling generic methods (see #679)

Bug fixes:
- Anonymous functions defined in for loop expressions generate invalid IL (closes #683)

Technical:
- Migrate references to concrete NAMED class to abstract base class Type where possible
- Split type classes out into separate files
- Remove dead code for looking up built in types
degory added a commit that referenced this issue Dec 17, 2021
Enhancements:
- Tactical solution for explicit generic specialization (closes #884) (see #883, #679, #731)

Technical:
- Defeat NuGet cache when bootstrapping locally
- Be more defensive against log stack being corrupted
- Fix issue where diagnostic messages including an instance of the UNDEFINED type could cause an exception
- Update to latest ghul.targets and ghul.test
- When running integration tests locally, use published compiler because installing as local tool requires version bump or NuGet cache clean on every rebuild.
degory added a commit that referenced this issue Dec 17, 2021
Enhancements:
- Tactical solution for explicit generic specialization (closes #884) (see #883, #679, #731)

Technical:
- Defeat NuGet cache when bootstrapping locally
- Be more defensive against log stack being corrupted
- Fix issue where diagnostic messages including an instance of the UNDEFINED type could cause an exception
- Update to latest ghul.targets and ghul.test
- When running integration tests locally, use published compiler because installing as local tool requires version bump or NuGet cache clean on every rebuild.
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

1 participant