Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0c777e7
RequirementMachine: Split up PropertyMap::addProperty()
slavapestov Feb 2, 2022
b28d35f
RequirementMachine: Introduce RewriteSystem::computeTypeDifference()
slavapestov Feb 2, 2022
8eb8e8d
RequirementMachine: Make RewriteSystem::recordRewriteLoop() public fo…
slavapestov Feb 2, 2022
e19ee4d
RequirementMachine: Refactor PropertyMap::addConcreteTypeProperty() t…
slavapestov Feb 2, 2022
73296ed
RequirementMachine: Less indirect TypeDifference representation
slavapestov Feb 3, 2022
7464a5f
RequirementMachine: Make recordTypeDifference() and buildTypeDifferen…
slavapestov Feb 3, 2022
d8aa79c
RequirementMachine: Rename RewriteStep::AdjustConcreteType to ::Prefi…
slavapestov Feb 3, 2022
7e4a587
RequirementMachine: Introduce RewriteStep::DecomposeConcrete
slavapestov Feb 3, 2022
730941b
RequirementMachine: Implement PropertyMap::concretelySimplifyLeftHand…
slavapestov Feb 3, 2022
634ca55
RequirementMachine: Rework completion limits a bit
slavapestov Feb 4, 2022
0060592
RequirementMachine: Add concrete nesting depth check
slavapestov Feb 4, 2022
b0dd114
RequirementMachine: Add a FIXME comment
slavapestov Feb 3, 2022
37be2d5
RequirementMachine: Emit a diagnostic note with the offending rewrite…
slavapestov Feb 4, 2022
037dc98
RequirementMachine: Generalize compare() methods to return None inste…
slavapestov Feb 4, 2022
06d4770
RequirementMachine: Teach homotopy reduction to better deal with inco…
slavapestov Feb 4, 2022
00d226f
RequirementMachine: Store the base term in the TypeDifference
slavapestov Feb 4, 2022
2c355de
RequirementMachine: Introduce RewriteStep::{Left,Right}ConcreteProjec…
slavapestov Feb 4, 2022
fcd467a
RequirementMachine: Factor out TypeDifference::getReplacementSubstitu…
slavapestov Feb 4, 2022
60db917
RequirementMachine: Factor out PropertyMap::processTypeDifference()
slavapestov Feb 4, 2022
9ee7020
RequirementMachine: Factor out TypeDifference::getOriginalSubstitution()
slavapestov Feb 4, 2022
7087617
RequirementMachine: Build rewrite paths for concrete unification indu…
slavapestov Feb 4, 2022
5bb8028
RequirementMachine: Factor out a utility for building a rewrite path …
slavapestov Feb 6, 2022
9e234a0
RequirementMachine: Record rewrite loop relating concrete type rules …
slavapestov Feb 6, 2022
868e48c
RequirementMachine: Mark rules as simplified in PropertyMap::addConcr…
slavapestov Feb 6, 2022
729dfc7
RequirementMachine: Add some tests for concrete type unification
slavapestov Feb 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -2559,8 +2559,10 @@ WARNING(associated_type_override_typealias,none,

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

ERROR(associated_type_objc,none,
"associated type %0 cannot be declared inside '@objc' protocol %1",
Expand Down
10 changes: 7 additions & 3 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,17 @@ namespace swift {
/// Enables fine-grained debug output from the requirement machine.
std::string DebugRequirementMachine;

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

/// Maximum term length for requirement machine Knuth-Bendix completion
/// algorithm.
unsigned RequirementMachineDepthLimit = 12;
unsigned RequirementMachineMaxRuleLength = 12;

/// Maximum concrete type nesting depth for requirement machine property map
/// algorithm.
unsigned RequirementMachineMaxConcreteNesting = 30;

/// Enable the new experimental protocol requirement signature minimization
/// algorithm.
Expand Down
12 changes: 8 additions & 4 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,17 @@ def analyze_requirement_machine : Flag<["-"], "analyze-requirement-machine">,
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
HelpText<"Print out requirement machine statistics at the end of the compilation job">;

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

def requirement_machine_depth_limit : Separate<["-"], "requirement-machine-depth-limit">,
def requirement_machine_max_rule_length : Joined<["-"], "requirement-machine-max-rule-length=">,
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
HelpText<"Set the maximum depth before we give up on confluent completion">;
HelpText<"Set the maximum rule length before giving up">;

def requirement_machine_max_concrete_nesting : Joined<["-"], "requirement-machine-max-concrete-nesting=">,
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
HelpText<"Set the maximum concrete type nesting depth before giving up">;

def disable_requirement_machine_merged_associated_types : Flag<["-"], "disable-requirement-machine-merged-associated-types">,
Flags<[FrontendOption, HelpHidden, DoesNotAffectIncrementalBuild]>,
Expand Down
1 change: 1 addition & 0 deletions lib/AST/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ add_swift_host_library(swiftAST STATIC
RequirementMachine/RewriteSystem.cpp
RequirementMachine/Symbol.cpp
RequirementMachine/Term.cpp
RequirementMachine/TypeDifference.cpp
SearchPathOptions.cpp
SILLayout.cpp
Stmt.cpp
Expand Down
14 changes: 7 additions & 7 deletions lib/AST/RequirementMachine/ConcreteTypeWitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,17 @@ void PropertyMap::recordConcreteConformanceRule(
/*ruleID=*/concreteRuleID,
/*inverse=*/true));

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

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

MutableTerm prefix(rhs.begin(), rhs.begin() + adjustment);
MutableTerm prefix(rhs.begin(), rhs.begin() + prefixLength);
concreteSymbol = concreteSymbol.prependPrefixToConcreteSubstitutions(
prefix, Context);
}
Expand Down
Loading