> On Mar 14, 2016, at 1:04 PM, Dmitri Gribenko via swift-evolution 
> <[email protected]> wrote:
> 
> On Mon, Mar 14, 2016 at 11:57 AM, Erica Sadun via swift-evolution
> <[email protected] <mailto:[email protected]>> wrote:
>> https://gist.github.com/erica/d20639b409fe1b318c0e
>> 
>> Feedback solicited. Thanks, -- Erica
>> 
>> Introducing a Debug Build Configuration Test
>> 
>> Proposal: SE-00XX
>> Author(s): Erica Sadun
>> Status: TBD
>> Review manager: TBD
>> 
>> Introduction
>> 
>> This proposal introduces a configuration test for debug builds.
>> 
>> This proposal was discussed on-list in the Introducing a Debug Build
>> Configuration Test thread.
>> 
>> Motivation
>> 
>> 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.
>> 
>> Detail Design
>> 
>> This proposal adds #if config(debug) to test for debug builds.
>> 
>> #if config(debug)
>>    // code for debug builds only
>> #endif
> 
> Hi Erica,
> 
> Based on Joe's rationale that you are quoting, I think the intent is
> that we want to restrict this directive to be statement-level only.
> The API vended by a module should not be affected by the build mode.

I think the right thing here would be (in a separate proposal) to introduce an 
expression-level test for build configurations, so you could say something like 
this:

func assertIf64Bit(condition: @autoclosure () -> Bool) {
  if #condition(config(debug) && bits(64)) && condition() {
    fatalError("64-bit assertion failed")
  }
}

and the #-expression would be lowered to a SIL intrinsic that gets 
guaranteed-optimized like our _is*Configuration hacks do today. That would 
allow for platform-dependent code that doesn't depend on platform-dependent 
declarations to still be type-checked and diagnosed, and share build products 
up to the SIL optimization stage of the pipeline. If we have that then our 
original objection to config(debug) goes away.

-Joe
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to