Skip to content

Lazy synthesis of implicit constructors in non-primary files #21133

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 2 commits into from
Dec 8, 2018
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
14 changes: 7 additions & 7 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ class ASTContext final {

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

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

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

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

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

/// Retrieve the declaration of Swift._unimplementedInitializer.
FuncDecl *getUnimplementedInitializerDecl(LazyResolver *resolver) const;
FuncDecl *getUnimplementedInitializerDecl() const;

/// Retrieve the declaration of Swift._undefined.
FuncDecl *getUndefinedDecl(LazyResolver *resolver) const;
FuncDecl *getUndefinedDecl() const;

// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast.
FuncDecl *getIsOSVersionAtLeastDecl(LazyResolver *resolver) const;
FuncDecl *getIsOSVersionAtLeastDecl() const;

/// Look for the declaration with the given name within the
/// Swift module.
Expand Down
51 changes: 23 additions & 28 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,13 +911,12 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {

/// Find the implementation for the given "intrinsic" library function.
static FuncDecl *findLibraryIntrinsic(const ASTContext &ctx,
StringRef name,
LazyResolver *resolver) {
StringRef name) {
SmallVector<ValueDecl *, 1> results;
ctx.lookupInSwiftModule(name, results);
if (results.size() == 1) {
if (auto FD = dyn_cast<FuncDecl>(results.front())) {
if (resolver)
if (auto *resolver = ctx.getLazyResolver())
resolver->resolveDeclSignature(FD);
return FD;
}
Expand Down Expand Up @@ -1169,14 +1168,12 @@ FuncDecl *ASTContext::getArrayReserveCapacityDecl() const {
}

FuncDecl *
ASTContext::getUnimplementedInitializerDecl(LazyResolver *resolver) const {
ASTContext::getUnimplementedInitializerDecl() const {
if (getImpl().UnimplementedInitializerDecl)
return getImpl().UnimplementedInitializerDecl;

// Look for the function.
Type input, output;
auto decl = findLibraryIntrinsic(*this, "_unimplementedInitializer",
resolver);
auto decl = findLibraryIntrinsic(*this, "_unimplementedInitializer");
if (!decl)
return nullptr;

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

FuncDecl *
ASTContext::getUndefinedDecl(LazyResolver *resolver) const {
ASTContext::getUndefinedDecl() const {
if (getImpl().UndefinedDecl)
return getImpl().UndefinedDecl;

// Look for the function.
CanType input, output;
auto decl = findLibraryIntrinsic(*this, "_undefined", resolver);
auto decl = findLibraryIntrinsic(*this, "_undefined");
if (!decl)
return nullptr;

getImpl().UndefinedDecl = decl;
return decl;
}

FuncDecl *ASTContext::getIsOSVersionAtLeastDecl(LazyResolver *resolver) const {
FuncDecl *ASTContext::getIsOSVersionAtLeastDecl() const {
if (getImpl().IsOSVersionAtLeastDecl)
return getImpl().IsOSVersionAtLeastDecl;

// Look for the function.
Type input, output;
auto decl =
findLibraryIntrinsic(*this, "_stdlib_isOSVersionAtLeast", resolver);
findLibraryIntrinsic(*this, "_stdlib_isOSVersionAtLeast");
if (!decl)
return nullptr;

Expand Down Expand Up @@ -1333,44 +1328,44 @@ ASTContext::associateInfixOperators(PrecedenceGroupDecl *left,

// Find library intrinsic function.
static FuncDecl *findLibraryFunction(const ASTContext &ctx, FuncDecl *&cache,
StringRef name, LazyResolver *resolver) {
StringRef name) {
if (cache) return cache;

// Look for a generic function.
cache = findLibraryIntrinsic(ctx, name, resolver);
cache = findLibraryIntrinsic(ctx, name);
return cache;
}

#define FUNC_DECL(Name, Id) \
FuncDecl *ASTContext::get##Name(LazyResolver *resolver) const { \
return findLibraryFunction(*this, getImpl().Get##Name, Id, resolver); \
FuncDecl *ASTContext::get##Name() const { \
return findLibraryFunction(*this, getImpl().Get##Name, Id); \
}
#include "swift/AST/KnownDecls.def"

bool ASTContext::hasOptionalIntrinsics(LazyResolver *resolver) const {
bool ASTContext::hasOptionalIntrinsics() const {
return getOptionalDecl() &&
getOptionalSomeDecl() &&
getOptionalNoneDecl() &&
getDiagnoseUnexpectedNilOptional(resolver);
getDiagnoseUnexpectedNilOptional();
}

bool ASTContext::hasPointerArgumentIntrinsics(LazyResolver *resolver) const {
bool ASTContext::hasPointerArgumentIntrinsics() const {
return getUnsafeMutableRawPointerDecl()
&& getUnsafeRawPointerDecl()
&& getUnsafeMutablePointerDecl()
&& getUnsafePointerDecl()
&& (!LangOpts.EnableObjCInterop || getAutoreleasingUnsafeMutablePointerDecl())
&& getConvertPointerToPointerArgument(resolver)
&& getConvertMutableArrayToPointerArgument(resolver)
&& getConvertConstArrayToPointerArgument(resolver)
&& getConvertConstStringToUTF8PointerArgument(resolver)
&& getConvertInOutToPointerArgument(resolver);
&& getConvertPointerToPointerArgument()
&& getConvertMutableArrayToPointerArgument()
&& getConvertConstArrayToPointerArgument()
&& getConvertConstStringToUTF8PointerArgument()
&& getConvertInOutToPointerArgument();
}

bool ASTContext::hasArrayLiteralIntrinsics(LazyResolver *resolver) const {
bool ASTContext::hasArrayLiteralIntrinsics() const {
return getArrayDecl()
&& getAllocateUninitializedArray(resolver)
&& getDeallocateUninitializedArray(resolver);
&& getAllocateUninitializedArray()
&& getDeallocateUninitializedArray();
}

void ASTContext::addExternalDecl(Decl *decl) {
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static FuncDecl *diagnoseMissingIntrinsic(SILGenModule &sgm,

#define FUNC_DECL(NAME, ID) \
FuncDecl *SILGenModule::get##NAME(SILLocation loc) { \
if (auto fn = getASTContext().get##NAME(nullptr)) \
if (auto fn = getASTContext().get##NAME()) \
return fn; \
return diagnoseMissingIntrinsic(*this, loc, ID); \
}
Expand Down
4 changes: 2 additions & 2 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5579,7 +5579,7 @@ SILGenFunction::emitUninitializedArrayAllocation(Type ArrayTy,
SILValue Length,
SILLocation Loc) {
auto &Ctx = getASTContext();
auto allocate = Ctx.getAllocateUninitializedArray(nullptr);
auto allocate = Ctx.getAllocateUninitializedArray();

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

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

Expand Down
4 changes: 2 additions & 2 deletions lib/SILGen/SILGenBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ static ManagedValue emitNativeToCBridgedNonoptionalValue(SILGenFunction &SGF,

// Call into the stdlib intrinsic.
if (auto bridgeAnything =
SGF.getASTContext().getBridgeAnythingToObjectiveC(nullptr)) {
SGF.getASTContext().getBridgeAnythingToObjectiveC()) {
auto *genericSig = bridgeAnything->getGenericSignature();
auto subMap = SubstitutionMap::get(
genericSig,
Expand Down Expand Up @@ -1098,7 +1098,7 @@ static ManagedValue emitCBridgedToNativeValue(SILGenFunction &SGF,
auto optionalMV =
SGF.B.createUncheckedBitCast(loc, v, optionalBridgedTy);
return SGF.emitApplyOfLibraryIntrinsic(loc,
SGF.getASTContext().getBridgeAnyObjectToAny(nullptr),
SGF.getASTContext().getBridgeAnyObjectToAny(),
SubstitutionMap(), optionalMV, C)
.getAsSingleValue(SGF, loc);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/SILGen/SILGenConvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ SILGenFunction::emitPreconditionOptionalHasValue(SILLocation loc,

// Call the standard library implementation of _diagnoseUnexpectedNilOptional.
if (auto diagnoseFailure =
getASTContext().getDiagnoseUnexpectedNilOptional(nullptr)) {
getASTContext().getDiagnoseUnexpectedNilOptional()) {
auto args = emitSourceLocationArgs(loc.getSourceLoc(), loc);

auto i1Ty = SILType::getBuiltinIntegerType(1, getASTContext());
Expand Down Expand Up @@ -481,7 +481,7 @@ SILGenFunction::emitPointerToPointer(SILLocation loc,
CanType inputType,
CanType outputType,
SGFContext C) {
auto converter = getASTContext().getConvertPointerToPointerArgument(nullptr);
auto converter = getASTContext().getConvertPointerToPointerArgument();

auto origValue = input;
if (silConv.useLoweredAddresses()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ SILValue SILGenFunction::emitOSVersionRangeCheck(SILLocation loc,

// Emit call to _stdlib_isOSVersionAtLeast(major, minor, patch)
FuncDecl *versionQueryDecl =
getASTContext().getIsOSVersionAtLeastDecl(nullptr);
getASTContext().getIsOSVersionAtLeastDecl();
assert(versionQueryDecl);

auto silDeclRef = SILDeclRef(versionQueryDecl);
Expand Down
12 changes: 6 additions & 6 deletions lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ void SILGenFunction::ForceTryEmission::finish() {
// Otherwise, we need to emit it.
SILGenSavedInsertionPoint scope(SGF, catchBB, FunctionSection::Postmatter);

if (auto diagnoseError = SGF.getASTContext().getDiagnoseUnexpectedError(nullptr)) {
if (auto diagnoseError = SGF.getASTContext().getDiagnoseUnexpectedError()) {
ASTContext &ctx = SGF.getASTContext();
auto error = SGF.B.createOwnedPhiArgument(SILType::getExceptionType(ctx));
auto args = SGF.emitSourceLocationArgs(Loc->getExclaimLoc(), Loc);
Expand Down Expand Up @@ -5137,7 +5137,7 @@ ManagedValue SILGenFunction::emitLValueToPointer(SILLocation loc, LValue &&lv,

// Invoke the conversion intrinsic.
FuncDecl *converter =
getASTContext().getConvertInOutToPointerArgument(nullptr);
getASTContext().getConvertInOutToPointerArgument();

auto pointerType = pointerInfo.PointerType;
auto subMap = pointerType->getContextSubstitutionMap(SGM.M.getSwiftModule(),
Expand Down Expand Up @@ -5191,12 +5191,12 @@ SILGenFunction::emitArrayToPointer(SILLocation loc, ManagedValue array,
FuncDecl *converter;
if (accessInfo.AccessKind != SGFAccessKind::ReadWrite) {
assert(isReadAccess(accessInfo.AccessKind));
converter = ctx.getConvertConstArrayToPointerArgument(nullptr);
converter = ctx.getConvertConstArrayToPointerArgument();
if (array.isLValue())
array = B.createLoadCopy(loc, array);

} else {
converter = ctx.getConvertMutableArrayToPointerArgument(nullptr);
converter = ctx.getConvertMutableArrayToPointerArgument();
assert(array.isLValue());
}

Expand Down Expand Up @@ -5242,7 +5242,7 @@ std::pair<ManagedValue, ManagedValue>
SILGenFunction::emitStringToPointer(SILLocation loc, ManagedValue stringValue,
Type pointerType) {
auto &Ctx = getASTContext();
FuncDecl *converter = Ctx.getConvertConstStringToUTF8PointerArgument(nullptr);
FuncDecl *converter = Ctx.getConvertConstStringToUTF8PointerArgument();

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

// Get the original pointer value, abstracted to the converter function's
// expected level.
Expand Down
10 changes: 5 additions & 5 deletions lib/SILGen/SILGenLValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1754,13 +1754,13 @@ namespace {
SmallVector<Type, 2> typeArgs;
typeArgs.push_back(BaseFormalType);
if (TypeKind == KPTK_AnyKeyPath) {
projectFn = SGF.getASTContext().getGetAtAnyKeyPath(nullptr);
projectFn = SGF.getASTContext().getGetAtAnyKeyPath();
} else if (TypeKind == KPTK_PartialKeyPath) {
projectFn = SGF.getASTContext().getGetAtPartialKeyPath(nullptr);
projectFn = SGF.getASTContext().getGetAtPartialKeyPath();
} else if (TypeKind == KPTK_KeyPath ||
TypeKind == KPTK_WritableKeyPath ||
TypeKind == KPTK_ReferenceWritableKeyPath) {
projectFn = SGF.getASTContext().getGetAtKeyPath(nullptr);
projectFn = SGF.getASTContext().getGetAtKeyPath();

auto keyPathTy = keyPathValue.getType().castTo<BoundGenericType>();
assert(keyPathTy->getGenericArgs().size() == 2);
Expand Down Expand Up @@ -1790,10 +1790,10 @@ namespace {
auto keyPathValue = KeyPath;
FuncDecl *setFn;
if (TypeKind == KPTK_WritableKeyPath) {
setFn = SGF.getASTContext().getSetAtWritableKeyPath(nullptr);
setFn = SGF.getASTContext().getSetAtWritableKeyPath();
assert(base.isLValue());
} else if (TypeKind == KPTK_ReferenceWritableKeyPath) {
setFn = SGF.getASTContext().getSetAtReferenceWritableKeyPath(nullptr);
setFn = SGF.getASTContext().getSetAtReferenceWritableKeyPath();
base = makeBaseConsumableMaterializedRValue(SGF, loc, base);
} else {
llvm_unreachable("bad writable type kind");
Expand Down
4 changes: 2 additions & 2 deletions lib/SILGen/SILGenPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ static void emitDiagnoseOfUnexpectedEnumCaseValue(SILGenFunction &SGF,
Type subjectTy,
const EnumDecl *enumDecl) {
ASTContext &ctx = SGF.getASTContext();
auto diagnoseFailure = ctx.getDiagnoseUnexpectedEnumCaseValue(nullptr);
auto diagnoseFailure = ctx.getDiagnoseUnexpectedEnumCaseValue();
if (!diagnoseFailure) {
SGF.B.createBuiltinTrap(loc);
return;
Expand Down Expand Up @@ -2596,7 +2596,7 @@ static void emitDiagnoseOfUnexpectedEnumCase(SILGenFunction &SGF,
ManagedValue value,
Type subjectTy) {
ASTContext &ctx = SGF.getASTContext();
auto diagnoseFailure = ctx.getDiagnoseUnexpectedEnumCase(nullptr);
auto diagnoseFailure = ctx.getDiagnoseUnexpectedEnumCase();
if (!diagnoseFailure) {
SGF.B.createBuiltinTrap(loc);
return;
Expand Down
6 changes: 3 additions & 3 deletions lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@ static StringRef extractExprText(const Expr *E, SourceManager &SM) {
/// it is in the ifndef.
#ifndef NDEBUG
static bool isCallToStandardLibrarySwap(CallExpr *CE, ASTContext &Ctx) {
if (CE->getCalledValue() == Ctx.getSwap(nullptr))
if (CE->getCalledValue() == Ctx.getSwap())
return true;

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

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

return FD == Ctx.getSwap(nullptr);
return FD == Ctx.getSwap();
}

static llvm::cl::opt<bool> ShouldAssertOnFailure(
Expand Down
5 changes: 2 additions & 3 deletions lib/SILOptimizer/Utils/CastOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ SILInstruction *CastOptimizer::optimizeBridgedObjCToSwiftCast(
// to _BridgedToObjectiveC can be proven.
FuncDecl *BridgeFuncDecl =
isConditional
? M.getASTContext().getConditionallyBridgeFromObjectiveCBridgeable(
nullptr)
: M.getASTContext().getForceBridgeFromObjectiveCBridgeable(nullptr);
? M.getASTContext().getConditionallyBridgeFromObjectiveCBridgeable()
: M.getASTContext().getForceBridgeFromObjectiveCBridgeable();

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

Expand Down
Loading