@@ -149,9 +149,19 @@ object Plugins {
149
149
type OrderingReq = (Set [Class [_]], Set [Class [_]])
150
150
151
151
val orderRequirements = MMap [Class [_], OrderingReq ]()
152
- val primitivePhases = plan.flatMap(ps => ps.map(_.getClass : Class [_])).toSet
153
152
154
- def isPrimitive (phase : Class [_]): Boolean = primitivePhases.contains(phase)
153
+ // 1. already inserted phases don't need constraints themselves.
154
+ // 2. no need to propagate beyond boundary of inserted phases, as the information
155
+ // beyond boundary is less useful than the boundary.
156
+ // 3. unsatisfiable constraints will still be exposed by the first plugin in a loop
157
+ // due to its conflicting `runAfter` and `runBefore` after propagation. The ordering
158
+ // of primitive phases (`plan`) are used to check `runAfter` and `runBefore`, thus
159
+ // there is no need to propagate the primitive phases.
160
+
161
+ var insertedPhase = plan.flatMap(ps => ps.map(_.getClass : Class [_])).toSet
162
+ def isInserted (phase : Class [_]): Boolean = insertedPhase.contains(phase)
163
+
164
+ var updatedPlan = plan
155
165
156
166
def constraintConflict (phase : Phase ): String = {
157
167
val (runsAfter, runsBefore) = orderRequirements(phase.getClass)
@@ -176,12 +186,12 @@ object Plugins {
176
186
var (runsAfter, runsBefore) = orderRequirements(phase.getClass)
177
187
178
188
// propagate transitive constraints to related phases
179
- runsAfter.filter(! isPrimitive (_)).foreach { phaseClass =>
189
+ runsAfter.filter(! isInserted (_)).foreach { phaseClass =>
180
190
val (runsAfter1, runsBefore1) = orderRequirements(phaseClass)
181
191
orderRequirements.update(phaseClass, (runsAfter1, runsBefore1 + phase.getClass))
182
192
}
183
193
184
- runsBefore.filter(! isPrimitive (_)).foreach { phaseClass =>
194
+ runsBefore.filter(! isInserted (_)).foreach { phaseClass =>
185
195
val (runsAfter1, runsBefore1) = orderRequirements(phaseClass)
186
196
orderRequirements.update(phaseClass, (runsAfter1 + phase.getClass, runsBefore1))
187
197
}
@@ -199,7 +209,7 @@ object Plugins {
199
209
def propagateRunsBefore (beforePhase : Class [_]): Set [Class [_]] =
200
210
if (beforePhase == phase.getClass)
201
211
throw new Exception (constraintConflict(phase))
202
- else if (primitivePhases.contains (beforePhase))
212
+ else if (isInserted (beforePhase))
203
213
Set (beforePhase)
204
214
else {
205
215
val (_, runsBefore) = orderRequirements(beforePhase)
@@ -209,7 +219,7 @@ object Plugins {
209
219
def propagateRunsAfter (afterPhase : Class [_]): Set [Class [_]] =
210
220
if (afterPhase == phase.getClass)
211
221
throw new Exception (constraintConflict(phase))
212
- else if (primitivePhases.contains (afterPhase))
222
+ else if (isInserted (afterPhase))
213
223
Set (afterPhase)
214
224
else {
215
225
val (runsAfter, _) = orderRequirements(afterPhase)
@@ -224,8 +234,6 @@ object Plugins {
224
234
(runsAfter, runsBefore)
225
235
}
226
236
227
- var updatedPlan = plan
228
- var insertedPhase = primitivePhases
229
237
pluginPhases.sortBy(_.phaseName).foreach { phase =>
230
238
var (runsAfter1, runsBefore1) = propagate(phase)
231
239
0 commit comments