Skip to content

Handle exports presenting in scala3doc #10504

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

Merged
merged 5 commits into from
Nov 30, 2020

Conversation

BarkingBad
Copy link
Contributor

No description provided.

@nicolasstucki nicolasstucki linked an issue Nov 26, 2020 that may be closed by this pull request
@nicolasstucki
Copy link
Contributor

The reflection API changes look good.

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

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

Otherwise, the reflection part of the code looks good.

case _ => link(tr.termSymbol)
}
case tr @ TermRef(qual, typeName) =>
tr.termSymbol.tree match
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one here is a little bit tricky. The reason behind this is to extract ConstantType when one occurs

@BarkingBad BarkingBad marked this pull request as ready for review November 27, 2020 11:48
@BarkingBad
Copy link
Contributor Author

BarkingBad commented Nov 27, 2020

class A:
  def defInt: Int = 1
  def def1: 1 = 1
  val valInt: Int = 1
  val val1: 1 = 1
  var varInt: Int = 1
  var var1: 1 = 1

class B:
  val a = new A
  export a._

obraz

I know that setters and getters could be bundled into var or val, but these are synthetic defs obtained from tasty. Merging them is not crucial at that moment, as it requires somekind of hacking.

Copy link
Contributor

@abgruszecki abgruszecki left a comment

Choose a reason for hiding this comment

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

What are the files where I can see how this is displayed?

@@ -43,6 +43,7 @@ object FilterAttributes:
case Origin.InheritedFrom(name, _) => Map("inherited" -> name)
case Origin.ImplicitlyAddedBy(name, _) => Map("implicitly" -> s"by $name")
case Origin.ExtensionFrom(name, _) => Map("extension" -> s"from $name")
case Origin.ExportedFrom(name, _) => Map("export" -> s"Exported from $name")
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this used? Why is the previous line "from $name", but this one is "Exported from $name", i.e. why is the "Exported" part necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I could add some exports to the test cases.

For this one with Exported from... is my fault, will fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@romanowski romanowski left a comment

Choose a reason for hiding this comment

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

Asked some question about exporting members from objects plus some minor style things.

}
val functionName = exportedTarget.fold("instance")(_.name)
val instanceName = exportedTarget.fold("function")(_.qualifier.asInstanceOf[Select].name)
val dri = dd.rhs.flatMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can rhs be empy? If not we can simplify this code a lot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, but I followed the API that returns an Option

@@ -123,6 +123,26 @@ trait ClassLikeSupport:
.map { _ =>
parseMethod(dd.symbol, kind = Kind.Given(getGivenInstance(dd).map(_.asSignature), None))
}

case dd: DefDef if !dd.symbol.isHiddenByVisibility && dd.symbol.isExported =>
val exportedTarget = dd.rhs.flatMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

dd.rhs.collect { 
    case a: Apply => a.fun
    case s: Select => s
}

will do the same what flatmap and map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change

case s: Select => s
}
val functionName = exportedTarget.fold("instance")(_.name)
val instanceName = exportedTarget.fold("function")(_.qualifier.asInstanceOf[Select].name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need to a Select? What if we have

object A:
  def a = 1  

object B extends App:                                                                                                                                                                      
     export A._
     

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a wrong assumption that led to exception breaking the scala3doc generation while having object. Fixed it though

case a: Apply => None
case s: Select =>
val dri = s.symbol.dri
dri.getCallable match
Copy link
Contributor

Choose a reason for hiding this comment

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

we should check if symbol is method not check if callable is set in DRI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I recall it was my first attempt then it came out everything he perceives as method, so I had to find another way to determine it, but I will double check that

dri.getCallable match
case null => None
case _ => Some(dri)
}.orElse(exportedTarget.map(_.qualifier.tpe.typeSymbol.dri))
Copy link
Contributor

Choose a reason for hiding this comment

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

Will typeSymbol works with object? See comment above.

Copy link
Contributor Author

@BarkingBad BarkingBad Nov 27, 2020

Choose a reason for hiding this comment

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

Hard to tell. Could not produce anything breaking the generation.

EDIT: That was my misinterpretation

However, there is one interesting thing, for that code:

object X:
  def x: Int = 1
  val x2: Int = 1
  var x3: Int = 1

class B:
  val a = new A
  export a._
  export X._

we get following output:

obraz

I will have to check is it our bug, but it sees x2 as Int, not literal 1, which is odd, since that type is stable and safe to assume it's literal type (as it did with previous vals)

@@ -49,6 +49,8 @@ object ScalaSignatureProvider:
extensionSignature(extension, builder)
case method: DFunction if method.kind.isInstanceOf[Kind.Given] =>
givenMethodSignature(method, builder)
case exprt: DFunction if exprt.kind == Kind.Exported =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need that case and exportedMethodSignature since we handle it as methodSignature anyway ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can delete, but thought it would be more reasonable to state that explicitly

@romanowski romanowski merged commit 85e48f7 into scala:master Nov 30, 2020
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 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.

Add Exported flag to reflection API
5 participants