Skip to content

Commit c2fd49c

Browse files
authored
Merge pull request #39473 from apple/rebranch
Update swift:main to support llvm-project:stable/20210726 changes (Rebranch merge)
2 parents 0f73410 + adf8ba3 commit c2fd49c

File tree

183 files changed

+1039
-648
lines changed

Some content is hidden

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

183 files changed

+1039
-648
lines changed

benchmark/scripts/compare_perf_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

44
# ===--- compare_perf_tests.py -------------------------------------------===//

benchmark/scripts/test_Benchmark_Driver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

44
# ===--- test_Benchmark_Driver.py ----------------------------------------===//

benchmark/scripts/test_compare_perf_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

44
# ===--- test_compare_perf_tests.py --------------------------------------===//

benchmark/scripts/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

44
# ===--- test_utils.py ---------------------------------------------------===//

include/swift/AST/ASTWalker.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_AST_ASTWALKER_H
1414
#define SWIFT_AST_ASTWALKER_H
1515

16+
#include "llvm/ADT/Optional.h"
1617
#include "llvm/ADT/PointerUnion.h"
1718
#include <utility>
1819

include/swift/AST/DiagnosticsParse.def

+2
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ ERROR(sil_invalid_column_in_sil_location,none,
528528
"column number must be a positive integer", ())
529529
ERROR(sil_invalid_scope_slot,none,
530530
"scope number must be a positive integer ", ())
531+
ERROR(sil_invalid_constant,none,
532+
"constant operand must be an integer literal ", ())
531533
ERROR(sil_scope_undeclared,none,
532534
"scope number %0 needs to be declared before first use", (unsigned))
533535
ERROR(sil_scope_redefined,none,

include/swift/AST/Identifier.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/Basic/EditorPlaceholder.h"
2121
#include "swift/Basic/Debug.h"
2222
#include "swift/Basic/LLVM.h"
23+
#include "llvm/ADT/ArrayRef.h"
2324
#include "llvm/ADT/FoldingSet.h"
2425
#include "llvm/ADT/PointerUnion.h"
2526
#include "llvm/Support/TrailingObjects.h"

include/swift/AST/Module.h

+9
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ class ModuleDecl
257257

258258
AccessNotesFile accessNotes;
259259

260+
/// Used by the debugger to bypass resilient access to fields.
261+
bool BypassResilience = false;
262+
260263
ModuleDecl(Identifier name, ASTContext &ctx, ImplicitImportInfo importInfo);
261264

262265
public:
@@ -290,6 +293,12 @@ class ModuleDecl
290293
AccessNotesFile &getAccessNotes() { return accessNotes; }
291294
const AccessNotesFile &getAccessNotes() const { return accessNotes; }
292295

296+
/// Return whether the module was imported with resilience disabled. The
297+
/// debugger does this to access private fields.
298+
bool getBypassResilience() const { return BypassResilience; }
299+
/// Only to be called by MemoryBufferSerializedModuleLoader.
300+
void setBypassResilience() { BypassResilience = true; }
301+
293302
ArrayRef<FileUnit *> getFiles() {
294303
assert(!Files.empty() || failedToLoad());
295304
return Files;

include/swift/AST/Ownership.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/Support/raw_ostream.h"
2727
#include <stdint.h>
2828
#include <assert.h>
29+
#include <climits>
2930

3031
namespace swift {
3132

include/swift/AST/TBDGenRequests.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class TBDGenDescriptor final {
7070
const TBDGenOptions &getOptions() const { return Opts; }
7171
TBDGenOptions &getOptions() { return Opts; }
7272

73-
const llvm::DataLayout &getDataLayout() const;
73+
const StringRef getDataLayoutString() const;
7474
const llvm::Triple &getTarget() const;
7575

7676
bool operator==(const TBDGenDescriptor &other) const;

include/swift/Basic/BlotSetVector.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/Basic/LLVM.h"
1717
#include "llvm/ADT/DenseMap.h"
18+
#include "llvm/ADT/Optional.h"
1819
#include "llvm/ADT/SmallVector.h"
1920
#include <vector>
2021

include/swift/Basic/MultiMapCache.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_BASIC_MULTIMAPCACHE_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "llvm/ADT/ArrayRef.h"
1718
#include "llvm/ADT/DenseMap.h"
1819

1920
namespace swift {

include/swift/Basic/Platform.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "swift/Basic/LLVM.h"
1717
#include "swift/Config.h"
1818
#include "llvm/ADT/StringRef.h"
19-
#include "clang/Driver/DarwinSDKInfo.h"
19+
#include "clang/Basic/DarwinSDKInfo.h"
2020

2121
namespace llvm {
2222
class Triple;
@@ -105,7 +105,7 @@ namespace swift {
105105
getSwiftRuntimeCompatibilityVersionForTarget(const llvm::Triple &Triple);
106106

107107
/// Retrieve the target SDK version for the given SDKInfo and target triple.
108-
llvm::VersionTuple getTargetSDKVersion(clang::driver::DarwinSDKInfo &SDKInfo,
108+
llvm::VersionTuple getTargetSDKVersion(clang::DarwinSDKInfo &SDKInfo,
109109
const llvm::Triple &triple);
110110

111111
/// Get SDK build version.

include/swift/Basic/Version.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/ADT/SmallVector.h"
2626
#include "llvm/ADT/StringRef.h"
2727
#include "llvm/Support/VersionTuple.h"
28+
#include <array>
2829
#include <string>
2930

3031
namespace swift {

include/swift/LLVMPasses/Passes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace swift {
3434
using AAResultBase::getModRefInfo;
3535
llvm::ModRefInfo getModRefInfo(const llvm::CallBase *Call,
3636
const llvm::MemoryLocation &Loc) {
37-
llvm::AAQueryInfo AAQI;
37+
llvm::SimpleAAQueryInfo AAQI;
3838
return getModRefInfo(Call, Loc, AAQI);
3939
}
4040
llvm::ModRefInfo getModRefInfo(const llvm::CallBase *Call,

include/swift/SIL/Notifications.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/Basic/STLExtras.h"
1818
#include "llvm/ADT/PointerUnion.h"
1919
#include "llvm/ADT/SmallVector.h"
20+
#include "llvm/ADT/StringRef.h"
2021
#include <memory>
2122

2223
namespace swift {

include/swift/SIL/SILBuilder.h

+24-4
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,34 @@ class SILBuilder {
363363
// SILInstruction Creation Methods
364364
//===--------------------------------------------------------------------===//
365365

366+
/// Substitute anonymous function arguments with "_$ArgNo".
367+
Optional<SILDebugVariable>
368+
substituteAnonymousArgs(llvm::SmallString<4> Name,
369+
Optional<SILDebugVariable> Var, SILLocation Loc) {
370+
if (!Var || !Var->ArgNo || !Var->Name.empty())
371+
return Var;
372+
373+
auto *VD = Loc.getAsASTNode<VarDecl>();
374+
if (VD && !VD->getName().empty())
375+
return Var;
376+
377+
llvm::raw_svector_ostream(Name) << '_' << (Var->ArgNo - 1);
378+
Var->Name = Name;
379+
return Var;
380+
}
381+
366382
AllocStackInst *createAllocStack(SILLocation Loc, SILType elementType,
367383
Optional<SILDebugVariable> Var = None,
368384
bool hasDynamicLifetime = false,
369385
bool isLexical = false) {
386+
llvm::SmallString<4> Name;
370387
Loc.markAsPrologue();
371388
assert((!dyn_cast_or_null<VarDecl>(Loc.getAsASTNode<Decl>()) || Var) &&
372389
"location is a VarDecl, but SILDebugVariable is empty");
373-
return insert(AllocStackInst::create(getSILDebugLocation(Loc), elementType,
374-
getFunction(), Var, hasDynamicLifetime,
375-
isLexical));
390+
return insert(AllocStackInst::create(
391+
getSILDebugLocation(Loc), elementType, getFunction(),
392+
substituteAnonymousArgs(Name, Var, Loc), hasDynamicLifetime,
393+
isLexical));
376394
}
377395

378396
AllocRefInst *createAllocRef(SILLocation Loc, SILType ObjectType,
@@ -402,11 +420,13 @@ class SILBuilder {
402420
AllocBoxInst *createAllocBox(SILLocation Loc, CanSILBoxType BoxType,
403421
Optional<SILDebugVariable> Var = None,
404422
bool hasDynamicLifetime = false) {
423+
llvm::SmallString<4> Name;
405424
Loc.markAsPrologue();
406425
assert((!dyn_cast_or_null<VarDecl>(Loc.getAsASTNode<Decl>()) || Var) &&
407426
"location is a VarDecl, but SILDebugVariable is empty");
408427
return insert(AllocBoxInst::create(getSILDebugLocation(Loc), BoxType, *F,
409-
Var, hasDynamicLifetime));
428+
substituteAnonymousArgs(Name, Var, Loc),
429+
hasDynamicLifetime));
410430
}
411431

412432
AllocExistentialBoxInst *

include/swift/SIL/SILDebugInfoExpression.h

+45-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef SWIFT_SIL_DEBUGINFOEXPRESSION_H
1919
#define SWIFT_SIL_DEBUGINFOEXPRESSION_H
2020
#include "swift/AST/Decl.h"
21+
#include "llvm/ADT/APInt.h"
2122
#include "llvm/ADT/ArrayRef.h"
2223
#include "llvm/ADT/Optional.h"
2324
#include "llvm/ADT/iterator_range.h"
@@ -36,17 +37,30 @@ enum class SILDIExprOperator : unsigned {
3637
/// VarDecl operand pointing to the field declaration.
3738
/// Note that this directive can only appear at the end of an
3839
/// expression.
39-
Fragment
40+
Fragment,
41+
/// Perform arithmetic addition on the top two elements of the
42+
/// expression stack and push the result back to the stack.
43+
Plus,
44+
/// Subtract the top element in expression stack by the second
45+
/// element. Then push the result back to the stack.
46+
Minus,
47+
/// Push an unsigned integer constant onto the stack.
48+
ConstUInt,
49+
/// Push a signed integer constant onto the stack.
50+
ConstSInt
4051
};
4152

4253
/// Represents a single component in a debug info expression.
4354
/// Including operator and operand.
4455
struct SILDIExprElement {
4556
enum Kind {
46-
/// A di-expression operator
57+
/// A di-expression operator.
4758
OperatorKind,
48-
/// An operand that has declaration type
49-
DeclKind
59+
/// An operand that has declaration type.
60+
DeclKind,
61+
/// An integer constant value. Note that
62+
/// we don't specify its signedness here.
63+
ConstIntKind
5064
};
5165

5266
private:
@@ -55,6 +69,7 @@ struct SILDIExprElement {
5569
union {
5670
SILDIExprOperator Operator;
5771
Decl *Declaration;
72+
uint64_t ConstantInt;
5873
};
5974

6075
explicit SILDIExprElement(Kind OpK) : OpKind(OpK) {}
@@ -68,6 +83,13 @@ struct SILDIExprElement {
6883

6984
Decl *getAsDecl() const { return OpKind == DeclKind ? Declaration : nullptr; }
7085

86+
Optional<uint64_t> getAsConstInt() const {
87+
if (OpKind == ConstIntKind)
88+
return ConstantInt;
89+
else
90+
return {};
91+
}
92+
7193
static SILDIExprElement createOperator(SILDIExprOperator Op) {
7294
SILDIExprElement DIOp(OperatorKind);
7395
DIOp.Operator = Op;
@@ -79,6 +101,12 @@ struct SILDIExprElement {
79101
DIOp.Declaration = D;
80102
return DIOp;
81103
}
104+
105+
static SILDIExprElement createConstInt(uint64_t V) {
106+
SILDIExprElement DIOp(ConstIntKind);
107+
DIOp.ConstantInt = V;
108+
return DIOp;
109+
}
82110
};
83111

84112
/// For a given SILDIExprOperator, provides information
@@ -231,6 +259,19 @@ class SILDebugInfoExpression {
231259

232260
/// Create a op_fragment expression
233261
static SILDebugInfoExpression createFragment(VarDecl *Field);
262+
263+
/// Return true if this DIExpression starts with op_deref
264+
bool startsWithDeref() const {
265+
return Elements.size() &&
266+
Elements[0].getAsOperator() == SILDIExprOperator::Dereference;
267+
}
268+
269+
/// Return true if this DIExpression has op_fragment (at the end)
270+
bool hasFragment() const {
271+
return Elements.size() >= 2 &&
272+
Elements[Elements.size() - 2].getAsOperator() ==
273+
SILDIExprOperator::Fragment;
274+
}
234275
};
235276
} // end namespace swift
236277
#endif

include/swift/SIL/SILInstruction.h

+5-7
Original file line numberDiff line numberDiff line change
@@ -1810,13 +1810,11 @@ class TailAllocatedDebugVariable {
18101810
if (!Bits.Data.HasValue)
18111811
return None;
18121812

1813-
if (VD)
1814-
return SILDebugVariable(VD->getName().empty() ? "" : VD->getName().str(),
1815-
VD->isLet(), getArgNo(), isImplicit(), AuxVarType,
1816-
DeclLoc, DeclScope, DIExprElements);
1817-
else
1818-
return SILDebugVariable(getName(buf), isLet(), getArgNo(), isImplicit(),
1819-
AuxVarType, DeclLoc, DeclScope, DIExprElements);
1813+
StringRef name = getName(buf);
1814+
if (VD && name.empty())
1815+
name = VD->getName().str();
1816+
return SILDebugVariable(name, isLet(), getArgNo(), isImplicit(), AuxVarType,
1817+
DeclLoc, DeclScope, DIExprElements);
18201818
}
18211819
};
18221820
static_assert(sizeof(TailAllocatedDebugVariable) == 4,

include/swift/SIL/SILInstructionWorklist.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "swift/SIL/SILInstruction.h"
3838
#include "swift/SIL/InstructionUtils.h"
3939
#include "swift/SIL/SILValue.h"
40+
#include "swift/SILOptimizer/Utils/DebugOptUtils.h"
4041
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
4142
#include "llvm/ADT/DenseMap.h"
4243
#include "llvm/ADT/SmallVector.h"
@@ -309,7 +310,9 @@ class SILInstructionWorklist : SILInstructionWorklistBase {
309310
void eraseInstFromFunction(SILInstruction &instruction,
310311
SILBasicBlock::iterator &iterator,
311312
bool addOperandsToWorklist = true) {
312-
// Delete any debug users first.
313+
// Try to salvage debug info first.
314+
swift::salvageDebugInfo(&instruction);
315+
// Then delete old debug users.
313316
for (auto result : instruction.getResults()) {
314317
while (!result->use_empty()) {
315318
auto *user = result->use_begin()->getUser();

include/swift/Serialization/SerializedModuleLoader.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,11 @@ class MemoryBufferSerializedModuleLoader : public SerializedModuleLoaderBase {
263263
MemoryBufferSerializedModuleLoader(ASTContext &ctx,
264264
DependencyTracker *tracker,
265265
ModuleLoadingMode loadMode,
266-
bool IgnoreSwiftSourceInfo)
266+
bool IgnoreSwiftSourceInfo,
267+
bool BypassResilience)
267268
: SerializedModuleLoaderBase(ctx, tracker, loadMode,
268-
IgnoreSwiftSourceInfo) {}
269+
IgnoreSwiftSourceInfo),
270+
BypassResilience(BypassResilience) {}
269271

270272
std::error_code findModuleFilesInDirectory(
271273
ImportPath::Element ModuleID,
@@ -281,6 +283,7 @@ class MemoryBufferSerializedModuleLoader : public SerializedModuleLoaderBase {
281283
StringRef moduleName,
282284
const SerializedModuleBaseName &BaseName) override;
283285

286+
bool BypassResilience;
284287
public:
285288
virtual ~MemoryBufferSerializedModuleLoader();
286289

@@ -310,10 +313,10 @@ class MemoryBufferSerializedModuleLoader : public SerializedModuleLoaderBase {
310313
static std::unique_ptr<MemoryBufferSerializedModuleLoader>
311314
create(ASTContext &ctx, DependencyTracker *tracker = nullptr,
312315
ModuleLoadingMode loadMode = ModuleLoadingMode::PreferSerialized,
313-
bool IgnoreSwiftSourceInfo = false) {
316+
bool IgnoreSwiftSourceInfo = false, bool BypassResilience = false) {
314317
return std::unique_ptr<MemoryBufferSerializedModuleLoader>{
315-
new MemoryBufferSerializedModuleLoader(ctx, tracker, loadMode,
316-
IgnoreSwiftSourceInfo)};
318+
new MemoryBufferSerializedModuleLoader(
319+
ctx, tracker, loadMode, IgnoreSwiftSourceInfo, BypassResilience)};
317320
}
318321
};
319322

include/swift/Syntax/AbsoluteRawSyntax.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "swift/Basic/SourceLoc.h"
1717
#include "swift/Syntax/RawSyntax.h"
1818

19+
#include "llvm/ADT/STLForwardCompat.h"
20+
1921
namespace swift {
2022
namespace syntax {
2123

@@ -388,8 +390,7 @@ class OptionalStorage<AbsoluteRawSyntax> {
388390
OptionalStorage(OptionalStorage &&other) = default;
389391

390392
template <class... ArgTypes>
391-
explicit OptionalStorage(llvm::optional_detail::in_place_t,
392-
ArgTypes &&...Args)
393+
explicit OptionalStorage(llvm::in_place_t, ArgTypes &&...Args)
393394
: Storage(std::forward<ArgTypes>(Args)...) {}
394395

395396
void reset() { Storage = AbsoluteRawSyntax(nullptr); }

0 commit comments

Comments
 (0)