Skip to content

Commit cfd8fed

Browse files
Merge pull request #5435 from swiftwasm/main
[pull] swiftwasm from main
2 parents 46eff4b + cae6746 commit cfd8fed

File tree

58 files changed

+794
-353
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

+794
-353
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ set(SWIFT_BENCH_MODULES
121121
single-source/NSDictionaryCastToSwift
122122
single-source/NSErrorTest
123123
single-source/NSStringConversion
124+
single-source/NaiveRangeReplaceableCollectionConformance
124125
single-source/NibbleSort
125126
single-source/NIOChannelPipeline
126127
single-source/NopDeinit
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
//===--- NaiveRangeReplaceableCollectionConformance.swift -----------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
15+
var contiguous:[UInt8] = []
16+
17+
public let benchmarks = [
18+
BenchmarkInfo(name: "NaiveRRC.append.largeContiguous",
19+
runFunction: runAppendLargeContiguous,
20+
tags: [.validation, .api],
21+
setUpFunction: { contiguous = [UInt8](repeating: 7, count: 1_000) }),
22+
BenchmarkInfo(name: "NaiveRRC.append.smallContiguousRepeated",
23+
runFunction: runAppendSmallContiguousRepeatedly,
24+
tags: [.validation, .api],
25+
setUpFunction: { contiguous = [UInt8](repeating: 7, count: 1) }),
26+
BenchmarkInfo(name: "NaiveRRC.init.largeContiguous",
27+
runFunction: runInitLargeContiguous,
28+
tags: [.validation, .api],
29+
setUpFunction: { contiguous = [UInt8](repeating: 7, count: 1_000) })
30+
]
31+
32+
struct NaiveRRC : RangeReplaceableCollection {
33+
34+
var storage:[UInt8] = []
35+
36+
init() {}
37+
38+
func index(after i: Int) -> Int {
39+
i + 1
40+
}
41+
42+
func index(before i: Int) -> Int {
43+
i - 1
44+
}
45+
46+
var startIndex: Int {
47+
0
48+
}
49+
50+
var endIndex: Int {
51+
count
52+
}
53+
54+
var count: Int {
55+
storage.count
56+
}
57+
58+
subscript(position: Int) -> UInt8 {
59+
get {
60+
storage[position]
61+
}
62+
set(newValue) {
63+
storage[position] = newValue
64+
}
65+
}
66+
67+
mutating func replaceSubrange(_ subrange: Range<Int>, with newElements: some Collection<UInt8>) {
68+
storage.replaceSubrange(subrange, with: newElements)
69+
}
70+
71+
mutating func reserveCapacity(_ n: Int) {
72+
storage.reserveCapacity(n)
73+
}
74+
}
75+
76+
@inline(never)
77+
public func runAppendLargeContiguous(N: Int) {
78+
for _ in 1...N {
79+
var rrc = NaiveRRC()
80+
rrc.append(contentsOf: contiguous)
81+
blackHole(rrc)
82+
}
83+
}
84+
85+
@inline(never)
86+
public func runAppendSmallContiguousRepeatedly(N: Int) {
87+
for _ in 1...N {
88+
var rrc = NaiveRRC()
89+
for _ in 1...5_000 {
90+
rrc.append(contentsOf: contiguous)
91+
}
92+
blackHole(rrc)
93+
}
94+
}
95+
96+
@inline(never)
97+
public func runInitLargeContiguous(N: Int) {
98+
for _ in 1...N {
99+
blackHole(NaiveRRC(contiguous))
100+
}
101+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ import Memset
112112
import MirrorTest
113113
import MonteCarloE
114114
import MonteCarloPi
115+
import NaiveRangeReplaceableCollectionConformance
115116
import NibbleSort
116117
import NIOChannelPipeline
117118
import NSDictionaryCastToSwift
@@ -303,6 +304,7 @@ register(Memset.benchmarks)
303304
register(MirrorTest.benchmarks)
304305
register(MonteCarloE.benchmarks)
305306
register(MonteCarloPi.benchmarks)
307+
register(NaiveRangeReplaceableCollectionConformance.benchmarks)
306308
register(NSDictionaryCastToSwift.benchmarks)
307309
register(NSErrorTest.benchmarks)
308310
#if canImport(Darwin)

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7143,6 +7143,8 @@ ERROR(moveonly_cannot_conform_to_type, none,
71437143
(DescriptiveDeclKind, DeclName, Type))
71447144
ERROR(moveonly_parameter_missing_ownership, none,
71457145
"noncopyable parameter must specify its ownership", ())
7146+
ERROR(moveonly_parameter_subscript_unsupported, none,
7147+
"subscripts cannot have noncopyable parameters yet", ())
71467148
NOTE(moveonly_parameter_ownership_suggestion, none,
71477149
"add '%0' %1", (StringRef, StringRef))
71487150
ERROR(ownership_specifier_copyable,none,

include/swift/IDE/CodeCompletionResult.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ enum class CompletionKind : uint8_t {
228228
ForEachPatternBeginning,
229229
TypeAttrBeginning,
230230
OptionalBinding,
231+
232+
/// Completion after `~` in an inheritance clause.
233+
WithoutConstraintType
231234
};
232235

233236
enum class CodeCompletionDiagnosticSeverity : uint8_t {

include/swift/IDE/CompletionLookup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
620620
void getStmtLabelCompletions(SourceLoc Loc, bool isContinue);
621621

622622
void getOptionalBindingCompletions(SourceLoc Loc);
623+
624+
void getWithoutConstraintTypes();
623625
};
624626

625627
} // end namespace ide

include/swift/Parse/IDEInspectionCallbacks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ class CodeCompletionCallbacks {
261261
virtual void completeTypeAttrBeginning() {};
262262

263263
virtual void completeOptionalBinding(){};
264+
265+
virtual void completeWithoutConstraintType(){};
264266
};
265267

266268
class DoneParsingCallback {

lib/AST/ASTScopeCreation.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ class ScopeCreator final : public ASTAllocated<ScopeCreator> {
100100
ASTScopeAssert(expr,
101101
"If looking for closures, must have an expression to search.");
102102

103-
/// AST walker that finds top-level closures in an expression.
104-
class ClosureFinder : public ASTWalker {
103+
/// AST walker that finds nested scopes in expressions. This handles both
104+
/// closures and if/switch expressions.
105+
class NestedExprScopeFinder : public ASTWalker {
105106
ScopeCreator &scopeCreator;
106107
ASTScopeImpl *parent;
107108

108109
public:
109-
ClosureFinder(ScopeCreator &scopeCreator, ASTScopeImpl *parent)
110+
NestedExprScopeFinder(ScopeCreator &scopeCreator, ASTScopeImpl *parent)
110111
: scopeCreator(scopeCreator), parent(parent) {}
111112

112113
PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
@@ -122,6 +123,13 @@ class ScopeCreator final : public ASTAllocated<ScopeCreator> {
122123
parent, capture);
123124
return Action::SkipChildren(E);
124125
}
126+
127+
// If we have a single value statement expression, we need to add any
128+
// scopes in the underlying statement.
129+
if (auto *SVE = dyn_cast<SingleValueStmtExpr>(E)) {
130+
scopeCreator.addToScopeTree(SVE->getStmt(), parent);
131+
return Action::SkipChildren(E);
132+
}
125133
return Action::Continue(E);
126134
}
127135
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override {
@@ -148,7 +156,7 @@ class ScopeCreator final : public ASTAllocated<ScopeCreator> {
148156
}
149157
};
150158

151-
expr->walk(ClosureFinder(*this, parent));
159+
expr->walk(NestedExprScopeFinder(*this, parent));
152160
}
153161

154162
public:
@@ -518,11 +526,6 @@ class NodeAdder
518526
if (!expr)
519527
return p;
520528

521-
// If we have a single value statement expression, we expand scopes based
522-
// on the underlying statement.
523-
if (auto *SVE = dyn_cast<SingleValueStmtExpr>(expr))
524-
return visit(SVE->getStmt(), p, scopeCreator);
525-
526529
scopeCreator.addExprToScopeTree(expr, p);
527530
return p;
528531
}

lib/AST/Decl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5416,11 +5416,12 @@ NominalTypeDecl::getExecutorLegacyUnownedEnqueueFunction() const {
54165416

54175417
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(candidate)) {
54185418
auto params = funcDecl->getParameters();
5419-
54205419
if (params->size() != 1)
54215420
continue;
54225421

5423-
if (params->get(0)->getType()->isEqual(unownedJobDecl->getDeclaredInterfaceType())) {
5422+
auto param = params->get(0);
5423+
if (param->getSpecifier() == ParamSpecifier::LegacyOwned ||
5424+
param->getSpecifier() == ParamSpecifier::Consuming) {
54245425
return funcDecl;
54255426
}
54265427
}

lib/AST/GenericSignature.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -724,16 +724,16 @@ Type GenericSignatureImpl::getDependentUpperBounds(Type type) const {
724724
argTypes.push_back(reducedType);
725725
}
726726

727-
// We should have either constrained all primary associated types,
728-
// or none of them.
729-
if (!argTypes.empty()) {
730-
if (argTypes.size() != primaryAssocTypes.size()) {
731-
llvm::errs() << "Not all primary associated types constrained?\n";
732-
llvm::errs() << "Interface type: " << type << "\n";
733-
llvm::errs() << GenericSignature(this) << "\n";
734-
abort();
735-
}
736-
727+
// If we have constrained all primary associated types, create a
728+
// parameterized protocol type. During code completion, we might call
729+
// `getExistentialType` (which calls this method) on a generic parameter
730+
// that doesn't have all parameters specified, e.g. to get a consise
731+
// description of the parameter type to the following function.
732+
//
733+
// func foo<P: Publisher>(p: P) where P.Failure == Never
734+
//
735+
// In that case just add the base type in the default branch below.
736+
if (argTypes.size() == primaryAssocTypes.size()) {
737737
types.push_back(ParameterizedProtocolType::get(ctx, baseType, argTypes));
738738
continue;
739739
}

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ bool TypeBase::isMarkerExistential() {
189189
}
190190

191191
bool TypeBase::isPureMoveOnly() {
192-
if (auto *nom = getNominalOrBoundGenericNominal())
192+
if (auto *nom = getAnyNominal())
193193
return nom->isMoveOnly();
194194

195195
// if any components of the tuple are move-only, then the tuple is move-only.

lib/ASTGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ add_pure_swift_host_library(swiftASTGen STATIC
3232
SwiftSyntax::SwiftParserDiagnostics
3333
SwiftSyntax::SwiftSyntax
3434
SwiftSyntax::SwiftSyntaxMacros
35+
SwiftSyntax::SwiftSyntaxMacroExpansion
3536
swiftLLVMJSON
3637
)

lib/ASTGen/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ let package = Package(
3737
.product(name: "SwiftOperators", package: "swift-syntax"),
3838
.product(name: "SwiftParser", package: "swift-syntax"),
3939
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
40+
.product(name: "SwiftSyntaxMacroExpansion", package: "swift-syntax"),
4041
"swiftLLVMJSON"
4142
],
4243
path: "Sources/ASTGen",
43-
exclude: ["CMakeLists.txt"],
4444
swiftSettings: swiftSetttings
4545
),
4646
.target(

0 commit comments

Comments
 (0)