From 164ac421d623482cf407934ff394a3b127341de0 Mon Sep 17 00:00:00 2001 From: Allan Shortlidge Date: Wed, 30 Nov 2022 14:58:26 -0800 Subject: [PATCH] Sema: Lift restriction preventing use of `#_hasSymbol` on non-Darwin platforms. An early approach to codegen for `#_hasSymbol` relied on the Darwin platfom SDK, but now that the feature lowers directly to NULL checks in LLVM IR a platform restriction is no longer needed. However, the tests for `#_hasSymbol` remain unsupported on Windows since that OS does not support weak linking. --- include/swift/AST/DiagnosticsSema.def | 2 -- lib/Sema/MiscDiagnostics.cpp | 9 --------- test/AutoDiff/SILGen/has_symbol.swift | 2 +- test/IRGen/has_symbol.swift | 2 +- test/IRGen/has_symbol_async.swift | 2 +- test/Interpreter/has_symbol.swift | 2 +- test/Parse/has_symbol.swift | 2 +- test/SIL/Parser/has_symbol.sil | 2 +- test/SILGen/has_symbol.swift | 2 +- test/SILOptimizer/has_symbol.swift | 2 +- test/Sema/has_symbol.swift | 2 +- test/Sema/has_symbol_unsupported.swift | 8 -------- 12 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 test/Sema/has_symbol_unsupported.swift diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 1f0b8ae0bbb44..91031f88668b0 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -6716,8 +6716,6 @@ WARNING(has_symbol_decl_must_be_weak,none, (DescriptiveDeclKind, DeclName)) ERROR(has_symbol_invalid_expr,none, "'#_hasSymbol' condition must refer to a declaration", ()) -ERROR(has_symbol_unsupported_on_target,none, - "'#_hasSymbol' is unsupported on target '%0'", (StringRef)) //------------------------------------------------------------------------------ // MARK: Type erasure diff --git a/lib/Sema/MiscDiagnostics.cpp b/lib/Sema/MiscDiagnostics.cpp index f8cef545d0509..75b02a8f627fe 100644 --- a/lib/Sema/MiscDiagnostics.cpp +++ b/lib/Sema/MiscDiagnostics.cpp @@ -4506,15 +4506,6 @@ static bool diagnoseHasSymbolCondition(PoundHasSymbolInfo *info, return false; auto &ctx = DC->getASTContext(); - if (!ctx.LangOpts.Target.isOSDarwin()) { - // SILGen for #_hasSymbol is currently implemented assuming the target OS - // is a Darwin platform. - ctx.Diags.diagnose(info->getStartLoc(), - diag::has_symbol_unsupported_on_target, - ctx.LangOpts.Target.str()); - return true; - } - auto decl = info->getReferencedDecl().getDecl(); if (!decl) { // Diagnose because we weren't able to interpret the expression as one diff --git a/test/AutoDiff/SILGen/has_symbol.swift b/test/AutoDiff/SILGen/has_symbol.swift index cd3931f857348..f2041fa381f1f 100644 --- a/test/AutoDiff/SILGen/has_symbol.swift +++ b/test/AutoDiff/SILGen/has_symbol.swift @@ -3,7 +3,7 @@ // RUN: %target-swift-frontend -emit-module -emit-module-path %t/Library.swiftmodule -parse-as-library %t/Library.swift -enable-library-evolution // RUN: %target-swift-frontend -emit-silgen %t/Client.swift -I %t -module-name test | %FileCheck %t/Client.swift -// REQUIRES: VENDOR=apple +// UNSUPPORTED: OS=windows-msvc //--- Library.swift diff --git a/test/IRGen/has_symbol.swift b/test/IRGen/has_symbol.swift index 86a7b5bcc5167..4b993ad5423e1 100644 --- a/test/IRGen/has_symbol.swift +++ b/test/IRGen/has_symbol.swift @@ -2,7 +2,7 @@ // RUN: %target-swift-frontend -emit-module -emit-module-path %t/has_symbol_helper.swiftmodule -parse-as-library %S/Inputs/has_symbol_helper.swift -enable-library-evolution -disable-availability-checking // RUN: %target-swift-frontend -emit-irgen %s -I %t -module-name test | %FileCheck %s -// REQUIRES: VENDOR=apple +// UNSUPPORTED: OS=windows-msvc // rdar://102246128 // REQUIRES: PTRSIZE=64 diff --git a/test/IRGen/has_symbol_async.swift b/test/IRGen/has_symbol_async.swift index f94943f6ac379..ad2b544af2828 100644 --- a/test/IRGen/has_symbol_async.swift +++ b/test/IRGen/has_symbol_async.swift @@ -3,7 +3,7 @@ // RUN: %target-swift-frontend -emit-irgen %s -I %t -module-name test | %FileCheck %s // REQUIRES: concurrency -// REQUIRES: VENDOR=apple +// UNSUPPORTED: OS=windows-msvc @_weakLinked import has_symbol_helper diff --git a/test/Interpreter/has_symbol.swift b/test/Interpreter/has_symbol.swift index 1929a6f2c9a12..b1ad0f14cca4a 100644 --- a/test/Interpreter/has_symbol.swift +++ b/test/Interpreter/has_symbol.swift @@ -26,7 +26,7 @@ // RUN: %target-run %t/test %t/%target-library-name(helper) | %FileCheck %s --check-prefix=NO-ANSWER // REQUIRES: executable_test -// REQUIRES: VENDOR=apple +// UNSUPPORTED: OS=windows-msvc // This test requires executable tests to be run on the same machine as the // compiler, as it links with a dylib that it doesn't arrange to get uploaded diff --git a/test/Parse/has_symbol.swift b/test/Parse/has_symbol.swift index e4e0e5ec6b826..5c2c65aeb22a5 100644 --- a/test/Parse/has_symbol.swift +++ b/test/Parse/has_symbol.swift @@ -3,7 +3,7 @@ // RUN: %target-swift-frontend -emit-module -emit-module-path %t/Library.swiftmodule -parse-as-library %t/Library.swift -enable-library-evolution // RUN: %target-swift-frontend -typecheck -verify %t/Client.swift -I %t -// REQUIRES: VENDOR=apple +// UNSUPPORTED: OS=windows-msvc //--- Library.swift diff --git a/test/SIL/Parser/has_symbol.sil b/test/SIL/Parser/has_symbol.sil index 4aa52c2b7d61a..637052629a835 100644 --- a/test/SIL/Parser/has_symbol.sil +++ b/test/SIL/Parser/has_symbol.sil @@ -3,7 +3,7 @@ // RUN: %target-swift-frontend -emit-module -emit-module-path %t/has_symbol_helper.swiftmodule -parse-as-library -enable-library-evolution %t/has_symbol_helper.swift // RUN: %target-swift-frontend -emit-sil -verify %s -I %t/ -// REQUIRES: vendor=apple +// UNSUPPORTED: OS=windows-msvc sil_stage raw diff --git a/test/SILGen/has_symbol.swift b/test/SILGen/has_symbol.swift index 2b244b1b0c7ff..e144a34bc0549 100644 --- a/test/SILGen/has_symbol.swift +++ b/test/SILGen/has_symbol.swift @@ -2,7 +2,7 @@ // RUN: %target-swift-frontend -emit-module -emit-module-path %t/has_symbol_helper.swiftmodule -parse-as-library %S/Inputs/has_symbol_helper.swift -enable-library-evolution // RUN: %target-swift-frontend -emit-silgen %s -I %t -module-name test | %FileCheck %s -// REQUIRES: VENDOR=apple +// UNSUPPORTED: OS=windows-msvc @_weakLinked import has_symbol_helper diff --git a/test/SILOptimizer/has_symbol.swift b/test/SILOptimizer/has_symbol.swift index 9a578b40b3b98..80fc2fe05a1f7 100644 --- a/test/SILOptimizer/has_symbol.swift +++ b/test/SILOptimizer/has_symbol.swift @@ -3,7 +3,7 @@ // RUN: %target-swift-frontend -O -emit-module -emit-module-path %t/Library.swiftmodule -parse-as-library %t/Library.swift -enable-library-evolution // RUN: %target-swift-frontend -O -emit-sil %t/Client.swift -I %t -module-name test | %FileCheck %s -// REQUIRES: VENDOR=apple +// UNSUPPORTED: OS=windows-msvc //--- Library.swift diff --git a/test/Sema/has_symbol.swift b/test/Sema/has_symbol.swift index 5162d33352871..6b358c6343ab4 100644 --- a/test/Sema/has_symbol.swift +++ b/test/Sema/has_symbol.swift @@ -3,7 +3,7 @@ // RUN: %target-typecheck-verify-swift -disable-availability-checking -I %t // RUN: %target-typecheck-verify-swift -disable-availability-checking -I %t -enable-experimental-feature ResultBuilderASTTransform -// REQUIRES: VENDOR=apple +// UNSUPPORTED: OS=windows-msvc @_weakLinked import has_symbol_helper diff --git a/test/Sema/has_symbol_unsupported.swift b/test/Sema/has_symbol_unsupported.swift deleted file mode 100644 index 2bcd24eee8d53..0000000000000 --- a/test/Sema/has_symbol_unsupported.swift +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: %target-typecheck-verify-swift -// UNSUPPORTED: VENDOR=apple - -// Verify that #_hasSymbol is rejected on non-Darwin platforms - -func foo() {} - -if #_hasSymbol(foo) { } // expected-error {{'#_hasSymbol' is unsupported on target}}