Commits

Andrew Trick committed 8007dc8cfa0
Add Builtin.castReference and internal API _unsafeCastReference. _unsafeCastReference allows casting of any references types, regardless of whether they are references to objects or class existentials. The implementation is responsible for converting between representations. _unsafeCastReference provides a dynamic check to ensure that the source and dest are both actually references. If not, the implementation will trap at runtime. Generally, the optimizer can prove that the source and dest are references, and promote this cast to an unchecked_ref_cast bitcast. There is no dynamic check that the references types are compatible. This differs from unsafeDownCast in two ways: (1) The source and dest types are not statically typed AnyObjects. Therefore, unsafeCastReference can be used when the surrounding code dynamically handles both reference and nonreference types. (2) The source and dest also need not dynamically conform to AnyObject. Either side of the cast may be a class existential. The primary requirement is that the source and dest refer to the same reference counted object. Swift SVN r32588