Skip to content

Commit c08372a

Browse files
committed
ClangImporter: remove Darwin alias workaround, introduce feature
Introduce a feature flag to add the importing of macro aliases. Remove the Darwin specific carve out.
1 parent 06aa42b commit c08372a

File tree

8 files changed

+21
-16
lines changed

8 files changed

+21
-16
lines changed

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(Lifetimes, true)
536536
/// to SendableMetatype (or Sendable).
537537
EXPERIMENTAL_FEATURE(SendableProhibitsMainActorInference, true)
538538

539+
/// Allow macro based aliases to be imported into Swift
540+
EXPERIMENTAL_FEATURE(ImportMacroAliases, true)
541+
539542
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
540543
#undef EXPERIMENTAL_FEATURE
541544
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ UNINTERESTING_FEATURE(MacrosOnImports)
126126
UNINTERESTING_FEATURE(NonisolatedNonsendingByDefault)
127127
UNINTERESTING_FEATURE(KeyPathWithMethodMembers)
128128
UNINTERESTING_FEATURE(SendableProhibitsMainActorInference)
129+
UNINTERESTING_FEATURE(ImportMacroAliases)
129130

130131
// TODO: Return true for inlinable function bodies with module selectors in them
131132
UNINTERESTING_FEATURE(ModuleSelector)

lib/ClangImporter/ImportMacro.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,7 @@ namespace {
377377
ValueDecl *importDeclAlias(ClangImporter::Implementation &clang,
378378
swift::DeclContext *DC, const clang::ValueDecl *D,
379379
Identifier alias) {
380-
if (DC->getASTContext().LangOpts.Target.isOSDarwin() &&
381-
DC->getParentModule()->getName().str() == StringRef("_stdio") &&
382-
llvm::any_of(llvm::ArrayRef<StringRef>{"stdin", "stdout", "stderr"},
383-
[alias = alias.str()](StringRef Id) { return alias == Id; }))
380+
if (!DC->getASTContext().LangOpts.hasFeature(Feature::ImportMacroAliases))
384381
return nullptr;
385382

386383
// Variadic functions cannot be imported into Swift.

test/ClangImporter/alias-invalid.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-typecheck-verify-swift -I %S/Inputs/custom-modules
2+
// RUN: %target-typecheck-verify-swift -I %S/Inputs/custom-modules -enable-experimental-feature ImportMacroAliases
3+
4+
// REQUIRES: swift_feature_ImportMacroAliases
35

46
import Aliases
57

test/ClangImporter/alias.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// RUN: %target-typecheck-verify-swift -I %S/Inputs/custom-modules %s
2-
// RUN: %target-swift-frontend -I %S/Inputs/custom-modules -parse-as-library -module-name Alias -Osize -emit-ir -o - %s | %FileCheck %s -check-prefix CHECK-ANSI-IR
3-
// RUN: %target-typecheck-verify-swift -I %S/Inputs/custom-modules %s -Xcc -DUNICODE
4-
// RUN: %target-swift-frontend -I %S/Inputs/custom-modules -parse-as-library -module-name Alias -Osize -emit-ir -o - %s -Xcc -DUNICODE | %FileCheck %s -check-prefix CHECK-UNICODE-IR
5-
// RUN: not %target-swift-frontend -I %S/Inputs/custom-modules -parse-as-library -module-name Alias -c %s -DINVALID -o /dev/null 2>&1 | %FileCheck --dry-run %s -check-prefix CHECK-INVALID
1+
// RUN: %target-typecheck-verify-swift -I %S/Inputs/custom-modules %s -enable-experimental-feature ImportMacroAliases
2+
// RUN: %target-swift-frontend -I %S/Inputs/custom-modules -parse-as-library -module-name Alias -Osize -emit-ir -o - %s -enable-experimental-feature ImportMacroAliases | %FileCheck %s -check-prefix CHECK-ANSI-IR
3+
// RUN: %target-typecheck-verify-swift -I %S/Inputs/custom-modules %s -Xcc -DUNICODE -enable-experimental-feature ImportMacroAliases
4+
// RUN: %target-swift-frontend -I %S/Inputs/custom-modules -parse-as-library -module-name Alias -Osize -emit-ir -o - %s -Xcc -DUNICODE -enable-experimental-feature ImportMacroAliases | %FileCheck %s -check-prefix CHECK-UNICODE-IR
5+
// RUN: not %target-swift-frontend -I %S/Inputs/custom-modules -parse-as-library -module-name Alias -c %s -DINVALID -o /dev/null 2>&1 -enable-experimental-feature ImportMacroAliases | %FileCheck --dry-run %s -check-prefix CHECK-INVALID
6+
7+
// REQUIRES: swift_feature_ImportMacroAliases
68

79
// expected-no-diagnostics
810

test/ClangImporter/ignore-darwin-aliasing.swift

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/ClangImporter/versioning.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// RUN: %target-typecheck-verify-swift %s -I %S/Inputs/custom-modules
1+
// RUN: %target-typecheck-verify-swift %s -I %S/Inputs/custom-modules -enable-experimental-feature ImportMacroAliases
22
// XFAIL: *
33

4+
// REQUIRES: swift_feature_ImportMacroAliases
5+
46
// expected-no-diagnostics
57

68
import RetroactiveVersioning

test/SILGen/variadic.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %swift_frontend_plain -emit-silgen %s -I %S/Inputs -o - -parse-as-library -verify | %FileCheck %s
1+
// RUN: %swift_frontend_plain -emit-silgen %s -I %S/Inputs -o - -parse-as-library -verify -enable-experimental-feature ImportMacroAliases | %FileCheck %s
2+
3+
// REQUIRES: swift_feature_ImportMacroAliases
24

35
import Variadic
46

0 commit comments

Comments
 (0)