Skip to content

Commit a970a73

Browse files
authored
Merge pull request #1348 from swiftwasm/maxd/5.3-merge
Resolve conflicts with release/5.3
2 parents d2e1ae0 + 25529bf commit a970a73

File tree

337 files changed

+1182
-47375
lines changed

Some content is hidden

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

337 files changed

+1182
-47375
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ jobs:
6363
path: ../build-cache
6464
key: ${{ runner.os }}-sccache-v5-5.3
6565
- name: Build macOS installable archive
66-
run: ./utils/webassembly/ci.sh
66+
run: |
67+
sudo xcode-select --switch /Applications/Xcode_12_beta.app/Contents/Developer/
68+
./utils/webassembly/ci.sh
6769
- name: Upload macOS installable archive
6870
uses: actions/upload-artifact@v1
6971
with:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Please make sure you use Python 2.x. Python 3.x is not supported currently.
9191

9292
#### macOS
9393

94-
To build for macOS, you need [Xcode 11.4](https://developer.apple.com/xcode/resources/).
94+
To build for macOS, you need [Xcode 12 beta](https://developer.apple.com/xcode/resources/).
9595
The required version of Xcode changes frequently, and is often a beta release.
9696
Check this document or the host information on <https://ci.swift.org> for the
9797
current required version.

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,11 @@ function (swift_benchmark_compile_archopts)
660660
"-m${triple_platform}-version-min=${ver}"
661661
"-lobjc"
662662
"-L${SWIFT_LIBRARY_PATH}/${BENCH_COMPILE_ARCHOPTS_PLATFORM}"
663+
"-L${sdk}/usr/lib/swift"
663664
"-Xlinker" "-rpath"
664665
"-Xlinker" "${SWIFT_LINK_RPATH}"
666+
"-Xlinker" "-rpath"
667+
"-Xlinker" "/usr/lib/swift"
665668
${bench_library_objects}
666669
${bench_driver_objects}
667670
${ld64_add_ast_path_opts}

include/swift/IDE/ConformingMethodList.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ConformingMethodListConsumer {
4242
public:
4343
virtual ~ConformingMethodListConsumer() {}
4444
virtual void handleResult(const ConformingMethodListResult &result) = 0;
45+
virtual void setReusingASTContext(bool flag) = 0;
4546
};
4647

4748
/// Printing consumer
@@ -53,6 +54,7 @@ class PrintingConformingMethodListConsumer
5354
PrintingConformingMethodListConsumer(llvm::raw_ostream &OS) : OS(OS) {}
5455

5556
void handleResult(const ConformingMethodListResult &result) override;
57+
void setReusingASTContext(bool flag) override {}
5658
};
5759

5860
/// Create a factory for code completion callbacks.

include/swift/IDE/TypeContextInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TypeContextInfoConsumer {
3838
public:
3939
virtual ~TypeContextInfoConsumer() {}
4040
virtual void handleResults(ArrayRef<TypeContextInfoItem>) = 0;
41+
virtual void setReusingASTContext(bool flag) = 0;
4142
};
4243

4344
/// Printing consumer
@@ -48,6 +49,7 @@ class PrintingTypeContextInfoConsumer : public TypeContextInfoConsumer {
4849
PrintingTypeContextInfoConsumer(llvm::raw_ostream &OS) : OS(OS) {}
4950

5051
void handleResults(ArrayRef<TypeContextInfoItem>) override;
52+
void setReusingASTContext(bool flag) override {}
5153
};
5254

5355
/// Create a factory for code completion callbacks.

lib/AST/Attr.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,11 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
749749
if (auto *VD = dyn_cast<ValueDecl>(D)) {
750750
if (auto *BD = VD->getOverriddenDecl()) {
751751
if (!BD->hasClangNode() &&
752-
VD->isEffectiveLinkageMoreVisibleThan(BD))
752+
!BD->getFormalAccessScope(VD->getDeclContext(),
753+
/*treatUsableFromInlineAsPublic*/ true)
754+
.isPublic()) {
753755
return false;
756+
}
754757
}
755758
}
756759
break;

