Skip to content

Commit a597c61

Browse files
Merge pull request #4423 from swiftwasm/main
[pull] swiftwasm from main
2 parents 6586930 + 7e0ef44 commit a597c61

Some content is hidden

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

47 files changed

+739
-222
lines changed

docs/CppInteroperability/CppInteroperabilityStatus.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Unless stated otherwise (i.e., imported reference types) all Swift features work
108108

109109
### C++ Standard Library Support
110110

111-
Parts of libc++ can be imported and used from Swift.
111+
Parts of libc++ can be imported and used from Swift. C++ standard library types are bridged directly to Swift, and there is not automatic bridging to native Swift types. This means that if an imported C++ API returns `std::string`, you will get a `std::string` value in Swift as well, and not Swift's `String`.
112112

113113
This status table describes which of the following C++ standard library features have some experimental support for using them in Swift. Please note that this is not a comprehensive list and other libc++ APIs that use the above supported C++ language features could be imported into Swift.
114114

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# C++ Interoperability Oddities
2+
3+
C++ APIs may have slightly different behavior than other C++ APIs. This is a general catch-all document where these
4+
oddities are recorded along with a few other things that are good to know when using C++ interop.
5+
6+
**Parameters with reference types**
7+
8+
Parameters that have mutable reference types are bridged as inout. Parameters with immutable reference types (const ref)
9+
are bridged as value types. ⚠️ This will change as soon as Swift has a way to represent immutable borrows. ⚠️
10+
11+
**Lifetimes**
12+
13+
Currently, lifetimes are extended to the end of the lexical scope if any unsafe pointers are used in that scope. TODO:
14+
this should be updated to extend lifetimes whenever a C++ type is used in that scope. Currently, if there is no
15+
unsafe pointer used in teh scope, then normal Swift lifetime rules apply.
16+
17+
**Borrowing Self**
18+
19+
For mutating methods, self is borrowed and the access to self lasts for the duration of the call. For non-mutating
20+
methods, the access to self is currently instantanious. ⚠️ In the very near future we plan to borrow self in both cases.
21+
This will be a source breaking change from what native Swift methods do. ⚠️
22+
23+
_More to come soon :)_

