[swift-evolution] [DRAFT] Introducing a Debug Build Configuration Test
erica at ericasadun.com
Mon Mar 14 13:57:25 CDT 2016
Feedback solicited. Thanks, -- Erica
Introducing a Debug Build Configuration Test
Author(s): Erica Sadun <http://github.com/erica>
Review manager: TBD
This proposal introduces a configuration test for debug builds.
This proposal was discussed on-list in the Introducing a Debug Build Configuration Test <applewebdata://0C1DDEF4-7986-4D7B-B837-C0CAEB2B24C2> thread.
Developers are used to including code specific to debug builds in their projects. Having a debug configuration test is an industry standard option. Under the current version of Swift you must add a command-line flag using -D <#flag#> (e.g. -D debug) and test in-code (#if debug), there's no consistent system-supplied way to differentiate code meant only for debug builds.
This proposal adds #if config(debug) to test for debug builds.
// code for debug builds only
Joe Groff writes, "We specifically avoided making debug/release an #if condition because we considered #if to be the wrong point at which to start conditionalizing code generation for assertions. Though the final executable image's behavior is unavoidably dependent on whether asserts are enabled, we didn't want the SIL for inlineable code to be, since that would mean libraries with inlineable code would need to ship three times the amount of serialized SIL to support the right behavior in -Onone, -O, and -Ounchecked builds. Instead, the standard library has some hidden helper functions, _isDebugAssertConfiguration, _isReleaseAssertConfiguration, and _isFastAssertConfiguration, which are guaranteed to be constant-folded away before final code generation."
Swift currently supports the following configuration tests:
The literals true and false
The os() function that tests for OSX, iOS, watchOS, tvOS, and Linux
The arch() function that tests for x86_64, arm, arm64, and i386
The swift() function that tests for specific Swift language releases, e.g. swift(>=2.2)
There are no alternatives considered.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution