Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 15cd450

Browse files
committed
Merge branch 'main' of github.com:apple/swift into tensorflow-stage
* 'main' of github.com:apple/swift: [Concurrency] Include Task.sleep(until:) and Task.yield() placeholders [Concurrency] Task cancellation and deadline stubs [NameLookup] Retain invalid decls when filtering via access path [CodeCompletion] Do not include decl completion in its own initializer [cxx-interop] Fix infinite recursion of PackExpansion type. [Parse] Remove unused HandleCodeCompletion param in parseType() SILVerifier: async functions can be called from async functions only Revert change for storedDiagnosticInfos [CodeCompletion] Fix crashes in TypeCheckASTNodeAtLocRequest [CodeCompletion] Avoid prechecking twice when typeCheckForCodeCompletion is given a non-applicable expression (NFC) SILMem2Reg : Delete phi args added by Mem2Reg if there are no uses [ownership] Add a new ReborrowVerifier SIL: Look through SILBoxType when checking for invalid non-escaping function value captures [SR-13639][Diag] Don't diagnose local type declarations as unreachable Change macro to DIAG in storedDiagnosticInfos array Import Foundation in cxx interop tests that explicitly use/bridge its types [DiagnosticsQol] Modify diagnostic macro into single DIAG [Clang Importer] Do not rely on being able to always import Foundation on-demand When importing Clang types. This is not an option with Explicit Module Builds. If the module being built does not (directly or transitively) depend on `Foundation`, then attempting to load it will produce an error because Implicit module loading is no longer allowed.. [Async CC] Auth'd parent context pointer.
2 parents 3f379b4 + 6c46841 commit 15cd450

File tree

58 files changed

+2559
-495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2559
-495
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ struct PointerAuthOptions : clang::PointerAuthOptions {
137137

138138
/// Resilient class stub initializer callbacks.
139139
PointerAuthSchema ResilientClassStubInitCallbacks;
140+
141+
/// The parent async context stored within a child async context.
142+
PointerAuthSchema AsyncContextParent;
140143
};
141144

