Skip to content

Commit bab066c

Browse files
committed
Inkuire Implicit conversions WIP
1 parent 8b2f676 commit bab066c

File tree

6 files changed

+1868
-1889
lines changed

6 files changed

+1868
-1889
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"inkuirePaths": [
3-
{"path" : "../inkuire-db.json"}
3+
"../inkuire-db.json"
44
]
55
}

scaladoc/resources/dotty_res/scripts/inkuire.js

Lines changed: 1838 additions & 1851 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scaladoc/src/dotty/tools/scaladoc/Inkuire.scala

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,12 @@ import scala.collection.mutable.{ Map => MMap}
55

66
object Inkuire {
77

8-
var db = InkuireDb(Seq.empty, Map.empty)
9-
10-
var postTransformations: MMap[String, Option[Inkuire.Contravariance]] = MMap.empty
11-
12-
def postTransform(): Unit = //TODO doesn't append. Dunno why
13-
postTransformations.foreach {
14-
case (name, t) =>
15-
if(name == "RichByte") {
16-
println(t)
17-
}
18-
}
19-
val newFunctions = Inkuire.db.functions.flatMap { eSgn =>
20-
postTransformations.get(eSgn.signature.receiver.map(_.typ.name.name).getOrElse("")) match
21-
case Some(receiver) =>
22-
List(eSgn.copy(signature = eSgn.signature.copy(receiver = receiver)))
23-
case _ =>
24-
List.empty
25-
}
26-
Inkuire.db = Inkuire.db.copy(functions = Inkuire.db.functions ++ newFunctions)
8+
var db = InkuireDb(Seq.empty, Map.empty, Seq.empty)
279

2810
case class InkuireDb(
29-
functions: Seq[ExternalSignature],
30-
types: Map[ITID, (Type, Seq[Type])]
11+
functions: Seq[ExternalSignature],
12+
types: Map[ITID, (Type, Seq[Type])],
13+
implicitConversions: Seq[(ITID, Type)]
3114
)
3215

3316
case class ITID(uuid: String, isParsed: Boolean)
@@ -107,7 +90,17 @@ object Inkuire {
10790
def serialize(db: InkuireDb): JSON = {
10891
jsonObject(
10992
("types", serialize(db.types)),
110-
("functions", jsonList(db.functions.map(serialize)))
93+
("functions", jsonList(db.functions.map(serialize))),
94+
("implicitConversions", jsonList(db.implicitConversions.map(serializeConversion)))
95+
)
96+
}
97+
98+
private def serializeConversion(conversion: (ITID, Type)): JSON = {
99+
jsonList(
100+
Seq(
101+
serialize(conversion._1),
102+
serialize(conversion._2)
103+
)
111104
)
112105
}
113106

scaladoc/src/dotty/tools/scaladoc/Scaladoc.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ object Scaladoc:
8888
ctx.reporter
8989

9090
def dumpInkuireDB(output: String) = {
91-
Inkuire.postTransform()
9291
val path = Paths.get(output, "inkuire-db.json")
9392
println("InkuireDB created successfully!")
9493
println(s"Types: ${Inkuire.db.types.size}")

scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,6 @@ trait ClassLikeSupport:
9696

9797
if summon[DocContext].args.generateInkuire then {
9898

99-
/**
100-
* Stuff the doesn't work yet:
101-
* - Type parameters work in types but don't work in parents and in types that are arguments or results of functions
102-
* - Extension functions
103-
* - Inheritance of special types (Any, AnyVal, AnyRef, Nothing, ...)
104-
* - SYNTAX!!! <- that's in Inkuire e.g. tuples, different arrows, different parentheses with type params, different constraint syntax
105-
* - Type param constraints
106-
*/
107-
10899
val classType = classDef.asInkuire(Set.empty, true)
109100
val variableNames = classType.params.map(_.typ.name.name).toSet
110101

@@ -115,13 +106,17 @@ trait ClassLikeSupport:
115106
if !isModule then Inkuire.db = Inkuire.db.copy(types = Inkuire.db.types.updated(classType.itid.get, (classType, parents)))
116107

117108
classDef.symbol.declaredMethods.foreach {
118-
case implicitConversion: Symbol if implicitConversion.flags.is(Flags.Implicit) || implicitConversion.isGiven =>
109+
case implicitConversion: Symbol if implicitConversion.flags.is(Flags.Implicit)
110+
&& !implicitConversion.flags.is(Flags.Private)
111+
&& classDef.symbol.flags.is(Flags.Module) =>
119112
val defdef = implicitConversion.tree.asInstanceOf[DefDef]
120-
val name = defdef.returnTpt.tpe.typeSymbol.name
121-
val receiver = defdef.paramss.flatMap(_.params).collectFirst {
122-
case v: ValDef => Inkuire.Contravariance(v.tpt.asInkuire(variableNames, false))
113+
val from = defdef.returnTpt.asInkuire(variableNames, false)
114+
val to = defdef.paramss.flatMap(_.params).collectFirst {
115+
case v: ValDef => v.tpt.asInkuire(variableNames, false)
123116
}
124-
Inkuire.postTransformations.addOne(name -> receiver)
117+
to match
118+
case Some(to) => Inkuire.db = Inkuire.db.copy(implicitConversions = Inkuire.db.implicitConversions :+ (from.itid.get -> to))
119+
case None =>
125120
case methodSymbol: Symbol =>
126121
val defdef = methodSymbol.tree.asInstanceOf[DefDef]
127122
val methodVars = defdef.paramss.flatMap(_.params).collect {

scaladoc/src/dotty/tools/scaladoc/tasty/InkuireSupport.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ trait InkuireSupport:
3535
inner(tpeTree.tpe, vars)
3636
case term: Term => inner(term.tpe, vars)
3737
case classDef: ClassDef => mkTypeFromClassDef(classDef, vars, isVariable)
38+
case typeDef: TypeDef =>
39+
Inkuire.Type(
40+
name = Inkuire.TypeName(typeDef.name),
41+
itid = typeDef.symbol.itid
42+
)
3843
}
3944

4045
def mkTypeFromClassDef(classDef: ClassDef, vars: Set[String], isVariable: Boolean): Inkuire.Type = {

0 commit comments

Comments
 (0)