Skip to content

Cache AppliedType#tryNormalize #14864

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

Closed

Conversation

mbovel
Copy link
Member

@mbovel mbovel commented Apr 6, 2022

No description provided.

@mbovel
Copy link
Member Author

mbovel commented Apr 6, 2022

test performance please

@dottybot
Copy link
Member

dottybot commented Apr 6, 2022

performance test scheduled: 3 job(s) in queue, 1 running.

@mbovel mbovel marked this pull request as draft April 6, 2022 14:11
@dottybot
Copy link
Member

dottybot commented Apr 6, 2022

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/14864/ to see the changes.

Benchmarks is based on merging with main (8d3083b)

@mbovel
Copy link
Member Author

mbovel commented Apr 6, 2022

test performance with #compiletime please

@dottybot
Copy link
Member

dottybot commented Apr 6, 2022

performance test scheduled: 2 job(s) in queue, 1 running.

@dottybot
Copy link
Member

dottybot commented Apr 6, 2022

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/14864/ to see the changes.

Benchmarks is based on merging with main (8d3083b)

@mbovel mbovel force-pushed the mb/cache-applied-type-try-normalize branch from 06bc8d5 to 96e1870 Compare April 7, 2022 07:16
@mbovel
Copy link
Member Author

mbovel commented Apr 7, 2022

test performance with #compiletime please

@dottybot
Copy link
Member

dottybot commented Apr 7, 2022

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

dottybot commented Apr 7, 2022

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/14864/ to see the changes.

Benchmarks is based on merging with main (3d1d299)

@mbovel
Copy link
Member Author

mbovel commented May 23, 2022

The failing test is tests/pos/singleton-ops-test-issue-8280.scala:

2022-04-07T07:39:12.0790256Z [info] Test dotty.tools.dotc.CompilationTests.pos started
2022-04-07T07:40:34.7480775Z -- [E007] Type Mismatch Error: tests/pos/singleton-ops-test-issue-8280.scala:13:30 -------------------------------------
2022-04-07T07:40:34.7481337Z 13 |val fincP1  : Foo[2] = Foo(1).incP
2022-04-07T07:40:34.7481642Z    |                       ^^^^^^^^^^^
2022-04-07T07:40:34.7483873Z    |                       Found:    Foo[(1 : Int) + (1 : Int)]
2022-04-07T07:40:34.7484893Z    |                       Required: Foo[(2 : Int)]
2022-04-07T07:40:34.7485544Z    |
2022-04-07T07:40:34.7487102Z Compilation failed for: 'tests/pos/singleton-ops-test-issue-8280.scala'         
2022-04-07T07:40:34.7488290Z    | longer explanation available when compiling with `-explain`
2022-04-07T07:41:14.1344363Z [error] Test dotty.tools.dotc.CompilationTests.pos failed: java.lang.AssertionError: Expected no errors when compiling, failed for the following reason(s):
2022-04-07T07:41:14.1345530Z [error] 
2022-04-07T07:41:14.1346804Z [error]   - encountered 1 test failures(s), took 122.055 sec
2022-04-07T07:41:14.1347856Z [error]     at dotty.tools.vulpix.ParallelTesting$CompilationTest.checkCompile(ParallelTesting.scala:983)
2022-04-07T07:41:14.1349688Z [error]     at dotty.tools.dotc.CompilationTests.pos(CompilationTests.scala:67)
2022-04-07T07:41:14.1350854Z [error]     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2022-04-07T07:41:14.1352110Z [error]     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
2022-04-07T07:41:14.1353575Z [error]     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2022-04-07T07:41:14.1355280Z [error]     at java.lang.reflect.Method.invoke(Method.java:567)
2022-04-07T07:41:14.1355950Z [error]     ...

@mbovel
Copy link
Member Author

mbovel commented May 23, 2022

image

@mbovel
Copy link
Member Author

mbovel commented Jun 8, 2022

The failing test is tests/pos/singleton-ops-test-issue-8280.scala

Checking for isProvisional solves this problem for tests/pos/singleton-ops-test-issue-8280 but introduces cyclic errors due to reading flags:

> sbt:scala3> scalac -Ydebug-type-error tests/neg/t1292.scala
-- [E046] Cyclic Error: tests/neg/t1292.scala:2:13 -----------------------------
2 |  type StV = Enum#Value // error: Enum is not a legal path
  |             ^
  |             Cyclic reference involving class Value
  |
  | longer explanation available when compiling with `-explain`
