title: Swift 4 error on Release configuration
body: <p>If you run this code on Xcode 9.1 using the Optimization level <code>Fast, whole Module Optimization</code>, it crashes. If the Optimization level is set to <code>None</code>, everything goes fine.</p>
  
  <p>Does anyone have an idea of the issue?</p>
  
  <pre><code>protocol FooProtocol {
      func foo()
  }
  
  class FooProtocolImplementation : NSObject, FooProtocol {
      func foo() {}
  }
  
  var set: Set&lt;AnyHashable&gt; = []
  _ = set.insert(FooProtocolImplementation())
  let array = set.flatMap { $0 as? FooProtocol } // filtering out nils
  _ = array[0] // # error (EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  </code></pre>