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

[SR-15407] DocC (wrongly) renders actors as classes #212

Open
ktoso opened this issue Oct 28, 2021 · 7 comments
Open

[SR-15407] DocC (wrongly) renders actors as classes #212

ktoso opened this issue Oct 28, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@ktoso
Copy link
Member

ktoso commented Oct 28, 2021

Previous ID SR-15407
Radar rdar://84751310
Original Reporter @ktoso
Type Bug

Attachment: Download

Environment

Nightly `main` toolchain from October 27th

Additional Detail from JIRA
Votes 0
Component/s Swift-DocC
Labels Bug
Assignee @QuietMisdreavus
Priority Medium

md5: 314cf0c884190d9ab14edc3fb2ab9753

Issue Description:

Summary:
Actors are listed as classes under the Classes: section. This is very confusing, they should be listed as their own category as they are stand alone nominal types.

Steps To Reproduce:

  1. Declare an actor public actor NEIN {}

Results:
Actor shows up under classes as class NEIN which is misleading.

Expected:
Should get their own section.

Extra:
And distributed actors should get their own section as well, perhaps under actors?

@ktoso
Copy link
Member Author

ktoso commented Oct 28, 2021

@franklinsch
Copy link
Member

It looks like the Swift compiler is treating actors as classes in symbol graph file generation. This is the data I'm seeing for an actor I defined:

{
  "kind": {
    "identifier": "swift.class",
    "displayName": "Class"
  },
  "identifier": {
    "precise": "s:12Test5HelloC",
    "interfaceLanguage": "swift"
  },
  "pathComponents": [],
  "names": {},
  "declarationFragments": [
    {
      "kind": "keyword",
      "spelling": "actor"
    },
    {},
    {}
  ],
  "accessLevel": "public",
  "availability": [],
  "location": {}
},

@ktoso
Copy link
Member Author

ktoso commented Oct 28, 2021

Yeah, that's correct – they are `ClassDecl` but you need to check the keyword it is declared with and treat it separately as an actor if it was declared as actor.

A distributed actor will also have a modifier distributed. so "is distributed actor?" means: was introduced using actor keyword + has modifier distributed.
Those should also be listed as distributed actor but they can be under the actors "section" I guess.

@ktoso
Copy link
Member Author

ktoso commented Oct 28, 2021

If it helps, this is how we detect them in SwiftSyntax, if you want to do this on the consuming end of symbols you'd do the same here I suppose:

extension ClassDeclSyntax {
    var isActor: Bool {
        classOrActorKeyword.text == "actor"
    }

    var isDistributedActor: Bool {
        guard isActor else {
            return false
        }

        guard let mods = self.modifiers else {
            return false
        }

        for mod in mods where mod.name.text ==  "distributed" {
            return true
        }

        return false
    }
}

If you want to do it in the compiler, then the Decls have accurate isActor() and isDistributedActor() functions you can use 🙂

@QuietMisdreavus
Copy link
Contributor

It looks like there are two parts to this issue:

  1. Ensuring actors show up as `actor SomeActor` in topic listings, and

  2. Organizing actors (and potentially also distributed actors) into separate topic listings.

The first is relatively easy; the second requires some greater design effort in Swift-DocC to allow symbol graphs to customize the automatic topic organization behavior. I would suggest proposing that on the forums and splitting it into its own issue.

For the first, the change needs to happen in the compiler, in lib/SymbolGraphGen/DeclarationFragmentsPrinter.cpp, in the printAbridgedType function. This is used by SymbolGraphGen to emit "sub-headings" and "navigator headings", which are used by DocC to render symbols in topic listings. Changing the lines that emit the kw_class keyword to instead convert TD into a ClassDecl and check isActor() to determine which keyword to emit (and additionally check isDistributedActor() to emit the distributed keyword as well) will allow actors to properly show up in class listings with the actor keyword.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 3, 2022
@FranzBusch
Copy link

+1 just ran into this myself and found it pretty confusing

@akbashev
Copy link

akbashev commented Jun 21, 2023

+1
Also just noticed that, a bit misleading when working with actors.

UPD: +1 also for distributed actors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants