Skip to content

Commit 4c7a313

Browse files
authored
Merge pull request #84488 from xymus/c-impl-in-swiftinterfaces
ModuleInterface: Don't print `@c @implementation` functions
2 parents dc7e5fc + 0eaab86 commit 4c7a313

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
353353
}
354354
}
355355

356+
// Skip @c @implementation functions along with the attribute.
357+
if (auto AFD = dyn_cast<AbstractFunctionDecl>(D)) {
358+
if (options.excludeAttrKind(DeclAttrKind::ObjCImplementation) &&
359+
AFD->isObjCImplementation() && AFD->getCDeclKind())
360+
return false;
361+
}
362+
356363
// Skip extensions that extend things we wouldn't print.
357364
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
358365
if (!shouldPrint(ED->getExtendedNominal(), options))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t --leading-lines
3+
4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
5+
// RUN: -emit-module %t/Lib.swift -o %t -I %t \
6+
// RUN: -swift-version 6 -enable-library-evolution \
7+
// RUN: -emit-module-interface-path %t/Lib.swiftinterface \
8+
// RUN: -enable-experimental-feature CDecl \
9+
// RUN: -enable-experimental-feature CImplementation
10+
11+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %t \
12+
// RUN: -typecheck-module-from-interface %t/Lib.swiftinterface
13+
14+
// RUN: %FileCheck %s --input-file %t/Lib.swiftinterface
15+
16+
// REQUIRES: objc_interop
17+
// REQUIRES: swift_feature_CDecl
18+
// REQUIRES: swift_feature_CImplementation
19+
20+
//--- module.modulemap
21+
module Lib {
22+
header "Lib.h"
23+
}
24+
25+
//--- Lib.h
26+
extern void cImplFunc();
27+
extern void objcImplFunc();
28+
29+
//--- Lib.swift
30+
@_exported import Lib
31+
import Foundation
32+
33+
/// Don't print the implementation functions.
34+
// CHECK-NOT: @implementation
35+
// CHECK-NOT: ImplFunc
36+
37+
@c @implementation
38+
public func cImplFunc() { }
39+
40+
@_cdecl("objcImplFunc") @implementation
41+
public func objcImplFunc() { }
42+
43+
/// Print other @c functions.
44+
@c
45+
public func bareCDecl() {}
46+
// CHECK: @c
47+
// CHECK-NEXT: public func bareCDecl
48+
49+
@c(c_name)
50+
public func namedCDecl() {}
51+
// CHECK: @c(c_name)
52+
// CHECK-NEXT: public func namedCDecl
53+
54+
@_cdecl("objc_name")
55+
public func namedLegacyCDecl() {}
56+
// CHECK: @_cdecl("objc_name")
57+
// CHECK-NEXT: public func namedLegacyCDecl

0 commit comments

Comments
 (0)