Skip to content

Commit 296ce3f

Browse files
committed
AST: Remove hack-around for getInterfaceType() on ParamDecl returning InOutType
Most callers did not want the InOutType here, and checked the ParamDecl's flags instead.
1 parent 02cf20b commit 296ce3f

18 files changed

+78
-78
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ static void printParameterFlags(ASTPrinter &printer, PrintOptions options,
21372137
/* nothing */
21382138
break;
21392139
case ValueOwnership::InOut:
2140-
/* handled as part of an InOutType */
2140+
printer << "inout ";
21412141
break;
21422142
case ValueOwnership::Shared:
21432143
printer << "__shared ";
@@ -2266,12 +2266,15 @@ void PrintAST::printOneParameter(const ParamDecl *param,
22662266
// through the paren types so that we don't print excessive @escapings.
22672267
unsigned numParens = 0;
22682268
if (!willUseTypeReprPrinting(TheTypeLoc, CurrentType, Options)) {
2269+
auto type = TheTypeLoc.getType()->getInOutObjectType();
2270+
22692271
printParameterFlags(Printer, Options, paramFlags);
2270-
while (auto parenTy =
2271-
dyn_cast<ParenType>(TheTypeLoc.getType().getPointer())) {
2272+
while (auto parenTy = dyn_cast<ParenType>(type.getPointer())) {
22722273
++numParens;
2273-
TheTypeLoc = TypeLoc::withoutLoc(parenTy->getUnderlyingType());
2274+
type = parenTy->getUnderlyingType();
22742275
}
2276+
2277+
TheTypeLoc = TypeLoc::withoutLoc(type);
22752278
}
22762279

22772280
for (unsigned i = 0; i < numParens; ++i)
@@ -3252,7 +3255,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
32523255
void visitParenType(ParenType *T) {
32533256
Printer << "(";
32543257
printParameterFlags(Printer, Options, T->getParameterFlags());
3255-
visit(T->getUnderlyingType());
3258+
visit(T->getUnderlyingType()->getInOutObjectType());
32563259
Printer << ")";
32573260
}
32583261

@@ -3267,7 +3270,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
32673270
if (i)
32683271
Printer << ", ";
32693272
const TupleTypeElt &TD = Fields[i];
3270-
Type EltType = TD.getType();
3273+
Type EltType = TD.getType()->getInOutObjectType();
32713274

32723275
Printer.callPrintStructurePre(PrintStructureKind::TupleElement);
32733276
SWIFT_DEFER {
@@ -3540,7 +3543,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
35403543
}
35413544

35423545
printParameterFlags(Printer, Options, Param.getParameterFlags());
3543-
visit(Param.getType());
3546+
visit(Param.getPlainType());
35443547
if (Param.isVariadic())
35453548
Printer << "...";
35463549
}

lib/AST/ASTVerifier.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,15 +2255,15 @@ class Verifier : public ASTWalker {
22552255

22562256
// Variables must have materializable type, unless they are parameters,
22572257
// in which case they must either have l-value type or be anonymous.
2258-
if (!var->getInterfaceType()->isMaterializable() || var->isInOut()) {
2258+
if (!var->getInterfaceType()->isMaterializable()) {
22592259
if (!isa<ParamDecl>(var)) {
2260-
Out << "Non-parameter VarDecl has non-materializable type: ";
2260+
Out << "VarDecl has non-materializable type: ";
22612261
var->getType().print(Out);
22622262
Out << "\n";
22632263
abort();
22642264
}
22652265

2266-
if (!var->getInterfaceType()->is<InOutType>() && var->hasName()) {
2266+
if (!var->isInOut() && var->hasName()) {
22672267
Out << "ParamDecl may only have non-materializable tuple type "
22682268
"when it is anonymous: ";
22692269
var->getType().print(Out);
@@ -2340,8 +2340,7 @@ class Verifier : public ASTWalker {
23402340

23412341
if (var->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>()) {
23422342
auto varTy = var->getInterfaceType()
2343-
->getReferenceStorageReferent()
2344-
->getWithoutSpecifierType();
2343+
->getReferenceStorageReferent();
23452344

23462345
// FIXME: Update to look for plain Optional once
23472346
// ImplicitlyUnwrappedOptional is removed
@@ -2906,13 +2905,13 @@ class Verifier : public ASTWalker {
29062905
abort();
29072906
}
29082907
const ParamDecl *selfParam = FD->getImplicitSelfDecl();
2909-
if (!selfParam->getInterfaceType()->is<InOutType>()) {
2908+
if (!selfParam->isInOut()) {
29102909
Out << "mutating function does not have inout 'self'\n";
29112910
abort();
29122911
}
29132912
} else {
29142913
const ParamDecl *selfParam = FD->getImplicitSelfDecl();
2915-
if (selfParam && selfParam->getInterfaceType()->is<InOutType>()) {
2914+
if (selfParam && selfParam->isInOut()) {
29162915
Out << "non-mutating function has inout 'self'\n";
29172916
abort();
29182917
}
@@ -2925,7 +2924,7 @@ class Verifier : public ASTWalker {
29252924
abort();
29262925
}
29272926

2928-
auto resultTy = FD->getResultInterfaceType()->getWithoutSpecifierType();
2927+
auto resultTy = FD->getResultInterfaceType();
29292928

29302929
// FIXME: Update to look for plain Optional once
29312930
// ImplicitlyUnwrappedOptional is removed

lib/AST/Decl.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,14 +1960,7 @@ bool ValueDecl::hasInterfaceType() const {
19601960

19611961
Type ValueDecl::getInterfaceType() const {
19621962
assert(hasInterfaceType() && "No interface type was set");
1963-
auto ty = TypeAndAccess.getPointer();
1964-
// FIXME(Remove InOutType): This grossness will go away when Sema is weaned
1965-
// off of InOutType. Until then we should respect our parameter flags and
1966-
// return the type it expects.
1967-
if (auto *VD = dyn_cast<ParamDecl>(this)) {
1968-
ty = VD->isInOut() ? InOutType::get(ty) : ty;
1969-
}
1970-
return ty;
1963+
return TypeAndAccess.getPointer();
19711964
}
19721965

19731966
void ValueDecl::setInterfaceType(Type type) {
@@ -4072,13 +4065,9 @@ Type VarDecl::getType() const {
40724065
if (!typeInContext) {
40734066
const_cast<VarDecl *>(this)->typeInContext =
40744067
getDeclContext()->mapTypeIntoContext(
4075-
getInterfaceType())->getInOutObjectType();
4068+
getInterfaceType());
40764069
}
40774070

4078-
// FIXME(Remove InOutType): This grossness will go away when Sema is weaned
4079-
// off of InOutType. Until then we should respect our parameter flags and
4080-
// return the type it expects.
4081-
if (isInOut()) return InOutType::get(typeInContext);
40824071
return typeInContext;
40834072
}
40844073

@@ -4380,7 +4369,7 @@ ParamDecl::ParamDecl(ParamDecl *PD, bool withTypes)
43804369
: VarDecl(DeclKind::Param, /*IsStatic*/false, PD->getSpecifier(),
43814370
/*IsCaptureList*/false, PD->getNameLoc(), PD->getName(),
43824371
PD->hasType() && withTypes
4383-
? PD->getType()->getInOutObjectType()
4372+
? PD->getType()
43844373
: Type(),
43854374
PD->getDeclContext()),
43864375
ArgumentName(PD->getArgumentName()),

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ makeEnumRawValueConstructor(ClangImporter::Implementation &Impl,
439439
return ctorDecl;
440440

441441
auto selfRef = new (C) DeclRefExpr(selfDecl, DeclNameLoc(), /*implicit*/true);
442-
selfRef->setType(LValueType::get(selfDecl->getType()->getInOutObjectType()));
442+
selfRef->setType(LValueType::get(selfDecl->getType()));
443443
selfRef->propagateLValueAccessKind(AccessKind::Write);
444444

445445
auto paramRef = new (C) DeclRefExpr(param, DeclNameLoc(),
@@ -1308,7 +1308,7 @@ createValueConstructor(ClangImporter::Implementation &Impl,
13081308
// Construct left-hand side.
13091309
Expr *lhs = new (context) DeclRefExpr(selfDecl, DeclNameLoc(),
13101310
/*Implicit=*/true);
1311-
lhs->setType(LValueType::get(selfDecl->getType()->getInOutObjectType()));
1311+
lhs->setType(LValueType::get(selfDecl->getType()));
13121312

13131313
auto semantics = (var->hasStorage()
13141314
? AccessSemantics::DirectToStorage
@@ -1460,7 +1460,7 @@ static ConstructorDecl *createRawValueBridgingConstructor(
14601460
// Construct left-hand side.
14611461
Expr *lhs = new (ctx) DeclRefExpr(selfDecl, DeclNameLoc(),
14621462
/*Implicit=*/true);
1463-
lhs->setType(LValueType::get(selfDecl->getType()->getInOutObjectType()));
1463+
lhs->setType(LValueType::get(selfDecl->getType()));
14641464

14651465
lhs = new (ctx) MemberRefExpr(lhs, SourceLoc(), storedRawValue,
14661466
DeclNameLoc(), /*Implicit=*/true,
@@ -5663,7 +5663,7 @@ Decl *SwiftDeclConverter::importGlobalAsInitializer(
56635663
Type selfType = selfParam->getType();
56645664
Type initType = FunctionType::get(selfType, fnType);
56655665
result->setInitializerInterfaceType(initType);
5666-
Type selfMetaType = MetatypeType::get(selfType->getInOutObjectType());
5666+
Type selfMetaType = MetatypeType::get(selfType);
56675667
Type allocType = FunctionType::get(selfMetaType, fnType);
56685668
result->setInterfaceType(allocType);
56695669
Impl.recordImplicitUnwrapForDecl(result,

lib/IDE/CodeCompletion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,10 +2104,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
21042104
setClangDeclKeywords(VD, Pairs, Builder);
21052105
// Add a type annotation.
21062106
Type VarType = getTypeOfMember(VD);
2107-
if (VD->getName() == Ctx.Id_self) {
2108-
// Strip inout from 'self'. It is useful to show inout for function
2109-
// parameters. But for 'self' it is just noise.
2110-
VarType = VarType->getInOutObjectType();
2107+
if (VD->getName() != Ctx.Id_self && VD->isInOut()) {
2108+
// It is useful to show inout for function parameters.
2109+
// But for 'self' it is just noise.
2110+
VarType = InOutType::get(VarType);
21112111
}
21122112
auto DynamicOrOptional =
21132113
IsDynamicLookup || VD->getAttrs().hasAttribute<OptionalAttr>();

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ DebugTypeInfo DebugTypeInfo::getLocalVariable(DeclContext *DC,
7272
if (Unwrap) {
7373
DeclType = DeclType->getInOutObjectType();
7474
RealType = RealType->getInOutObjectType();
75+
// FIXME FIXME FIXME
7576
}
7677

7778
// DynamicSelfType is also sugar as far as debug info is concerned.

lib/IRGen/DebugTypeInfo.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ class DebugTypeInfo {
8484
DeclContext *getDeclContext() const { return DeclCtx; }
8585
GenericEnvironment *getGenericEnvironment() const { return GenericEnv; }
8686

87-
void unwrapLValueOrInOutType() {
88-
Type = Type->getWithoutSpecifierType().getPointer();
89-
}
90-
9187
// Determine whether this type is an Archetype itself.
9288
bool isArchetype() const {
9389
return Type->getWithoutSpecifierType()->is<ArchetypeType>();

lib/IRGen/MetadataRequest.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,7 @@ namespace {
891891
}
892892

893893
llvm::Value *getFunctionParameterRef(AnyFunctionType::CanParam &param) {
894-
auto type = param.getType();
895-
if (param.getParameterFlags().isInOut())
896-
type = type->getInOutObjectType()->getCanonicalType();
894+
auto type = param.getPlainType()->getCanonicalType();
897895
return IGF.emitAbstractTypeMetadataRef(type);
898896
}
899897

lib/SIL/AbstractionPattern.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ AbstractionPattern TypeConverter::getAbstractionPattern(VarDecl *var) {
7373
genericSig = sig->getCanonicalSignature();
7474

7575
CanType swiftType = var->getInterfaceType()
76-
->getInOutObjectType()
7776
->getCanonicalType();
7877

7978
if (auto clangDecl = var->getClangDecl()) {

lib/SILGen/SILGenConstructor.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
8585
// FIXME: Handle 'self' along with the other arguments.
8686
auto *paramList = ctor->getParameterList(1);
8787
auto *selfDecl = ctor->getImplicitSelfDecl();
88-
auto selfTyCan = selfDecl->getType()->getInOutObjectType();
89-
auto selfIfaceTyCan = selfDecl->getInterfaceType()->getInOutObjectType();
88+
auto selfTyCan = selfDecl->getType();
89+
auto selfIfaceTyCan = selfDecl->getInterfaceType();
9090
SILType selfTy = SGF.getLoweredType(selfTyCan);
9191

9292
// Emit the indirect return argument, if any.
@@ -199,7 +199,7 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {
199199

200200
// Get the 'self' decl and type.
201201
VarDecl *selfDecl = ctor->getImplicitSelfDecl();
202-
auto &lowering = getTypeLowering(selfDecl->getType()->getInOutObjectType());
202+
auto &lowering = getTypeLowering(selfDecl->getType());
203203
SILType selfTy = lowering.getLoweredType();
204204
(void)selfTy;
205205
assert(!selfTy.getClassOrBoundGenericClass()
@@ -782,8 +782,7 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
782782

783783
static ManagedValue emitSelfForMemberInit(SILGenFunction &SGF, SILLocation loc,
784784
VarDecl *selfDecl) {
785-
CanType selfFormalType = selfDecl->getType()
786-
->getInOutObjectType()->getCanonicalType();
785+
CanType selfFormalType = selfDecl->getType()->getCanonicalType();
787786
if (selfFormalType->hasReferenceSemantics())
788787
return SGF.emitRValueForDecl(loc, selfDecl, selfDecl->getType(),
789788
AccessSemantics::DirectToStorage,
@@ -799,8 +798,7 @@ static ManagedValue emitSelfForMemberInit(SILGenFunction &SGF, SILLocation loc,
799798
static LValue emitLValueForMemberInit(SILGenFunction &SGF, SILLocation loc,
800799
VarDecl *selfDecl,
801800
VarDecl *property) {
802-
CanType selfFormalType = selfDecl->getType()
803-
->getInOutObjectType()->getCanonicalType();
801+
CanType selfFormalType = selfDecl->getType()->getCanonicalType();
804802
auto self = emitSelfForMemberInit(SGF, loc, selfDecl);
805803
return SGF.emitPropertyLValue(loc, self, selfFormalType, property,
806804
LValueOptions(), AccessKind::Write,

lib/SILGen/SILGenPoly.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,8 @@ ManagedValue Transform::transform(ManagedValue v,
358358
CanType outputSubstType,
359359
SGFContext ctxt) {
360360
// Look through inout types.
361-
if (isa<InOutType>(inputSubstType))
362-
inputSubstType = CanType(inputSubstType->getInOutObjectType());
363-
361+
inputSubstType = inputSubstType->getInOutObjectType()->getCanonicalType();
362+
364363
// Load if the result isn't address-only. All the translation routines
365364
// expect this.
366365
if (v.getType().isAddress()) {

lib/SILGen/SILGenProlog.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ struct ArgumentInitHelper {
225225
if (vd->isInOut()) {
226226
SILValue address = argrv.getUnmanagedValue();
227227

228-
CanType objectType = vd->getType()->getInOutObjectType()->getCanonicalType();
228+
CanType objectType = vd->getType()->getCanonicalType();
229229

230230
// As a special case, don't introduce a local variable for
231231
// Builtin.UnsafeValueBuffer, which is not copyable.
@@ -265,6 +265,8 @@ struct ArgumentInitHelper {
265265

266266
void emitParam(ParamDecl *PD) {
267267
auto type = PD->getType();
268+
if (PD->isInOut())
269+
type = InOutType::get(type); // FIXME remove InOutType
268270

269271
++ArgNo;
270272
if (PD->hasName()) {
@@ -331,6 +333,8 @@ void SILGenFunction::bindParametersForForwarding(const ParameterList *params,
331333
Type type = (param->hasType()
332334
? param->getType()
333335
: F.mapTypeIntoContext(param->getInterfaceType()));
336+
if (param->isInOut())
337+
type = InOutType::get(type); // FIXME remove InOutType
334338
makeArgument(type->eraseDynamicSelfType(), param, parameters, *this);
335339
}
336340
}

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ void LifetimeChecker::handleStoreUse(unsigned UseID) {
999999
Type selfTy;
10001000
SILLocation fnLoc = TheMemory.getFunction().getLocation();
10011001
if (auto *ctor = fnLoc.getAsASTNode<ConstructorDecl>())
1002-
selfTy = ctor->getImplicitSelfDecl()->getType()->getInOutObjectType();
1002+
selfTy = ctor->getImplicitSelfDecl()->getType();
10031003
else
10041004
selfTy = TheMemory.getType();
10051005

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5779,7 +5779,7 @@ Expr *ExprRewriter::coerceCallArguments(
57795779

57805780
for (size_t i = 0; i < params.size(); i++) {
57815781
if (auto dotExpr = dyn_cast<DotSyntaxCallExpr>(argElts[i])) {
5782-
auto paramTy = params[i].getType()->getWithoutSpecifierType();
5782+
auto paramTy = params[i].getType();
57835783
auto argTy = cs.getType(dotExpr)->getWithoutSpecifierType();
57845784
if (!paramTy->isEqual(argTy)) {
57855785
allParamsMatch = false;

lib/Sema/CSSolver.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,10 +2151,8 @@ bool DisjunctionChoice::isSymmetricOperator() const {
21512151
if (paramList->size() != 2)
21522152
return true;
21532153

2154-
auto firstType =
2155-
paramList->get(0)->getInterfaceType()->getWithoutSpecifierType();
2156-
auto secondType =
2157-
paramList->get(1)->getInterfaceType()->getWithoutSpecifierType();
2154+
auto firstType = paramList->get(0)->getInterfaceType();
2155+
auto secondType = paramList->get(1)->getInterfaceType();
21582156
return firstType->isEqual(secondType);
21592157
}
21602158

0 commit comments

Comments
 (0)