Skip to content

Commit 4a2aa6b

Browse files
authored
---
yaml --- r: 341243 b: refs/heads/rxwei-patch-1 c: 946587c h: refs/heads/master i: 341241: a1b6308 341239: a9f4604
1 parent b061b96 commit 4a2aa6b

Some content is hidden

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

46 files changed

+2126
-1140
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: aee0b0b23a80d58c7803f0ff26f78338dcc955b5
1018+
refs/heads/rxwei-patch-1: 946587c61bb91d504bcda40db6dd34c713e63a0f
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/include/swift/AST/ASTScope.h

Lines changed: 126 additions & 107 deletions
Large diffs are not rendered by default.

branches/rxwei-patch-1/include/swift/AST/AnyFunctionRef.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ class AnyFunctionRef {
116116
return TheFunction.dyn_cast<AbstractClosureExpr*>();
117117
}
118118

119+
bool isDeferBody() const {
120+
if (auto *fd = dyn_cast_or_null<FuncDecl>(getAbstractFunctionDecl()))
121+
return fd->isDeferBody();
122+
return false;
123+
}
124+
119125
/// Return true if this closure is passed as an argument to a function and is
120126
/// known not to escape from that function. In this case, captures can be
121127
/// more efficient.

branches/rxwei-patch-1/include/swift/AST/CaptureInfo.h

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_AST_CAPTURE_INFO_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "swift/Basic/SourceLoc.h"
1718
#include "swift/AST/TypeAlignments.h"
1819
#include "llvm/ADT/ArrayRef.h"
1920
#include "llvm/ADT/PointerIntPair.h"
@@ -44,8 +45,9 @@ class CapturedValue {
4445

4546
private:
4647
Storage Value;
48+
SourceLoc Loc;
4749

48-
explicit CapturedValue(Storage V) : Value(V) {}
50+
explicit CapturedValue(Storage V, SourceLoc Loc) : Value(V), Loc(Loc) {}
4951

5052
public:
5153
friend struct llvm::DenseMapInfo<CapturedValue>;
@@ -61,12 +63,14 @@ class CapturedValue {
6163
IsNoEscape = 1 << 1
6264
};
6365

64-
CapturedValue(llvm::PointerUnion<ValueDecl*, OpaqueValueExpr*> Ptr,
65-
unsigned Flags)
66-
: Value(Ptr, Flags) {}
66+
CapturedValue(ValueDecl *Val, unsigned Flags, SourceLoc Loc)
67+
: Value(Val, Flags), Loc(Loc) {}
68+
69+
CapturedValue(OpaqueValueExpr *Val, unsigned Flags)
70+
: Value(Val, Flags), Loc(SourceLoc()) {}
6771

6872
static CapturedValue getDynamicSelfMetadata() {
69-
return CapturedValue((ValueDecl *)nullptr, 0);
73+
return CapturedValue((ValueDecl *)nullptr, 0, SourceLoc());
7074
}
7175

7276
bool isDirect() const { return Value.getInt() & IsDirect; }
@@ -80,7 +84,9 @@ class CapturedValue {
8084
CapturedValue mergeFlags(CapturedValue cv) {
8185
assert(Value.getPointer() == cv.Value.getPointer() &&
8286
"merging flags on two different value decls");
83-
return CapturedValue(Value.getPointer(), getFlags() & cv.getFlags());
87+
return CapturedValue(
88+
Storage(Value.getPointer(), getFlags() & cv.getFlags()),
89+
Loc);
8490
}
8591

8692
ValueDecl *getDecl() const {
@@ -95,49 +101,13 @@ class CapturedValue {
95101
return Value.getPointer().dyn_cast<OpaqueValueExpr *>();
96102
}
97103

98-
unsigned getFlags() const { return Value.getInt(); }
99-
100-
bool operator==(CapturedValue RHS) const {
101-
return Value == RHS.Value;
102-
}
103-
104-
bool operator!=(CapturedValue RHS) const {
105-
return Value != RHS.Value;
106-
}
104+
SourceLoc getLoc() const { return Loc; }
107105

108-
bool operator<(CapturedValue RHS) const {
109-
return Value < RHS.Value;
110-
}
106+
unsigned getFlags() const { return Value.getInt(); }
111107
};
112108

113109
} // end swift namespace
114110

115-
namespace llvm {
116-
117-
template <> struct DenseMapInfo<swift::CapturedValue> {
118-
using CapturedValue = swift::CapturedValue;
119-
120-
using PtrIntPairDenseMapInfo = DenseMapInfo<CapturedValue::Storage>;
121-
122-
static inline swift::CapturedValue getEmptyKey() {
123-
return CapturedValue{PtrIntPairDenseMapInfo::getEmptyKey()};
124-
}
125-
126-
static inline CapturedValue getTombstoneKey() {
127-
return CapturedValue{PtrIntPairDenseMapInfo::getTombstoneKey()};
128-
}
129-
130-
static unsigned getHashValue(const CapturedValue &Val) {
131-
return PtrIntPairDenseMapInfo::getHashValue(Val.Value);
132-
}
133-
134-
static bool isEqual(const CapturedValue &LHS, const CapturedValue &RHS) {
135-
return PtrIntPairDenseMapInfo::isEqual(LHS.Value, RHS.Value);
136-
}
137-
};
138-
139-
} // end llvm namespace
140-
141111
namespace swift {
142112

143113
class DynamicSelfType;

branches/rxwei-patch-1/include/swift/AST/DiagnosticsSIL.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ ERROR(unsupported_c_function_pointer_conversion,none,
116116
ERROR(objc_selector_malformed,none,"the type ObjectiveC.Selector is malformed",
117117
())
118118

119+
// Capture before declaration diagnostics.
120+
ERROR(capture_before_declaration,none,
121+
"closure captures %0 before it is declared", (Identifier))
122+
ERROR(capture_before_declaration_defer,none,
123+
"'defer' block captures %0 before it is declared", (Identifier))
124+
NOTE(captured_value_declared_here,none,
125+
"captured value declared here", ())
126+
119127
// Invalid escaping capture diagnostics.
120128
ERROR(escaping_inout_capture,none,
121129
"escaping closure captures 'inout' parameter %0", (Identifier))

branches/rxwei-patch-1/include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,14 +3016,6 @@ ERROR(method_call_in_closure_without_explicit_self,none,
30163016
ERROR(implicit_use_of_self_in_closure,none,
30173017
"implicit use of 'self' in closure; use 'self.' to make"
30183018
" capture semantics explicit", ())
3019-
ERROR(capture_before_declaration,none,
3020-
"cannot capture %0 before it is declared", (Identifier))
3021-
ERROR(transitive_capture_before_declaration,none,
3022-
"cannot capture %0, which would use %1 before it is declared",
3023-
(Identifier, Identifier))
3024-
NOTE(transitive_capture_through_here,none,
3025-
"%0, declared here, captures %1",
3026-
(Identifier, Identifier))
30273019

30283020
WARNING(recursive_accessor_reference,none,
30293021
"attempting to %select{access|modify}1 %0 within its own "

branches/rxwei-patch-1/include/swift/AST/NameLookup.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -592,17 +592,18 @@ class AbstractASTScopeDeclConsumer {
592592
/// Takes an array in order to batch the consumption before setting
593593
/// IndexOfFirstOuterResult when necessary.
594594
virtual bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
595-
Optional<bool> isCascadingUse,
596595
NullablePtr<DeclContext> baseDC = nullptr) = 0;
597596

598597
/// Eventually this functionality should move into ASTScopeLookup
599-
virtual std::pair<bool, Optional<bool>>
600-
lookupInSelfType(NullablePtr<DeclContext> selfDC, DeclContext *const scopeDC,
601-
NominalTypeDecl *const nominal,
602-
Optional<bool> isCascadingUse) = 0;
598+
virtual bool
599+
lookInMembers(NullablePtr<DeclContext> selfDC, DeclContext *const scopeDC,
600+
NominalTypeDecl *const nominal,
601+
function_ref<bool(Optional<bool>)> calculateIsCascadingUse) = 0;
603602

604603
#ifndef NDEBUG
605-
virtual void stopForDebuggingIfTargetLookup() = 0;
604+
virtual void startingNextLookupStep() = 0;
605+
virtual void finishingLookup(std::string) const = 0;
606+
virtual bool isTargetLookup() const = 0;
606607
#endif
607608
};
608609

@@ -615,19 +616,19 @@ class ASTScopeDeclGatherer : public AbstractASTScopeDeclConsumer {
615616
virtual ~ASTScopeDeclGatherer() = default;
616617

617618
bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
618-
Optional<bool> isCascadingUse,
619619
NullablePtr<DeclContext> baseDC = nullptr) override;
620620

621621
/// Eventually this functionality should move into ASTScopeLookup
622-
std::pair<bool, Optional<bool>>
623-
lookupInSelfType(NullablePtr<DeclContext>, DeclContext *const,
624-
NominalTypeDecl *const,
625-
Optional<bool> isCascadingUse) override {
626-
return std::make_pair(false, isCascadingUse);
622+
bool lookInMembers(NullablePtr<DeclContext>, DeclContext *const,
623+
NominalTypeDecl *const,
624+
function_ref<bool(Optional<bool>)>) override {
625+
return false;
627626
}
628627

629628
#ifndef NDEBUG
630-
void stopForDebuggingIfTargetLookup() override {}
629+
void startingNextLookupStep() override {}
630+
void finishingLookup(std::string) const override {}
631+
bool isTargetLookup() const override { return false; }
631632
#endif
632633

633634
ArrayRef<ValueDecl *> getDecls() { return values; }
@@ -641,12 +642,17 @@ class ASTScope {
641642

642643
public:
643644
ASTScope(SourceFile *);
644-
static Optional<bool>
645+
646+
/// \return the scopes traversed
647+
static llvm::SmallVector<const ast_scope::ASTScopeImpl *, 0>
645648
unqualifiedLookup(SourceFile *, DeclName, SourceLoc,
646649
const DeclContext *startingContext,
647-
Optional<bool> isCascadingUse,
648650
namelookup::AbstractASTScopeDeclConsumer &);
649651

652+
static Optional<bool>
653+
computeIsCascadingUse(ArrayRef<const ast_scope::ASTScopeImpl *> history,
654+
Optional<bool> initialIsCascadingUse);
655+
650656
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
651657
"only for use within the debugger");
652658
void print(llvm::raw_ostream &) const;

branches/rxwei-patch-1/include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,11 @@ namespace swift {
247247
bool EnableDeserializationRecovery = true;
248248

249249
/// Should we use \c ASTScope-based resolution for unqualified name lookup?
250+
/// Default is in \c ParseLangArgs
251+
///
252+
/// This is a staging flag; eventually it will be removed.
250253
bool EnableASTScopeLookup = false;
251-
254+
252255
/// Someday, ASTScopeLookup will supplant lookup in the parser
253256
bool DisableParserLookup = false;
254257

branches/rxwei-patch-1/include/swift/Option/Options.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,12 @@ def enable_astscope_lookup : Flag<["-"], "enable-astscope-lookup">,
869869
Flags<[FrontendOption]>,
870870
HelpText<"Enable ASTScope-based unqualified name lookup">;
871871

872-
def disable_parser_lookup : Flag<["-"], "disable_parser_lookup">,
872+
def disable_astscope_lookup : Flag<["-"], "disable-astscope-lookup">,
873+
Flags<[FrontendOption]>,
874+
HelpText<"Disable ASTScope-based unqualified name lookup">;
875+
876+
def disable_parser_lookup : Flag<["-"], "disable-parser-lookup">,
877+
Flags<[FrontendOption]>,
873878
HelpText<"Disable parser lookup & use ast scope lookup only (experimental)">;
874879

875880
def index_file : Flag<["-"], "index-file">,

branches/rxwei-patch-1/include/swift/SIL/TypeLowering.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,6 @@ struct SILConstantInfo {
568568

569569
/// Different ways in which a function can capture context.
570570
enum class CaptureKind {
571-
/// No context arguments are necessary.
572-
None,
573571
/// A local value captured as a mutable box.
574572
Box,
575573
/// A local value captured as a single pointer to storage (formed with

branches/rxwei-patch-1/lib/AST/ASTScope.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ using namespace ast_scope;
3737

3838
#pragma mark ASTScope
3939

40-
41-
Optional<bool> ASTScope::unqualifiedLookup(
40+
llvm::SmallVector<const ASTScopeImpl *, 0> ASTScope::unqualifiedLookup(
4241
SourceFile *SF, DeclName name, SourceLoc loc,
43-
const DeclContext *startingContext, Optional<bool> isCascadingUse,
42+
const DeclContext *startingContext,
4443
namelookup::AbstractASTScopeDeclConsumer &consumer) {
4544
return ASTScopeImpl::unqualifiedLookup(SF, name, loc, startingContext,
46-
isCascadingUse, consumer);
45+
consumer);
46+
}
47+
48+
Optional<bool> ASTScope::computeIsCascadingUse(
49+
ArrayRef<const ast_scope::ASTScopeImpl *> history,
50+
Optional<bool> initialIsCascadingUse) {
51+
return ASTScopeImpl::computeIsCascadingUse(history, initialIsCascadingUse);
4752
}
4853

4954
void ASTScope::dump() const { impl->dump(); }
@@ -108,6 +113,20 @@ Stmt *LabeledConditionalStmtScope::getStmt() const {
108113
return getLabeledConditionalStmt();
109114
}
110115

116+
bool AbstractFunctionBodyScope::isAMethod(
117+
const AbstractFunctionDecl *const afd) {
118+
// What makes this interesting is that a method named "init" which is not
119+
// in a nominal type or extension decl body still gets an implicit self
120+
// parameter (even though the program is illegal).
121+
// So when choosing between creating a MethodBodyScope and a
122+
// PureFunctionBodyScope do we go by the enclosing Decl (i.e.
123+
// "afd->getDeclContext()->isTypeContext()") or by
124+
// "bool(afd->getImplicitSelfDecl())"?
125+
//
126+
// Since the code uses \c getImplicitSelfDecl, use that.
127+
return afd->getImplicitSelfDecl();
128+
}
129+
111130
#pragma mark getLabeledConditionalStmt
112131
LabeledConditionalStmt *IfStmtScope::getLabeledConditionalStmt() const {
113132
return stmt;
@@ -132,6 +151,14 @@ ASTContext &ASTScopeImpl::getASTContext() const {
132151

133152
#pragma mark getDeclContext
134153

154+
NullablePtr<DeclContext> ASTScopeImpl::getDeclContext() const {
155+
return nullptr;
156+
}
157+
158+
NullablePtr<DeclContext> ASTSourceFileScope::getDeclContext() const {
159+
return NullablePtr<DeclContext>(SF);
160+
}
161+
135162
NullablePtr<DeclContext> GenericTypeOrExtensionScope::getDeclContext() const {
136163
return getGenericContext();
137164
}
@@ -168,6 +195,10 @@ NullablePtr<DeclContext> AttachedPropertyWrapperScope::getDeclContext() const {
168195
.getInitContext();
169196
}
170197

198+
NullablePtr<DeclContext> AbstractFunctionDeclScope::getDeclContext() const {
199+
return decl;
200+
}
201+
171202
NullablePtr<DeclContext> AbstractFunctionParamsScope::getDeclContext() const {
172203
return matchingContext;
173204
}

0 commit comments

Comments
 (0)