scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.86k stars 1.06k forks source link

Project compiles in 18 seconds on scala 2, compilation never ends on scala 3 #19892

Closed urieli closed 7 months ago

urieli commented 7 months ago

Compiler version

3.3.3 and 3.4.0

Minimized code

The project I'm attempting to compile is here.

git clone https://gitlab.com/joliciel/test-server.git
cd test-server
sbt

I removed the business modules (which compile quickly) and kept only the api module (whose compilation never ends). I haven't minimized the code further as I could find no way of determining which parts were freezing the compiler.

Output

 % sbt
[info] welcome to sbt 1.9.9 (Eclipse Adoptium Java 17.0.2)
[info] loading global plugins from /home/assaf/.sbt/1.0/plugins
[info] loading settings for project test-server-build from plugins.sbt ...
[info] loading project definition from /home/assaf/javawork/jochre3/test-server/project
[info] loading settings for project jochre3-server from build.sbt ...
[warn] JOCHRE3_SERVER_VERSION env var not found
[info] set current project to jochre3-server (in build file:/home/assaf/javawork/jochre3/test-server/)
[info] sbt server started at local:///home/assaf/.sbt/1.0/server/92affff4cbf1ff9d4214/sock
[info] started sbt server
sbt:jochre3-server> clean
[success] Total time: 0 s, completed Mar 6, 2024, 4:02:19 PM
sbt:jochre3-server> compile
[info] compiling 22 Scala sources to /home/assaf/javawork/jochre3/test-server/modules/api/target/scala-2.13/classes ...
[warn] 1 deprecation
[warn] 1 deprecation (since 3.7.0)
[warn] 2 deprecations in total; re-run with -deprecation for details
[warn] three warnings found
[success] Total time: 18 s, completed Mar 6, 2024, 4:02:40 PM
sbt:jochre3-server> ++ 3.3.3
[info] Setting Scala version to 3.3.3 on 1 projects.
[info] Excluded 1 projects, run ++ 3.3.3 -v for more details.
[info] Reapplying settings...
[info] set current project to jochre3-server (in build file:/home/assaf/javawork/jochre3/test-server/)
sbt:jochre3-server> compile
[info] compiling 22 Scala sources to /home/assaf/javawork/jochre3/test-server/modules/api/target/scala-3.3.3/classes ...

  | => api / Compile / compileIncremental 3292s

Expectation

I would expect scala 3 to compile the code, which scala 2.13.13 compiles in 18 seconds, in a reasonable amount of time.

som-snytt commented 7 months ago

more annoyingly,

