Skip to content

Turn off SWIFT_ENABLE_REFLECTION on the stdlib_minimal preset #39030

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stdlib/private/StdlibUnittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ if (NOT IS_BUILD_TYPE_OPTIMIZED)
list(APPEND swift_stdlib_unittest_compile_flags "-DSWIFT_STDLIB_DEBUG")
endif()

if(SWIFT_ENABLE_REFLECTION)
list(APPEND swift_stdlib_unittest_compile_flags "-DSWIFT_ENABLE_REFLECTION")
endif()

set(swift_stdlib_unittest_link_libraries "")
set(swift_stdlib_unittest_modules "")
if (SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY)
Expand Down
8 changes: 8 additions & 0 deletions stdlib/private/StdlibUnittest/StdlibCoreExtras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,11 @@ public struct LinearCongruentialGenerator: RandomNumberGenerator {
return _state
}
}

#if !SWIFT_ENABLE_REFLECTION

public func dump<T, TargetStream: TextOutputStream>(_ value: T, to target: inout TargetStream) {
target.write("(reflection not available)")
}

#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch makes sense to me, but I was a bit disheartened by the sheer number of #if SWIFT_ENABLE_REFLECTION directives needed (77 files touched).

Would it be possible to leave Mirror declarations and uses intact, but "compile out" its implementation and return dummy values or crash. Similarly to what we do here for String.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you're actually proposing. I think the @available attribute is required here, otherwise your code still compiles. I need to make let m = Mirror(x) not compile. Given that we can't #ifdef-out only the attribute, I'm not sure how else can I do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use availability macros for this? -define-availability 'SwiftReflection *' normally, and -define-availability 'SwiftReflection unavailable' when this stuff is turned off, then annotate everything with @available(SwiftReflection). I'm not entirely sure that availability macros actually work this way....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool idea, though I don't think -define-availability lets us specify either "*" or "unavailable", I think it today only accepts specific platform names/versions:

-define-availability argument:1:18: error: expected version number
Dummy:unavailable
                 ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well nuts. I wonder if it would be worth extending this feature to work here, or otherwise modifying @available or #if so that we can accomplish this.

8 changes: 8 additions & 0 deletions stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ if(NOT BUILD_STANDALONE)
list(APPEND darwin_depends copy_apinotes)
endif()

set(swift_platform_compile_flags)
if(SWIFT_ENABLE_REFLECTION)
list(APPEND swift_platform_compile_flags "-DSWIFT_ENABLE_REFLECTION")
endif()

set(swiftDarwin_target_sdks ALL_APPLE_PLATFORMS)
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple")
set(swiftDarwin_target_sdks ALL_APPLE_PLATFORMS FREESTANDING)
Expand All @@ -30,6 +35,7 @@ add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
-Xfrontend -disable-objc-attr-requires-foundation-module
${swift_platform_compile_flags}
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS "${swiftDarwin_target_sdks}"
INSTALL_IN_COMPONENT sdk-overlay
Expand All @@ -51,6 +57,7 @@ add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_O
SWIFT_COMPILE_FLAGS
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
${swift_platform_compile_flags}
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS "${swiftGlibc_target_sdks}"
INSTALL_IN_COMPONENT sdk-overlay
Expand All @@ -68,6 +75,7 @@ add_swift_target_library(swiftCRT ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVE
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
-Xcc -D_USE_MATH_DEFINES
${swift_platform_compile_flags}
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS WINDOWS
INSTALL_IN_COMPONENT sdk-overlay)
Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/Platform/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ public struct DarwinBoolean : ExpressibleByBooleanLiteral {
}
}

#if SWIFT_ENABLE_REFLECTION
extension DarwinBoolean : CustomReflectable {
/// Returns a mirror that reflects `self`.
public var customMirror: Mirror {
return Mirror(reflecting: boolValue)
}
}
#endif

