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

IrTypeparameter resolution #780

Closed
wants to merge 7 commits into from
Closed

IrTypeparameter resolution #780

wants to merge 7 commits into from

Conversation

i-walker
Copy link
Member

@i-walker i-walker commented Oct 28, 2020

addresses #749, as in adding new members and utilities to resolve IrTypeParameters through the IrTree and recursively walking the parent hierarchy for potentially unsubstituted type parameters.

Conceptually, it enables the functionality found in IrTypeSubstituter, which is specialized for IrValueParameters for IrMemberAccessExpressions, by breaking down its API and behavioral aspects.

In a further PR, this can be used to refine the targetType, when extension proofs are injected, that have missing type information. But the technical debt persists to improve the detection of that very targetType consistently for all expressions.

An example is here - given that List has an Functor instance:

call-site: 
listOf(2).fmap{ it * 2 }
// in this case the call-site is broken down by each "call expression"
expression unsubstituted type missing type information resolved Type
listOf(2) List<T> T Int
fmap { it * 2} B from fmap B Int

To further resolve fmap the remaining Type parameters in the parent hierarchy need to be resolved of Functor and Functor.Ops, which is:

expression unsubstituted type missing type information resolved Type
fmap { it * 2} Functor.Ops<F, A> F, A F -> ListOf<Int>, A -> Int
fmap { it * 2} Functor<F> F ListOf<Int>

implying that ListOf<A> is an typealias for Kind<List(_), A> and established as an isomorphism to List<T>

This is necessary, because the expected value- and target type for an extensionproof injection at the aforementioned call-site would be:

  • valueType: List<Int> or worst case: List<T> <- detection works
  • targetType: Functor<F, A> <- which can now be refined to Functor<ListOf<Int>, Int>
    But currently the target Type is not resolved to Functor<F, A>

container.allTypeParameters.withIndex().associate {
it.value to getTypeArgument(it.index)!!
}
fun IrTypeParametersContainer.getTypeSubstitutionMap(expression: IrMemberAccessExpression): Map<IrTypeParameter, Either<KotlinType?, TypeProjection?>> =
Copy link
Member Author

@i-walker i-walker Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I was also keen on return Map<IrTypeParameter, Either<IrSimpleType, IrTypeArgument>>, depending on how we use it in other places, besides Extensions.
But we can change it to one or the other, it's not fixed.

Copy link
Contributor

@danimontoya danimontoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @i-walker looks good! 🙌

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 thanks @i-walker !

@i-walker i-walker closed this May 7, 2021
@i-walker i-walker deleted the irtypeparameter-res branch May 7, 2021 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants