Skip to content

Commit 7a12964

Browse files
committed
Add a hidden flag to disable the swift bridge attribute
This will be used for writing performance tests
1 parent 12593ef commit 7a12964

File tree

7 files changed

+38
-2
lines changed

7 files changed

+38
-2
lines changed

include/swift/ClangImporter/ClangImporterOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class ClangImporterOptions {
6767
/// member of some type instead. This includes inits, computed properties,
6868
/// and methods.
6969
bool InferImportAsMember = false;
70+
71+
/// If true ignore the swift bridged attribute.
72+
bool DisableSwiftBridgeAttr = false;
7073
};
7174

7275
} // end namespace swift

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ def solver_memory_threshold : Separate<["-"], "solver-memory-threshold">,
218218
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
219219
HelpText<"Set the upper bound for memory consumption, in bytes, by the constraint solver">;
220220

221+
def disable_swift_bridge_attr : Flag<["-"], "disable-swift-bridge-attr">,
222+
Flags<[FrontendOption, HelpHidden]>,
223+
HelpText<"Disable using the swift bridge attribute">;
224+
221225
// Diagnostic control options
222226
def suppress_warnings : Flag<["-"], "suppress-warnings">,
223227
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,

lib/ClangImporter/ClangImporter.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,7 @@ ClangImporter::Implementation::Implementation(ASTContext &ctx,
11831183
: SwiftContext(ctx),
11841184
ImportForwardDeclarations(opts.ImportForwardDeclarations),
11851185
InferImportAsMember(opts.InferImportAsMember),
1186+
DisableSwiftBridgeAttr(opts.DisableSwiftBridgeAttr),
11861187
BridgingHeaderLookupTable(nullptr)
11871188
{
11881189
// Add filters to determine if a Clang availability attribute
@@ -1957,7 +1958,11 @@ namespace {
19571958
/// Determine whether the given Objective-C class, or any of its
19581959
/// superclasses, either has or inherits a swift_bridge attribute.
19591960
static bool hasOrInheritsSwiftBridgeAttr(
1960-
const clang::ObjCInterfaceDecl *objcClass) {
1961+
const clang::ObjCInterfaceDecl *objcClass,
1962+
bool DisableSwiftBridgeAttr) {
1963+
// If we have disabled the attribute just return that there is none.
1964+
if (DisableSwiftBridgeAttr)
1965+
return false;
19611966
do {
19621967
// Look at the definition, if there is one.
19631968
if (auto def = objcClass->getDefinition())
@@ -2481,7 +2486,8 @@ auto ClangImporter::Implementation::importFullName(
24812486
if (D->getDeclContext()->getRedeclContext()->isFileContext() &&
24822487
(isa<clang::TypeDecl>(D) ||
24832488
(isa<clang::ObjCInterfaceDecl>(D) &&
2484-
!hasOrInheritsSwiftBridgeAttr(cast<clang::ObjCInterfaceDecl>(D))) ||
2489+
!hasOrInheritsSwiftBridgeAttr(cast<clang::ObjCInterfaceDecl>(D),
2490+
DisableSwiftBridgeAttr)) ||
24852491
isa<clang::ObjCProtocolDecl>(D))) {
24862492
// Find the original declaration, from which we can determine
24872493
// the owning module.

lib/ClangImporter/ImportType.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ namespace {
677677
/// Map the Clang swift_bridge attribute to a specific type.
678678
Type mapSwiftBridgeAttr(const clang::NamedDecl *clangDecl) {
679679
// Check whether there is a swift_bridge attribute.
680+
if (Impl.DisableSwiftBridgeAttr)
681+
return Type();
680682
auto bridgeAttr = clangDecl->getAttr<clang::SwiftBridgeAttr>();
681683
if (!bridgeAttr) return Type();
682684

lib/ClangImporter/ImporterImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
262262

263263
const bool ImportForwardDeclarations;
264264
const bool InferImportAsMember;
265+
const bool DisableSwiftBridgeAttr;
265266

266267
constexpr static const char * const moduleImportBufferName =
267268
"<swift-imported-modules>";

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,8 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
884884
if (Args.hasArg(OPT_embed_bitcode))
885885
Opts.Mode = ClangImporterOptions::Modes::EmbedBitcode;
886886

887+
Opts.DisableSwiftBridgeAttr |= Args.hasArg(OPT_disable_swift_bridge_attr);
888+
887889
return false;
888890
}
889891

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: %build-silgen-test-overlays
3+
// RUN: %target-swift-frontend -emit-module -o %t -sdk %S/Inputs -I %S/../Inputs/ObjCBridging %S/../Inputs/ObjCBridging/Appliances.swift -I %t
4+
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t -I %S/../Inputs/ObjCBridging) -disable-swift-bridge-attr -Xllvm -sil-full-demangle -emit-silgen %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-cpu --check-prefix=CHECK-%target-os-%target-cpu
5+
6+
// REQUIRES: objc_interop
7+
8+
import Foundation
9+
import Appliances
10+
11+
// This tests the -disable-swift-bridge-attr flag. Make sure we don't emit bridging code.
12+
13+
// CHECK-LABEL: sil hidden @{{.*}}objc_disable_brigding16updateFridgeTemp
14+
func updateFridgeTemp(home: APPHouse, delta: Double) {
15+
// CHECK-NOT: function_ref @{{.*}}BridgeFromObjectiveC
16+
home.fridge.temperature += delta
17+
// CHECK: return
18+
}

0 commit comments

Comments
 (0)