Skip to content

Commit e4ddd56

Browse files
authored
Merge pull request #12559 from CodaFi/inouthouse
2 parents 706c08c + 8bdfb91 commit e4ddd56

10 files changed

+42
-39
lines changed

lib/SIL/AbstractionPattern.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ AbstractionPattern TypeConverter::getAbstractionPattern(VarDecl *var) {
7272
if (auto sig = var->getDeclContext()->getGenericSignatureOfContext())
7373
genericSig = sig->getCanonicalSignature();
7474

75-
CanType swiftType = var->getInterfaceType()->getCanonicalType();
76-
if (auto inout = dyn_cast<InOutType>(swiftType))
77-
swiftType = inout.getObjectType();
75+
CanType swiftType = var->getInterfaceType()
76+
->getInOutObjectType()
77+
->getCanonicalType();
7878

7979
if (auto clangDecl = var->getClangDecl()) {
8080
auto clangType = getClangType(clangDecl);

lib/SILGen/SILGenMaterializeForSet.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,18 +433,14 @@ struct MaterializeForSetEmitter {
433433
return LValue::forValue(self, SubstSelfType);
434434
}
435435

436+
auto selfParam = computeSelfParam(Witness);
436437
CanType witnessSelfType =
437-
computeSelfParam(Witness).getType()->getCanonicalType(GenericSig);
438+
selfParam.getPlainType()->getCanonicalType(GenericSig);
438439
witnessSelfType = getSubstWitnessInterfaceType(witnessSelfType);
439440

440-
// Get the inout object type, but remember whether we needed to.
441-
auto witnessSelfInOutType = dyn_cast<InOutType>(witnessSelfType);
442-
if (witnessSelfInOutType)
443-
witnessSelfType = witnessSelfInOutType.getObjectType();
444-
445441
// If the witness wants an inout and the types match, just use
446442
// this value.
447-
if (witnessSelfInOutType && witnessSelfType == SubstSelfType) {
443+
if (selfParam.isInOut() && witnessSelfType == SubstSelfType) {
448444
return LValue::forValue(self, witnessSelfType);
449445
}
450446

@@ -462,7 +458,7 @@ struct MaterializeForSetEmitter {
462458
}
463459

464460
// Put the object back in memory if necessary.
465-
if (witnessSelfInOutType) {
461+
if (selfParam.isInOut()) {
466462
self = self.materialize(SGF, loc);
467463
}
468464

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,7 @@ namespace {
12931293
// Create an overload choice referencing this declaration and immediately
12941294
// resolve it. This records the overload for use later.
12951295
auto tv = CS.createTypeVariable(locator,
1296-
TVO_CanBindToLValue |
1297-
TVO_CanBindToInOut);
1296+
TVO_CanBindToLValue);
12981297
CS.resolveOverload(locator, tv,
12991298
OverloadChoice(Type(), E->getDecl(),
13001299
E->getFunctionRefKind()),
@@ -1635,8 +1634,9 @@ namespace {
16351634
SmallVector<TupleTypeElt, 4> elements;
16361635
elements.reserve(expr->getNumElements());
16371636
for (unsigned i = 0, n = expr->getNumElements(); i != n; ++i) {
1638-
auto ty = CS.getType(expr->getElement(i));
1639-
auto flags = ParameterTypeFlags().withInOut(ty->is<InOutType>());
1637+
auto *elt = expr->getElement(i);
1638+
auto ty = CS.getType(elt);
1639+
auto flags = ParameterTypeFlags().withInOut(elt->isSemanticallyInOutExpr());
16401640
elements.push_back(TupleTypeElt(ty->getInOutObjectType(),
16411641
expr->getElementName(i), flags));
16421642
}

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4444,11 +4444,8 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
44444444
// T <p U ===> T[] <a UnsafeMutablePointer<U>
44454445
case ConversionRestrictionKind::ArrayToPointer: {
44464446
addContextualScore();
4447-
auto obj1 = type1;
44484447
// Unwrap an inout type.
4449-
if (auto inout1 = obj1->getAs<InOutType>()) {
4450-
obj1 = inout1->getObjectType();
4451-
}
4448+
auto obj1 = type1->getInOutObjectType();
44524449

44534450
obj1 = getFixedTypeRecursive(obj1, false, false);
44544451

lib/Sema/CalleeCandidateInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ CalleeCandidateInfo::evaluateCloseness(UncurriedCandidate candidate,
370370
// Bindings specify the arguments that source the parameter. The only case
371371
// this returns a non-singular value is when there are varargs in play.
372372
auto &bindings = paramBindings[i];
373-
auto paramType = getParamResultType(candArgs[i]);
373+
auto param = candArgs[i];
374+
auto paramType = getParamResultType(param);
374375

375376
for (auto argNo : bindings) {
376377
auto argType = getParamResultType(actualArgs[argNo]);
@@ -392,7 +393,7 @@ CalleeCandidateInfo::evaluateCloseness(UncurriedCandidate candidate,
392393
auto matchType = paramType;
393394
// If the parameter is an inout type, and we have a proper lvalue, match
394395
// against the type contained therein.
395-
if (paramType->is<InOutType>() && argType->is<LValueType>())
396+
if (param.isInOut() && argType->is<LValueType>())
396397
matchType = matchType->getInOutObjectType();
397398

398399
if (candidate.substituted) {

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,8 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
675675
unsigned inoutCount = 0;
676676
for (auto C : Captures) {
677677
if (auto PD = dyn_cast<ParamDecl>(C.getDecl()))
678-
if (PD->hasType())
679-
if (auto type = PD->getType())
680-
if (isa<InOutType>(type.getPointer()))
681-
inoutCount++;
678+
if (PD->isInOut())
679+
inoutCount++;
682680
}
683681

684682
if (inoutCount > 0) {

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,28 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
21792179

21802180
auto resultTy = typeCheckExpression(initializer, DC, contextualType,
21812181
contextualPurpose, flags, &listener);
2182+
2183+
// If we detected that the initializer would have a non-materializable type,
2184+
// complain.
2185+
if (resultTy && listener.isInOut()) {
2186+
diagnose(pattern->getStartLoc(), diag::var_type_not_materializable,
2187+
resultTy);
2188+
2189+
pattern->setType(ErrorType::get(Context));
2190+
pattern->forEachVariable([&](VarDecl *var) {
2191+
// Don't change the type of a variable that we've been able to
2192+
// compute a type for.
2193+
if (var->hasType() &&
2194+
!var->getType()->hasUnboundGenericType() &&
2195+
!var->getType()->hasError())
2196+
return;
2197+
2198+
var->markInvalid();
2199+
});
2200+
2201+
return true;
2202+
}
2203+
21822204
if (resultTy) {
21832205
TypeResolutionOptions options;
21842206
options |= TR_OverrideType;
@@ -2196,7 +2218,7 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
21962218

21972219
// Apply the solution to the pattern as well.
21982220
if (coercePatternToType(pattern, DC, initTy, options,
2199-
nullptr, TypeLoc(), listener.isInOut())) {
2221+
nullptr, TypeLoc())) {
22002222
return true;
22012223
}
22022224
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3984,12 +3984,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
39843984

39853985
void visitBoundVariable(VarDecl *VD) {
39863986
TC.validateDecl(VD);
3987-
3988-
if (!VD->getType()->isMaterializable()) {
3989-
TC.diagnose(VD->getStartLoc(), diag::var_type_not_materializable,
3990-
VD->getType());
3991-
VD->markInvalid();
3992-
}
39933987

39943988
// Check the behavior.
39953989
checkVarBehavior(VD, TC);

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,7 @@ bool TypeChecker::typeCheckPattern(Pattern *P, DeclContext *dc,
914914
bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
915915
TypeResolutionOptions options,
916916
GenericTypeResolver *resolver,
917-
TypeLoc tyLoc,
918-
bool forceInOut) {
917+
TypeLoc tyLoc) {
919918
recur:
920919
if (tyLoc.isNull()) {
921920
tyLoc = TypeLoc::withoutLoc(type);
@@ -1001,9 +1000,6 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
10011000
VarDecl *var = NP->getDecl();
10021001
if (var->isInvalid())
10031002
type = ErrorType::get(Context);
1004-
if (forceInOut) {
1005-
var->setSpecifier(VarDecl::Specifier::InOut);
1006-
}
10071003
var->setType(type->getInOutObjectType());
10081004
// FIXME: wtf
10091005
if (type->hasTypeParameter())

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,8 +1799,7 @@ class TypeChecker final : public LazyResolver {
17991799
bool coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
18001800
TypeResolutionOptions options,
18011801
GenericTypeResolver *resolver = nullptr,
1802-
TypeLoc tyLoc = TypeLoc(),
1803-
bool forceInOut = false);
1802+
TypeLoc tyLoc = TypeLoc());
18041803
bool typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
18051804
Type type);
18061805

0 commit comments

Comments
 (0)