Skip to content

Commit 288a704

Browse files
authored
Merge pull request #4231 from swiftwasm/main
2 parents ef481ee + d1eabf1 commit 288a704

File tree

65 files changed

+2894
-742
lines changed

Some content is hidden

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

65 files changed

+2894
-742
lines changed

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ documentation, please create a thread on the Swift forums under the
102102
- [DependencyAnalysis.md](/docs/DependencyAnalysis.md):
103103
Describes different kinds of dependencies across files in the same module,
104104
important for understanding incremental builds.
105+
- [DifferentiableProgrammingImplementation.md](/docs/DifferentiableProgrammingImplementation.md):
106+
Describes how automatic differentiation is implemented in the Swift compiler.
105107
- C and ObjC interoperability: Clang Importer and PrintAsClang
106108
- [CToSwiftNameTranslation.md](/docs/CToSwiftNameTranslation.md):
107109
Describes how C and ObjC entities are imported into Swift

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5396,6 +5396,10 @@ class VarDecl : public AbstractStorageDecl {
53965396
/// an attached property wrapper.
53975397
VarDecl *getPropertyWrapperWrappedValueVar() const;
53985398

5399+
/// Return true if this property either has storage or has an attached property
5400+
/// wrapper that has storage.
5401+
bool hasStorageOrWrapsStorage() const;
5402+
53995403
/// Visit all auxiliary declarations to this VarDecl.
54005404
///
54015405
/// An auxiliary declaration is a declaration synthesized by the compiler to support

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2559,8 +2559,10 @@ WARNING(associated_type_override_typealias,none,
25592559

25602560
ERROR(requirement_machine_completion_failed,none,
25612561
"cannot build rewrite system for %select{generic signature|protocol}0; "
2562-
"%select{step|depth}1 limit exceeded",
2562+
"%select{%error|rule count|rule length|concrete nesting}1 limit exceeded",
25632563
(unsigned, unsigned))
2564+
NOTE(requirement_machine_completion_rule,none,
2565+
"failed rewrite rule is %0", (StringRef))
25642566

25652567
ERROR(associated_type_objc,none,
25662568
"associated type %0 cannot be declared inside '@objc' protocol %1",

include/swift/Basic/LangOptions.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,17 @@ namespace swift {
510510
/// Enables fine-grained debug output from the requirement machine.
511511
std::string DebugRequirementMachine;
512512

513-
/// Maximum iteration count for requirement machine Knuth-Bendix completion
513+
/// Maximum rule count for requirement machine Knuth-Bendix completion
514514
/// algorithm.
515-
unsigned RequirementMachineStepLimit = 4000;
515+
unsigned RequirementMachineMaxRuleCount = 4000;
516516

517517
/// Maximum term length for requirement machine Knuth-Bendix completion
518518
/// algorithm.
519-
unsigned RequirementMachineDepthLimit = 12;
519+
unsigned RequirementMachineMaxRuleLength = 12;
520+
521+
/// Maximum concrete type nesting depth for requirement machine property map
522+
/// algorithm.
523+
unsigned RequirementMachineMaxConcreteNesting = 30;
520524

521525
/// Enable the new experimental protocol requirement signature minimization
522526
/// algorithm.

include/swift/Option/FrontendOptions.td

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,17 @@ def analyze_requirement_machine : Flag<["-"], "analyze-requirement-machine">,
343343
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
344344
HelpText<"Print out requirement machine statistics at the end of the compilation job">;
345345

346-
def requirement_machine_step_limit : Separate<["-"], "requirement-machine-step-limit">,
346+
def requirement_machine_max_rule_count : Joined<["-"], "requirement-machine-max-rule-count=">,
347347
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
348-
HelpText<"Set the maximum steps before we give up on confluent completion">;
348+
HelpText<"Set the maximum number of rules before giving up">;
349349

350-
def requirement_machine_depth_limit : Separate<["-"], "requirement-machine-depth-limit">,
350+
def requirement_machine_max_rule_length : Joined<["-"], "requirement-machine-max-rule-length=">,
351351
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
352-
HelpText<"Set the maximum depth before we give up on confluent completion">;
352+
HelpText<"Set the maximum rule length before giving up">;
353+
354+
def requirement_machine_max_concrete_nesting : Joined<["-"], "requirement-machine-max-concrete-nesting=">,
355+
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
356+
HelpText<"Set the maximum concrete type nesting depth before giving up">;
353357

354358
def disable_requirement_machine_merged_associated_types : Flag<["-"], "disable-requirement-machine-merged-associated-types">,
355359
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,

include/swift/Runtime/Atomic.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class alignas(Size) atomic_impl {
7272
return value.compare_exchange_weak(oldValue, newValue, successOrder,
7373
failureOrder);
7474
}
75+
76+
bool compare_exchange_strong(Value &oldValue, Value newValue,
77+
std::memory_order successOrder,
78+
std::memory_order failureOrder) {
79+
return value.compare_exchange_strong(oldValue, newValue, successOrder,
80+
failureOrder);
81+
}
7582
};
7683

7784
#if defined(_WIN64)
@@ -128,11 +135,14 @@ class alignas(2 * sizeof(void*)) atomic_impl<Value, 2 * sizeof(void*)> {
128135
bool compare_exchange_weak(Value &oldValue, Value newValue,
129136
std::memory_order successOrder,
130137
std::memory_order failureOrder) {
131-
assert(failureOrder == std::memory_order_relaxed ||
132-
failureOrder == std::memory_order_acquire ||
133-
failureOrder == std::memory_order_consume);
134-
assert(successOrder == std::memory_order_relaxed ||
135-
successOrder == std::memory_order_release);
138+
// We do not have weak CAS intrinsics, fallback to strong
139+
return compare_exchange_strong(oldValue, newValue, successOrder,
140+
failureOrder);
141+
}
142+
143+
bool compare_exchange_strong(Value &oldValue, Value newValue,
144+
std::memory_order successOrder,
145+
std::memory_order failureOrder) {
136146
#if SWIFT_HAS_MSVC_ARM_ATOMICS
137147
if (successOrder == std::memory_order_relaxed &&
138148
failureOrder != std::memory_order_acquire) {
@@ -180,7 +190,7 @@ class alignas(2 * sizeof(void*)) atomic_impl<Value, 2 * sizeof(void*)> {
180190
template <class T>
181191
class atomic : public impl::atomic_impl<T> {
182192
public:
183-
atomic(T value) : impl::atomic_impl<T>(value) {}
193+
constexpr atomic(T value) : impl::atomic_impl<T>(value) {}
184194
};
185195

186196
} // end namespace swift

include/swift/SILOptimizer/Utils/UpdatingInstructionIterator.h

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,31 +169,33 @@ class UpdatingInstructionIteratorRegistry {
169169
SmallVector<UpdatingInstructionIterator *, 4> forwardIterators;
170170
SmallVector<UpdatingReverseInstructionIterator *, 4> reverseIterators;
171171

172+
std::function<void(SILInstruction *)> chainedDelete;
173+
std::function<void(SILInstruction *)> chainedNew;
174+
172175
/// Callbacks used when adding/deleting instructions.
173176
InstModCallbacks callbacks;
174177

175-
public:
176-
UpdatingInstructionIteratorRegistry(
177-
InstModCallbacks chainedCallbacks = InstModCallbacks()) {
178-
rechainCallbacks(chainedCallbacks);
179-
}
180-
181-
// The callbacks capture 'this'. So copying is invalid.
182-
UpdatingInstructionIteratorRegistry(
183-
const UpdatingInstructionIteratorRegistry &) = delete;
184-
185-
UpdatingInstructionIteratorRegistry &
186-
operator=(const UpdatingInstructionIteratorRegistry &) = delete;
187178

188-
InstModCallbacks &getCallbacks() { return callbacks; }
179+
public:
180+
UpdatingInstructionIteratorRegistry() :
181+
callbacks(InstModCallbacks()
182+
.onDelete([this](SILInstruction *toDelete) {
183+
notifyDelete(toDelete);
184+
toDelete->eraseFromParent();
185+
})
186+
.onCreateNewInst(
187+
[this](SILInstruction *newlyCreatedInst) {
188+
notifyNew(newlyCreatedInst);
189+
}))
190+
{}
189191

190-
void rechainCallbacks(InstModCallbacks chainedCallbacks) {
192+
UpdatingInstructionIteratorRegistry(InstModCallbacks &&chainedCallbacks) :
191193
// Copy the two std::functions that we need. The rest of the callbacks are
192194
// copied implicitly by assignment.
193-
auto chainedDelete = chainedCallbacks.deleteInstFunc;
194-
auto chainedNew = chainedCallbacks.createdNewInstFunc;
195-
callbacks = chainedCallbacks
196-
.onDelete([this, chainedDelete](SILInstruction *toDelete) {
195+
chainedDelete(std::move(chainedCallbacks.deleteInstFunc)),
196+
chainedNew(std::move(chainedCallbacks.createdNewInstFunc)),
197+
callbacks(std::move(chainedCallbacks
198+
.onDelete([this](SILInstruction *toDelete) {
197199
notifyDelete(toDelete);
198200
if (chainedDelete) {
199201
chainedDelete(toDelete);
@@ -202,13 +204,22 @@ class UpdatingInstructionIteratorRegistry {
202204
toDelete->eraseFromParent();
203205
})
204206
.onCreateNewInst(
205-
[this, chainedNew](SILInstruction *newlyCreatedInst) {
207+
[this](SILInstruction *newlyCreatedInst) {
206208
notifyNew(newlyCreatedInst);
207209
if (chainedNew) {
208210
chainedNew(newlyCreatedInst);
209211
}
210-
});
211-
}
212+
})))
213+
{}
214+
215+
// The callbacks capture 'this'. So copying is invalid.
216+
UpdatingInstructionIteratorRegistry(
217+
const UpdatingInstructionIteratorRegistry &) = delete;
218+
219+
UpdatingInstructionIteratorRegistry &
220+
operator=(const UpdatingInstructionIteratorRegistry &) = delete;
221+
222+
InstModCallbacks &getCallbacks() { return callbacks; }
212223

213224
void registerIterator(UpdatingInstructionIterator *i) {
214225
forwardIterators.push_back(i);

lib/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ add_swift_host_library(swiftAST STATIC
9191
RequirementMachine/RewriteSystem.cpp
9292
RequirementMachine/Symbol.cpp
9393
RequirementMachine/Term.cpp
94+
RequirementMachine/TypeDifference.cpp
9495
SearchPathOptions.cpp
9596
SILLayout.cpp
9697
Stmt.cpp

lib/AST/Decl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6524,6 +6524,20 @@ VarDecl *VarDecl::getPropertyWrapperWrappedValueVar() const {
65246524
return getPropertyWrapperAuxiliaryVariables().localWrappedValueVar;
65256525
}
65266526

6527+
bool VarDecl::hasStorageOrWrapsStorage() const {
6528+
if (hasStorage())
6529+
return true;
6530+
6531+
if (getAttrs().hasAttribute<LazyAttr>())
6532+
return true;
6533+
6534+
auto *backing = getPropertyWrapperBackingProperty();
6535+
if (backing && backing->hasStorage())
6536+
return true;
6537+
6538+
return false;
6539+
}
6540+
65276541
void VarDecl::visitAuxiliaryDecls(llvm::function_ref<void(VarDecl *)> visit) const {
65286542
if (getDeclContext()->isTypeContext() || isImplicit())
65296543
return;

lib/AST/RequirementMachine/ConcreteTypeWitness.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,17 +458,17 @@ void PropertyMap::recordConcreteConformanceRule(
458458
/*ruleID=*/concreteRuleID,
459459
/*inverse=*/true));
460460

461-
// Apply a concrete type adjustment to the concrete symbol if T' is shorter
462-
// than T.
461+
// If T' is a suffix of T, prepend the prefix to the concrete type's
462+
// substitutions.
463463
auto concreteSymbol = *concreteRule.isPropertyRule();
464-
unsigned adjustment = rhs.size() - concreteRule.getRHS().size();
464+
unsigned prefixLength = rhs.size() - concreteRule.getRHS().size();
465465

466-
if (adjustment > 0 &&
466+
if (prefixLength > 0 &&
467467
!concreteConformanceSymbol.getSubstitutions().empty()) {
468-
path.add(RewriteStep::forAdjustment(adjustment, /*endOffset=*/1,
469-
/*inverse=*/false));
468+
path.add(RewriteStep::forPrefixSubstitutions(prefixLength, /*endOffset=*/1,
469+
/*inverse=*/false));
470470

471-
MutableTerm prefix(rhs.begin(), rhs.begin() + adjustment);
471+
MutableTerm prefix(rhs.begin(), rhs.begin() + prefixLength);
472472
concreteSymbol = concreteSymbol.prependPrefixToConcreteSubstitutions(
473473
prefix, Context);
474474
}

0 commit comments

Comments
 (0)