mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Refactor cast representation in AST and SIL, and implement 'is'.
Improve our representations of casts in the AST and SIL so that 'as!' and 'is' (and eventually 'as?') can share almost all of the same type-checking, SILGen, and IRGen code. In the AST, we now represent 'as!' and 'is' as UnconditionalCheckedCastExpr and IsaExpr, respectively, with the semantic variations of cast (downcast, super-to-archetype, archetype-to-concrete, etc.) discriminated by an enum field. This keeps the user-visible syntactic and type behavior differences of the two forms cleanly separated for AST consumers. At the SIL level, we transpose the representation so that the different cast semantics get their own instructions and the conditional/unconditional cast behavior is indicated by an enum, making it easy for IRGen to discriminate the different code paths for the different semantics. We also add an 'IsNonnull' instruction to cover the conditional-cast-result-to-boolean conversion common to all the forms of 'is'. The upshot of all this is that 'x is T' now works for all the new archetype and existential cast forms supported by 'as!'. Swift SVN r5737
This commit is contained in:
@@ -51,6 +51,7 @@ namespace swift {
|
||||
class TranslationUnit;
|
||||
class ValueDecl;
|
||||
class VarDecl;
|
||||
enum class CheckedCastMode : unsigned char;
|
||||
|
||||
namespace Mangle {
|
||||
enum class ExplosionKind : unsigned;
|
||||
@@ -181,12 +182,14 @@ public:
|
||||
/// \brief Convert the given explosion to the given destination archetype,
|
||||
/// using a runtime-checked cast.
|
||||
llvm::Value *emitSuperToClassArchetypeConversion(llvm::Value *super,
|
||||
SILType destType);
|
||||
SILType destType,
|
||||
CheckedCastMode mode);
|
||||
|
||||
/// \brief Convert the given value to the given destination type, using a
|
||||
/// runtime-checked cast.
|
||||
llvm::Value *emitUnconditionalDowncast(llvm::Value *from,
|
||||
SILType toType);
|
||||
llvm::Value *emitDowncast(llvm::Value *from,
|
||||
SILType toType,
|
||||
CheckedCastMode mode);
|
||||
|
||||
|
||||
//--- Declaration emission -----------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user