Skip to content

Commit e326c01

Browse files
committed
RequirementMachine: Write some comments
1 parent a3ab5f4 commit e326c01

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

lib/AST/RequirementMachine/SimplifySubstitutions.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- PropertyUnification.cpp - Rules added w/ building property map ---===//
1+
//===--- SimplifySubstitutions.cpp - Simplify concrete type rules ---------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -9,6 +9,57 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12+
//
13+
// Implements a pass for simplifying substitutions in concrete type symbols.
14+
// Substitutions can be simplifed in one of two ways; either a substitution
15+
// term can be replaced by a more canonical term, or it can be replaced by a
16+
// concrete type.
17+
//
18+
// For example, given pair of rewrite rules:
19+
//
20+
// T.[concrete: G<Y>] => T
21+
// Y => X
22+
//
23+
// We can apply (Y => X) to the term appearing in the concrete type symbol
24+
// [concrete: G<Y>] to obtain the rule:
25+
//
26+
// T.[concrete: G<X>] => T
27+
//
28+
// Similarly, if we have a pair of rewrite rules:
29+
//
30+
// T.[concrete: G<Y>] => T
31+
// Y.[concrete: Int] => Y
32+
//
33+
// We can obtain the new rule:
34+
//
35+
// T.[concrete: G<Int>] => T
36+
//
37+
// Substitution simplification occurs during the Knuth-Bendix completion
38+
// procedure, and after property map construction.
39+
//
40+
// In the first case, no property map is available yet, so substitution terms
41+
// are simplified to other terms, but concrete type replacement is not
42+
// performed. In the second case, the property map is consulted to perform
43+
// concrete type replacement where appropriate.
44+
//
45+
// Either the new rule or the old rule can become redundant; they are related
46+
// by rewrite loops. Additionally, rewrite loops are introduced for each
47+
// transformation applied to the substitutions to relate them to the concrete
48+
// type rules via "projections".
49+
//
50+
// These rewrite loops are in a sense dual to the property map's concrete type
51+
// unification, and share a lot of the code; whereas the property map will
52+
// relate two rules (T.[concrete: G<X>] => T) with (T.[concrete: G<Y>] => T)
53+
// and add the induced rule (Y => X), substitution simplification will use
54+
// (Y => X) to transform (T.[concrete: G<Y>] => T) into
55+
// (T.[concrete: G<X>] => T).
56+
//
57+
// This logic (and concrete type unification) heavily relies on the "type
58+
// difference" abstraction implemented in TypeDifference.cpp. Technical details
59+
// about the various rewrite loops introduced here can be found in comments at
60+
// the top of various functions below.
61+
//
62+
//===----------------------------------------------------------------------===//
1263

1364
#include "PropertyMap.h"
1465
#include "RewriteSystem.h"

lib/AST/RequirementMachine/TypeDifference.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12+
//
13+
// A mechanism for working with types that are related via the transformation
14+
// of replacing a type parameter term with another type parameter term or
15+
// concrete type.
16+
//
17+
// Used by concrete type unification (in PropertyUnification.cpp) and for
18+
// substitution simplification (SimplifySubstitutions.cpp) to define rewrite
19+
// loops relating various rules for rewrite system minimization.
20+
//
21+
//===----------------------------------------------------------------------===//
1222

1323
#include "TypeDifference.h"
1424
#include "swift/AST/Types.h"

0 commit comments

Comments
 (0)