Skip to content

Conversation

@xedin
Copy link
Contributor

@xedin xedin commented Nov 13, 2025

…eworks

printModuleInterfaceDecl printes extensions right after the type they are associated with is printed. Extensions associated with a type that appears in the "target" module shouldn't be added to SwiftDecls because that would lead to double printing them.

@xedin
Copy link
Contributor Author

xedin commented Nov 13, 2025

@swift-ci please test

continue;
}

if (auto extendedTy = Ext->getExtendedNominal()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's already a check in printModuleInterfaceDecl for extensions, which seems like dead code after this change? It currently skips printing extensions if they don't have a clang node and are part of the same module:

  if (auto Ext = dyn_cast<ExtensionDecl>(D)) {
    // Clang extensions (categories) are always printed in source order.
    // Swift extensions are printed with their associated type unless it's
    // a cross-module extension.
    if (!extensionHasClangNode(Ext)) {
      auto ExtendedNominal = Ext->getExtendedNominal();
      if (!ExtendedNominal ||
          Ext->getModuleContext() == ExtendedNominal->getModuleContext())
        return false;
    }
  }

Though that also means we're skipping more than before. Does this change prevent printing of categories for pure ObjC imports (no Swift)?

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 forgot to remove this condition which is not no-op and for ObjC categories - they are added to clang decls and would be printed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the old check.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change prevent printing of categories for pure ObjC imports (no Swift)?

Note the check above this means we're only looking at Swift extensions specifically here

Copy link
Contributor

Choose a reason for hiding this comment

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

Note the check above this means we're only looking at Swift extensions specifically here

Which check 🤔?

Copy link
Contributor

@hamishknight hamishknight Nov 13, 2025

Choose a reason for hiding this comment

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

      if (extensionHasClangNode(Ext)) {
        addToClangDecls(Ext, extensionGetClangNode(Ext));
        continue;
      }

@xedin xedin force-pushed the prevent-printModuleInterface-from-printing-extensions-twice branch from 62109cf to 7bc7eed Compare November 13, 2025 22:46
Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Thanks!

…eworks

`printModuleInterfaceDecl` printes extensions right after the type
they are associated with is printed. Extensions associated with a
type that appears in the "target" module shouldn't be added to
`SwiftDecls` because that would lead to double printing them.
@xedin xedin force-pushed the prevent-printModuleInterface-from-printing-extensions-twice branch from 7bc7eed to 700d9fd Compare November 13, 2025 23:07
@xedin
Copy link
Contributor Author

xedin commented Nov 13, 2025

@swift-ci please test

@xedin xedin merged commit d8549ec into swiftlang:main Nov 14, 2025
5 checks passed
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