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

TypeVariable.nameHint lost in constraint solving and type simplification #39

Closed
fo5for opened this issue Dec 9, 2021 · 3 comments · Fixed by #41
Closed

TypeVariable.nameHint lost in constraint solving and type simplification #39

fo5for opened this issue Dec 9, 2021 · 3 comments · Fixed by #41
Labels
bug Something isn't working

Comments

@fo5for
Copy link
Collaborator

fo5for commented Dec 9, 2021

class Test[A]: { x: A }
    method Mth[B]: (A -> B) -> B
    method Mth[B] (f: A -> B) = f this.x
//│ Defined class Test
//│ Declared Test.Mth: Test['A] -> ('A -> 'B) -> 'B
//│ Defined Test.Mth: Test['A] -> ('A -> 'a) -> 'a

The name hint for the type parameter B in the method definition is lost. I have identified two sources of this issue:

  1. nameHint is not preserved in extrusion

    val nv = freshVar(tv.prov)(lvl)

    (That's a downside of providing default arguments. You are not forced to review every invocation and provide the appropriate argument...)

  2. nameHint is not unified when simplifying polar variables
    Looking at the debug output of the above code snippet (after fixing 1.), the name hint is still present in the canonical inferred type:
    //│ Canon: ((test<> & {Test#A: (A31 -> A31), x: A31}) -> ((((A31 | α32) -> (α33 & B34)) & α35) -> α33))
    But it is later simplified away since it only cooccurs with α33 in one polarity:
    //│ [sub] α32 -> None, B34 -> None, α35 -> None

@fo5for fo5for added the bug Something isn't working label Dec 9, 2021
@LPTK
Copy link
Contributor

LPTK commented Dec 10, 2021

Nice job tracing this to the root causes. I tried to fix it, but there is one more thing that's going wrong here. In fact I noticed that method type parameters don't seem to be treated correctly.

class C
  method Foo[A](a: A) = a + 1
//│ Defined class C
//│ Defined C.Foo: C -> int -> int

Here A should be treated as a rigid type variable (implemented as a trait tag). I'm looking into fixing it now.

(That's a downside of providing default arguments. You are not forced to review every invocation and provide the appropriate argument...)

Very true. They should be used sparingly!

LPTK added a commit that referenced this issue Dec 10, 2021
Fix explicit method parameters (they were not rigid)
Fix method signature typing level
Fix typing of type ascriptions in patterns – constrain in both directions
Propagates name hints more
LPTK added a commit that referenced this issue Dec 10, 2021
Fix explicit method type parameters (they were not rigid)
Fix method signature typing level
Fix typing of type ascriptions in patterns – constrain in both directions
Propagates name hints more
@LPTK
Copy link
Contributor

LPTK commented Dec 10, 2021

Man, the method typing code is quite hairy. I noticed it also performs some needless subsumption checks. It's in dire need of simplification (let's look at this in the next meeting).

LPTK added a commit that referenced this issue Dec 10, 2021
Fix explicit method type parameters (they were not rigid)
Fix method signature typing level
Fix typing of type ascriptions in patterns – constrain in both directions
Propagates name hints more
@fo5for fo5for linked a pull request Dec 10, 2021 that will close this issue
@fo5for
Copy link
Collaborator Author

fo5for commented Dec 10, 2021

Man, the method typing code is quite hairy. I noticed it also performs some needless subsumption checks. It's in dire need of simplification (let's look at this in the next meeting).

Right... The unnecessary subsumption checks can be skipped with a guard. But ultimately refactoring should be the way to go.

@LPTK LPTK closed this as completed in #41 Dec 10, 2021
LPTK added a commit that referenced this issue Dec 10, 2021
Fix explicit method type parameters (they were not rigid)
Fix method signature typing level
Fix typing of type ascriptions in patterns – constrain in both directions
Propagates name hints more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants