Skip to content

Commit f17f344

Browse files
Merge remote-tracking branch 'apple/main' into katei/merge-main-2022-08-19
2 parents 960226b + 93a78b4 commit f17f344

File tree

174 files changed

+1606
-2144
lines changed

Some content is hidden

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

174 files changed

+1606
-2144
lines changed

docs/DevelopmentTips.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ Going further, for various reasons the standard library has lots of warnings. Th
2121
Copy the invocation that has ` -o <build-path>/swift-macosx-x86_64/stdlib/public/core/iphonesimulator/i386/Swift.o`, so that we can perform the actual call to swiftc ourselves. Tack on `-suppress-warnings` at the end, and now we have the command to just build `Swift.o` for i386 while only displaying the actual errors.
2222

2323
### Choosing the bootstrapping mode
24-
By default, the compiler builds with the `boostrapping-with-hostlibs` (macOS) or `bootstrapping` (Linux) bootstrapping mode. To speed up local development it's recommended to build with the `hosttools` mode: `utils/build-script --bootstrapping=hosttools`.
24+
By default, the compiler builds with the `bootstrapping-with-hostlibs` (macOS) or `bootstrapping` (Linux) bootstrapping mode. To speed up local development it's recommended to build with the `hosttools` mode: `utils/build-script --bootstrapping=hosttools`.
2525

2626
It requires a recently new swift toolchain to be installed on your build machine. You might need to download and install a nightly Swift toolchain to build the Swift project in `hosttools` mode.
2727

2828
Not that changing the bootstrapping mode needs a reconfiguration.
2929

3030
#### Using a locally built Swift toolchain
3131

32-
If you do not want to install a nightly Swift toolchain, or you need to debug Swift code within SwiftCompilerSources, you can build the Swift toolchain in `boostrapping-with-hostlibs` mode on your local machine once, and then use this toolchain to iterate on your changes with the `hosttools` mode:
32+
If you do not want to install a nightly Swift toolchain, or you need to debug Swift code within SwiftCompilerSources, you can build the Swift toolchain in `bootstrapping-with-hostlibs` mode on your local machine once, and then use this toolchain to iterate on your changes with the `hosttools` mode:
3333

34-
* Build the toolchain locally in `boostrapping-with-hostlibs` mode: `./utils/build-toolchain com.yourname`.
34+
* Build the toolchain locally in `bootstrapping-with-hostlibs` mode: `./utils/build-toolchain com.yourname`.
3535
* Copy the `swift-LOCAL-YYYY-MM-DD.xctoolchain` file from `./swift-nightly-install/Library/Developer/Toolchains` to `/Library/Developer/Toolchains`.
3636
* Launch Xcode, in the menu bar select _Xcode_ > _Toolchains_ > _Local Swift Development Snapshot YYYY-MM-DD_.
3737
* Remove the Swift build directory: `./build`.
@@ -124,4 +124,4 @@ To setup this environment a few steps are necessary:
124124

125125
Now you are all set. You can build and debug like with a native Xcode project.
126126

127-
If the project structure changes, e.g. new source files are added or deleted, you just have to re-create the LLVM and Swift projects with `utils/build-script --skip-build --xcode --skip-early-swift-driver`.
127+
If the project structure changes, e.g. new source files are added or deleted, you just have to re-create the LLVM and Swift projects with `utils/build-script --skip-build --xcode --skip-early-swift-driver`.

docs/SIL.rst

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4862,36 +4862,6 @@ into a ``copy_block`` and a ``is_escaping``/``cond_fail``/``destroy_value`` at
48624862
the end of the lifetime of the objective c closure parameter to check whether
48634863
the sentinel closure was escaped.
48644864

4865-
builtin "unsafeGuaranteed"
4866-
``````````````````````````
4867-
4868-
::
4869-
4870-
sil-instruction := 'builtin' '"unsafeGuaranteed"' '<' sil-type '>' '(' sil-operand')' ':' sil-type
4871-
4872-
%1 = builtin "unsafeGuaranteed"<T>(%0 : $T) : ($T, Builtin.Int1)
4873-
// $T must be of AnyObject type.
4874-
4875-
Asserts that there exists another reference of the value ``%0`` for the scope
4876-
delineated by the call of this builtin up to the first call of a ``builtin
4877-
"unsafeGuaranteedEnd"`` instruction that uses the second element ``%1.1`` of the
4878-
returned value. If no such instruction can be found nothing can be assumed. This
4879-
assertion holds for uses of the first tuple element of the returned value
4880-
``%1.0`` within this scope. The returned reference value equals the input
4881-
``%0``.
4882-
4883-
builtin "unsafeGuaranteedEnd"
4884-
`````````````````````````````
4885-
4886-
::
4887-
4888-
sil-instruction := 'builtin' '"unsafeGuaranteedEnd"' '(' sil-operand')'
4889-
4890-
%1 = builtin "unsafeGuaranteedEnd"(%0 : $Builtin.Int1)
4891-
// $T must be of AnyObject type.
4892-
4893-
Ends the scope for the ``builtin "unsafeGuaranteed"`` instruction.
4894-
48954865
Literals
48964866
~~~~~~~~
48974867

include/swift/AST/ASTWalker.h

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ struct ReferenceMetaData {
5050
: Kind(Kind), AccKind(AccKind), isImplicit(isImplicit) {}
5151
};
5252

53+
/// Specifies how the initialization expression of a \c lazy variable should be
54+
/// walked by the ASTWalker.
55+
enum class LazyInitializerWalking {
56+
/// No lazy initialization expressions will be walked.
57+
None,
58+
59+
/// The lazy initialization expression will only be walked as a part of
60+
/// the variable's pattern binding decl. This is the default behavior, and is
61+
/// consistent with the initializer being syntactically part of the pattern
62+
/// binding.
63+
InPatternBinding,
64+
65+
/// The lazy initialization expression will only be walked as part of the
66+
/// body of the synthesized accessor for the lazy variable. In such an
67+
/// accessor, the expression is denoted by LazyInitializerExpr. This is mainly
68+
/// useful for code emission.
69+
InAccessor
70+
};
71+
5372
/// An abstract class used to traverse an AST.
5473
class ASTWalker {
5574
public:
@@ -193,15 +212,13 @@ class ASTWalker {
193212
/// params in AbstractFunctionDecl and NominalTypeDecl.
194213
virtual bool shouldWalkIntoGenericParams() { return false; }
195214

196-
/// This method configures whether the walker should walk into the
197-
/// initializers of lazy variables. These initializers are semantically
198-
/// different from other initializers in their context and so sometimes
199-
/// should not be visited.
200-
///
201-
/// Note that visiting the body of the lazy getter will find a
202-
/// LazyInitializerExpr with the initializer as its sub-expression.
203-
/// However, ASTWalker does not walk into LazyInitializerExprs on its own.
204-
virtual bool shouldWalkIntoLazyInitializers() { return true; }
215+
/// This method configures how the walker should walk the initializers of
216+
/// lazy variables. These initializers are semantically different from other
217+
/// initializers in their context and so sometimes should be visited as part
218+
/// of the synthesized getter, or should not be visited at all.
219+
virtual LazyInitializerWalking getLazyInitializerWalkingBehavior() {
220+
return LazyInitializerWalking::InPatternBinding;
221+
}
205222

206223
/// This method configures whether the walker should visit the body of a
207224
/// closure that was checked separately from its enclosing expression.

include/swift/AST/Builtins.def

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,6 @@ BUILTIN_MISC_OPERATION(AssignTakeArray, "assignTakeArray", "", Special)
723723
/// This builtin indicates to the optimizer that the buffer is not mutable.
724724
BUILTIN_MISC_OPERATION(COWBufferForReading, "COWBufferForReading", "n", Special)
725725

726-
// unsafeGuaranteed has type <T: AnyObject> T -> (T, Builtin.Int8)
727-
BUILTIN_MISC_OPERATION(UnsafeGuaranteed, "unsafeGuaranteed", "", Special)
728-
729-
// unsafeGuaranteedEnd has type (Builtin.Int8) -> ()
730-
BUILTIN_MISC_OPERATION(UnsafeGuaranteedEnd, "unsafeGuaranteedEnd", "", Special)
731-
732726
// getObjCTypeEncoding has type <T> T.Type -> RawPointer
733727
BUILTIN_MISC_OPERATION(GetObjCTypeEncoding, "getObjCTypeEncoding", "n", Special)
734728

include/swift/AST/Expr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5314,6 +5314,7 @@ class LazyInitializerExpr : public Expr {
53145314
SourceLoc getLoc() const { return SubExpr->getLoc(); }
53155315

53165316
Expr *getSubExpr() const { return SubExpr; }
5317+
void setSubExpr(Expr *subExpr) { SubExpr = subExpr; }
53175318

53185319
static bool classof(const Expr *E) {
53195320
return E->getKind() == ExprKind::LazyInitializer;

include/swift/AST/Module.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,8 @@ class ModuleDecl
685685
// Is \p spiGroup accessible as an explicitly imported SPI from this module?
686686
bool isImportedAsSPI(Identifier spiGroup, const ModuleDecl *fromModule) const;
687687

688-
/// Is \p targetDecl from a module that is imported as \c @_weakLinked from
689-
/// this module?
690-
bool isImportedAsWeakLinked(const Decl *targetDecl) const;
688+
/// Is \p module imported as \c @_weakLinked from this module?
689+
bool isImportedAsWeakLinked(const ModuleDecl *module) const;
691690

692691
/// \sa getImportedModules
693692
enum class ImportFilterKind {

include/swift/SIL/SILFunction.h

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "swift/AST/ASTNode.h"
2121
#include "swift/AST/Availability.h"
22+
#include "swift/AST/Module.h"
2223
#include "swift/AST/ResilienceExpansion.h"
2324
#include "swift/Basic/ProfileCounter.h"
2425
#include "swift/Basic/SwiftObjectHeader.h"
@@ -64,11 +65,6 @@ enum IsDistributed_t {
6465
IsNotDistributed,
6566
IsDistributed,
6667
};
67-
enum IsWeakImported_t {
68-
IsNotWeakImported,
69-
IsWeakImportedByModule,
70-
IsAlwaysWeakImported,
71-
};
7268

7369
enum class PerformanceConstraints : uint8_t {
7470
None = 0,
@@ -222,6 +218,10 @@ class SILFunction
222218
/// The AST decl context of the function.
223219
DeclContext *DeclCtxt = nullptr;
224220

221+
/// The module that defines this function. This member should only be set as
222+
/// a fallback when a \c DeclCtxt is unavailable.
223+
ModuleDecl *ParentModule = nullptr;
224+
225225
/// The profiler for instrumentation based profiling, or null if profiling is
226226
/// disabled.
227227
SILProfiler *Profiler = nullptr;
@@ -322,8 +322,9 @@ class SILFunction
322322
/// would indicate.
323323
unsigned HasCReferences : 1;
324324

325-
/// Whether cross-module references to this function should use weak linking.
326-
unsigned IsWeakImported : 2;
325+
/// Whether cross-module references to this function should always use weak
326+
/// linking.
327+
unsigned IsAlwaysWeakImported : 1;
327328

328329
/// Whether the implementation can be dynamically replaced.
329330
unsigned IsDynamicReplaceable : 1;
@@ -801,19 +802,11 @@ class SILFunction
801802

802803
/// Returns whether this function's symbol must always be weakly referenced
803804
/// across module boundaries.
804-
bool isAlwaysWeakImported() const {
805-
return IsWeakImported == IsWeakImported_t::IsAlwaysWeakImported;
806-
}
807-
808-
/// Returns whether this function's symbol was referenced by a module that
809-
/// imports the defining module \c @_weakLinked.
810-
bool isWeakImportedByModule() const {
811-
return IsWeakImported == IsWeakImported_t::IsWeakImportedByModule;
812-
}
805+
bool isAlwaysWeakImported() const { return IsAlwaysWeakImported; }
813806

814-
void setIsWeakImported(IsWeakImported_t value) { IsWeakImported = value; }
807+
void setIsAlwaysWeakImported(bool value) { IsAlwaysWeakImported = value; }
815808

816-
bool isWeakImported() const;
809+
bool isWeakImported(ModuleDecl *module) const;
817810

818811
/// Returns whether this function implementation can be dynamically replaced.
819812
IsDynamicallyReplaceable_t isDynamicallyReplaceable() const {
@@ -960,6 +953,18 @@ class SILFunction
960953
DeclCtxt = (DS ? DebugScope->Loc.getAsDeclContext() : nullptr);
961954
}
962955

956+
/// Returns the module that defines this function.
957+
ModuleDecl *getParentModule() const {
958+
return DeclCtxt ? DeclCtxt->getParentModule() : ParentModule;
959+
}
960+
961+
/// Sets \c ParentModule as fallback if \c DeclCtxt is not available to
962+
/// provide the parent module.
963+
void setParentModule(ModuleDecl *module) {
964+
assert(!DeclCtxt && "already have a DeclCtxt");
965+
ParentModule = module;
966+
}
967+
963968
/// Initialize the debug scope for debug info on SIL level
964969
/// (-sil-based-debuginfo).
965970
void setSILDebugScope(const SILDebugScope *DS) {

include/swift/SILOptimizer/Analysis/ARCAnalysis.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -392,35 +392,6 @@ class ConsumedArgToEpilogueReleaseMatcher {
392392
/// Match a call to a trap BB with no ARC relevant side effects.
393393
bool isARCInertTrapBB(const SILBasicBlock *BB);
394394

395-
/// Get the two result values of the builtin "unsafeGuaranteed" instruction.
396-
///
397-
/// Gets the (GuaranteedValue, Token) tuple from a call to "unsafeGuaranteed"
398-
/// if the tuple elements are identified by a single tuple_extract use.
399-
/// Otherwise, returns a (nullptr, nullptr) tuple.
400-
std::pair<SingleValueInstruction *, SingleValueInstruction *>
401-
getSingleUnsafeGuaranteedValueResult(BuiltinInst *UnsafeGuaranteedInst);
402-
403-
/// Get the single builtin "unsafeGuaranteedEnd" user of a builtin
404-
/// "unsafeGuaranteed"'s token.
405-
BuiltinInst *getUnsafeGuaranteedEndUser(SILValue UnsafeGuaranteedToken);
406-
407-
/// Walk forwards from an unsafeGuaranteedEnd builtin instruction looking for a
408-
/// release on the reference returned by the matching unsafeGuaranteed builtin
409-
/// ignoring releases on the way.
410-
/// Return nullptr if no release is found.
411-
///
412-
/// %4 = builtin "unsafeGuaranteed"<Foo>(%0 : $Foo) : $(Foo, Builtin.Int8)
413-
/// %5 = tuple_extract %4 : $(Foo, Builtin.Int8), 0
414-
/// %6 = tuple_extract %4 : $(Foo, Builtin.Int8), 1
415-
/// %12 = builtin "unsafeGuaranteedEnd"(%6 : $Builtin.Int8) : $()
416-
/// strong_release %5 : $Foo // <-- Matching release.
417-
///
418-
/// Alternatively, look for the release before the unsafeGuaranteedEnd.
419-
SILInstruction *findReleaseToMatchUnsafeGuaranteedValue(
420-
SILInstruction *UnsafeGuaranteedEndI, SILInstruction *UnsafeGuaranteedI,
421-
SILValue UnsafeGuaranteedValue, SILBasicBlock &BB,
422-
RCIdentityFunctionInfo &RCFI);
423-
424395
} // end namespace swift
425396

426397
#endif

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,6 @@ PASS(StringOptimization, "string-optimization",
410410
"Optimization for String operations")
411411
PASS(SwiftArrayPropertyOpt, "array-property-opt",
412412
"Loop Specialization for Array Properties")
413-
PASS(UnsafeGuaranteedPeephole, "unsafe-guaranteed-peephole",
414-
"SIL retain/release Peephole Removal for Builtin.unsafeGuaranteed")
415413
PASS(UsePrespecialized, "use-prespecialized",
416414
"Use Pre-Specialized Functions")
417415
PASS(OwnershipDumper, "ownership-dumper",

include/swift/Sema/IDETypeChecking.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ namespace swift {
304304
BuildArray,
305305
BuildLimitedAvailability,
306306
BuildFinalResult,
307+
BuildPartialBlockFirst,
308+
BuildPartialBlockAccumulated,
307309
};
308310

309311
/// Try to infer the component type of a result builder from the type

0 commit comments

Comments
 (0)