In many places, we're interested in whether a type with archetypes *might be* a superclass of another type with the right bindings, particularly in the optimizer. Provide a separate Type::isBindableToSuperclassOf method that performs this check. Use it in the devirtualizer to fix rdar://problem/24993618. Using it might unblock other places where the optimizer is conservative, but we can fix those separately.
Having a separate address and container value returned from alloc_stack is not really needed in SIL.
Even if they differ we have both addresses available during IRGen, because a dealloc_stack is always dominated by the corresponding alloc_stack in the same function.
Although this commit quite large, most changes are trivial. The largest non-trivial change is in IRGenSIL.
This commit is a NFC regarding the generated code. Even the generated SIL is the same (except removed #0, #1 and @local_storage).
This avoids us using reserved identifiers as the enum case names of all
our underscored protocols like _ObjectiveCBridgeable. I used the
convention PROTOCOL_WITH_NAME to mirror how the known identifiers work.
Swift SVN r32924
It fixes a compiler crash which occurs on the following code if Foundation is not imported:
class C {}
let x: Int = C() as! Int
The crash happened because Int was considered ObjC-bridgeable, but its ObjC counterpart was not known as Foundation was not imported.
Swift SVN r32594
Another step toward fixing rdar://problem/16238475, though Sema-level warnings still need to be suppressed, and container bridging still needs to be exercised.
Swift SVN r29962
checked_cast_br promises to maintain RC identity, but a cast from an ErrorType-conforming class to NSError may change the RC identity by bridging. Make sure that potential class-to-NSError casts go through the indirect cast entry points for now. The runtime implementation still needs to be fixed to handle the class-to-NSError case, but this is part of rdar://problem/21116814.
Swift SVN r29089
It looks like we don't know how to open-code the "is-a metatype" check
for scalar casts, so just tighten up canUseScalarCheckedCastInstructions()
so that if the target type is a metatype, the source also has to be a
metatype.
This fixes a regression from "SIL: Use scalar casts more".
Fixes <rdar://problem/21003923>.
Swift SVN r28729
Now that scalar casts work better, we can make the
canUseScalarCheckedCastInstructions() predicate a bit more
permissive.
This patch can be reverted if it is found that emitting scalar
casts in these additional cases introduces a regression.
Swift SVN r28713
Running the test quite with check-swift-optimize revealed that metatypes were not covered by the assert, even though it may occur in the real code.
Swift SVN r28297
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".
Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).
Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.
Swift SVN r28284
DynamicCasts was not considering the fact that subclasses of a given class may implement a protocol, even if the class does not implement it.
Swift SVN r27265
The protocol_lookup the testcase from Interpreter test-cases exposed two bugs, once I tried to compiler with with -O:
- SILCloner was generating an open_existential_ref from an open_existential_metatype instruction during cloning even if the existential in question was not a class existential.
- DynamicCasts was not considering the fact that subclasses of a given class may implement a protocol, even if the class does not implement it.
Swift SVN r27260
Add more checks and logic into emitSuccessfulIndirectUnconditionalCast and emitSuccessfulScalarUnconditionalCast, so that its clients in sil-combine can be simplified by avoiding looking into special cases.
Swift SVN r26885
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:
internal func foo() {}
has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.
Part of rdar://problem/17732115 (testability)
Swift SVN r26472
Check if the outcome of a cast from an ObjC type to a Swift type or from a Swift type to an ObjC type can be statically determined.
This allows for folding of many such casts.
Swift SVN r26125
Do not fall through from the metatypes analysis code if the analysis could not decide whether the cast would succeed or fail. Make a more explicit decision instead based on the instance type of a metatype.
This fixes some logical errors in analysis of casts between bridged types. They were caused by falling through from the metatypes analysis.
Swift SVN r26120
This patch does the following:
- Improvements and correctness fixes for conversions of existential metatypes. They may succeed if you have a concrete or existential metatype that conforms to the protocol. Based on Joe's review of my previous patch.
- Removes special-cases for AnyObject. AnyObject is handled as any other class existential.
- Improves folding of conversions from class existential metatypes to concrete non-class metatypes
- Improves comments.
- Adds more tests to cover new test-cases.
- Adjusts a few existing tests.
Swift SVN r25690
This patch does the following:
- Moves the logic for handling special-case of converting to/from AnyObject.Protocol (and existential.Protocol in general) into DynamicCasts, where all other cases are handled already.
- Moves the peephole which was folding checked_cast_br into an unchecked cast and branch from sil-combine into sil-simplify-cfg, because it is a better place for it, since this peephole affects the CFG. The corresponding test is also moved from sil_combine.sil into simplify_cfg.sil.
- Adds a few checked_cast_br peepholes to sil-combine. They try to simplify checked_cond_br instructions using existential metatypes by propagating a concrete type whenever it can be determined statically.
- Adds a new test with a lot of test-cases that make sure we are really folding many type-checks at compile-time now.
Swift SVN r25504
The logic for different special cases of type casting is spread over multiple places currently. This patch simply re-factors some of that code (folding of of type casts using statically known protocol conformances) and moves it into one central place, which makes it easier to maintain. Plus, it allows other clients of DynamicCasts benefit from it as well, e.g. the inliner can use this now. NFC.
Swift SVN r25486