Skip to content

A few minor cleanups #27653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/swift/AST/AnyFunctionRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class AnyFunctionRef {
}
}

const CaptureInfo &getCaptureInfo() const {
CaptureInfo getCaptureInfo() const {
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
return AFD->getCaptureInfo();
return TheFunction.get<AbstractClosureExpr *>()->getCaptureInfo();
}

void setCaptureInfo(const CaptureInfo &captures) const {
void setCaptureInfo(CaptureInfo captures) const {
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
AFD->setCaptureInfo(captures);
return;
Expand Down
16 changes: 8 additions & 8 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2021,8 +2021,8 @@ class PatternBindingEntry {
/// from the source range.
SourceRange getSourceRange(bool omitAccessors = false) const;

const CaptureInfo &getCaptureInfo() const { return Captures; }
void setCaptureInfo(const CaptureInfo &captures) { Captures = captures; }
CaptureInfo getCaptureInfo() const { return Captures; }
void setCaptureInfo(CaptureInfo captures) { Captures = captures; }

private:
SourceLoc getLastAccessorEndLoc() const;
Expand Down Expand Up @@ -2126,11 +2126,11 @@ class PatternBindingDecl final : public Decl,
return getPatternList()[i].getInitContext();
}

const CaptureInfo &getCaptureInfo(unsigned i) const {
CaptureInfo getCaptureInfo(unsigned i) const {
return getPatternList()[i].getCaptureInfo();
}

void setCaptureInfo(unsigned i, const CaptureInfo &captures) {
void setCaptureInfo(unsigned i, CaptureInfo captures) {
getMutablePatternList()[i].setCaptureInfo(captures);
}

Expand Down Expand Up @@ -5237,12 +5237,12 @@ class ParamDecl : public VarDecl {

void setDefaultArgumentInitContext(Initializer *initContext);

const CaptureInfo &getDefaultArgumentCaptureInfo() const {
CaptureInfo getDefaultArgumentCaptureInfo() const {
assert(DefaultValueAndFlags.getPointer());
return DefaultValueAndFlags.getPointer()->Captures;
}

void setDefaultArgumentCaptureInfo(const CaptureInfo &captures);
void setDefaultArgumentCaptureInfo(CaptureInfo captures);

/// Extracts the text of the default argument attached to the provided
/// ParamDecl, removing all inactive #if clauses and providing only the
Expand Down Expand Up @@ -5814,8 +5814,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
/// Retrieve the source range of the function declaration name + patterns.
SourceRange getSignatureSourceRange() const;

const CaptureInfo &getCaptureInfo() const { return Captures; }
void setCaptureInfo(const CaptureInfo &captures) { Captures = captures; }
CaptureInfo getCaptureInfo() const { return Captures; }
void setCaptureInfo(CaptureInfo captures) { Captures = captures; }

/// Retrieve the Objective-C selector that names this method.
ObjCSelector getObjCSelector(DeclName preferredName = DeclName(),
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3449,7 +3449,7 @@ class AbstractClosureExpr : public DeclContext, public Expr {
Bits.AbstractClosureExpr.Discriminator = Discriminator;
}

const CaptureInfo &getCaptureInfo() const { return Captures; }
CaptureInfo getCaptureInfo() const { return Captures; }
void setCaptureInfo(CaptureInfo captures) { Captures = captures; }

/// Retrieve the parameters of this closure.
Expand Down
6 changes: 0 additions & 6 deletions include/swift/AST/Initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ class SerializedPatternBindingInitializer : public SerializedLocalDeclContext {
/// A default argument expression. The parent context is the function
/// (possibly a closure) for which this is a default argument.
class DefaultArgumentInitializer : public Initializer {
friend class ASTContext; // calls reset on unused contexts
void reset(DeclContext *parent, unsigned index) {
setParent(parent);
SpareBits = index;
}

public:
explicit DefaultArgumentInitializer(DeclContext *parent, unsigned index)
: Initializer(InitializerKind::DefaultArgument, parent) {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5850,7 +5850,7 @@ void ParamDecl::setDefaultArgumentInitContext(Initializer *initContext) {
DefaultValueAndFlags.getPointer()->InitContext = initContext;
}

void ParamDecl::setDefaultArgumentCaptureInfo(const CaptureInfo &captures) {
void ParamDecl::setDefaultArgumentCaptureInfo(CaptureInfo captures) {
assert(DefaultValueAndFlags.getPointer());
DefaultValueAndFlags.getPointer()->Captures = captures;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/SIL/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ static CanAnyFunctionType getDefaultArgGeneratorInterfaceType(
if (auto *afd = dyn_cast<AbstractFunctionDecl>(vd)) {
auto *param = getParameterAt(afd, c.defaultArgIndex);
if (param->getDefaultValue()) {
auto &captureInfo = param->getDefaultArgumentCaptureInfo();
auto captureInfo = param->getDefaultArgumentCaptureInfo();
sig = getEffectiveGenericSignature(afd, captureInfo);
}
}
Expand Down Expand Up @@ -2132,11 +2132,11 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
DynamicSelfType *capturesDynamicSelf = nullptr;
OpaqueValueExpr *capturesOpaqueValue = nullptr;

std::function<void (const CaptureInfo &captureInfo)> collectCaptures;
std::function<void (CaptureInfo captureInfo)> collectCaptures;
std::function<void (AnyFunctionRef)> collectFunctionCaptures;
std::function<void (SILDeclRef)> collectConstantCaptures;

collectCaptures = [&](const CaptureInfo &captureInfo) {
collectCaptures = [&](CaptureInfo captureInfo) {
if (captureInfo.hasGenericParamCaptures())
capturesGenericParams = true;
if (captureInfo.hasDynamicSelfCapture())
Expand Down
4 changes: 2 additions & 2 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ void SILGenModule::postEmitFunction(SILDeclRef constant,

void SILGenModule::
emitMarkFunctionEscapeForTopLevelCodeGlobals(SILLocation loc,
const CaptureInfo &captureInfo) {
CaptureInfo captureInfo) {
assert(TopLevelSGF && TopLevelSGF->B.hasValidInsertionPoint()
&& "no valid code generator for top-level function?!");

Expand Down Expand Up @@ -1100,7 +1100,7 @@ emitStoredPropertyInitialization(PatternBindingDecl *pbd, unsigned i) {
auto *var = pbdEntry.getAnchoringVarDecl();
auto *init = pbdEntry.getInit();
auto *initDC = pbdEntry.getInitContext();
auto &captureInfo = pbdEntry.getCaptureInfo();
auto captureInfo = pbdEntry.getCaptureInfo();
assert(!pbdEntry.isInitializerSubsumed());

// If this is the backing storage for a property with an attached wrapper
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
/// Emit a `mark_function_escape` instruction for top-level code when a
/// function or closure at top level refers to script globals.
void emitMarkFunctionEscapeForTopLevelCodeGlobals(SILLocation loc,
const CaptureInfo &captureInfo);
CaptureInfo captureInfo);

/// Map the substitutions for the original declaration to substitutions for
/// the overridden declaration.
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction

/// emitProlog - Generates prolog code to allocate and clean up mutable
/// storage for closure captures and local arguments.
void emitProlog(const CaptureInfo &captureInfo,
void emitProlog(CaptureInfo captureInfo,
ParameterList *paramList, ParamDecl *selfParam,
DeclContext *DC, Type resultType,
bool throws, SourceLoc throwsLoc);
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ static void emitCaptureArguments(SILGenFunction &SGF,
}
}

void SILGenFunction::emitProlog(const CaptureInfo &captureInfo,
void SILGenFunction::emitProlog(CaptureInfo captureInfo,
ParameterList *paramList,
ParamDecl *selfParam,
DeclContext *DC,
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/TypeCheckCaptures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ class FindCapturedVars : public ASTWalker {
return { false, DRE };
}

void propagateCaptures(const CaptureInfo &captureInfo,
SourceLoc loc) {
void propagateCaptures(CaptureInfo captureInfo, SourceLoc loc) {
for (auto capture : captureInfo.getCaptures()) {
// If the decl was captured from us, it isn't captured *by* us.
if (capture.getDecl()->getDeclContext() == CurDC)
Expand Down
29 changes: 13 additions & 16 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,8 +1906,7 @@ getParamIndex(const ParameterList *paramList, const ParamDecl *decl) {
return None;
}

static void
checkInheritedDefaultValueRestrictions(TypeChecker &TC, ParamDecl *PD) {
static void checkInheritedDefaultValueRestrictions(ParamDecl *PD) {
if (PD->getDefaultArgumentKind() != DefaultArgumentKind::Inherited)
return;

Expand All @@ -1919,18 +1918,17 @@ checkInheritedDefaultValueRestrictions(TypeChecker &TC, ParamDecl *PD) {
// The containing decl should be a designated initializer.
auto ctor = dyn_cast<ConstructorDecl>(DC);
if (!ctor || ctor->isConvenienceInit()) {
TC.diagnose(
PD, diag::inherited_default_value_not_in_designated_constructor);
PD->diagnose(diag::inherited_default_value_not_in_designated_constructor);
return;
}

// The decl it overrides should also be a designated initializer.
auto overridden = ctor->getOverriddenDecl();
if (!overridden || overridden->isConvenienceInit()) {
TC.diagnose(
PD, diag::inherited_default_value_used_in_non_overriding_constructor);
PD->diagnose(
diag::inherited_default_value_used_in_non_overriding_constructor);
if (overridden)
TC.diagnose(overridden, diag::overridden_here);
overridden->diagnose(diag::overridden_here);
return;
}

Expand All @@ -1939,16 +1937,15 @@ checkInheritedDefaultValueRestrictions(TypeChecker &TC, ParamDecl *PD) {
assert(idx && "containing decl does not contain param?");
ParamDecl *equivalentParam = overridden->getParameters()->get(*idx);
if (equivalentParam->getDefaultArgumentKind() == DefaultArgumentKind::None) {
TC.diagnose(PD, diag::corresponding_param_not_defaulted);
TC.diagnose(equivalentParam, diag::inherited_default_param_here);
PD->diagnose(diag::corresponding_param_not_defaulted);
equivalentParam->diagnose(diag::inherited_default_param_here);
}
}

/// Check the default arguments that occur within this pattern.
static void checkDefaultArguments(TypeChecker &tc, ParameterList *params,
ValueDecl *VD) {
static void checkDefaultArguments(TypeChecker &tc, ParameterList *params) {
for (auto *param : *params) {
checkInheritedDefaultValueRestrictions(tc, param);
checkInheritedDefaultValueRestrictions(param);
if (!param->getDefaultValue() ||
!param->hasInterfaceType() ||
param->getInterfaceType()->hasError())
Expand Down Expand Up @@ -2600,7 +2597,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
(void) SD->getImplInfo();

TC.checkParameterAttributes(SD->getIndices());
checkDefaultArguments(TC, SD->getIndices(), SD);
checkDefaultArguments(TC, SD->getIndices());

if (SD->getDeclContext()->getSelfClassDecl()) {
checkDynamicSelfType(SD, SD->getValueInterfaceType());
Expand Down Expand Up @@ -3221,7 +3218,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
if (FD->getDeclContext()->getSelfClassDecl())
checkDynamicSelfType(FD, FD->getResultInterfaceType());

checkDefaultArguments(TC, FD->getParameters(), FD);
checkDefaultArguments(TC, FD->getParameters());

// Validate 'static'/'class' on functions in extensions.
auto StaticSpelling = FD->getStaticSpelling();
Expand Down Expand Up @@ -3279,7 +3276,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {

if (auto *PL = EED->getParameterList()) {
TC.checkParameterAttributes(PL);
checkDefaultArguments(TC, PL, EED);
checkDefaultArguments(TC, PL);
}

// We don't yet support raw values on payload cases.
Expand Down Expand Up @@ -3539,7 +3536,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
TC.definedFunctions.push_back(CD);
}

checkDefaultArguments(TC, CD->getParameters(), CD);
checkDefaultArguments(TC, CD->getParameters());
}

void visitDestructorDecl(DestructorDecl *DD) {
Expand Down