Skip to content

Commit 586aff3

Browse files
Merge pull request #5143 from swiftwasm/release/5.8
[pull] swiftwasm-release/5.8 from release/5.8
2 parents 89cf1dc + 5a0eb50 commit 586aff3

File tree

54 files changed

+1234
-367
lines changed

Some content is hidden

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

54 files changed

+1234
-367
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,10 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
810810
switch effect.kind {
811811
case .escapingToReturn(let toPath, let exclusive):
812812
if exclusive && path.projectionPath.matches(pattern: toPath) {
813-
let arg = apply.arguments[effect.argumentIndex]
813+
guard let callerArgIdx = apply.callerArgIndex(calleeArgIndex: effect.argumentIndex) else {
814+
return .abortWalk
815+
}
816+
let arg = apply.arguments[callerArgIdx]
814817

815818
let p = Path(projectionPath: effect.pathPattern, followStores: path.followStores, knownType: nil)
816819
if walkUp(addressOrValue: arg, path: p) == .abortWalk {

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,10 @@ class PatternBindingDecl final : public Decl,
19691969
getMutablePatternList()[i].setInit(E);
19701970
}
19711971

1972+
void setOriginalInit(unsigned i, Expr *E) {
1973+
getMutablePatternList()[i].setOriginalInit(E);
1974+
}
1975+
19721976
Pattern *getPattern(unsigned i) const {
19731977
return getPatternList()[i].getPattern();
19741978
}

include/swift/Basic/Features.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ EXPERIMENTAL_FEATURE(FlowSensitiveConcurrencyCaptures, false)
104104
EXPERIMENTAL_FEATURE(MoveOnly, false)
105105
EXPERIMENTAL_FEATURE(OneWayClosureParameters, false)
106106
EXPERIMENTAL_FEATURE(TypeWitnessSystemInference, false)
107-
EXPERIMENTAL_FEATURE(ResultBuilderASTTransform, true)
108107
EXPERIMENTAL_FEATURE(LayoutPrespecialization, false)
109108
EXPERIMENTAL_FEATURE(ModuleInterfaceExportAs, true)
110109

include/swift/Sema/ConstraintSystem.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,11 @@ class Solution {
16691669
Type getContextualType(ASTNode anchor) const {
16701670
for (const auto &entry : contextualTypes) {
16711671
if (entry.first == anchor) {
1672-
return simplifyType(entry.second.getType());
1672+
// The contextual information record could contain the purpose
1673+
// without a type i.e. when the context is an optional-some or
1674+
// an invalid pattern binding.
1675+
if (auto contextualTy = entry.second.getType())
1676+
return simplifyType(contextualTy);
16731677
}
16741678
}
16751679
return Type();
@@ -6460,6 +6464,10 @@ class ConjunctionElement {
64606464
Element->print(Out, SM, indent);
64616465
}
64626466

6467+
/// Returns \c false if this conjunction element is known not to contain the
6468+
/// code compleiton token.
6469+
bool mightContainCodeCompletionToken(const ConstraintSystem &cs) const;
6470+
64636471
private:
64646472
/// Find type variables referenced by this conjunction element.
64656473
/// If this is a closure body element, it would look inside \c ASTNode.

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,10 +3118,6 @@ static bool usesFeatureOneWayClosureParameters(Decl *decl) {
31183118
return false;
31193119
}
31203120

3121-
static bool usesFeatureResultBuilderASTTransform(Decl *decl) {
3122-
return false;
3123-
}
3124-
31253121
static bool usesFeatureTypeWitnessSystemInference(Decl *decl) {
31263122
return false;
31273123
}

lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,7 @@ PatternBindingDecl *PatternBindingDecl::createImplicit(
15291529
Pat, /*EqualLoc*/ SourceLoc(), nullptr, Parent);
15301530
Result->setImplicit();
15311531
Result->setInit(0, E);
1532+
Result->setOriginalInit(0, E);
15321533
return Result;
15331534
}
15341535

lib/IDE/CodeCompletionResultType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
184184
Ty = Ty->getCanonicalType();
185185

186186
// For opaque types like 'some View', consider them equivalent to 'View'.
187-
if (auto OpaqueType = Ty->getAs<OpaqueTypeArchetypeType>()) {
187+
if (auto OpaqueType = Ty->getAs<ArchetypeType>()) {
188188
if (auto Existential = OpaqueType->getExistentialType()) {
189189
Ty = Existential;
190190
}

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,11 @@ bool SILCombiner::tryOptimizeKeypathOffsetOf(ApplyInst *AI,
343343

344344
KeyPathPattern *pattern = kp->getPattern();
345345
SubstitutionMap patternSubs = kp->getSubstitutions();
346-
CanType rootTy = pattern->getRootType().subst(patternSubs)->getCanonicalType();
347-
CanType parentTy = rootTy;
346+
SILFunction *f = AI->getFunction();
347+
SILType rootTy = f->getLoweredType(Lowering::AbstractionPattern::getOpaque(),
348+
pattern->getRootType().subst(patternSubs)->getCanonicalType());
349+
350+
SILType parentTy = rootTy;
348351

349352
// First check if _storedInlineOffset would return an offset or nil. Basically
350353
// only stored struct and tuple elements produce an offset. Everything else
@@ -381,14 +384,15 @@ bool SILCombiner::tryOptimizeKeypathOffsetOf(ApplyInst *AI,
381384
hasOffset = false;
382385
break;
383386
}
384-
parentTy = component.getComponentType();
387+
parentTy = f->getLoweredType(Lowering::AbstractionPattern::getOpaque(),
388+
component.getComponentType());
385389
}
386390

387391
SILLocation loc = AI->getLoc();
388392
SILValue result;
389393

390394
if (hasOffset) {
391-
SILType rootAddrTy = SILType::getPrimitiveAddressType(rootTy);
395+
SILType rootAddrTy = rootTy.getAddressType();
392396
SILValue rootAddr = Builder.createBaseAddrForOffset(loc, rootAddrTy);
393397

394398
auto projector = KeyPathProjector::create(kp, rootAddr, loc, Builder);

lib/Sema/BuilderTransform.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,8 @@ class ResultBuilderTransform
959959
VarDecl *captureExpr(Expr *expr, SmallVectorImpl<ASTNode> &container) {
960960
auto *var = builder.buildVar(expr->getStartLoc());
961961
Pattern *pattern = NamedPattern::createImplicit(ctx, var);
962-
auto *PB = PatternBindingDecl::createImplicit(ctx, StaticSpellingKind::None,
963-
pattern, expr, dc);
962+
auto *PB = PatternBindingDecl::createImplicit(
963+
ctx, StaticSpellingKind::None, pattern, expr, dc, var->getStartLoc());
964964
return recordVar(PB, container);
965965
}
966966

@@ -972,7 +972,8 @@ class ResultBuilderTransform
972972
ctx, NamedPattern::createImplicit(ctx, var),
973973
type ? type : PlaceholderType::get(ctx, var));
974974
auto *PB = PatternBindingDecl::createImplicit(
975-
ctx, StaticSpellingKind::None, placeholder, /*init=*/initExpr, dc);
975+
ctx, StaticSpellingKind::None, placeholder, /*init=*/initExpr, dc,
976+
var->getStartLoc());
976977
return recordVar(PB, container);
977978
}
978979

@@ -1058,11 +1059,20 @@ class ResultBuilderTransform
10581059
{Identifier()});
10591060
}
10601061

1061-
auto *capture = captureExpr(expr, newBody);
1062-
// A reference to the synthesized variable is passed as an argument
1063-
// to buildBlock.
1064-
buildBlockArguments.push_back(
1065-
builder.buildVarRef(capture, element.getStartLoc()));
1062+
if (isa<CodeCompletionExpr>(expr)) {
1063+
// Insert the CodeCompletionExpr directly into the buildBlock call. That
1064+
// way, we can extract the contextual type of the code completion token
1065+
// to rank code completion items that match the type expected by
1066+
// buildBlock higher.
1067+
buildBlockArguments.push_back(expr);
1068+
} else {
1069+
auto *capture = captureExpr(expr, newBody);
1070+
// A reference to the synthesized variable is passed as an argument
1071+
// to buildBlock.
1072+
buildBlockArguments.push_back(
1073+
builder.buildVarRef(capture, element.getStartLoc()));
1074+
}
1075+
10661076
return None;
10671077
}
10681078

