633 Set<Unit> replaced = new LinkedHashSet<>(); |
633 Set<Unit> replaced = new LinkedHashSet<>(); |
634 // Loop until dependencies and errors are stable |
634 // Loop until dependencies and errors are stable |
635 while (true) { |
635 while (true) { |
636 state.debug(DBG_GEN, "compileAndLoad %s\n", ins); |
636 state.debug(DBG_GEN, "compileAndLoad %s\n", ins); |
637 |
637 |
638 ins.stream().forEach(u -> u.initialize()); |
638 ins.stream().forEach(Unit::initialize); |
639 ins.stream().forEach(u -> u.setWrap(ins, ins)); |
639 ins.stream().forEach(u -> u.setWrap(ins, ins)); |
640 AnalyzeTask at = state.taskFactory.new AnalyzeTask(outerWrapSet(ins)); |
640 AnalyzeTask at = state.taskFactory.new AnalyzeTask(outerWrapSet(ins)); |
641 ins.stream().forEach(u -> u.setDiagnostics(at)); |
641 ins.stream().forEach(u -> u.setDiagnostics(at)); |
642 |
642 |
643 // corral any Snippets that need it |
643 // corral any Snippets that need it |
652 ins.stream().forEach(u -> u.setStatus(cat)); |
652 ins.stream().forEach(u -> u.setStatus(cat)); |
653 // compile and load the legit snippets |
653 // compile and load the legit snippets |
654 boolean success; |
654 boolean success; |
655 while (true) { |
655 while (true) { |
656 List<Unit> legit = ins.stream() |
656 List<Unit> legit = ins.stream() |
657 .filter(u -> u.isDefined()) |
657 .filter(Unit::isDefined) |
658 .collect(toList()); |
658 .collect(toList()); |
659 state.debug(DBG_GEN, "compileAndLoad ins = %s -- legit = %s\n", |
659 state.debug(DBG_GEN, "compileAndLoad ins = %s -- legit = %s\n", |
660 ins, legit); |
660 ins, legit); |
661 if (legit.isEmpty()) { |
661 if (legit.isEmpty()) { |
662 // no class files can be generated |
662 // no class files can be generated |
691 |
691 |
692 // prevent alternating redefine/replace cyclic dependency |
692 // prevent alternating redefine/replace cyclic dependency |
693 // loop by replacing all that have been replaced |
693 // loop by replacing all that have been replaced |
694 if (!toReplace.isEmpty()) { |
694 if (!toReplace.isEmpty()) { |
695 replaced.addAll(toReplace); |
695 replaced.addAll(toReplace); |
696 replaced.stream().forEach(u -> u.markForReplacement()); |
696 replaced.stream().forEach(Unit::markForReplacement); |
697 } |
697 } |
698 |
698 |
699 success = toReplace.isEmpty(); |
699 success = toReplace.isEmpty(); |
700 } |
700 } |
701 break; |
701 break; |
702 } |
702 } |
703 |
703 |
704 // add any new dependencies to the working set |
704 // add any new dependencies to the working set |
705 List<Unit> newDependencies = ins.stream() |
705 List<Unit> newDependencies = ins.stream() |
706 .flatMap(u -> u.effectedDependents()) |
706 .flatMap(Unit::effectedDependents) |
707 .collect(toList()); |
707 .collect(toList()); |
708 state.debug(DBG_GEN, "compileAndLoad %s -- deps: %s success: %s\n", |
708 state.debug(DBG_GEN, "compileAndLoad %s -- deps: %s success: %s\n", |
709 ins, newDependencies, success); |
709 ins, newDependencies, success); |
710 if (!ins.addAll(newDependencies) && success) { |
710 if (!ins.addAll(newDependencies) && success) { |
711 // all classes that could not be directly loaded (because they |
711 // all classes that could not be directly loaded (because they |
712 // are new) have been redefined, and no new dependnencies were |
712 // are new) have been redefined, and no new dependnencies were |
713 // identified |
713 // identified |
714 ins.stream().forEach(u -> u.finish()); |
714 ins.stream().forEach(Unit::finish); |
715 return ins; |
715 return ins; |
716 } |
716 } |
717 } |
717 } |
718 } |
718 } |
719 |
719 |