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

Symbol Graphs Lack Operators #60140

Open
SDGGiesbrecht opened this issue Jul 19, 2022 · 4 comments
Open

Symbol Graphs Lack Operators #60140

SDGGiesbrecht opened this issue Jul 19, 2022 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. SymbolGraphGen The swiftSymbolGraphGen library, responsible for gathering and emitting symbol graphs.

Comments

@SDGGiesbrecht
Copy link

SDGGiesbrecht commented Jul 19, 2022

Describe the bug

Generated symbol graphs do not contain information about operators.

Steps To Reproduce

Package source files:

// swift-tools-version: 5.6
// Package.swift

import PackageDescription

let package = Package(
  name: "Experiment",
  products: [
    .library(
      name: "Experiment",
      targets: ["Experiment"]
    ),
  ],
  targets: [
    .target(
      name: "Experiment"
    ),
  ]
)
// Sources/Experiment/Experiment.swift
precedencegroup CustomPrecedence {}
infix operator : CustomPrecedence

Terminal command:

package dump-symbol-graph

Result:

{
  "metadata": {
    "formatVersion": {
      "major":0,
      "minor":5,
      "patch":3
    },
   "generator": "Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12)"
  },
  "module": {
    "name": "Experiment",
    "platform": {
      "architecture":"x86_64","vendor":"apple",
      "operatingSystem": {
        "name": "macosx",
        "minimumVersion": {
          "major":10,
          "minor":10,
          "patch":0
        }
      }
    }
  },
  "symbols": [],
  "relationships":[]
}

Expected behavior

There ought to be some sort of entry for CustomPrecedence and .

@SDGGiesbrecht SDGGiesbrecht added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Jul 19, 2022
@franklinsch franklinsch added the SymbolGraphGen The swiftSymbolGraphGen library, responsible for gathering and emitting symbol graphs. label Jul 20, 2022
@franklinsch
Copy link
Contributor

operator and precedencegroup declarations are implicitly public, so yes, I'd expect them to be in the symbol graph. cc @QuietMisdreavus

@QuietMisdreavus
Copy link
Contributor

We currently don't emit symbols for operator declarations themselves, only their implementations on types. I would be curious how a declaration like this could be used in a dependent package. Can someone import Experiment and implement the operator on their own type with the infix/precedence declarations given in their dependency?

As far as the symbol graph is concerned, what kind of information is necessary to include about an operator/precedence-group declaration? I didn't know about custom precedence groups before.

@tayloraswift
Copy link
Member

tayloraswift commented Jul 20, 2022

from tspl:

    precedencegroup precedence group name {
        higherThan: lower group names
        lowerThan: higher group names
        associativity: associativity
        assignment: assignment
    }

the higherThan/lowerThan fields are edge relations, which means we would probably need to emit the standard precedence groups as well.

i think to get started though, it should be enough to just emit a stub for each custom precedence group indicating its existence, which would allow us to attach documentation to it.

@SDGGiesbrecht
Copy link
Author

SDGGiesbrecht commented Jul 20, 2022

Can someone import Experiment and implement the ≠ operator on their own type with the infix/precedence declarations given in their dependency?

Yes. A client can declare its own operators in an imported precedence group, and can declare its own functions for an imported operator.

I didn't know about custom precedence groups before.

For details, see here.

what kind of information is necessary to include about an operator/precedence-group declaration?

As a rough initial sketch... (and not necessarily implemented all at once)

The declaration used for SymbolGraph.Symbol.names.subHeading and so on should retain the following:

  • fixity (prefix/infix/suffix)
  • associativity (none, left, right)
  • assignment (false/true)

The following should become new cases of SymbolGraph.Relationship.Kind:

  • implementsOperator (funcoperator)
  • hasPrecedence (operatorprecedencegroup)
  • evaluatedBefore (higherThan/lowerThan; precedencegroupprecedencegroup)

Any documentation comments should also be gathered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. SymbolGraphGen The swiftSymbolGraphGen library, responsible for gathering and emitting symbol graphs.
Projects
None yet
Development

No branches or pull requests

4 participants