Skip to content

Commit 06c2e98

Browse files
authored
Merge pull request #21133 from slavapestov/lazy-implicit-inits
Lazy synthesis of implicit constructors in non-primary files
2 parents b2ceb4b + a55283d commit 06c2e98

17 files changed

+123
-116
lines changed

include/swift/AST/ASTContext.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class ASTContext final {
484484

485485
// Declare accessors for the known declarations.
486486
#define FUNC_DECL(Name, Id) \
487-
FuncDecl *get##Name(LazyResolver *resolver) const;
487+
FuncDecl *get##Name() const;
488488
#include "swift/AST/KnownDecls.def"
489489

490490
/// Get the '+' function on two RangeReplaceableCollection.
@@ -498,21 +498,21 @@ class ASTContext final {
498498
///
499499
/// If this is true, the four methods above all promise to return
500500
/// non-null.
501-
bool hasOptionalIntrinsics(LazyResolver *resolver) const;
501+
bool hasOptionalIntrinsics() const;
502502

503503
/// Check whether the standard library provides all the correct
504504
/// intrinsic support for UnsafeMutablePointer<T> function arguments.
505505
///
506506
/// If this is true, the methods getConvert*ToPointerArgument
507507
/// all promise to return non-null.
508-
bool hasPointerArgumentIntrinsics(LazyResolver *resolver) const;
508+
bool hasPointerArgumentIntrinsics() const;
509509

510510
/// Check whether the standard library provides all the correct
511511
/// intrinsic support for array literals.
512512
///
513513
/// If this is true, the method getAllocateUninitializedArray
514514
/// promises to return non-null.
515-
bool hasArrayLiteralIntrinsics(LazyResolver *resolver) const;
515+
bool hasArrayLiteralIntrinsics() const;
516516

517517
/// Retrieve the declaration of Swift.Bool.init(_builtinBooleanLiteral:)
518518
ConstructorDecl *getBoolBuiltinInitDecl() const;
@@ -531,13 +531,13 @@ class ASTContext final {
531531
FuncDecl *getArrayReserveCapacityDecl() const;
532532

533533
/// Retrieve the declaration of Swift._unimplementedInitializer.
534-
FuncDecl *getUnimplementedInitializerDecl(LazyResolver *resolver) const;
534+
FuncDecl *getUnimplementedInitializerDecl() const;
535535

536536
/// Retrieve the declaration of Swift._undefined.
537-
FuncDecl *getUndefinedDecl(LazyResolver *resolver) const;
537+
FuncDecl *getUndefinedDecl() const;
538538

539539
// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast.
540-
FuncDecl *getIsOSVersionAtLeastDecl(LazyResolver *resolver) const;
540+
FuncDecl *getIsOSVersionAtLeastDecl() const;
541541

542542
/// Look for the declaration with the given name within the
543543
/// Swift module.

lib/AST/ASTContext.cpp

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -911,13 +911,12 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
911911

912912
/// Find the implementation for the given "intrinsic" library function.
913913
static FuncDecl *findLibraryIntrinsic(const ASTContext &ctx,
914-
StringRef name,
915-
LazyResolver *resolver) {
914+
StringRef name) {
916915
SmallVector<ValueDecl *, 1> results;
917916
ctx.lookupInSwiftModule(name, results);
918917
if (results.size() == 1) {
919918
if (auto FD = dyn_cast<FuncDecl>(results.front())) {
920-
if (resolver)
919+
if (auto *resolver = ctx.getLazyResolver())
921920
resolver->resolveDeclSignature(FD);
922921
return FD;
923922
}
@@ -1169,14 +1168,12 @@ FuncDecl *ASTContext::getArrayReserveCapacityDecl() const {
11691168
}
11701169

11711170
FuncDecl *
1172-
ASTContext::getUnimplementedInitializerDecl(LazyResolver *resolver) const {
1171+
ASTContext::getUnimplementedInitializerDecl() const {
11731172
if (getImpl().UnimplementedInitializerDecl)
11741173
return getImpl().UnimplementedInitializerDecl;
11751174

11761175
// Look for the function.
1177-
Type input, output;
1178-
auto decl = findLibraryIntrinsic(*this, "_unimplementedInitializer",
1179-
resolver);
1176+
auto decl = findLibraryIntrinsic(*this, "_unimplementedInitializer");
11801177
if (!decl)
11811178
return nullptr;
11821179

@@ -1190,28 +1187,26 @@ ASTContext::getUnimplementedInitializerDecl(LazyResolver *resolver) const {
11901187
}
11911188

11921189
FuncDecl *
1193-
ASTContext::getUndefinedDecl(LazyResolver *resolver) const {
1190+
ASTContext::getUndefinedDecl() const {
11941191
if (getImpl().UndefinedDecl)
11951192
return getImpl().UndefinedDecl;
11961193

11971194
// Look for the function.
1198-
CanType input, output;
1199-
auto decl = findLibraryIntrinsic(*this, "_undefined", resolver);
1195+
auto decl = findLibraryIntrinsic(*this, "_undefined");
12001196
if (!decl)
12011197
return nullptr;
12021198

12031199
getImpl().UndefinedDecl = decl;
12041200
return decl;
12051201
}
12061202

1207-
FuncDecl *ASTContext::getIsOSVersionAtLeastDecl(LazyResolver *resolver) const {
1203+
FuncDecl *ASTContext::getIsOSVersionAtLeastDecl() const {
12081204
if (getImpl().IsOSVersionAtLeastDecl)
12091205
return getImpl().IsOSVersionAtLeastDecl;
12101206

12111207
// Look for the function.
1212-
Type input, output;
12131208
auto decl =
1214-
findLibraryIntrinsic(*this, "_stdlib_isOSVersionAtLeast", resolver);
1209+
findLibraryIntrinsic(*this, "_stdlib_isOSVersionAtLeast");
12151210
if (!decl)
12161211
return nullptr;
12171212

@@ -1333,44 +1328,44 @@ ASTContext::associateInfixOperators(PrecedenceGroupDecl *left,
13331328

13341329
// Find library intrinsic function.
13351330
static FuncDecl *findLibraryFunction(const ASTContext &ctx, FuncDecl *&cache,
1336-
StringRef name, LazyResolver *resolver) {
1331+
StringRef name) {
13371332
if (cache) return cache;
13381333

13391334
// Look for a generic function.
1340-
cache = findLibraryIntrinsic(ctx, name, resolver);
1335+
cache = findLibraryIntrinsic(ctx, name);
13411336
return cache;
13421337
}
13431338

13441339
#define FUNC_DECL(Name, Id) \
1345-
FuncDecl *ASTContext::get##Name(LazyResolver *resolver) const { \
1346-
return findLibraryFunction(*this, getImpl().Get##Name, Id, resolver); \
1340+
FuncDecl *ASTContext::get##Name() const { \
1341+
return findLibraryFunction(*this, getImpl().Get##Name, Id); \
13471342
}
13481343
#include "swift/AST/KnownDecls.def"
13491344

1350-
bool ASTContext::hasOptionalIntrinsics(LazyResolver *resolver) const {
1345+
bool ASTContext::hasOptionalIntrinsics() const {
13511346
return getOptionalDecl() &&
13521347
getOptionalSomeDecl() &&
13531348
getOptionalNoneDecl() &&
1354-
getDiagnoseUnexpectedNilOptional(resolver);
1349+
getDiagnoseUnexpectedNilOptional();
13551350
}
13561351

1357-
bool ASTContext::hasPointerArgumentIntrinsics(LazyResolver *resolver) const {
1352+
bool ASTContext::hasPointerArgumentIntrinsics() const {
13581353
return getUnsafeMutableRawPointerDecl()
13591354
&& getUnsafeRawPointerDecl()
13601355
&& getUnsafeMutablePointerDecl()
13611356
&& getUnsafePointerDecl()
13621357
&& (!LangOpts.EnableObjCInterop || getAutoreleasingUnsafeMutablePointerDecl())
1363-
&& getConvertPointerToPointerArgument(resolver)
1364-
&& getConvertMutableArrayToPointerArgument(resolver)
1365-
&& getConvertConstArrayToPointerArgument(resolver)
1366-
&& getConvertConstStringToUTF8PointerArgument(resolver)
1367-
&& getConvertInOutToPointerArgument(resolver);
1358+
&& getConvertPointerToPointerArgument()
1359+
&& getConvertMutableArrayToPointerArgument()
1360+
&& getConvertConstArrayToPointerArgument()
1361+
&& getConvertConstStringToUTF8PointerArgument()
1362+
&& getConvertInOutToPointerArgument();
13681363
}
13691364

1370-
bool ASTContext::hasArrayLiteralIntrinsics(LazyResolver *resolver) const {
1365+
bool ASTContext::hasArrayLiteralIntrinsics() const {
13711366
return getArrayDecl()
1372-
&& getAllocateUninitializedArray(resolver)
1373-
&& getDeallocateUninitializedArray(resolver);
1367+
&& getAllocateUninitializedArray()
1368+
&& getDeallocateUninitializedArray();
13741369
}
13751370

13761371
void ASTContext::addExternalDecl(Decl *decl) {

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static FuncDecl *diagnoseMissingIntrinsic(SILGenModule &sgm,
179179

180180
#define FUNC_DECL(NAME, ID) \
181181
FuncDecl *SILGenModule::get##NAME(SILLocation loc) { \
182-
if (auto fn = getASTContext().get##NAME(nullptr)) \
182+
if (auto fn = getASTContext().get##NAME()) \
183183
return fn; \
184184
return diagnoseMissingIntrinsic(*this, loc, ID); \
185185
}

lib/SILGen/SILGenApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5579,7 +5579,7 @@ SILGenFunction::emitUninitializedArrayAllocation(Type ArrayTy,
55795579
SILValue Length,
55805580
SILLocation Loc) {
55815581
auto &Ctx = getASTContext();
5582-
auto allocate = Ctx.getAllocateUninitializedArray(nullptr);
5582+
auto allocate = Ctx.getAllocateUninitializedArray();
55835583

55845584
// Invoke the intrinsic, which returns a tuple.
55855585
auto subMap = ArrayTy->getContextSubstitutionMap(SGM.M.getSwiftModule(),
@@ -5600,7 +5600,7 @@ SILGenFunction::emitUninitializedArrayAllocation(Type ArrayTy,
56005600
void SILGenFunction::emitUninitializedArrayDeallocation(SILLocation loc,
56015601
SILValue array) {
56025602
auto &Ctx = getASTContext();
5603-
auto deallocate = Ctx.getDeallocateUninitializedArray(nullptr);
5603+
auto deallocate = Ctx.getDeallocateUninitializedArray();
56045604

56055605
CanType arrayTy = array->getType().getASTType();
56065606

lib/SILGen/SILGenBridging.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ static ManagedValue emitNativeToCBridgedNonoptionalValue(SILGenFunction &SGF,
719719

720720
// Call into the stdlib intrinsic.
721721
if (auto bridgeAnything =
722-
SGF.getASTContext().getBridgeAnythingToObjectiveC(nullptr)) {
722+
SGF.getASTContext().getBridgeAnythingToObjectiveC()) {
723723
auto *genericSig = bridgeAnything->getGenericSignature();
724724
auto subMap = SubstitutionMap::get(
725725
genericSig,
@@ -1098,7 +1098,7 @@ static ManagedValue emitCBridgedToNativeValue(SILGenFunction &SGF,
10981098
auto optionalMV =
10991099
SGF.B.createUncheckedBitCast(loc, v, optionalBridgedTy);
11001100
return SGF.emitApplyOfLibraryIntrinsic(loc,
1101-
SGF.getASTContext().getBridgeAnyObjectToAny(nullptr),
1101+
SGF.getASTContext().getBridgeAnyObjectToAny(),
11021102
SubstitutionMap(), optionalMV, C)
11031103
.getAsSingleValue(SGF, loc);
11041104
}

lib/SILGen/SILGenConvert.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ SILGenFunction::emitPreconditionOptionalHasValue(SILLocation loc,
214214

215215
// Call the standard library implementation of _diagnoseUnexpectedNilOptional.
216216
if (auto diagnoseFailure =
217-
getASTContext().getDiagnoseUnexpectedNilOptional(nullptr)) {
217+
getASTContext().getDiagnoseUnexpectedNilOptional()) {
218218
auto args = emitSourceLocationArgs(loc.getSourceLoc(), loc);
219219

220220
auto i1Ty = SILType::getBuiltinIntegerType(1, getASTContext());
@@ -481,7 +481,7 @@ SILGenFunction::emitPointerToPointer(SILLocation loc,
481481
CanType inputType,
482482
CanType outputType,
483483
SGFContext C) {
484-
auto converter = getASTContext().getConvertPointerToPointerArgument(nullptr);
484+
auto converter = getASTContext().getConvertPointerToPointerArgument();
485485

486486
auto origValue = input;
487487
if (silConv.useLoweredAddresses()) {

lib/SILGen/SILGenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ SILValue SILGenFunction::emitOSVersionRangeCheck(SILLocation loc,
12181218

12191219
// Emit call to _stdlib_isOSVersionAtLeast(major, minor, patch)
12201220
FuncDecl *versionQueryDecl =
1221-
getASTContext().getIsOSVersionAtLeastDecl(nullptr);
1221+
getASTContext().getIsOSVersionAtLeastDecl();
12221222
assert(versionQueryDecl);
12231223

12241224
auto silDeclRef = SILDeclRef(versionQueryDecl);

lib/SILGen/SILGenExpr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ void SILGenFunction::ForceTryEmission::finish() {
10471047
// Otherwise, we need to emit it.
10481048
SILGenSavedInsertionPoint scope(SGF, catchBB, FunctionSection::Postmatter);
10491049

1050-
if (auto diagnoseError = SGF.getASTContext().getDiagnoseUnexpectedError(nullptr)) {
1050+
if (auto diagnoseError = SGF.getASTContext().getDiagnoseUnexpectedError()) {
10511051
ASTContext &ctx = SGF.getASTContext();
10521052
auto error = SGF.B.createOwnedPhiArgument(SILType::getExceptionType(ctx));
10531053
auto args = SGF.emitSourceLocationArgs(Loc->getExclaimLoc(), Loc);
@@ -5135,7 +5135,7 @@ ManagedValue SILGenFunction::emitLValueToPointer(SILLocation loc, LValue &&lv,
51355135

51365136
// Invoke the conversion intrinsic.
51375137
FuncDecl *converter =
5138-
getASTContext().getConvertInOutToPointerArgument(nullptr);
5138+
getASTContext().getConvertInOutToPointerArgument();
51395139

51405140
auto pointerType = pointerInfo.PointerType;
51415141
auto subMap = pointerType->getContextSubstitutionMap(SGM.M.getSwiftModule(),
@@ -5189,12 +5189,12 @@ SILGenFunction::emitArrayToPointer(SILLocation loc, ManagedValue array,
51895189
FuncDecl *converter;
51905190
if (accessInfo.AccessKind != SGFAccessKind::ReadWrite) {
51915191
assert(isReadAccess(accessInfo.AccessKind));
5192-
converter = ctx.getConvertConstArrayToPointerArgument(nullptr);
5192+
converter = ctx.getConvertConstArrayToPointerArgument();
51935193
if (array.isLValue())
51945194
array = B.createLoadCopy(loc, array);
51955195

51965196
} else {
5197-
converter = ctx.getConvertMutableArrayToPointerArgument(nullptr);
5197+
converter = ctx.getConvertMutableArrayToPointerArgument();
51985198
assert(array.isLValue());
51995199
}
52005200

@@ -5240,7 +5240,7 @@ std::pair<ManagedValue, ManagedValue>
52405240
SILGenFunction::emitStringToPointer(SILLocation loc, ManagedValue stringValue,
52415241
Type pointerType) {
52425242
auto &Ctx = getASTContext();
5243-
FuncDecl *converter = Ctx.getConvertConstStringToUTF8PointerArgument(nullptr);
5243+
FuncDecl *converter = Ctx.getConvertConstStringToUTF8PointerArgument();
52445244

52455245
// Invoke the conversion intrinsic, which will produce an owner-pointer pair.
52465246
auto subMap = pointerType->getContextSubstitutionMap(SGM.M.getSwiftModule(),
@@ -5261,7 +5261,7 @@ SILGenFunction::emitStringToPointer(SILLocation loc, ManagedValue stringValue,
52615261
RValue RValueEmitter::visitPointerToPointerExpr(PointerToPointerExpr *E,
52625262
SGFContext C) {
52635263
auto &Ctx = SGF.getASTContext();
5264-
auto converter = Ctx.getConvertPointerToPointerArgument(nullptr);
5264+
auto converter = Ctx.getConvertPointerToPointerArgument();
52655265

52665266
// Get the original pointer value, abstracted to the converter function's
52675267
// expected level.

lib/SILGen/SILGenLValue.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,13 +1754,13 @@ namespace {
17541754
SmallVector<Type, 2> typeArgs;
17551755
typeArgs.push_back(BaseFormalType);
17561756
if (TypeKind == KPTK_AnyKeyPath) {
1757-
projectFn = SGF.getASTContext().getGetAtAnyKeyPath(nullptr);
1757+
projectFn = SGF.getASTContext().getGetAtAnyKeyPath();
17581758
} else if (TypeKind == KPTK_PartialKeyPath) {
1759-
projectFn = SGF.getASTContext().getGetAtPartialKeyPath(nullptr);
1759+
projectFn = SGF.getASTContext().getGetAtPartialKeyPath();
17601760
} else if (TypeKind == KPTK_KeyPath ||
17611761
TypeKind == KPTK_WritableKeyPath ||
17621762
TypeKind == KPTK_ReferenceWritableKeyPath) {
1763-
projectFn = SGF.getASTContext().getGetAtKeyPath(nullptr);
1763+
projectFn = SGF.getASTContext().getGetAtKeyPath();
17641764

17651765
auto keyPathTy = keyPathValue.getType().castTo<BoundGenericType>();
17661766
assert(keyPathTy->getGenericArgs().size() == 2);
@@ -1790,10 +1790,10 @@ namespace {
17901790
auto keyPathValue = KeyPath;
17911791
FuncDecl *setFn;
17921792
if (TypeKind == KPTK_WritableKeyPath) {
1793-
setFn = SGF.getASTContext().getSetAtWritableKeyPath(nullptr);
1793+
setFn = SGF.getASTContext().getSetAtWritableKeyPath();
17941794
assert(base.isLValue());
17951795
} else if (TypeKind == KPTK_ReferenceWritableKeyPath) {
1796-
setFn = SGF.getASTContext().getSetAtReferenceWritableKeyPath(nullptr);
1796+
setFn = SGF.getASTContext().getSetAtReferenceWritableKeyPath();
17971797
base = makeBaseConsumableMaterializedRValue(SGF, loc, base);
17981798
} else {
17991799
llvm_unreachable("bad writable type kind");

lib/SILGen/SILGenPattern.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ static void emitDiagnoseOfUnexpectedEnumCaseValue(SILGenFunction &SGF,
25402540
Type subjectTy,
25412541
const EnumDecl *enumDecl) {
25422542
ASTContext &ctx = SGF.getASTContext();
2543-
auto diagnoseFailure = ctx.getDiagnoseUnexpectedEnumCaseValue(nullptr);
2543+
auto diagnoseFailure = ctx.getDiagnoseUnexpectedEnumCaseValue();
25442544
if (!diagnoseFailure) {
25452545
SGF.B.createBuiltinTrap(loc);
25462546
return;
@@ -2596,7 +2596,7 @@ static void emitDiagnoseOfUnexpectedEnumCase(SILGenFunction &SGF,
25962596
ManagedValue value,
25972597
Type subjectTy) {
25982598
ASTContext &ctx = SGF.getASTContext();
2599-
auto diagnoseFailure = ctx.getDiagnoseUnexpectedEnumCase(nullptr);
2599+
auto diagnoseFailure = ctx.getDiagnoseUnexpectedEnumCase();
26002600
if (!diagnoseFailure) {
26012601
SGF.B.createBuiltinTrap(loc);
26022602
return;

lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,13 @@ static StringRef extractExprText(const Expr *E, SourceManager &SM) {
335335
/// it is in the ifndef.
336336
#ifndef NDEBUG
337337
static bool isCallToStandardLibrarySwap(CallExpr *CE, ASTContext &Ctx) {
338-
if (CE->getCalledValue() == Ctx.getSwap(nullptr))
338+
if (CE->getCalledValue() == Ctx.getSwap())
339339
return true;
340340

341341
// Is the call module qualified, i.e. Swift.swap(&a[i], &[j)?
342342
if (auto *DSBIE = dyn_cast<DotSyntaxBaseIgnoredExpr>(CE->getFn())) {
343343
if (auto *DRE = dyn_cast<DeclRefExpr>(DSBIE->getRHS())) {
344-
return DRE->getDecl() == Ctx.getSwap(nullptr);
344+
return DRE->getDecl() == Ctx.getSwap();
345345
}
346346
}
347347

@@ -605,7 +605,7 @@ static bool isCallToStandardLibrarySwap(ApplyInst *AI, ASTContext &Ctx) {
605605
if (!FD)
606606
return false;
607607

608-
return FD == Ctx.getSwap(nullptr);
608+
return FD == Ctx.getSwap();
609609
}
610610

611611
static llvm::cl::opt<bool> ShouldAssertOnFailure(

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ SILInstruction *CastOptimizer::optimizeBridgedObjCToSwiftCast(
8181
// to _BridgedToObjectiveC can be proven.
8282
FuncDecl *BridgeFuncDecl =
8383
isConditional
84-
? M.getASTContext().getConditionallyBridgeFromObjectiveCBridgeable(
85-
nullptr)
86-
: M.getASTContext().getForceBridgeFromObjectiveCBridgeable(nullptr);
84+
? M.getASTContext().getConditionallyBridgeFromObjectiveCBridgeable()
85+
: M.getASTContext().getForceBridgeFromObjectiveCBridgeable();
8786

8887
assert(BridgeFuncDecl && "_forceBridgeFromObjectiveC should exist");
8988

0 commit comments

Comments
 (0)