dotty.tools.dotc.core.CyclicReference: 
        at dotty.tools.dotc.core.CyclicReference$.apply(TypeErrors.scala:155)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:165)
        at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
        at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:369)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.flags(SymDenotations.scala:64)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.is(SymDenotations.scala:106)
        at dotty.tools.dotc.core.Types$Type.dotty$tools$dotc$core$Types$Type$$_$test$1(Types.scala:120)
        at dotty.tools.dotc.core.Types$Type.foldArgs$1(Types.scala:130)
        at dotty.tools.dotc.core.Types$Type.dotty$tools$dotc$core$Types$Type$$_$test$1(Types.scala:4178)
        at dotty.tools.dotc.core.Types$Type.testProvisional(Types.scala:140)
        at dotty.tools.dotc.core.Types$Type.isProvisional(Types.scala:109)
        at dotty.tools.dotc.core.Types$AppliedType.tryCompiletimeConstantFold(Types.scala:4219)
        at dotty.tools.dotc.core.Types$AppliedType.tryNormalize(Types.scala:4191)
        at dotty.tools.dotc.core.Types$Type.normalized(Types.scala:1427)
        at dotty.tools.dotc.core.TypeApplications$.tryReduce$1(TypeApplications.scala:348)
        at dotty.tools.dotc.core.TypeApplications$.appliedTo$extension(TypeApplications.scala:370)
        at dotty.tools.dotc.core.TypeApplications$.safeAppliedTo$extension(TypeApplications.scala:407)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler.readType(Scala2Unpickler.scala:823)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler.readTypeRef$$anonfun$1(Scala2Unpickler.scala:950)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler.atReadPos(Scala2Unpickler.scala:313)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler.at(Scala2Unpickler.scala:303)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler.readTypeRef(Scala2Unpickler.scala:950)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler.readType$$anonfun$3(Scala2Unpickler.scala:845)
        at dotty.tools.dotc.core.unpickleScala2.PickleBuffer.until(PickleBuffer.scala:163)
        at dotty.tools.dotc.core.unpickleScala2.PickleBuffer.until(PickleBuffer.scala:163)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler.readType(Scala2Unpickler.scala:845)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler$LocalUnpickler.$anonfun$6(Scala2Unpickler.scala:600)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler.atReadPos(Scala2Unpickler.scala:313)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler.at(Scala2Unpickler.scala:303)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler$LocalUnpickler.parseToCompletion$1(Scala2Unpickler.scala:600)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler$LocalUnpickler.complete$$anonfun$1(Scala2Unpickler.scala:638)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler.atReadPos(Scala2Unpickler.scala:313)
        at dotty.tools.dotc.core.unpickleScala2.Scala2Unpickler$LocalUnpickler.complete(Scala2Unpickler.scala:640)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
        at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
        at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1121)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1079)
        at dotty.tools.dotc.core.Denotations$PreDenotation.asSeenFrom(Denotations.scala:134)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2065)
        at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:683)
        at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:876)
        at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:666)
        at dotty.tools.dotc.core.Types$Type.member(Types.scala:650)
        at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.isMatchedBy(ProtoTypes.scala:193)
        at dotty.tools.dotc.core.TypeComparer.isMatchedByProto(TypeComparer.scala:1904)
        at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:309)
        at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1323)
        at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:189)
        at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:199)
        at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:126)
        at dotty.tools.dotc.core.TypeComparer$.topLevelSubType(TypeComparer.scala:2734)
        at dotty.tools.dotc.core.Types$Type.$less$colon$less(Types.scala:1038)
        at dotty.tools.dotc.typer.Typer.adaptType$1(Typer.scala:3924)
        at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3994)
        at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3329)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
        at dotty.tools.dotc.typer.Typer.typedType(Typer.scala:3083)
        at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:687)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2801)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2894)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
        at dotty.tools.dotc.typer.Typer.typedType(Typer.scala:3083)
        at dotty.tools.dotc.typer.Namer.typedAheadType$$anonfun$1(Namer.scala:1476)
        at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1469)
        at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:1476)
        at dotty.tools.dotc.typer.Namer$TypeDefCompleter.typeSig(Namer.scala:1019)
        at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:920)
        at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:808)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
        at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
        at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:369)
        at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2773)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2798)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2894)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2986)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3036)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2476)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2820)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2824)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2894)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2986)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3036)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2603)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2865)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2895)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2960)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2964)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3080)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:43)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:50)
        at scala.Function0.apply$mcV$sp(Function0.scala:39)
        at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:414)

Could we use flagsUNSAFE in isProvisional and child methods? Or should we have a caching method similar to what is done in MatchType (manually checking if type variables changed)?

if myTryCompiletimeConstantFoldPeriod != ctx.period then
myTryCompiletimeConstantFoldPeriod = ctx.period
myTryCompiletimeConstantFold = tryCompiletimeConstantFoldImpl
myTryCompiletimeConstantFold.nn
Copy link
Member Author

@mbovel mbovel Jun 8, 2022

Choose a reason for hiding this comment

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

Minor: looking at flame charts from the async profiler, it seems that a significant amount of time is spend in .nn. Probably should avoid using it here.

@mbovel mbovel changed the title Cache AppliedType#tryNormalize [Experiment] Cache AppliedType#tryNormalize Jun 8, 2022
@mbovel mbovel force-pushed the mb/cache-applied-type-try-normalize branch from 0582474 to 8eeb070 Compare June 10, 2022 15:51
@mbovel
Copy link
Member Author

mbovel commented Jun 10, 2022

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/14864/ to see the changes.

Benchmarks is based on merging with main (9614fb9)

@mbovel
Copy link
Member Author

mbovel commented Jun 13, 2022

test performance with #compiletime please

@dottybot
Copy link
Member

performance test scheduled: 4 job(s) in queue, 1 running.

@mbovel mbovel changed the title [Experiment] Cache AppliedType#tryNormalize Cache AppliedType#tryNormalize Jun 13, 2022
@mbovel mbovel marked this pull request as ready for review June 13, 2022 14:05
@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/14864/ to see the changes.

Benchmarks is based on merging with main (836ed97)

@mbovel
Copy link
Member Author

mbovel commented Jun 15, 2022

Done in #15453.

@mbovel mbovel closed this Jun 15, 2022
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.

2 participants