Treat potentially unavailable global variable references as optional.

This patch adds the ability (-enable-experimental-unavailable-as-optional) to
treat potentially unavailable declarations as if they had optional types. For
the moment, this is only implemented for global variables.

The high-level approach is to (1) record the potential unavailability of a
declaration reference in the overload choice during constraint generation; (2)
treat the declaration as if it had an optional type during overload resolution
(this is similar to how optional protocol members are treated); and (3) add an
implicit conversion (UnavailableToOptionalExpr) during constraint application
to represent the run-time availability check and optional injection.

This patch does not implement SILGen for UnavailableToOptionalExpr.


Swift SVN r22245
This commit is contained in:
Devin Coughlin
2014-09-24 00:07:46 +00:00
parent c8d0747ad9
commit b727b6d932
17 changed files with 193 additions and 47 deletions

View File

@@ -3450,6 +3450,11 @@ Type ConstraintSystem::getBaseTypeForArrayType(TypeBase *type) {
llvm_unreachable("attempted to extract a base type from a non-array type");
}
Type ConstraintSystem::getTypeWhenUnavailable(Type declType) {
// Drop lvalue-ness and make optional.
return OptionalType::get(declType->getRValueType());
}
static Type getBaseTypeForPointer(ConstraintSystem &cs, TypeBase *type) {
auto bgt = type->castTo<BoundGenericType>();
assert((bgt->getDecl() == cs.getASTContext().getUnsafeMutablePointerDecl()