From: Matt S Trout Date: Fri, 15 Jul 2016 21:22:09 +0000 (+0000) Subject: extract recheck setup logic into its own step X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=614f3d93fa2a59549c00c849354763a681b8a3e6;p=scpubgit%2FDX.git extract recheck setup logic into its own step --- diff --git a/lib/DX/Step/EnterRecheck.pm b/lib/DX/Step/EnterRecheck.pm new file mode 100644 index 0000000..4b9d76e --- /dev/null +++ b/lib/DX/Step/EnterRecheck.pm @@ -0,0 +1,58 @@ +package DX::Step::EnterRecheck; + +use DX::Class; + +with 'DX::Role::Step'; + +has proposition_list => (is => 'ro', required => 1); + +sub apply_to { + my ($self, $old_ss) = @_; + + my ($prop, @rest) = @{$self->proposition_list}; + + die "NOT YET DAMNIT" if @rest; + + my $old_hyp = $old_ss->current_hypothesis; + + # we should probably be doing something about pruning the scope + # but that's completely pointless until we have rules (and also, + # the lock_to_depth arg needs to come from the proposition somehow) + + my $ap = DX::ActionPolicy::LockScope->new( + lock_to_depth => $old_hyp->scope->depth, + next_policy => $old_hyp->action_policy, + ); + + my $hyp = ref($old_hyp)->new( + scope => $old_hyp->scope, + resolved_propositions => DX::ResolvedPropositionSet->new_empty, + actions => [], + action_applications => [], + action_policy => $ap, + ); + + my $pseq = DX::PropositionSequence->new( + members => [ $prop ], + external_names => {}, + internal_names => {}, + ); + + trace 'step.recheck.hyp' => $hyp; + + my $ss = DX::SearchState->new( + current_hypothesis => $hyp, + alternatives => [], + propositions => $pseq, + next_step => DX::Step::ConsiderProposition->new( + proposition => $prop, + ), + is_solution_state => 0, + on_exhaustion_step => undef, + on_solution_step => DX::Step::MarkAsSolution->new, + ); + + return $ss; +} + +1; diff --git a/lib/DX/Step/ResolveProposition.pm b/lib/DX/Step/ResolveProposition.pm index 66a980d..900c182 100644 --- a/lib/DX/Step/ResolveProposition.pm +++ b/lib/DX/Step/ResolveProposition.pm @@ -1,7 +1,10 @@ package DX::Step::ResolveProposition; +use DX::Step::EnterRecheck; + use Types::Standard qw(ArrayRef); use DX::Utils qw(deparse); + use DX::Class; with 'DX::Role::Step'; @@ -81,42 +84,10 @@ sub _recheck_for { sub _recheck_one { my ($self, $old_ss, $prop) = @_; - my $old_hyp = $old_ss->current_hypothesis; - - my $ap = DX::ActionPolicy::LockScope->new( - lock_to_depth => $old_hyp->scope->depth, - next_policy => $old_hyp->action_policy, - ); - - # we should probably be doing something about pruning the scope - # but that's completely pointless until we have rules - - my $hyp = ref($old_hyp)->new( - scope => $old_hyp->scope, - resolved_propositions => DX::ResolvedPropositionSet->new_empty, - actions => [], - action_applications => [], - action_policy => $ap, - ); - - my $pseq = DX::PropositionSequence->new( - members => [ $prop ], - external_names => {}, - internal_names => {}, - ); - - trace 'step.recheck.hyp' => $hyp; - - my $ss = DX::SearchState->new( - current_hypothesis => $hyp, - alternatives => [], - propositions => $pseq, - next_step => DX::Step::ConsiderProposition->new( - proposition => $prop, - ), - is_solution_state => 0, - on_exhaustion_step => undef, - on_solution_step => DX::Step::MarkAsSolution->new, + my $ss = $old_ss->but( + next_step => DX::Step::EnterRecheck->new( + proposition_list => [ $prop ], + ), ); my $sp = DX::SearchProcess->new( @@ -132,6 +103,8 @@ sub _recheck_one { my $sol_rps = $sol_sp->current_hypothesis->resolved_propositions; + my $old_hyp = $old_ss->current_hypothesis; + my $rps = $old_hyp->resolved_propositions; $rps = $rps->with_updated_dependencies_for(