Skip to content

[SourceKit] Update for primary associated types #58973

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

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented May 18, 2022

  • InterfaceGen reports a primary associated type as a reference to the 'associatedtype' declaration
  • CursorInfo on a primary associated type returns information of the 'associatedtype' declaration

rdar://93275458

* InterfaceGen reports a primary associated type as a reference to the
  'associatedtype' declaration
* CursorInfo on a primary associated type returns information of the
  'associatedtype' declaration

rdar://93275458
@rintaro rintaro force-pushed the ide-primaryassociatedtype-rdar93275458 branch from 59172c9 to 8bda524 Compare May 19, 2022 00:16
@rintaro
Copy link
Member Author

rintaro commented May 19, 2022

@swift-ci Please smoke test

@rintaro rintaro requested a review from bnbarham May 19, 2022 00:17
@rintaro
Copy link
Member Author

rintaro commented May 19, 2022

@QuietMisdreavus With this change, DeclarationFragmentPrinter::printTypeRef() is now called on primary associated types, and also SymbolGraphASTWalker might be affected by the SourceEntityWalker.cpp changes (since it's not overriding visitDeclReference(), probably not).

Could you double check? Let me know you need additional test, or you can add test cases for SymbolGraph after merging it as you need.

@QuietMisdreavus
Copy link
Contributor

@rintaro Can you take the snippet you're using for Index and SourceKit tests and use it in a SymbolGraph test? I can build up a specific one tomorrow if you need, but copying the build lines from something like test/SymbolGraph/Symbols/Names.swift and inspecting the graph that comes out will probably suffice.

@rintaro
Copy link
Member Author

rintaro commented Jun 2, 2022

@QuietMisdreavus Does this look good? If it looks good, let me merge this as is, and could you add a test case after that if needed?

// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -module-name MyModule -emit-module -emit-module-path %t/
// RUN: %target-swift-symbolgraph-extract -module-name MyModule -I %t -pretty-print -output-dir %t

public protocol WithPrimary<Assoc> {
   associatedtype Assoc
}

Result

{
  "metadata": {
    "formatVersion": {
      "major": 0,
      "minor": 5,
      "patch": 3
    },
    "generator": "Swift version 5.8-dev (LLVM 278d67f38c6a910, Swift 4ae16bfef7bb240)"
  },
  "module": {
    "name": "MyModule",
    "platform": {
      "architecture": "x86_64",
      "vendor": "apple",
      "operatingSystem": {
        "name": "macosx",
        "minimumVersion": {
          "major": 10,
          "minor": 9,
          "patch": 0
        }
      }
    }
  },
  "symbols": [
    {
      "kind": {
        "identifier": "swift.protocol",
        "displayName": "Protocol"
      },
      "identifier": {
        "precise": "s:8MyModule11WithPrimaryP",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "WithPrimary"
      ],
      "names": {
        "title": "WithPrimary",
        "navigator": [
          {
            "kind": "identifier",
            "spelling": "WithPrimary"
          }
        ],
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "protocol"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "WithPrimary"
          }
        ]
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "protocol"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "WithPrimary"
        },
        {
          "kind": "text",
          "spelling": "<"
        },
        {
          "kind": "typeIdentifier",
          "spelling": "Assoc"
        },
        {
          "kind": "text",
          "spelling": ">"
        }
      ],
      "accessLevel": "public"
    },
    {
      "kind": {
        "identifier": "swift.associatedtype",
        "displayName": "Associated Type"
      },
      "identifier": {
        "precise": "s:8MyModule11WithPrimaryP5AssocQa",
        "interfaceLanguage": "swift"
      },
      "pathComponents": [
        "WithPrimary",
        "Assoc"
      ],
      "names": {
        "title": "Assoc",
        "subHeading": [
          {
            "kind": "keyword",
            "spelling": "associatedtype"
          },
          {
            "kind": "text",
            "spelling": " "
          },
          {
            "kind": "identifier",
            "spelling": "Assoc"
          }
        ]
      },
      "declarationFragments": [
        {
          "kind": "keyword",
          "spelling": "associatedtype"
        },
        {
          "kind": "text",
          "spelling": " "
        },
        {
          "kind": "identifier",
          "spelling": "Assoc"
        }
      ],
      "accessLevel": "public"
    }
  ],
  "relationships": [
    {
      "kind": "requirementOf",
      "source": "s:8MyModule11WithPrimaryP5AssocQa",
      "target": "s:8MyModule11WithPrimaryP"
    }
  ]
}

@QuietMisdreavus
Copy link
Contributor

@rintaro That looks great, thanks! I can add the test once this is merged.

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.

3 participants