1 package DX::Step::ResolveProposition;
3 use Types::Standard qw(ArrayRef);
4 use DX::Utils qw(deparse);
9 has actions => (is => 'ro', isa => ArrayRef[Action], required => 1);
11 has depends_on => (is => 'ro', isa => DependencyGroupList, required => 1);
13 has resolves => (is => 'ro', isa => Proposition);
15 has alternative_step => (is => 'ro', isa => Step);
18 my ($self, @actions) = @_;
19 $self->but(actions => [ @actions, @{$self->actions} ]);
22 sub but_with_dependencies_on {
23 my ($self, @deps) = @_;
24 $self->but(depends_on => [ @{$self->depends_on}, @deps ]);
29 my $old_hyp = $ss->current_hypothesis;
30 trace 'step.apply.old_hyp '.$self => $old_hyp;
31 trace 'step.apply.actions '.$self => $self->actions;
32 my $new_ss = $self->_apply_to_ss($ss);
33 return $ss->but(next_step => DX::Step::Backtrack->new) unless $new_ss;
34 my $new_hyp = $new_ss->current_hypothesis;
35 trace 'step.apply.new_hyp '.$self => $new_hyp;
37 if (my $prop = $ss->next_proposition($new_hyp)) {
38 DX::Step::ConsiderProposition->new(
45 my $alt_step = $self->alternative_step;
48 current_hypothesis => $new_hyp,
51 ? (alternatives => [ [ $old_hyp, $alt_step ], @{$ss->alternatives} ])
59 my ($self, $old_ss) = @_;
60 my $old_hyp = $old_ss->current_hypothesis;
61 (my $hyp, my @recheck) = $old_hyp->with_resolution(
62 $self->resolves, $self->depends_on, $self->actions
64 return undef unless $hyp;
65 return $self->_recheck_for(
66 $old_ss->but(current_hypothesis => $hyp),
72 my ($self, $old_ss, @recheck) = @_;
73 return $old_ss unless @recheck;
75 foreach my $prop (@recheck) {
76 return undef unless $ss = $self->_recheck_one($ss, $prop);
82 my ($self, $old_ss, $prop) = @_;
84 my $old_hyp = $old_ss->current_hypothesis;
86 my $ap = DX::ActionPolicy::LockScope->new(
87 lock_to_depth => $old_hyp->scope->depth,
88 next_policy => $old_hyp->action_policy,
91 # we should probably be doing something about pruning the scope
92 # but that's completely pointless until we have rules
94 my $hyp = ref($old_hyp)->new(
95 scope => $old_hyp->scope,
96 resolved_propositions => DX::ResolvedPropositionSet->new_empty,
98 action_applications => [],
102 my $pseq = DX::PropositionSequence->new(
103 members => [ $prop ],
104 external_names => {},
105 internal_names => {},
108 trace 'step.recheck.hyp' => $hyp;
110 my $ss = DX::SearchState->new(
111 current_hypothesis => $hyp,
113 propositions => $pseq,
114 next_step => DX::Step::ConsiderProposition->new(
115 proposition => $prop,
117 is_solution_state => 0,
118 on_exhaustion_step => undef,
119 on_solution_step => DX::Step::MarkAsSolution->new,
122 my $sp = DX::SearchProcess->new(
123 current_search_state => $ss,
126 my $sol_sp = $sp->find_solution;
129 trace 'step.recheck.fail' => 'argh';
133 my $sol_rps = $sol_sp->current_hypothesis->resolved_propositions;
135 my $rps = $old_hyp->resolved_propositions;
137 $rps = $rps->with_updated_dependencies_for(
138 $prop, $sol_rps->dependencies_for($prop)
141 trace 'step.recheck.done' => 'yay';
144 current_hypothesis => $old_hyp->but(resolved_propositions => $rps),