@@ -2459,7 +2469,9 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
24592469
return None;
24602470
}
24612471

2462-
if (Context.LangOpts.hasFeature(Feature::ResultBuilderASTTransform)) {
2472+
auto disableASTTransform = [&](NominalTypeDecl *builder) { return false; };
2473+
2474+
if (!disableASTTransform(builder)) {
24632475
auto transformedBody = getBuilderTransformedBody(fn, builder);
24642476
// If this builder transform has not yet been applied to this function,
24652477
// let's do it and cache the result.
@@ -2517,7 +2529,7 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
25172529
auto &log = llvm::errs();
25182530
auto indent = solverState ? solverState->getCurrentIndent() : 0;
25192531
log.indent(indent) << "------- Transfomed Body -------\n";
2520-
transformedBody->second->dump(log);
2532+
transformedBody->second->dump(log, &getASTContext(), indent);
25212533
log << '\n';
25222534
}
25232535

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,25 +2055,10 @@ static bool isInPatternMatchingContext(ConstraintLocatorBuilder locator) {
20552055
SmallVector<LocatorPathElt, 4> path;
20562056
(void)locator.getLocatorParts(path);
20572057

2058-
while (!path.empty() && path.back().is<LocatorPathElt::TupleType>())
2059-
path.pop_back();
2060-
2061-
if (!path.empty()) {
2062-
// Direct pattern matching between tuple pattern and tuple type.
2063-
if (path.back().is<LocatorPathElt::PatternMatch>()) {
2064-
return true;
2065-
} else if (path.size() > 1) {
2066-
// sub-pattern matching as part of the enum element matching
2067-
// where sub-element is a tuple pattern e.g.
2068-
// `case .foo((a: 42, _)) = question`
2069-
auto lastIdx = path.size() - 1;
2070-
if (path[lastIdx - 1].is<LocatorPathElt::PatternMatch>() &&
2071-
path[lastIdx].is<LocatorPathElt::FunctionArgument>())
2072-
return true;
2073-
}
2074-
}
2075-
2076-
return false;
2058+
auto pathElement = llvm::find_if(path, [](LocatorPathElt &elt) {
2059+
return elt.is<LocatorPathElt::PatternMatch>();
2060+
});
2061+
return pathElement != path.end();
20772062
}
20782063

20792064
namespace {

0 commit comments

Comments
 (0)