extension DarwinBoolean : CustomStringConvertible {
/// A textual representation of `self`.
Expand Down
3 changes: 3 additions & 0 deletions test/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ if "@SWIFT_OPTIMIZED@" == "TRUE":
if "@SWIFT_STDLIB_SINGLE_THREADED_RUNTIME@" == "TRUE":
config.available_features.add("single_threaded_runtime")

if "@SWIFT_ENABLE_REFLECTION@" == "TRUE":
config.available_features.add("reflection")

if "@SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS@" == "TRUE":
config.available_features.add('runtime_function_counters')

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/DebuggerSupport.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// RUN: %target-codesign %t/Error
// RUN: %target-run %t/Error
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/ForEachField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

@_spi(Reflection) import Swift
import StdlibUnittest
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/Mirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

// REQUIRES: executable_test
// REQUIRES: shell
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/Optional.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import Swift
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/Print.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import PrintTestTypes
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/PrintArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import PrintTestTypes
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/PrintBoolean.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/PrintClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import PrintTestTypes
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/PrintDictionary.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/PrintInteger.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/PrintPointer.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/PrintSet.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/PrintString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import PrintTestTypes
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/PrintStruct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import PrintTestTypes
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/PrintTuple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import PrintTestTypes
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/Reflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// RUN: %target-codesign %t/a.out
// RUN: %{python} %S/../Inputs/timeout.py 360 %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: reflection
// FIXME: timeout wrapper is necessary because the ASan test runs for hours

//
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/ReflectionHashing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// RUN: %target-codesign %t.out
// RUN: %target-run %t.out
// REQUIRES: executable_test
// REQUIRES: reflection

// This file contains reflection tests that depend on hash values.
// Don't add other tests here.
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/Runtime.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// RUN: %target-codesign %t.out
// RUN: %target-run %t.out
// REQUIRES: executable_test
// REQUIRES: reflection

import Swift
import StdlibUnittest
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/RuntimeRetroactiveConformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// RUN: %target-run %t/a.out

// REQUIRES: executable_test
// REQUIRES: reflection

import A
import B
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/StaticString.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/StringAPI.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

//
// Tests for the non-Foundation API of String
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/StringCompatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-codesign %t/a.out4 && %target-run %t/a.out4

// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/StringDescribing.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/UnicodeMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// RUN: %target-codesign %t.out
// RUN: %target-run %t.out | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: reflection


class myClass { }
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/UnsafePointer.swift.gyb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swiftgyb
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/WeakMirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// REQUIRES: executable_test
// REQUIRES: shell
// REQUIRES: reflection

import StdlibUnittest

Expand Down
1 change: 1 addition & 0 deletions test/stdlib/integer_conversions.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swift | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: reflection

var a : Int

Expand Down
2 changes: 1 addition & 1 deletion utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2452,7 +2452,7 @@ build-swift-dynamic-stdlib=0
build-swift-static-stdlib=1
swift-objc-interop=0
swift-enable-compatibility-overrides=0
swift-enable-reflection=1
swift-enable-reflection=0
swift-runtime-macho-no-dyld=1
swift-stdlib-has-darwin-libmalloc=0
swift-stdlib-single-threaded-runtime=1
Expand Down
1 change: 1 addition & 0 deletions validation-test/stdlib/AnyHashable.swift.gyb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swiftgyb
// REQUIRES: executable_test
// REQUIRES: reflection

// FIXME(id-as-any): make Swift errors boxed in NSError eagerly bridged.

Expand Down
1 change: 1 addition & 0 deletions validation-test/stdlib/Array.swift.gyb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %enable-cow-checking %target-run-simple-swiftgyb
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import StdlibCollectionUnittest
Expand Down
1 change: 1 addition & 0 deletions validation-test/stdlib/ArraySlice.swift.gyb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swiftgyb
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import StdlibCollectionUnittest
Expand Down
1 change: 1 addition & 0 deletions validation-test/stdlib/ContiguousArray.swift.gyb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swiftgyb
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import StdlibCollectionUnittest
Expand Down
2 changes: 1 addition & 1 deletion validation-test/stdlib/HashingRandomization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// environment variable is set.

print("Deterministic: \(Hasher._isDeterministic)")
print("Seed: \(Hasher._executionSeed)")
print("Seed: (\(Hasher._executionSeed.0), \(Hasher._executionSeed.1))")
print("Hash values: <\(0.hashValue), \(1.hashValue)>")

// With randomized hashing, we get a new seed and a new set of hash values on
Expand Down
1 change: 1 addition & 0 deletions validation-test/stdlib/Lazy.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
// RUN: %target-run-simple-swiftgyb
// REQUIRES: executable_test
// REQUIRES: reflection

// With a non-optimized stdlib the test takes very long.
// REQUIRES: optimized_stdlib
Expand Down
1 change: 1 addition & 0 deletions validation-test/stdlib/NewArray.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out 2>&1 | %line-directive %t/NewArray.swift -- %FileCheck %t/NewArray.swift --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import StdlibCollectionUnittest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: %target-codesign %t/a.out
// RUN: %line-directive %t/PersistentVector.swift -- %target-run %t/a.out
// REQUIRES: executable_test
// REQUIRES: reflection

/*

Expand Down
1 change: 1 addition & 0 deletions validation-test/stdlib/Range.swift.gyb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-run-simple-swiftgyb
// REQUIRES: executable_test
// REQUIRES: reflection

import StdlibUnittest
import StdlibCollectionUnittest
Expand Down