-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[MacrosOnImports][Swiftify] Copy module imports from clang node's module to its Swift macro SourceFile #81859
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
typedef int a_t; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
typedef int b_t; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#pragma once | ||
typedef int c_t; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#pragma once | ||
typedef int d_t; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#pragma once | ||
typedef int e_t; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ModuleA { | ||
header "module-a.h" | ||
export * | ||
} | ||
module ModuleB { | ||
header "module-b.h" | ||
} | ||
module ModuleOuter { | ||
module ModuleC { | ||
header "module-c.h" | ||
export * | ||
} | ||
explicit module ModuleD { | ||
header "module-d.h" | ||
export * | ||
} | ||
} | ||
module ModuleDeep { | ||
module ModuleDeepNested { | ||
module ModuleDeepNestedNested { | ||
header "module-e.h" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include "TransitiveModules/module-a.h" | ||
#include "TransitiveModules/module-b.h" | ||
#include "TransitiveModules/module-c.h" | ||
#include "TransitiveModules/module-d.h" | ||
#include "TransitiveModules/module-e.h" | ||
|
||
#define __counted_by(x) __attribute__((__counted_by__(x))) | ||
#define __noescape __attribute__((noescape)) | ||
|
||
void basic_include(const a_t *__counted_by(len) p __noescape, a_t len); | ||
|
||
void non_exported_include(const b_t *__counted_by(len) p __noescape, b_t len); | ||
|
||
void submodule_include(const c_t *__counted_by(len) p __noescape, c_t len); | ||
|
||
void explicit_submodule_include(const d_t *__counted_by(len) p __noescape, d_t len); | ||
|
||
void deep_submodule_noexport(const e_t *__counted_by(len) p __noescape, e_t len); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// REQUIRES: swift_feature_SafeInteropWrappers | ||
|
||
// RUN: %target-swift-ide-test -print-module -module-to-print=ClangIncludesNoExportModule -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s | ||
|
||
// swift-ide-test doesn't currently typecheck the macro expansions, so run the compiler as well | ||
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/ClangIncludesNoExport.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers %s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice to have a run line with C++ interop enabled just in case. Sometimes there are subtle differences between the two modes. |
||
|
||
import ClangIncludesNoExportModule | ||
|
||
// CHECK: import ModuleA | ||
// CHECK-NEXT: import ModuleB | ||
// CHECK-NOT: import | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DougGregor I don't fully get why only the module's imports that themselves are top-level modules show up in the dump. It seems to work regardless, but it seems a bit off. Do you know if this is intended? |
||
// CHECK-EMPTY: | ||
|
||
// CHECK-NEXT: func basic_include(_ p: UnsafePointer<a_t>!, _ len: a_t) | ||
// CHECK-NEXT: func non_exported_include(_ p: UnsafePointer<b_t>!, _ len: b_t) | ||
// CHECK-NEXT: func submodule_include(_ p: UnsafePointer<c_t>!, _ len: c_t) | ||
// CHECK-NEXT: func explicit_submodule_include(_ p: UnsafePointer<d_t>!, _ len: d_t) | ||
// CHECK-NEXT: func deep_submodule_noexport(_ p: UnsafePointer<e_t>!, _ len: e_t) | ||
|
||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop | ||
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) | ||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func basic_include(_ p: Span<a_t>) | ||
|
||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop | ||
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) | ||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func deep_submodule_noexport(_ p: Span<e_t>) | ||
|
||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop | ||
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) | ||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func explicit_submodule_include(_ p: Span<d_t>) | ||
|
||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop | ||
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) | ||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func non_exported_include(_ p: Span<b_t>) | ||
|
||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop | ||
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) | ||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func submodule_include(_ p: Span<c_t>) | ||
|
||
public func callBasicInclude(_ p: Span<CInt>) { | ||
basic_include(p) | ||
} | ||
|
||
public func callNonExported(_ p: Span<CInt>) { | ||
non_exported_include(p) | ||
} | ||
|
||
public func callSubmoduleInclude(_ p: Span<CInt>) { | ||
submodule_include(p) | ||
} | ||
|
||
public func callExplicitSubmoduleInclude(_ p: Span<CInt>) { | ||
explicit_submodule_include(p) | ||
} | ||
|
||
public func callDeepSubmoduleNoexport(_ p: Span<CInt>) { | ||
deep_submodule_noexport(p) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// REQUIRES: swift_feature_SafeInteropWrappers | ||
|
||
// RUN: %target-swift-ide-test -print-module -module-to-print=ClangIncludesModule -plugin-path %swift-plugin-dir -I %S/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s | ||
|
||
// swift-ide-test doesn't currently typecheck the macro expansions, so run the compiler as well | ||
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -o %t/ClangIncludes.swiftmodule -I %S/Inputs -enable-experimental-feature SafeInteropWrappers %s | ||
|
||
import ClangIncludesModule | ||
|
||
// CHECK: @_exported import ModuleA | ||
// CHECK-NEXT: @_exported import ModuleB | ||
// CHECK-NOT: import | ||
// CHECK-EMPTY: | ||
|
||
// CHECK-NEXT: func basic_include(_ p: UnsafePointer<a_t>!, _ len: a_t) | ||
// CHECK-NEXT: func non_exported_include(_ p: UnsafePointer<b_t>!, _ len: b_t) | ||
// CHECK-NEXT: func submodule_include(_ p: UnsafePointer<c_t>!, _ len: c_t) | ||
// CHECK-NEXT: func explicit_submodule_include(_ p: UnsafePointer<d_t>!, _ len: d_t) | ||
// CHECK-NEXT: func deep_submodule_noexport(_ p: UnsafePointer<e_t>!, _ len: e_t) | ||
|
||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop | ||
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) | ||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func basic_include(_ p: Span<a_t>) | ||
|
||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop | ||
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) | ||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func deep_submodule_noexport(_ p: Span<e_t>) | ||
|
||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop | ||
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) | ||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func explicit_submodule_include(_ p: Span<d_t>) | ||
|
||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop | ||
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) | ||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func non_exported_include(_ p: Span<b_t>) | ||
|
||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop | ||
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) | ||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func submodule_include(_ p: Span<c_t>) | ||
|
||
public func callBasicInclude(_ p: Span<CInt>) { | ||
basic_include(p) | ||
} | ||
|
||
public func callNonExported(_ p: Span<CInt>) { | ||
non_exported_include(p) | ||
} | ||
|
||
public func callSubmoduleInclude(_ p: Span<CInt>) { | ||
submodule_include(p) | ||
} | ||
|
||
public func callExplicitSubmoduleInclude(_ p: Span<CInt>) { | ||
explicit_submodule_include(p) | ||
} | ||
|
||
public func callDeepSubmoduleNoexport(_ p: Span<CInt>) { | ||
deep_submodule_noexport(p) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.