lib/Demangling/Demangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,8 @@ NodePointer Demangler::demangleArchetype() {
20072007
if (!demangleBoundGenerics(boundGenericArgs, retroactiveConformances))
20082008
return nullptr;
20092009
auto Name = popNode();
2010+
if (!Name)
2011+
return nullptr;
20102012
auto opaque = createWithChildren(Node::Kind::OpaqueType, Name,
20112013
createNode(Node::Kind::Index, index));
20122014
auto boundGenerics = createNode(Node::Kind::TypeList);

lib/IDE/CodeCompletion.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6158,15 +6158,29 @@ void CodeCompletionCallbacksImpl::doneParsing() {
61586158
if (IsAtStartOfLine) {
61596159
// foo() {}
61606160
// <HERE>
6161-
// Global completion.
6161+
61626162
auto &Sink = CompletionContext.getResultSink();
6163-
addDeclKeywords(Sink);
6164-
addStmtKeywords(Sink, MaybeFuncBody);
6165-
addSuperKeyword(Sink);
6166-
addLetVarKeywords(Sink);
6167-
addExprKeywords(Sink);
6168-
addAnyTypeKeyword(Sink, CurDeclContext->getASTContext().TheAnyType);
6169-
DoPostfixExprBeginning();
6163+
if (isa<Initializer>(CurDeclContext))
6164+
CurDeclContext = CurDeclContext->getParent();
6165+
6166+
if (CurDeclContext->isTypeContext()) {
6167+
// Override completion (CompletionKind::NominalMemberBeginning).
6168+
addDeclKeywords(Sink);
6169+
addLetVarKeywords(Sink);
6170+
SmallVector<StringRef, 0> ParsedKeywords;
6171+
CompletionOverrideLookup OverrideLookup(Sink, Context, CurDeclContext,
6172+
ParsedKeywords, SourceLoc());
6173+
OverrideLookup.getOverrideCompletions(SourceLoc());
6174+
} else {
6175+
// Global completion (CompletionKind::PostfixExprBeginning).
6176+
addDeclKeywords(Sink);
6177+
addStmtKeywords(Sink, MaybeFuncBody);
6178+
addSuperKeyword(Sink);
6179+
addLetVarKeywords(Sink);
6180+
addExprKeywords(Sink);
6181+
addAnyTypeKeyword(Sink, Context.TheAnyType);
6182+
DoPostfixExprBeginning();
6183+
}
61706184
} else {
61716185
// foo() {} <HERE>
61726186
// Member completion.

lib/IDE/Formatting.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,11 @@ class FormatWalker : public ASTWalker {
19061906
return Aligner.getContextAndSetAlignment(CtxOverride);
19071907
}
19081908

1909+
// There are no parens at this point, so if there are no parameters either,
1910+
// this shouldn't be a context (it's an implicit parameter list).
1911+
if (!PL->size())
1912+
return None;
1913+
19091914
ListAligner Aligner(SM, TargetLocation, ContextLoc, Range.Start);
19101915
for (auto *PD: *PL)
19111916
Aligner.updateAlignment(PD->getSourceRange(), PD);
@@ -2336,8 +2341,17 @@ class FormatWalker : public ASTWalker {
23362341
return None;
23372342

23382343
ListAligner Aligner(SM, TargetLocation, L, L, R, true);
2339-
for (auto *Elem: AE->getElements())
2340-
Aligner.updateAlignment(Elem->getStartLoc(), Elem->getEndLoc(), Elem);
2344+
for (auto *Elem: AE->getElements()) {
2345+
SourceRange ElemRange = Elem->getSourceRange();
2346+
Aligner.updateAlignment(ElemRange, Elem);
2347+
if (isTargetContext(ElemRange)) {
2348+
Aligner.setAlignmentIfNeeded(CtxOverride);
2349+
return IndentContext {
2350+
ElemRange.Start,
2351+
!OutdentChecker::hasOutdent(SM, ElemRange, Elem)
2352+
};
2353+
}
2354+
}
23412355
return Aligner.getContextAndSetAlignment(CtxOverride);
23422356
}
23432357

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3228,7 +3228,7 @@ Parser::parseTrailingClosures(bool isExprBasic, SourceRange calleeRange,
32283228
if (CodeCompletion)
32293229
CodeCompletion->completeLabeledTrailingClosure(CCExpr, Tok.isAtStartOfLine());
32303230
consumeToken(tok::code_complete);
3231-
result.hasCodeCompletion();
3231+
result.setHasCodeCompletion();
32323232
closures.push_back({Identifier(), SourceLoc(), CCExpr});
32333233
continue;
32343234
}

lib/SILOptimizer/Transforms/CopyForwarding.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ namespace {
322322
/// This returns false and sets Oper to a valid operand if the instruction is a
323323
/// projection of the value at the given address. The assumption is that we
324324
/// cannot deinitialize memory via projections.
325+
///
326+
/// This returns true with Oper == nullptr for trivial stores (without a proper
327+
/// deinit).
325328
class AnalyzeForwardUse
326329
: public SILInstructionVisitor<AnalyzeForwardUse, bool> {
327330
public:
@@ -352,7 +355,10 @@ class AnalyzeForwardUse
352355
return true;
353356
}
354357
bool visitStoreInst(StoreInst *Store) {
355-
llvm_unreachable("illegal reinitialization or store of an address");
358+
// Trivial values may be stored prior to the next deinit. A store is an
359+
// implicit "deinit" with no operand to replace.
360+
assert(Store->getOperand(0)->getType().isTrivial(*Store->getFunction()));
361+
return true;
356362
}
357363
bool visitDestroyAddrInst(DestroyAddrInst *UserInst) {
358364
Oper = &UserInst->getOperandRef();
@@ -1011,15 +1017,17 @@ bool CopyForwarding::forwardPropagateCopy() {
10111017
continue;
10121018

10131019
AnalyzeForwardUse AnalyzeUse(CopyDest);
1014-
bool seenDeinit = AnalyzeUse.visit(UserInst);
1015-
// If this use cannot be analyzed, then abort.
1020+
bool seenDeinitOrStore = AnalyzeUse.visit(UserInst);
1021+
if (AnalyzeUse.Oper)
1022+
ValueUses.push_back(AnalyzeUse.Oper);
1023+
1024+
// If this is a deinit or store, we're done searching.
1025+
if (seenDeinitOrStore)
1026+
break;
1027+
1028+
// If this non-deinit instruction wasn't fully analyzed, bail-out.
10161029
if (!AnalyzeUse.Oper)
10171030
return false;
1018-
// Otherwise record the operand.
1019-
ValueUses.push_back(AnalyzeUse.Oper);
1020-
// If this is a deinit, we're done searching.
1021-
if (seenDeinit)
1022-
break;
10231031
}
10241032
if (SI == SE)
10251033
return false;

lib/Sema/BuilderTransform.cpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,10 @@ class BuilderClosureVisitor
283283
auto target = SolutionApplicationTarget::forInitialization(
284284
patternBinding->getInit(index), dc, patternType, pattern,
285285
/*bindPatternVarsOneWay=*/true);
286-
if (cs->generateConstraints(target, FreeTypeVariableBinding::Disallow))
286+
if (cs->generateConstraints(target, FreeTypeVariableBinding::Disallow)) {
287+
hadError = true;
287288
continue;
289+
}
288290

289291
// Keep track of this binding entry.
290292
applied.patternBindingEntries.insert({{patternBinding, index}, target});
@@ -1223,6 +1225,65 @@ BraceStmt *swift::applyFunctionBuilderTransform(
12231225
captured.first, captured.second)));
12241226
}
12251227

1228+
/// Produce any additional syntactic diagnostics for the body of a
1229+
static void performAddOnDiagnostics(BraceStmt *stmt, DeclContext *dc) {
1230+
class AddOnDiagnosticWalker : public ASTWalker {
1231+
SmallVector<DeclContext *, 4> dcStack;
1232+
1233+
public:
1234+
AddOnDiagnosticWalker(DeclContext *dc) {
1235+
dcStack.push_back(dc);
1236+
}
1237+
1238+
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
1239+
performSyntacticExprDiagnostics(
1240+
expr, dcStack.back(), /*isExprStmt=*/false);
1241+
1242+
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
1243+
if (!closure->hasSingleExpressionBody() &&
1244+
!closure->hasAppliedFunctionBuilder()) {
1245+
dcStack.push_back(closure);
1246+
return { true, expr };
1247+
}
1248+
}
1249+
1250+
return { false, expr };
1251+
}
1252+
1253+
Expr *walkToExprPost(Expr *expr) override {
1254+
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
1255+
if (!closure->hasSingleExpressionBody() &&
1256+
!closure->hasAppliedFunctionBuilder()) {
1257+
assert(dcStack.back() == closure);
1258+
dcStack.pop_back();
1259+
}
1260+
}
1261+
1262+
return expr;
1263+
}
1264+
1265+
std::pair<bool, Stmt *> walkToStmtPre(Stmt *stmt) override {
1266+
performStmtDiagnostics(dcStack.back()->getASTContext(), stmt);
1267+
return { true, stmt };
1268+
}
1269+
1270+
std::pair<bool, Pattern*> walkToPatternPre(Pattern *pattern) override {
1271+
return { false, pattern };
1272+
}
1273+
1274+
bool walkToTypeLocPre(TypeLoc &typeLoc) override { return false; }
1275+
1276+
bool walkToTypeReprPre(TypeRepr *typeRepr) override { return false; }
1277+
1278+
bool walkToParameterListPre(ParameterList *params) override {
1279+
return false;
1280+
}
1281+
};
1282+
1283+
AddOnDiagnosticWalker walker(dc);
1284+
stmt->walk(walker);
1285+
}
1286+
12261287
Optional<BraceStmt *> TypeChecker::applyFunctionBuilderBodyTransform(
12271288
FuncDecl *func, Type builderType) {
12281289
// Pre-check the body: pre-check any expressions in it and look
@@ -1363,6 +1424,7 @@ Optional<BraceStmt *> TypeChecker::applyFunctionBuilderBodyTransform(
13631424
if (auto result = cs.applySolution(
13641425
solutions.front(),
13651426
SolutionApplicationTarget(func))) {
1427+
performAddOnDiagnostics(result->getFunctionBody(), func);
13661428
return result->getFunctionBody();
13671429
}
13681430

lib/Sema/CSGen.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,18 +1180,24 @@ namespace {
11801180
TVO_CanBindToLValue |
11811181
TVO_CanBindToNoEscape);
11821182

1183-
// Defaults to the type of the base expression if we have a base
1184-
// expression.
1185-
// FIXME: This is just to keep the old behavior where `foo(base.<HERE>)`
1186-
// the argument is type checked to the type of the 'base'. Ideally, code
1187-
// completion expression should be defauled to 'UnresolvedType'
1188-
// regardless of the existence of the base expression. But the constraint
1189-
// system is simply not ready for that.
11901183
if (auto base = E->getBase()) {
1184+
// Defaults to the type of the base expression if we have a base
1185+
// expression.
1186+
// FIXME: This is just to keep the old behavior where `foo(base.<HERE>)`
1187+
// the argument is type checked to the type of the 'base'. Ideally, code
1188+
// completion expression should be defauled to 'UnresolvedType'
1189+
// regardless of the existence of the base expression. But the
1190+
// constraint system is simply not ready for that.
11911191
CS.addConstraint(ConstraintKind::Defaultable, ty, CS.getType(base),
11921192
locator);
1193+
1194+
// Apply a viable solution even if it's ambiguous.
1195+
// FIXME: Remove this. This is a hack for code completion which only
1196+
// see solution applied AST. In future, code completion collects all
1197+
// viable solutions so we need to apply any solution at all.
1198+
CS.Options |= ConstraintSystemFlags::ForceApplyViableSolution;
11931199
}
1194-
1200+
11951201
return ty;
11961202
}
11971203

@@ -2321,12 +2327,18 @@ namespace {
23212327

23222328
return setType(ParenType::get(CS.getASTContext(), underlyingType));
23232329
}
2324-
case PatternKind::Var:
2330+
case PatternKind::Var: {
2331+
auto *subPattern = cast<VarPattern>(pattern)->getSubPattern();
2332+
auto type = getTypeForPattern(subPattern, locator, externalPatternType,
2333+
bindPatternVarsOneWay);
2334+
2335+
if (!type)
2336+
return Type();
2337+
23252338
// Var doesn't affect the type.
2326-
return setType(
2327-
getTypeForPattern(
2328-
cast<VarPattern>(pattern)->getSubPattern(), locator,
2329-
externalPatternType, bindPatternVarsOneWay));
2339+
return setType(type);
2340+
}
2341+
23302342
case PatternKind::Any: {
23312343
return setType(
23322344
CS.createTypeVariable(CS.getConstraintLocator(locator),
@@ -4235,7 +4247,9 @@ static bool generateInitPatternConstraints(
42354247
pattern, locator, target.shouldBindPatternVarsOneWay(),
42364248
target.getInitializationPatternBindingDecl(),
42374249
target.getInitializationPatternBindingIndex());
4238-
assert(patternType && "All patterns have a type");
4250+
4251+
if (!patternType)
4252+
return true;
42394253

42404254
if (auto wrappedVar = target.getInitializationWrappedVar()) {
42414255
// Add an equal constraint between the pattern type and the

lib/Sema/CSRanking.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,12 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
13351335
return bestIdx;
13361336
}
13371337

1338+
// FIXME: Terrible hack for code completion. But applying a solution is better
1339+
// than just failing.
1340+
if (Options.contains(ConstraintSystemFlags::ForceApplyViableSolution)) {
1341+
return bestIdx;
1342+
}
1343+
13381344
// If there is not a single "better" than others
13391345
// solution, which probably means that solutions
13401346
// were incomparable, let's just keep the original

lib/Sema/ConstraintSystem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,11 @@ enum class ConstraintSystemFlags {
10741074
/// If set, constraint system always reuses type of pre-typechecked
10751075
/// expression, and doesn't dig into its subexpressions.
10761076
ReusePrecheckedType = 0x08,
1077+
1078+
/// FIME: Temporary hack.
1079+
/// Force apply a viable solution even if they are ambiguous, so that the
1080+
/// client get a solution.
1081+
ForceApplyViableSolution = 0x10,
10771082
};
10781083

10791084
/// Options that affect the constraint system as a whole.

0 commit comments

Comments
 (0)