Remove the ability to map back from a ParamDecl to its enclosing Pattern. This

is used by precisely one thing (producing a warning in a scenario that is obsolete
because we deprecated the entire thing), so the complexity isn't worth it anymore.
This commit is contained in:
Chris Lattner
2015-12-29 21:07:43 -08:00
parent 49cd50da01
commit 666a42f5c7
7 changed files with 3 additions and 31 deletions

View File

@@ -4007,7 +4007,7 @@ public:
/// VarDecl - 'var' and 'let' declarations. /// VarDecl - 'var' and 'let' declarations.
class VarDecl : public AbstractStorageDecl { class VarDecl : public AbstractStorageDecl {
protected: protected:
llvm::PointerUnion3<PatternBindingDecl*, Pattern*, Stmt*> ParentPattern; llvm::PointerUnion<PatternBindingDecl*, Stmt*> ParentPattern;
VarDecl(DeclKind Kind, bool IsStatic, bool IsLet, SourceLoc NameLoc, VarDecl(DeclKind Kind, bool IsStatic, bool IsLet, SourceLoc NameLoc,
Identifier Name, Type Ty, DeclContext *DC) Identifier Name, Type Ty, DeclContext *DC)
@@ -4186,13 +4186,6 @@ public:
return SourceRange(ArgumentNameLoc, getNameLoc()); return SourceRange(ArgumentNameLoc, getNameLoc());
} }
Pattern *getParamParentPattern() const {
return ParentPattern.dyn_cast<Pattern *>();
}
void setParamParentPattern(Pattern *Pat) {
ParentPattern = Pat;
}
// Implement isa/cast/dyncast/etc. // Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { static bool classof(const Decl *D) {
return D->getKind() == DeclKind::Param; return D->getKind() == DeclKind::Param;

View File

@@ -157,8 +157,6 @@ getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType,
Pattern *Pat = new (Context) NamedPattern(PD, /*implicit=*/true); Pattern *Pat = new (Context) NamedPattern(PD, /*implicit=*/true);
Pat = new (Context) TypedPattern(Pat, TypeLoc::withoutLoc(argType), Pat = new (Context) TypedPattern(Pat, TypeLoc::withoutLoc(argType),
/*implicit=*/true); /*implicit=*/true);
PD->setParamParentPattern(Pat);
ParamPatternElts.push_back(TuplePatternElt(Pat)); ParamPatternElts.push_back(TuplePatternElt(Pat));
} }
@@ -228,7 +226,6 @@ getBuiltinGenericFunction(Identifier Id,
Pattern *Pat = new (Context) NamedPattern(PD, /*implicit=*/true); Pattern *Pat = new (Context) NamedPattern(PD, /*implicit=*/true);
Pat = new (Context) TypedPattern(Pat, Pat = new (Context) TypedPattern(Pat,
TypeLoc::withoutLoc(ArgTupleElt.getType()), /*implicit=*/true); TypeLoc::withoutLoc(ArgTupleElt.getType()), /*implicit=*/true);
PD->setParamParentPattern(Pat);
ParamPatternElts.push_back(TuplePatternElt(Pat)); ParamPatternElts.push_back(TuplePatternElt(Pat));
} }

View File

@@ -3154,11 +3154,7 @@ SourceRange VarDecl::getSourceRange() const {
} }
SourceRange VarDecl::getTypeSourceRangeForDiagnostics() const { SourceRange VarDecl::getTypeSourceRangeForDiagnostics() const {
Pattern *Pat = nullptr; Pattern *Pat = getParentPattern();
if (ParentPattern.is<Pattern*>())
Pat = ParentPattern.dyn_cast<Pattern *>();
else
Pat = getParentPattern();
if (!Pat || Pat->isImplicit()) if (!Pat || Pat->isImplicit())
return getSourceRange(); return getSourceRange();

View File

@@ -310,7 +310,6 @@ static Pattern *buildImplicitLetParameter(ASTContext &ctx, Identifier name,
P->setType(tyLoc.getType()); P->setType(tyLoc.getType());
P = new (ctx) TypedPattern(P, tyLoc, /*Implicit=*/true); P = new (ctx) TypedPattern(P, tyLoc, /*Implicit=*/true);
P->setType(tyLoc.getType()); P->setType(tyLoc.getType());
paramDecl->setParamParentPattern(P);
return P; return P;
} }

View File

@@ -392,9 +392,6 @@ mapParsedParameters(Parser &parser,
bool isLet = specifierKind == Parser::ParsedParameter::Let; bool isLet = specifierKind == Parser::ParsedParameter::Let;
param = new (ctx) VarPattern(letVarInOutLoc, isLet, param); param = new (ctx) VarPattern(letVarInOutLoc, isLet, param);
} }
if (var)
var->setParamParentPattern(param);
return param; return param;
}; };

View File

@@ -1492,17 +1492,7 @@ VarDeclUsageChecker::~VarDeclUsageChecker() {
} }
// If this is a parameter explicitly marked 'var', remove it. // If this is a parameter explicitly marked 'var', remove it.
if (auto *param = dyn_cast<ParamDecl>(var))
if (auto *pattern = param->getParamParentPattern())
if (auto *vp = dyn_cast<VarPattern>(pattern)) {
TC.diagnose(var->getLoc(), diag::variable_never_mutated,
var->getName(), /*param*/1)
.fixItRemove(vp->getLoc());
continue;
}
unsigned varKind = isa<ParamDecl>(var); unsigned varKind = isa<ParamDecl>(var);
// FIXME: fixit when we can find a pattern binding.
if (FixItLoc.isInvalid()) if (FixItLoc.isInvalid())
TC.diagnose(var->getLoc(), diag::variable_never_mutated, TC.diagnose(var->getLoc(), diag::variable_never_mutated,
var->getName(), varKind); var->getName(), varKind);

View File

@@ -38,7 +38,7 @@ func foo() -> Int {
} }
} }
func goo(e : ErrorType) {} func goo(var e : ErrorType) {}
struct Test1 : OptionSetType { struct Test1 : OptionSetType {
init(rawValue: Int) {} init(rawValue: Int) {}