docs/HowToGuides/GettingStarted.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ toolchain as a one-off, there are a couple of differences:
2525
- [Editing code](#editing-code)
2626
- [Setting up your fork](#setting-up-your-fork)
2727
- [First time Xcode setup](#first-time-xcode-setup)
28+
- [Other IDEs setup](#other-ides-setup)
2829
- [Editing](#editing)
2930
- [Incremental builds with Ninja](#incremental-builds-with-ninja)
3031
- [Incremental builds with Xcode](#incremental-builds-with-xcode)
@@ -358,6 +359,28 @@ select the following schemes:
358359
run.
359360
<!-- TODO: Insert SourceKit/stdlib specific instructions? -->
360361
362+
### Other IDEs setup
363+
364+
You can also use other editors and IDEs to work on Swift.
365+
366+
#### IntelliJ CLion
367+
368+
CLion supports CMake and Ninja. In order to configure it properly, build the swift project first using the `build-script`, then open the `swift` directory with CLion and proceed to project settings (`cmd + ,`).
369+
370+
In project settings, locate `Build, Execution, Deployment > CMake`. You will need to create a new profile named `RelWithDebInfoAssert` (or `Debug` if going to point it at the debug build). Enter the following information:
371+
372+
- Name: mirror the name of the build configuration here, e.g. `RelWithDebInfoAssert` or `Debug`
373+
- Build type: This corresponds to `CMAKE_BUILD_TYPE` so should be e.g. `RelWithDebInfoAssert` or `Debug`
374+
- latest versions of the IDE suggest valid values here. Generally `RelWithDebInfoAssert` is a good one to work with
375+
- Toolchain: Default should be fine
376+
- Generator: Ninja
377+
- CMake options:
378+
- `-D SWIFT_PATH_TO_CMARK_BUILD=SOME_PATH/swift-project/build/Ninja-RelWithDebInfoAssert/cmark-macosx-arm64 -D LLVM_DIR=SOME_PATH/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/lib/cmake/llvm -D Clang_DIR=SOME_PATH/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/lib/cmake/clang -D CMAKE_BUILD_TYPE=RelWithDebInfoAssert -G Ninja -S .`
379+
- replace the `SOME_PATH` to the path where your `swift-project` directory is
380+
- the CMAKE_BUILD_TYPE should match the build configuration name, so if you named this profile `RelWithDebInfo` the CMAKE_BUILD_TYPE should also be `RelWithDebInfo`
381+
382+
With this done, CLion should be able to successfully import the project and have full autocomplete and code navigation powers.
383+
361384
### Editing
362385
363386
Make changes to the code as appropriate. Implement a shiny new feature!

include/swift/AST/TypeCheckRequests.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,6 @@ struct WhereClauseOwner {
604604
return !(lhs == rhs);
605605
}
606606

607-
public:
608607
/// Retrieve the array of requirements.
609608
MutableArrayRef<RequirementRepr> getRequirements() const;
610609

@@ -1903,8 +1902,7 @@ class InferredGenericSignatureRequest :
19031902
/// InferredGenericSignatureRequest.
19041903
class InferredGenericSignatureRequestRQM :
19051904
public SimpleRequest<InferredGenericSignatureRequestRQM,
1906-
GenericSignatureWithError (ModuleDecl *,
1907-
const GenericSignatureImpl *,
1905+
GenericSignatureWithError (const GenericSignatureImpl *,
19081906
GenericParamList *,
19091907
WhereClauseOwner,
19101908
SmallVector<Requirement, 2>,
@@ -1920,7 +1918,6 @@ class InferredGenericSignatureRequestRQM :
19201918
// Evaluation.
19211919
GenericSignatureWithError
19221920
evaluate(Evaluator &evaluator,
1923-
ModuleDecl *parentModule,
19241921
const GenericSignatureImpl *baseSignature,
19251922
GenericParamList *genericParams,
19261923
WhereClauseOwner whereClause,

include/swift/IDE/CodeCompletionResult.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ enum class CompletionKind : uint8_t {
223223
StmtLabel,
224224
ForEachPatternBeginning,
225225
TypeAttrBeginning,
226+
OptionalBinding,
226227
};
227228

228229
enum class CodeCompletionDiagnosticSeverity : uint8_t {

include/swift/IDE/CompletionLookup.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@
3333
namespace swift {
3434
namespace ide {
3535

36-
using DeclFilter = std::function<bool(ValueDecl *, DeclVisibilityKind)>;
36+
using DeclFilter =
37+
std::function<bool(ValueDecl *, DeclVisibilityKind, DynamicLookupInfo)>;
3738

3839
/// A filter that always returns \c true.
39-
bool DefaultFilter(ValueDecl *VD, DeclVisibilityKind Kind);
40+
bool DefaultFilter(ValueDecl *VD, DeclVisibilityKind Kind,
41+
DynamicLookupInfo dynamicLookupInfo);
4042

41-
bool KeyPathFilter(ValueDecl *decl, DeclVisibilityKind);
43+
bool KeyPathFilter(ValueDecl *decl, DeclVisibilityKind,
44+
DynamicLookupInfo dynamicLookupInfo);
4245

4346
/// Returns \c true only if the completion is happening for top-level
4447
/// declrarations. i.e.:
@@ -528,7 +531,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
528531
: Consumer(Consumer), Filter(Filter) {}
529532
void foundDecl(ValueDecl *VD, DeclVisibilityKind Kind,
530533
DynamicLookupInfo dynamicLookupInfo) override {
531-
if (Filter(VD, Kind))
534+
if (Filter(VD, Kind, dynamicLookupInfo))
532535
Consumer.foundDecl(VD, Kind, dynamicLookupInfo);
533536
}
534537
};
@@ -588,6 +591,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
588591
bool ResultsHaveLeadingDot);
589592

590593
void getStmtLabelCompletions(SourceLoc Loc, bool isContinue);
594+
595+
void getOptionalBindingCompletions(SourceLoc Loc);
591596
};
592597

593598
} // end namespace ide

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ class CodeCompletionCallbacks {
236236

237237
virtual void completeTypeAttrBeginning() {};
238238

239+
virtual void completeOptionalBinding(){};
240+
239241
/// Signals that the AST for the all the delayed-parsed code was
240242
/// constructed. No \c complete*() callbacks will be done after this.
241243
virtual void doneParsing() = 0;

lib/AST/DeclContext.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ ProtocolDecl *DeclContext::getExtendedProtocolDecl() const {
8585

8686
VarDecl *DeclContext::getNonLocalVarDecl() const {
8787
if (auto *init = dyn_cast<PatternBindingInitializer>(this)) {
88-
if (auto *var =
89-
init->getBinding()->getAnchoringVarDecl(init->getBindingIndex())) {
90-
return var;
91-
}
88+
if (auto binding = init->getBinding()) {
89+
if (auto *var = binding->getAnchoringVarDecl(init->getBindingIndex())) {
90+
return var;
91+
}
92+
}
9293
}
9394
return nullptr;
9495
}

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8464,7 +8464,6 @@ InferredGenericSignatureRequest::evaluate(
84648464
return evaluateOrDefault(
84658465
ctx.evaluator,
84668466
InferredGenericSignatureRequestRQM{
8467-
parentModule,
84688467
parentSig,
84698468
genericParams,
84708469
whereClause,

lib/AST/RequirementMachine/KnuthBendix.cpp

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,66 @@ RewriteSystem::computeCriticalPair(ArrayRef<Symbol>::const_iterator from,
157157
return false;
158158
}
159159

160-
// Add the pair (X, TYV).
161-
pairs.emplace_back(x, tyv, path);
160+
// If X == TUW for some W, then the critical pair is (TUW, TYV),
161+
// and we have
162+
// - lhs == (TUV => TUW)
163+
// - rhs == (U => Y).
164+
//
165+
// We explicitly apply the rewrite step (Y => U) to the beginning of the
166+
// rewrite path, transforming the critical pair to (TYW, TYV).
167+
//
168+
// In particular, if V == W.[P] for some protocol P, then we in fact have
169+
// a property rule and a same-type rule:
170+
//
171+
// - lhs == (TUW.[P] => TUW)
172+
// - rhs == (U => Y)
173+
//
174+
// Without this hack, the critical pair would be:
175+
//
176+
// (TUW => TYW.[P])
177+
//
178+
// With this hack, the critical pair becomes:
179+
//
180+
// (TYW.[P] => TYW)
181+
//
182+
// This ensures that the newly-added rule is itself a property rule;
183+
// otherwise, this would only be the case if addRule() reduced TUW
184+
// into TYW without immediately reducing some subterm of TUW first.
185+
//
186+
// While completion will eventually simplify all such rules down into
187+
// property rules, their existance in the first place breaks subtle
188+
// invariants in the minimal conformances algorithm, which expects
189+
// homotopy generators describing redundant protocol conformance rules
190+
// to have a certain structure.
191+
if (t.size() + rhs.getLHS().size() <= x.size() &&
192+
std::equal(rhs.getLHS().begin(),
193+
rhs.getLHS().end(),
194+
x.begin() + t.size())) {
195+
// We have a path from TUW to TYV. Invert to get a path from TYV to
196+
// TUW.
197+
path.invert();
198+
199+
// Compute the term W.
200+
MutableTerm w(x.begin() + t.size() + rhs.getLHS().size(), x.end());
201+
202+
// Now add a rewrite step T.(U => Y).W to get a path from TYV to
203+
// TYW.
204+
path.add(RewriteStep::forRewriteRule(/*startOffset=*/t.size(),
205+
/*endOffset=*/w.size(),
206+
getRuleID(rhs),
207+
/*inverse=*/false));
208+
209+
// Compute the term TYW.
210+
MutableTerm tyw(t);
211+
tyw.append(rhs.getRHS());
212+
tyw.append(w);
213+
214+
// Add the pair (TYV, TYW).
215+
pairs.emplace_back(tyv, tyw, path);
216+
} else {
217+
// Add the pair (X, TYV).
218+
pairs.emplace_back(x, tyv, path);
219+
}
162220
} else {
163221
// lhs == TU -> X, rhs == UV -> Y.
164222

@@ -217,7 +275,7 @@ RewriteSystem::computeCriticalPair(ArrayRef<Symbol>::const_iterator from,
217275
// - lhs == (TU -> X)
218276
// - rhs == (UV -> UW).
219277
//
220-
// We explicitly apply the rewrite step (TU = X) to the rewrite path,
278+
// We explicitly apply the rewrite step (TU => X) to the rewrite path,
221279
// transforming the critical pair to (XV, XW).
222280
//
223281
// In particular, if T == X, U == [P] for some protocol P, and
@@ -229,15 +287,15 @@ RewriteSystem::computeCriticalPair(ArrayRef<Symbol>::const_iterator from,
229287
//
230288
// Without this hack, the critical pair would be:
231289
//
232-
// (T.w.[p] => T.[P].w)
290+
// (T.W.[p] => T.[P].W)
233291
//
234292
// With this hack, the critical pair becomes:
235293
//
236-
// (T.w.[p] => T.w)
294+
// (T.W.[p] => T.W)
237295
//
238296
// This ensures that the newly-added rule is itself a property rule;
239-
// otherwise, this would only be the case if addRule() reduced T.[P].w
240-
// into T.w without immediately reducing some subterm of T first.
297+
// otherwise, this would only be the case if addRule() reduced T.[P].W
298+
// into T.W without immediately reducing some subterm of T first.
241299
//
242300
// While completion will eventually simplify all such rules down into
243301
// property rules, their existance in the first place breaks subtle

0 commit comments

Comments
 (0)