[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...
^C
[warn] Canceling execution...

  | => api / Compile / compileIncremental 1567s
lrytz commented 7 months ago

Scala 2 PRs related to cancellation: https://github.com/scala/scala/pull/6479, https://github.com/scala/scala/pull/8448 [edit: is there a scala3 ticket already? should spin one off otherwise.]

WojciechMazur commented 7 months ago

Thread seems to be stuck in typer, might be related to #19907 (both use Tapir, but this project does. not use long list of server endpoint, instead might be coused by combination of 2 complex type systems coming from Tapir and ZIO

```scala "pool-8-thread-4" #124 prio=5 os_prio=31 cpu=185732.93ms elapsed=242.73s tid=0x0000000168035a00 nid=0xe007 runnable [0x00000002c90c1000] java.lang.Thread.State: RUNNABLE at java.lang.System.identityHashCode(java.base@17.0.7/Native Method) at dotty.tools.dotc.core.Types$BindingType.identityHash(Types.scala:2297) at dotty.tools.dotc.core.Types$BindingType.identityHash$(Types.scala:2286) at dotty.tools.dotc.core.Types$HKLambda.identityHash(Types.scala:3839) at dotty.tools.dotc.core.Types$ParamRef.computeHash(Types.scala:4697) at dotty.tools.dotc.core.Types$CachedProxyType.hash(Types.scala:2175) at dotty.tools.dotc.core.Hashable.typeHash(Hashable.scala:51) at dotty.tools.dotc.core.Hashable.typeHash$(Hashable.scala:42) at dotty.tools.dotc.core.Uniques$AppliedUniques.typeHash(Uniques.scala:66) at dotty.tools.dotc.core.Hashable.finishHash(Hashable.scala:72) at dotty.tools.dotc.core.Hashable.finishHash$(Hashable.scala:42) at dotty.tools.dotc.core.Uniques$AppliedUniques.finishHash(Uniques.scala:66) at dotty.tools.dotc.core.Hashable.finishHash(Hashable.scala:84) at dotty.tools.dotc.core.Hashable.finishHash$(Hashable.scala:42) at dotty.tools.dotc.core.Uniques$AppliedUniques.finishHash(Uniques.scala:66) at dotty.tools.dotc.core.Hashable.doHash(Hashable.scala:110) at dotty.tools.dotc.core.Hashable.doHash$(Hashable.scala:42) at dotty.tools.dotc.core.Uniques$AppliedUniques.doHash(Uniques.scala:66) at dotty.tools.dotc.core.Uniques$AppliedUniques.enterIfNew(Uniques.scala:70) at dotty.tools.dotc.core.Types$AppliedType$.apply(Types.scala:4672) at dotty.tools.dotc.core.TypeApplications$.appliedTo$extension(TypeApplications.scala:426) at dotty.tools.dotc.core.Types$AppliedType.derivedAppliedType(Types.scala:4646) at dotty.tools.dotc.core.Substituters$.subst(Substituters.scala:22) at dotty.tools.dotc.core.Types$Type.subst(Types.scala:1880) at dotty.tools.dotc.core.Types$HKTypeLambda.newLikeThis$$anonfun$4(Types.scala:4306) at dotty.tools.dotc.core.Types$HKTypeLambda$$Lambda$6301/0x0000000801131b68.apply(Unknown Source) at dotty.tools.dotc.core.Types$HKTypeLambda.(Types.scala:4263) at dotty.tools.dotc.core.Types$HKTypeLambda$.apply(Types.scala:4370) at dotty.tools.dotc.core.Types$HKTypeLambda.newLikeThis(Types.scala:4306) at dotty.tools.dotc.core.Types$HKTypeLambda.newLikeThis(Types.scala:4301) at dotty.tools.dotc.core.Types$HKTypeLambda.newLikeThis(Types.scala:4300) at dotty.tools.dotc.core.Types$LambdaType.derivedLambdaType(Types.scala:3823) at dotty.tools.dotc.core.Types$LambdaType.derivedLambdaType$(Types.scala:3762) at dotty.tools.dotc.core.Types$HKLambda.derivedLambdaType(Types.scala:3839) at dotty.tools.dotc.core.Types$ApproximatingTypeMap.derivedLambdaType(Types.scala:6534) at dotty.tools.dotc.core.Types$TypeMap.mapOverLambda(Types.scala:6097) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:105) at dotty.tools.dotc.core.Types$TypeMap.op$proxy20$1(Types.scala:6127) at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:6127) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:111) at dotty.tools.dotc.core.TypeOps$.asSeenFrom(TypeOps.scala:55) at dotty.tools.dotc.core.Types$Type.asSeenFrom(Types.scala:1091) at dotty.tools.dotc.core.Denotations$SingleDenotation.derived$1(Denotations.scala:1102) at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1129) at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1082) at dotty.tools.dotc.core.Denotations$PreDenotation.asSeenFrom(Denotations.scala:137) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2185) at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:756) at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:937) at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:729) at dotty.tools.dotc.core.Types$Type.nonPrivateMember(Types.scala:719) at dotty.tools.dotc.core.Types$NamedType.memberDenot(Types.scala:2553) at dotty.tools.dotc.core.Types$NamedType.memberDenot(Types.scala:2540) at dotty.tools.dotc.core.Types$NamedType.fromDesignator$1(Types.scala:2503) at dotty.tools.dotc.core.Types$NamedType.computeDenot(Types.scala:2518) at dotty.tools.dotc.core.Types$NamedType.denot(Types.scala:2475) at dotty.tools.dotc.core.Types$NamedType.info(Types.scala:2464) at dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:186) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeApplied$1(SymDenotations.scala:2274) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.recur$4(SymDenotations.scala:2282) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseTypeOf(SymDenotations.scala:2345) at dotty.tools.dotc.core.Types$Type.baseType(Types.scala:1195) at dotty.tools.dotc.core.Types$NamedType.argForParam(Types.scala:2755) at dotty.tools.dotc.core.Types$ApproximatingTypeMap.expandParam(Types.scala:6339) at dotty.tools.dotc.core.Types$ApproximatingTypeMap.derivedSelect(Types.scala:6357) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:103) at dotty.tools.dotc.core.Types$TypeMap.op$proxy18$1(Types.scala:6080) at dotty.tools.dotc.core.Types$TypeMap.mapArg(Types.scala:6080) at dotty.tools.dotc.core.Types$TypeMap.mapArgs(Types.scala:6084) at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:6121) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:111) at dotty.tools.dotc.core.Types$TypeMap.mapOverLambda(Types.scala:6097) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:105) at dotty.tools.dotc.core.Types$TypeMap.op$proxy20$1(Types.scala:6127) at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:6127) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:111) at dotty.tools.dotc.core.TypeOps$.asSeenFrom(TypeOps.scala:55) at dotty.tools.dotc.core.Types$Type.asSeenFrom(Types.scala:1091) at dotty.tools.dotc.core.Denotations$SingleDenotation.derived$1(Denotations.scala:1102) at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1129) at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1082) at dotty.tools.dotc.core.Denotations$PreDenotation.asSeenFrom(Denotations.scala:137) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2185) at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:756) at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:937) at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:729) at dotty.tools.dotc.core.Types$Type.nonPrivateMember(Types.scala:719) at dotty.tools.dotc.core.Types$NamedType.memberDenot(Types.scala:2553) at dotty.tools.dotc.core.Types$NamedType.memberDenot(Types.scala:2540) at dotty.tools.dotc.core.Types$NamedType.fromDesignator$1(Types.scala:2503) at dotty.tools.dotc.core.Types$NamedType.computeDenot(Types.scala:2518) at dotty.tools.dotc.core.Types$NamedType.denot(Types.scala:2475) at dotty.tools.dotc.core.Types$NamedType.info(Types.scala:2464) at dotty.tools.dotc.core.Types$TypeRef.underlying(Types.scala:3024) at dotty.tools.dotc.core.Types$TypeProxy.superType(Types.scala:2132) at dotty.tools.dotc.core.Types$AppliedType.superType(Types.scala:4556) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeApplied$1(SymDenotations.scala:2276) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.recur$4(SymDenotations.scala:2282) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseTypeOf(SymDenotations.scala:2345) at dotty.tools.dotc.core.Types$Type.baseType(Types.scala:1195) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.toPrefix$1(TypeOps.scala:83) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:107) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.op$proxy2$1(TypeOps.scala:103) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:103) at dotty.tools.dotc.core.Types$TypeMap.op$proxy18$1(Types.scala:6080) at dotty.tools.dotc.core.Types$TypeMap.mapArg(Types.scala:6080) at dotty.tools.dotc.core.Types$TypeMap.mapArgs(Types.scala:6084) at dotty.tools.dotc.core.Types$TypeMap.mapArgs(Types.scala:6085) at dotty.tools.dotc.core.Types$TypeMap.mapArgs(Types.scala:6085) at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:6121) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:111) at dotty.tools.dotc.core.Types$TypeMap.mapOverLambda(Types.scala:6097) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:105) at dotty.tools.dotc.core.Types$TypeMap.op$proxy20$1(Types.scala:6127) at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:6127) at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:111) at dotty.tools.dotc.core.TypeOps$.asSeenFrom(TypeOps.scala:55) at dotty.tools.dotc.core.Types$Type.asSeenFrom(Types.scala:1091) at dotty.tools.dotc.core.Denotations$SingleDenotation.derived$1(Denotations.scala:1102) at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1129) at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1082) at dotty.tools.dotc.core.Denotations$PreDenotation.asSeenFrom(Denotations.scala:137) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2185) at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:756) at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:937) at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:729) at dotty.tools.dotc.core.Types$Type.nonPrivateMember(Types.scala:719) at dotty.tools.dotc.core.Types$NamedType.memberDenot(Types.scala:2553) at dotty.tools.dotc.core.Types$NamedType.memberDenot(Types.scala:2540) at dotty.tools.dotc.core.Types$NamedType.fromDesignator$1(Types.scala:2503) at dotty.tools.dotc.core.Types$NamedType.computeDenot(Types.scala:2518) at dotty.tools.dotc.core.Types$NamedType.denot(Types.scala:2475) at dotty.tools.dotc.core.Types$NamedType.info(Types.scala:2464) at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$_$compute$1(Types.scala:3979) at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$_$compute$1(Types.scala:3986) at dotty.tools.dotc.core.Types$TermLambda.applyPrefix$1(Types.scala:3974) at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$_$compute$1(Types.scala:3978) at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$_$compute$1(Types.scala:3986) at dotty.tools.dotc.core.Types$TermLambda$DepAcc$1.apply(Types.scala:3965) at dotty.tools.dotc.core.Types$TermLambda$DepAcc$1.apply(Types.scala:3965) at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6608) at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$_$compute$1(Types.scala:4005) at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$depStatus(Types.scala:4006) at dotty.tools.dotc.core.Types$TermLambda.dependencyStatus(Types.scala:4020) at dotty.tools.dotc.core.Types$TermLambda.resultType(Types.scala:3944) at dotty.tools.dotc.core.Types$TermLambda.resultType$(Types.scala:3936) at dotty.tools.dotc.core.Types$MethodType.resultType(Types.scala:4081) at dotty.tools.dotc.core.Types$MethodOrPoly.computeSignature$2(Types.scala:3875) at dotty.tools.dotc.core.Types$MethodOrPoly.signature(Types.scala:3905) at dotty.tools.dotc.core.Types$MethodOrPoly.computeSignature$2(Types.scala:3876) at dotty.tools.dotc.core.Types$MethodOrPoly.signature(Types.scala:3905) at dotty.tools.dotc.core.Denotations$SingleDenotation.signature(Denotations.scala:623) at dotty.tools.dotc.core.Denotations$SingleDenotation.signature(Denotations.scala:613) at dotty.tools.dotc.core.Denotations$SingleDenotation.atSignature(Denotations.scala:654) at dotty.tools.dotc.core.Denotations$SingleDenotation.atSignature(Denotations.scala:650) at dotty.tools.dotc.core.Denotations$MultiDenotation.atSignature(Denotations.scala:1262) at dotty.tools.dotc.core.Types$NamedType.disambiguate(Types.scala:2529) at dotty.tools.dotc.core.Types$NamedType.disambiguate(Types.scala:2525) at dotty.tools.dotc.core.Types$NamedType.memberDenot(Types.scala:2548) at dotty.tools.dotc.core.Types$NamedType.fromDesignator$1(Types.scala:2503) at dotty.tools.dotc.core.Types$NamedType.computeDenot(Types.scala:2518) at dotty.tools.dotc.core.Types$NamedType.denot(Types.scala:2475) at dotty.tools.dotc.core.Types$TermRef.isOverloaded(Types.scala:2957) at dotty.tools.dotc.core.Types$Type.widenSingleton(Types.scala:1300) at dotty.tools.dotc.typer.ProtoTypes$Compatibility.normalizedCompatible(ProtoTypes.scala:64) at dotty.tools.dotc.typer.ProtoTypes$Compatibility.normalizedCompatible$(ProtoTypes.scala:31) at dotty.tools.dotc.typer.Typer.normalizedCompatible(Typer.scala:120) at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.qualifies$1(ProtoTypes.scala:227) at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.isMatchedBy$$anonfun$1(ProtoTypes.scala:230) at dotty.tools.dotc.typer.ProtoTypes$SelectionProto$$Lambda$5933/0x0000000801096ed8.apply(Unknown Source) at dotty.tools.dotc.core.Denotations$SingleDenotation.hasAltWith(Denotations.scala:645) at dotty.tools.dotc.core.Denotations$MultiDenotation.hasAltWith(Denotations.scala:1282) at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.isMatchedBy(ProtoTypes.scala:230) at dotty.tools.dotc.core.TypeComparer.isMatchedByProto(TypeComparer.scala:2145) at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:345) at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1553) at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:214) at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:224) at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:132) at dotty.tools.dotc.core.TypeComparer.testSubType(TypeComparer.scala:149) at dotty.tools.dotc.core.TypeComparer$.testSubType(TypeComparer.scala:3159) at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$1(Typer.scala:4090) at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4177) at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4406) at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3697) at dotty.tools.dotc.typer.Typer.readapt$1(Typer.scala:3709) at dotty.tools.dotc.typer.Typer.readaptSimplified$1(Typer.scala:3710) at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3942) at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3951) at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4153) at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4406) at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3697) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:767) at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:805) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3107) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:957) at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1117) at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:351) at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:120) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3132) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:767) at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:805) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3107) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:957) at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1117) at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:351) at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:120) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3132) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:767) at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:805) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3107) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:957) at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1117) at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:351) at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:120) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3132) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:767) at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:805) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3107) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:957) at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1117) at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:351) at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:120) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3132) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:767) at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:805) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3107) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:957) at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1117) at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:351) at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:120) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3132) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2552) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3111) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3319) at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3365) at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2809) at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3120) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3124) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3215) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3319) at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3365) at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2942) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3166) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3216) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3293) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3297) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3408) at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47) at dotty.tools.dotc.typer.TyperPhase$$Lambda$5931/0x000000080108dc78.applyVoid(Unknown Source) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:480) at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53) at dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99) at dotty.tools.dotc.typer.TyperPhase$$Lambda$5929/0x000000080108d4e0.apply(Unknown Source) at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479) at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583) at scala.collection.immutable.List.prependedAll(List.scala:155) at scala.collection.immutable.List$.from(List.scala:684) at scala.collection.immutable.List$.from(List.scala:681) at scala.collection.IterableOps$WithFilter.map(Iterable.scala:898) at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:100) at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315) at dotty.tools.dotc.Run$$Lambda$5742/0x0000000801014208.applyVoid(Unknown Source) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323) at dotty.tools.dotc.Run.runPhases$1(Run.scala:337) at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:350) at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:360) at dotty.tools.dotc.Run$$Lambda$5696/0x0000000800fdc568.apply(Unknown Source) at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69) at dotty.tools.dotc.Run.compileUnits(Run.scala:360) at dotty.tools.dotc.Run.compileSources(Run.scala:261) at dotty.tools.dotc.Run.compile(Run.scala:246) at dotty.tools.dotc.Driver.doCompile(Driver.scala:37) at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141) - locked <0x0000000404e362a8> (a dotty.tools.xsbt.CompilerBridgeDriver) at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22) at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193) at sbt.internal.inc.MixedAnalyzingCompiler$$Lambda$5411/0x0000000800d7e688.apply$mcV$sp(Unknown Source) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163) at sbt.internal.inc.MixedAnalyzingCompiler$$Lambda$5407/0x0000000800d7d718.apply(Unknown Source) at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239) at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163) at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534) at sbt.internal.inc.IncrementalCompilerImpl$$Lambda$3289/0x00000008009f7c38.apply(Unknown Source) at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180) at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178) at sbt.internal.inc.Incremental$$$Lambda$3296/0x00000008009f9fd8.apply(Unknown Source) at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464) at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116) at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56) at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52) at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263) at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419) at sbt.internal.inc.Incremental$$$Lambda$3333/0x0000000800a0d800.apply(Unknown Source) at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506) at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406) at sbt.internal.inc.Incremental$.apply(Incremental.scala:172) at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488) at sbt.internal.inc.IncrementalCompilerImpl$$Lambda$3194/0x00000008009b95d8.apply(Unknown Source) at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332) at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425) at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137) at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371) at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321) at sbt.Defaults$$$Lambda$3187/0x00000008009aaf98.apply(Unknown Source) at sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31) at sbt.internal.server.BspCompileTask$$$Lambda$3189/0x00000008009b7b08.apply(Unknown Source) at sbt.internal.io.Retry$.apply(Retry.scala:47) at sbt.internal.io.Retry$.apply(Retry.scala:29) at sbt.internal.io.Retry$.apply(Retry.scala:24) at sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31) at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2319) at sbt.Defaults$$$Lambda$840/0x0000000800522c50.apply(Unknown Source) at scala.Function1.$anonfun$compose$1(Function1.scala:49) at scala.Function1$$Lambda$350/0x00000008003577e0.apply(Unknown Source) at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63) at sbt.internal.util.$tilde$greater$$Lambda$2781/0x00000008008f9640.apply(Unknown Source) at sbt.std.Transform$$anon$4.work(Transform.scala:69) at sbt.Execute.$anonfun$submit$2(Execute.scala:283) at sbt.Execute$$Lambda$2807/0x0000000800904508.apply(Unknown Source) at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24) at sbt.Execute.work(Execute.scala:292) at sbt.Execute.$anonfun$submit$1(Execute.scala:283) at sbt.Execute$$Lambda$2791/0x00000008008fc6c8.apply(Unknown Source) at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265) at sbt.ConcurrentRestrictions$$anon$4$$Lambda$2802/0x00000008008fe890.apply(Unknown Source) at sbt.CompletionService$$anon$2.call(CompletionService.scala:65) at java.util.concurrent.FutureTask.run(java.base@17.0.7/FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call(java.base@17.0.7/Executors.java:539) at java.util.concurrent.FutureTask.run(java.base@17.0.7/FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@17.0.7/ThreadPoolExecutor.java:1136) at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@17.0.7/ThreadPoolExecutor.java:635) at java.lang.Thread.run(java.base@17.0.7/Thread.java:833) ```

When working on minimization for the issue mentioned above, I'll try to minimize this one as well.

WojciechMazur commented 7 months ago

Also based on draft of #19897 I was able to track the def that takes long to typecheck

val postBatchEndpoint: ZPartialServerEndpoint[Requirements, String, ValidToken, (ProjectCode, BatchRequest), HttpError, BatchResponse, Any] = ???
Screenshot 2024-03-11 at 17 32 10
WojciechMazur commented 7 months ago

The R parameter in def basicEndpoint[R] is inferred based on whole chain of method out invocations. The workaround to make compilation finish quickly is to hint the compiler about the type R

Self contained minimisation of issue:

abstract class ZPartialServerEndpoint[R, A, B, I, E, O, -C]
    extends EndpointOps[A, I, E, O, C]{
  override type ThisType[-_R] = ZPartialServerEndpoint[R, A, B, I, E, O, _R]
  override type EndpointType[_A, _I, _E, _O, -_R] =ZPartialServerEndpoint[R, _A, B, _I, _E, _O, _R]
}

trait EndpointOps[A, I, E, O, -R] {
  type EndpointType[_A, _I, _E, _O, -_R]
  type ThisType[-_R]
  def out[T]: EndpointType[A, I, E, T, R]
  def description(d: String): ThisType[R]
}

object Test {
  def basicEndpoint[R](): ZPartialServerEndpoint[R, Any, Any, Unit, Any, Unit, Any] = ???

  // commonts next to `.out[Any]` contain information about compilation time when chaining up to N `out` functions
  val case1 =
     basicEndpoint() // 1.5s
        .out[Any] // 1.6s
        .out[Any] // 1.7s
        .out[Any] // 2s
        .out[Any] // 4s
        .out[Any] // 33s
        .out[Any] // aborted after 5 min

  val case1Workaround =
    basicEndpoint[Any]() // 1.4s
      .out[Any] // 1.4s
      .out[Any] // 1.4s
      .out[Any] // 1.4s
      .out[Any] // 1.4s
      .out[Any] // 1.4s
      .out[Any] // 1.4s

  val case2_referToThisType =
    basicEndpoint()
      .out[Any] // 1.6s
      .out[Any] // 2.2s
      .out[Any] // 5.6s
      .out[Any] // 53s
      .description("Comment out to make compilation eventually finish")

  val case2Workaround =
    basicEndpoint[Any]()
      .out[Any] // 1.6s
      .out[Any] // 1.6s
      .out[Any] // 1.6s
      .out[Any] // 1.6s
      .description("Comment out to make compilation finish") // 1.6s
}

@Gedochao I suggest to move this issue to P1 similarly as other slow typer issue mentioned above @odersky @noti0na1 I'm initially assigning this issue to you as it is in the same area as the previous type-inference related bug

noti0na1 commented 7 months ago
abstract class ZPartialServerEndpoint[R, A, B, I, E, O, -C]

It seems the number of type parameter does affect the performance. I reduce the number of type parameters of ZPartialServerEndpoint to 3, only including the necessary types used by basicEndpoint, out and description. The 30-second compilations become 4s.

abstract class Z[R, O, -C]
    extends EndpointOps[O, C]{
  override type ThisType[-_R] = Z[R, O, _R]
  override type EndpointType[_O, -_R] =Z[R, _O, _R]
}

trait EndpointOps[O, -R] {
  type EndpointType[_O, -_R]
  type ThisType[-_R]
  def out[T]: EndpointType[T, R]
  def description(d: String): ThisType[R]
}

object Test {
  def basicEndpoint[R](): Z[R, Unit, Any] = ???

  ...
}
odersky commented 7 months ago

Thanks for the minimizations! I turned lots of logging on, but none of the usual subjects (type inference, implicit search, inlining) showed up. Instead it seemed to do lots of complicated memberDenot/findMember/asSeenFrom operations in deep recursions with complicated types like

ZPartialServerEndpoint[R, A, B, I, E, O, -C] # EndpointType[A, I, E, T, R] ... # EndpointType[A, I, E, T, R]    (6 times)

turns out those complicated types can be avoided by more aggressive dealiasing. So I am trying that as a fix.