142145
enum class JITDebugArtifact : unsigned {

include/swift/AST/Module.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,9 @@ class ModuleDecl : public DeclContext, public TypeDecl {
694694
/// \returns true if this module is the "SwiftOnoneSupport" module;
695695
bool isOnoneSupportModule() const;
696696

697+
/// \returns true if this module is the "Foundation" module;
698+
bool isFoundationModule() const;
699+
697700
/// \returns true if traversal was aborted, false otherwise.
698701
bool walk(ASTWalker &Walker);
699702

include/swift/AST/NameLookup.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,22 @@ class AccessFilteringDeclConsumer final : public VisibleDeclConsumer {
414414
DynamicLookupInfo dynamicLookupInfo = {}) override;
415415
};
416416

417+
/// Filters out decls that are not usable based on their source location, eg.
418+
/// a decl inside its own initializer or a non-type decl before its definition.
419+
class UsableFilteringDeclConsumer final : public VisibleDeclConsumer {
420+
const SourceManager &SM;
421+
SourceLoc Loc;
422+
VisibleDeclConsumer &ChainedConsumer;
423+
424+
public:
425+
UsableFilteringDeclConsumer(const SourceManager &SM, SourceLoc loc,
426+
VisibleDeclConsumer &consumer)
427+
: SM(SM), Loc(loc), ChainedConsumer(consumer) {}
428+
429+
void foundDecl(ValueDecl *D, DeclVisibilityKind reason,
430+
DynamicLookupInfo dynamicLookupInfo) override;
431+
};
432+
417433
/// Remove any declarations in the given set that were overridden by
418434
/// other declarations in that set.
419435
///

include/swift/Parse/Parser.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,15 +1176,12 @@ class Parser {
11761176

11771177
ParserResult<TypeRepr> parseType();
11781178
ParserResult<TypeRepr> parseType(Diag<> MessageID,
1179-
bool HandleCodeCompletion = true,
11801179
bool IsSILFuncDecl = false);
11811180

11821181
ParserResult<TypeRepr>
1183-
parseTypeSimpleOrComposition(Diag<> MessageID,
1184-
bool HandleCodeCompletion = true);
1182+
parseTypeSimpleOrComposition(Diag<> MessageID);
11851183

1186-
ParserResult<TypeRepr> parseTypeSimple(Diag<> MessageID,
1187-
bool HandleCodeCompletion = true);
1184+
ParserResult<TypeRepr> parseTypeSimple(Diag<> MessageID);
11881185

11891186
/// Parse layout constraint.
11901187
LayoutConstraint parseLayoutConstraint(Identifier LayoutConstraintID);

include/swift/SIL/LinearLifetimeChecker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class LinearLifetimeChecker {
5050
class ErrorBuilder;
5151

5252
private:
53+
friend class ReborrowVerifier;
5354
friend class SILOwnershipVerifier;
5455
friend class SILValueOwnershipChecker;
5556

include/swift/SIL/OwnershipUtils.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ bool isOwnedForwardingInstruction(SILInstruction *inst);
6666
/// previous terminator.
6767
bool isOwnedForwardingValue(SILValue value);
6868

69+
/// Returns true if the instruction is a 'reborrow'.
70+
bool isReborrowInstruction(const SILInstruction *inst);
71+
6972
class BorrowingOperandKind {
7073
public:
7174
enum Kind : uint8_t {
@@ -134,7 +137,7 @@ struct BorrowingOperand {
134137
return BorrowingOperand(*kind, op);
135138
}
136139

137-
void visitEndScopeInstructions(function_ref<void(Operand *)> func) const;
140+
void visitLocalEndScopeInstructions(function_ref<void(Operand *)> func) const;
138141

139142
/// Returns true if this borrow scope operand consumes guaranteed
140143
/// values and produces a new scope afterwards.
@@ -204,7 +207,7 @@ struct BorrowingOperand {
204207
/// \p errorFunction a callback that if non-null is passed an operand that
205208
/// triggers a mal-formed SIL error. This is just needed for the ownership
206209
/// verifier to emit good output.
207-
bool getImplicitUses(
210+
void getImplicitUses(
208211
SmallVectorImpl<Operand *> &foundUses,
209212
std::function<void(Operand *)> *errorFunction = nullptr) const;
210213

include/swift/SIL/SILValue.h

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class SILInstruction;
4040
class SILLocation;
4141
class DeadEndBlocks;
4242
class ValueBaseUseIterator;
43-
class ValueUseIterator;
43+
class ConsumingUseIterator;
44+
class NonConsumingUseIterator;
4445
class SILValue;
4546

4647
/// An enumeration which contains values for all the concrete ValueBase
@@ -263,10 +264,20 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
263264

264265
using use_iterator = ValueBaseUseIterator;
265266
using use_range = iterator_range<use_iterator>;
267+
using consuming_use_iterator = ConsumingUseIterator;
268+
using consuming_use_range = iterator_range<consuming_use_iterator>;
269+
using non_consuming_use_iterator = NonConsumingUseIterator;
270+
using non_consuming_use_range = iterator_range<non_consuming_use_iterator>;
266271

267272
inline use_iterator use_begin() const;
268273
inline use_iterator use_end() const;
269274

275+
inline consuming_use_iterator consuming_use_begin() const;
276+
inline consuming_use_iterator consuming_use_end() const;
277+
278+
inline non_consuming_use_iterator non_consuming_use_begin() const;
279+
inline non_consuming_use_iterator non_consuming_use_end() const;
280+
270281
/// Returns a range of all uses, which is useful for iterating over all uses.
271282
/// To ignore debug-info instructions use swift::getNonDebugUses instead
272283
/// (see comment in DebugUtils.h).
@@ -285,6 +296,12 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
285296
/// and it has a single consuming user. Returns .none otherwise.
286297
inline Operand *getSingleConsumingUse() const;
287298

299+
/// Returns a range of all consuming uses
300+
inline consuming_use_range getConsumingUses() const;
301+
302+
/// Returns a range of all non consuming uses
303+
inline non_consuming_use_range getNonConsumingUses() const;
304+
288305
template <class T>
289306
inline T *getSingleUserOfType() const;
290307

@@ -711,8 +728,10 @@ class Operand {
711728
TheValue->FirstUse = this;
712729
}
713730

731+
friend class ValueBase;
714732
friend class ValueBaseUseIterator;
715-
friend class ValueUseIterator;
733+
friend class ConsumingUseIterator;
734+
friend class NonConsumingUseIterator;
716735
template <unsigned N> friend class FixedOperandList;
717736
friend class TrailingOperandsList;
718737
};
@@ -729,6 +748,7 @@ using OperandValueArrayRef = ArrayRefView<Operand, SILValue, getSILValueType>;
729748
/// An iterator over all uses of a ValueBase.
730749
class ValueBaseUseIterator : public std::iterator<std::forward_iterator_tag,
731750
Operand*, ptrdiff_t> {
751+
protected:
732752
Operand *Cur;
733753
public:
734754
ValueBaseUseIterator() = default;
@@ -770,6 +790,74 @@ inline ValueBase::use_iterator ValueBase::use_end() const {
770790
inline iterator_range<ValueBase::use_iterator> ValueBase::getUses() const {
771791
return { use_begin(), use_end() };
772792
}
793+
794+
class ConsumingUseIterator : public ValueBaseUseIterator {
795+
public:
796+
explicit ConsumingUseIterator(Operand *cur) : ValueBaseUseIterator(cur) {}
797+
ConsumingUseIterator &operator++() {
798+
assert(Cur && "incrementing past end()!");
799+
assert(Cur->isConsumingUse());
800+
while ((Cur = Cur->NextUse)) {
801+
if (Cur->isConsumingUse())
802+
break;
803+
}
804+
return *this;
805+
}
806+
807+
ConsumingUseIterator operator++(int unused) {
808+
ConsumingUseIterator copy = *this;
809+
++*this;
810+
return copy;
811+
}
812+
};
813+
814+
inline ValueBase::consuming_use_iterator
815+
ValueBase::consuming_use_begin() const {
816+
auto cur = FirstUse;
817+
while (cur && !cur->isConsumingUse()) {
818+
cur = cur->NextUse;
819+
}
820+
return ValueBase::consuming_use_iterator(cur);
821+
}
822+
823+
inline ValueBase::consuming_use_iterator ValueBase::consuming_use_end() const {
824+
return ValueBase::consuming_use_iterator(nullptr);
825+
}
826+
827+
class NonConsumingUseIterator : public ValueBaseUseIterator {
828+
public:
829+
explicit NonConsumingUseIterator(Operand *cur) : ValueBaseUseIterator(cur) {}
830+
NonConsumingUseIterator &operator++() {
831+
assert(Cur && "incrementing past end()!");
832+
assert(!Cur->isConsumingUse());
833+
while ((Cur = Cur->NextUse)) {
834+
if (!Cur->isConsumingUse())
835+
break;
836+
}
837+
return *this;
838+
}
839+
840+
NonConsumingUseIterator operator++(int unused) {
841+
NonConsumingUseIterator copy = *this;
842+
++*this;
843+
return copy;
844+
}
845+
};
846+
847+
inline ValueBase::non_consuming_use_iterator
848+
ValueBase::non_consuming_use_begin() const {
849+
auto cur = FirstUse;
850+
while (cur && cur->isConsumingUse()) {
851+
cur = cur->NextUse;
852+
}
853+
return ValueBase::non_consuming_use_iterator(cur);
854+
}
855+
856+
inline ValueBase::non_consuming_use_iterator
857+
ValueBase::non_consuming_use_end() const {
858+
return ValueBase::non_consuming_use_iterator(nullptr);
859+
}
860+
773861
inline bool ValueBase::hasOneUse() const {
774862
auto I = use_begin(), E = use_end();
775863
if (I == E) return false;
@@ -806,6 +894,15 @@ inline Operand *ValueBase::getSingleConsumingUse() const {
806894
return result;
807895
}
808896

897+
inline ValueBase::consuming_use_range ValueBase::getConsumingUses() const {
898+
return {consuming_use_begin(), consuming_use_end()};
899+
}
900+
901+
inline ValueBase::non_consuming_use_range
902+
ValueBase::getNonConsumingUses() const {
903+
return {non_consuming_use_begin(), non_consuming_use_end()};
904+
}
905+
809906
inline bool ValueBase::hasTwoUses() const {
810907
auto iter = use_begin(), end = use_end();
811908
for (unsigned i = 0; i < 2; ++i) {

lib/AST/DiagnosticEngine.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,13 @@ static_assert(sizeof(storedDiagnosticInfos) / sizeof(StoredDiagnosticInfo) ==
9393
"array size mismatch");
9494

9595
static constexpr const char * const diagnosticStrings[] = {
96-
#define ERROR(ID, Options, Text, Signature) Text,
97-
#define WARNING(ID, Options, Text, Signature) Text,
98-
#define NOTE(ID, Options, Text, Signature) Text,
99-
#define REMARK(ID, Options, Text, Signature) Text,
96+
#define DIAG(KIND, ID, Options, Text, Signature) Text,
10097
#include "swift/AST/DiagnosticsAll.def"
10198
"<not a diagnostic>",
10299
};
103100

104101
static constexpr const char *const debugDiagnosticStrings[] = {
105-
#define ERROR(ID, Options, Text, Signature) Text " [" #ID "]",
106-
#define WARNING(ID, Options, Text, Signature) Text " [" #ID "]",
107-
#define NOTE(ID, Options, Text, Signature) Text " [" #ID "]",
108-
#define REMARK(ID, Options, Text, Signature) Text " [" #ID "]",
102+
#define DIAG(KIND, ID, Options, Text, Signature) Text " [" #ID "]",
109103
#include "swift/AST/DiagnosticsAll.def"
110104
"<not a diagnostic>",
111105
};

lib/AST/Module.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,10 @@ bool ModuleDecl::isOnoneSupportModule() const {
13361336
return !getParent() && getName().str() == SWIFT_ONONE_SUPPORT;
13371337
}
13381338

1339+
bool ModuleDecl::isFoundationModule() const {
1340+
return !getParent() && getName() == getASTContext().Id_Foundation;
1341+
}
1342+
13391343
bool ModuleDecl::isBuiltinModule() const {
13401344
return this == getASTContext().TheBuiltinModule;
13411345
}

lib/AST/NameLookup.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,40 @@ void DebuggerClient::anchor() {}
138138
void AccessFilteringDeclConsumer::foundDecl(
139139
ValueDecl *D, DeclVisibilityKind reason,
140140
DynamicLookupInfo dynamicLookupInfo) {
141-
if (D->hasInterfaceType() && D->isInvalid())
142-
return;
143141
if (!D->isAccessibleFrom(DC))
144142
return;
145143

146144
ChainedConsumer.foundDecl(D, reason, dynamicLookupInfo);
147145
}
148146

147+
void UsableFilteringDeclConsumer::foundDecl(ValueDecl *D,
148+
DeclVisibilityKind reason, DynamicLookupInfo dynamicLookupInfo) {
149+
// Skip when Loc is within the decl's own initializer
150+
if (auto *VD = dyn_cast<VarDecl>(D)) {
151+
if (auto *init = VD->getParentInitializer()) {
152+
auto initRange = init->getSourceRange();
153+
if (initRange.isValid() && SM.rangeContainsTokenLoc(initRange, Loc))
154+
return;
155+
}
156+
}
157+
158+
switch (reason) {
159+
case DeclVisibilityKind::LocalVariable:
160+
// Skip if Loc is before the found decl, unless its a TypeDecl (whose use
161+
// before its declaration is still allowed)
162+
if (!isa<TypeDecl>(D) && !SM.isBeforeInBuffer(D->getLoc(), Loc))
163+
return;
164+
break;
165+
default:
166+
// The rest of the file is currently skipped, so no need to check
167+
// decl location for VisibleAtTopLevel. Other visibility kinds are always
168+
// usable
169+
break;
170+
}
171+
172+
ChainedConsumer.foundDecl(D, reason, dynamicLookupInfo);
173+
}
174+
149175
void LookupResultEntry::print(llvm::raw_ostream& out) const {
150176
getValueDecl()->print(out);
151177
if (auto dc = getBaseDecl()) {

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5696,8 +5696,7 @@ namespace {
56965696
}
56975697

56985698
static bool conformsToProtocolInOriginalModule(NominalTypeDecl *nominal,
5699-
const ProtocolDecl *proto,
5700-
ModuleDecl *foundationModule) {
5699+
const ProtocolDecl *proto) {
57015700
auto &ctx = nominal->getASTContext();
57025701

57035702
if (inheritanceListContainsProtocol(nominal, proto))
@@ -5720,7 +5719,7 @@ static bool conformsToProtocolInOriginalModule(NominalTypeDecl *nominal,
57205719
for (ExtensionDecl *extension : nominal->getExtensions()) {
57215720
ModuleDecl *extensionModule = extension->getParentModule();
57225721
if (extensionModule != originalModule && extensionModule != overlayModule &&
5723-
extensionModule != foundationModule) {
5722+
!extensionModule->isFoundationModule()) {
57245723
continue;
57255724
}
57265725
if (inheritanceListContainsProtocol(extension, proto))
@@ -5815,8 +5814,7 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl,
58155814

58165815
// Break circularity by only looking for declared conformances in the
58175816
// original module, or possibly its overlay.
5818-
if (conformsToProtocolInOriginalModule(computedNominal, proto,
5819-
Impl.tryLoadFoundationModule())) {
5817+
if (conformsToProtocolInOriginalModule(computedNominal, proto)) {
58205818
synthesizedProtocols.push_back(kind);
58215819
return true;
58225820
}

0 commit comments

Comments
 (0)