<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2016-03-04-swift-asserts.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2016-03-04-swift-asserts.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sun, 15 Mar 2026 14:40:49 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Peter N Lewis - 2016-05-24 03:28:53</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2016-03-04-swift-asserts.html#comments</link><description>The lack of an equivalent #condition default message is a blow.  I use a lot of asserts and the condition is generally quite sufficient as a message.  But without a message, and just the line number, asserts from even a slightly older version (ie, one you released last week) would in practice be difficult to match up to the actual code.
&lt;br /&gt;
&lt;br /&gt;Adding a comment for each assertion is generally needless work (since they are never supposed to fire), and even just manually copying the condition would inevitably lead to stale messages.
&lt;br /&gt;
&lt;br /&gt;Ah well.</description><guid isPermaLink="true">8ce3e340786593589187be1100cea05f</guid><pubDate>Tue, 24 May 2016 03:28:53 GMT</pubDate></item><item><title>krzyzanowskim - 2016-03-08 13:11:40</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2016-03-04-swift-asserts.html#comments</link><description>The other day I wrote this post about asserts in Swift: &lt;a href="http://blog.krzyzanowskim.com/2015/03/09/swift-asserts-the-missing-manual/"&gt;http://blog.krzyzanowskim.com/2015/03/09/swift-asserts-the-missing-manual/&lt;/a&gt; - you may find it complementary to this great piece. </description><guid isPermaLink="true">f6dd90ef32a0f5088ef33fab44947096</guid><pubDate>Tue, 08 Mar 2016 13:11:40 GMT</pubDate></item><item><title>mikeash - 2016-03-06 22:26:21</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2016-03-04-swift-asserts.html#comments</link><description>&lt;b&gt;User:&lt;/b&gt; This comes from the comments on these functions. Paying close attention, I note that it merely says "the optimizer may assume" which doesn't necessarily mean it happens, only that it would be allowed. It's a bit ambiguous!
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Joseph:&lt;/b&gt; Do you have a handy link or file/line combo for the relevant bit of compiler code? I'd definitely be interested in seeing what the implementation looks like.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Mirek:&lt;/b&gt; "Debug build" is a bit vague, as it's just a collection of configurations which you can change as you see fit. *Usually* a debug build has optimizations off, to reduce build time and make the debugger work better. But they aren't entirely synonymous.
&lt;br /&gt;
&lt;br /&gt;As for what gets the asserts out, the code in the assert function itself checks the compiler's cofiguration, and doesn't check the asserted condition if optimizations are on. However, this will still leave a bunch of dead code. The optimizer is what comes along and completely removes all traces of the resulting do-nothing assert call.</description><guid isPermaLink="true">27f01a155ac70a3bd78b53cfba715b76</guid><pubDate>Sun, 06 Mar 2016 22:26:21 GMT</pubDate></item><item><title>Mirek - 2016-03-05 18:42:28</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2016-03-04-swift-asserts.html#comments</link><description>Does "non-optimized" build mean the same thing as debug build?
&lt;br /&gt;&amp;nbsp;
&lt;br /&gt;Is it optimisation that gets the asserts out?</description><guid isPermaLink="true">949ec25bc3a2efcd13b42e37ae64ea18</guid><pubDate>Sat, 05 Mar 2016 18:42:28 GMT</pubDate></item><item><title>Joseph - 2016-03-05 15:26:15</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2016-03-04-swift-asserts.html#comments</link><description>When I looked at the source code a few weeks ago it looked like unchecked optimises based on assertionFailure and both preconditions but not actually assert(). 
&lt;br /&gt;
&lt;br /&gt;It is documented on all four functions though. And I could be wrong too.</description><guid isPermaLink="true">6678413599a775b0328912652c9fc219</guid><pubDate>Sat, 05 Mar 2016 15:26:15 GMT</pubDate></item><item><title>Joe - 2016-03-04 17:28:21</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2016-03-04-swift-asserts.html#comments</link><description>@User This behavior should be described in the doc comments for assert and precondition. </description><guid isPermaLink="true">1c61b611ea746b05a2737b98d04523d6</guid><pubDate>Fri, 04 Mar 2016 17:28:21 GMT</pubDate></item><item><title>User - 2016-03-04 15:13:48</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2016-03-04-swift-asserts.html#comments</link><description>To the best of my knowledge the optimizer does not optimize based on assertions in Unchecked mode. Do you have an example to support your claim?</description><guid isPermaLink="true">136b7f2c7cb9932c071406334a22a6f8</guid><pubDate>Fri, 04 Mar 2016 15:13:48 GMT</pubDate></item></channel></rss>
