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

feat: [SemanticDB] support LambdaType (convert from HKTypeLambda) #16056

Merged
merged 1 commit into from
Apr 24, 2023

Conversation

tanishiking
Copy link
Member

@tanishiking tanishiking commented Sep 16, 2022

based on the new semanticdb schema
scalameta/scalameta#2867
tanishiking/semanticdb-for-scala3@3981424

This commit adds support for LambdaType that is converted from HKTypeLambda in Scala3.

For example, the following type signature
[A, B] =>> [C] =>> A | B | C

will be

LambdaType(
  parameters = Some(
    value = Scope(hardlinks =
      List(
        "....Union#[A]"
        "....Union#[B]"
      ), symlinks = List()
    )
  ),
  returnType = LambdaType(
    parameters = Some(
      value = Scope(hardlinks = List("....Union#[C]"), symlinks = List())
    ),
    returnType = UnionType(
      types = List(
        TypeRef(
          prefix = Empty,
          symbol = "....Union#[A]",
          typeArguments = List()
        ),
        TypeRef(
          prefix = Empty,
          symbol = "....Union#[B]",
          typeArguments = List()
        ),
        TypeRef(
          prefix = Empty,
          symbol = "....Union#[C]",
          typeArguments = List()
        )
      )
    )
  )
)

I'm wondering...

Previously, we embed type Id = [A] =>> A which is equivalent to type Id[A] = A
https://github.com/lampepfl/dotty/blob/afc6ce4d2135e3532bf28146a7700d2cc4338e90/compiler/src/dotty/tools/dotc/semanticdb/TypeOps.scala#L218-L231
because we didn't have a way to express [A] =>> A in SemanticDB.

Now we support LambdaType in SemanticDB, maybe we can save type Id[A] = A as type Id = [A] =>> A instead of converting it to type Id[A] = A when converting the signature into SemanticDB. 🤔

def flatMap/*<-hk::Monad#flatMap().*/[A/*<-hk::Monad#flatMap().[A]*/, B/*<-hk::Monad#flatMap().[B]*/](m/*<-hk::Monad#flatMap().(m)*/: M/*->hk::Monad#[M]*/[A/*->hk::Monad#flatMap().[A]*/])(f/*<-hk::Monad#flatMap().(f)*/: A/*->hk::Monad#flatMap().[A]*/ => M/*->hk::Monad#[M]*/[B/*->hk::Monad#flatMap().[B]*/]): M/*->hk::Monad#[M]*/[B/*->hk::Monad#flatMap().[B]*/] = ???/*->scala::Predef.`???`().*/
}

class EitherMonad/*<-hk::EitherMonad#*/[T/*<-hk::EitherMonad#[T]*/] extends Monad/*->hk::Monad#*/[[E/*<-hk::EitherMonad#`<init>`().[E]*/] =>> Either/*->scala::package.Either#*/[T/*->hk::EitherMonad#[T]*/, E]] {
Copy link
Member

@bishabosha bishabosha Sep 16, 2022

Choose a reason for hiding this comment

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

the lack of reference recorded for E when passed to Either I guess is the usual problem that it is backed by TypeTree?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it seems like so, I'll take a look in another PR :)

hk/hk$package. => final package object hk extends Object { self: hk.type => +4 decls }
hk/hk$package.Id# => type Id [typeparam A ] = A
hk/hk$package.Id#[A] => typeparam A
hk/hk$package.MapKV# => type MapKV [typeparam K ] = [V] =>> Map[K, V]
Copy link
Member

Choose a reason for hiding this comment

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

I wonder how a curried type lambda would look with three argument lists, does it nest?

Copy link
Member Author

Choose a reason for hiding this comment

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

@bishabosha
Copy link
Member

looks good!


type MapV/*<-hk::hk$package.MapV#*/ = [_] =>> [V/*<-hk::hk$package.MapV#[V]*/] =>> Map/*->scala::Predef.Map#*/[String/*->scala::Predef.String#*/, V/*->hk::hk$package.MapV#[V]*/]

type MapEither/*<-hk::hk$package.MapEither#*/ = [K/*<-hk::hk$package.MapEither#[K]*/] =>> [L/*<-hk::hk$package.MapEither#[L]*/] =>> [R/*<-hk::hk$package.MapEither#[R]*/] =>> Map/*->scala::Predef.Map#*/[K/*->hk::hk$package.MapEither#[K]*/, Either/*->scala::package.Either#*/[L/*->hk::hk$package.MapEither#[L]*/, R/*->hk::hk$package.MapEither#[R]*/]]
Copy link
Member

Choose a reason for hiding this comment

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

question for those who know semanticdb the best, should these lambda params after the first list be local symbols? like types in a refinement

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so yeah, if they cannot be accessed from the outside these can be local params.

@bishabosha
Copy link
Member

bishabosha commented Mar 27, 2023

I'm not sure what happened here, sorry! but now it needs another rebase

@tanishiking
Copy link
Member Author

Hey, I rebased on the latest main 👍

@bishabosha
Copy link
Member

seems like tests/neg-custom-args/fatal-warnings/i15503g.scala is now failing the tests with some unused parameters warnings

scalameta/scalameta#2867

This commit adds support for LambdaType that is converted from
HKTypeLambda in Scala3
@bishabosha bishabosha enabled auto-merge April 24, 2023 14:15
@bishabosha bishabosha merged commit 65bb700 into scala:main Apr 24, 2023
@Kordyjan Kordyjan added this to the 3.3.1 milestone Aug 1, 2023
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.

4 participants