From: Matt S Trout Date: Mon, 16 Apr 2018 01:44:41 +0000 (+0000) Subject: follow alternative rspace entries without backtracking, explicitly resolve X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6b0c811a7afc5fc2ca97f72ed1ab37b5c117e25;p=scpubgit%2FDX.git follow alternative rspace entries without backtracking, explicitly resolve --- diff --git a/fragment.output/btdemo b/fragment.output/btdemo index 0ed4020..c75951e 100644 --- a/fragment.output/btdemo +++ b/fragment.output/btdemo @@ -127,24 +127,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { depends_on { CONTENTS_OF 0.X } } backtrack - remaining resolution_space { - proposition eq ?X {{ a 1 b 2 c 3 }} - geometry_depends_on { CONTENTS_OF 0.X } - aperture { VALUE_SET 0.X } - members { } - } - backtrack fail_recheck } backtrack remaining resolution_space { - proposition eq XValue 2 - geometry_depends_on { CONTENTS_OF 0.XValue } - aperture { VALUE_SET 0.XValue; VALUE_SET 0.X.a } - members { } -} -backtrack -remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } aperture { VALUE_SET 0.YKey; VALUE_SET 0.YValue } @@ -199,24 +185,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { depends_on { CONTENTS_OF 0.X } } backtrack - remaining resolution_space { - proposition eq ?X {{ a 1 b 2 c 3 }} - geometry_depends_on { CONTENTS_OF 0.X } - aperture { VALUE_SET 0.X } - members { } - } - backtrack fail_recheck } backtrack remaining resolution_space { - proposition eq XValue 2 - geometry_depends_on { CONTENTS_OF 0.XValue } - aperture { VALUE_SET 0.XValue; VALUE_SET 0.X.a } - members { } -} -backtrack -remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } aperture { VALUE_SET 0.YKey; VALUE_SET 0.YValue } @@ -268,24 +240,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { depends_on { CONTENTS_OF 0.X } } backtrack - remaining resolution_space { - proposition eq ?X {{ a 1 b 2 c 3 }} - geometry_depends_on { CONTENTS_OF 0.X } - aperture { VALUE_SET 0.X } - members { } - } - backtrack fail_recheck } backtrack remaining resolution_space { - proposition eq XValue 2 - geometry_depends_on { CONTENTS_OF 0.XValue } - aperture { VALUE_SET 0.XValue; VALUE_SET 0.X.a } - members { } -} -backtrack -remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } aperture { VALUE_SET 0.YKey; VALUE_SET 0.YValue } @@ -378,24 +336,10 @@ recheck eq ?Y {{ d 1 e 2 f 3 }} { depends_on { CONTENTS_OF 0.Y } } backtrack - remaining resolution_space { - proposition eq ?Y {{ d 1 e 2 f 3 }} - geometry_depends_on { CONTENTS_OF 0.Y } - aperture { VALUE_SET 0.Y } - members { } - } - backtrack fail_recheck } backtrack remaining resolution_space { - proposition eq YValue 2 - geometry_depends_on { CONTENTS_OF 0.YValue } - aperture { VALUE_SET 0.YValue; VALUE_SET 0.Y.d } - members { } -} -backtrack -remaining resolution_space { proposition eq XValue 2 geometry_depends_on { CONTENTS_OF 0.XValue } aperture { VALUE_SET 0.XValue; VALUE_SET 0.X.b } @@ -500,24 +444,10 @@ recheck eq ?Y {{ d 1 e 2 f 3 }} { depends_on { CONTENTS_OF 0.Y } } backtrack - remaining resolution_space { - proposition eq ?Y {{ d 1 e 2 f 3 }} - geometry_depends_on { CONTENTS_OF 0.Y } - aperture { VALUE_SET 0.Y } - members { } - } - backtrack fail_recheck } backtrack remaining resolution_space { - proposition eq YValue 2 - geometry_depends_on { CONTENTS_OF 0.YValue } - aperture { VALUE_SET 0.YValue; VALUE_SET 0.Y.f } - members { } -} -backtrack -remaining resolution_space { proposition eq XValue 2 geometry_depends_on { CONTENTS_OF 0.XValue } aperture { VALUE_SET 0.XValue; VALUE_SET 0.X.b } @@ -604,24 +534,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { depends_on { CONTENTS_OF 0.X } } backtrack - remaining resolution_space { - proposition eq ?X {{ a 1 b 2 c 3 }} - geometry_depends_on { CONTENTS_OF 0.X } - aperture { VALUE_SET 0.X } - members { } - } - backtrack fail_recheck } backtrack remaining resolution_space { - proposition eq XValue 2 - geometry_depends_on { CONTENTS_OF 0.XValue } - aperture { VALUE_SET 0.XValue; VALUE_SET 0.X.c } - members { } -} -backtrack -remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } aperture { VALUE_SET 0.YKey; VALUE_SET 0.YValue } @@ -676,24 +592,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { depends_on { CONTENTS_OF 0.X } } backtrack - remaining resolution_space { - proposition eq ?X {{ a 1 b 2 c 3 }} - geometry_depends_on { CONTENTS_OF 0.X } - aperture { VALUE_SET 0.X } - members { } - } - backtrack fail_recheck } backtrack remaining resolution_space { - proposition eq XValue 2 - geometry_depends_on { CONTENTS_OF 0.XValue } - aperture { VALUE_SET 0.XValue; VALUE_SET 0.X.c } - members { } -} -backtrack -remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } aperture { VALUE_SET 0.YKey; VALUE_SET 0.YValue } @@ -745,24 +647,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { depends_on { CONTENTS_OF 0.X } } backtrack - remaining resolution_space { - proposition eq ?X {{ a 1 b 2 c 3 }} - geometry_depends_on { CONTENTS_OF 0.X } - aperture { VALUE_SET 0.X } - members { } - } - backtrack fail_recheck } backtrack remaining resolution_space { - proposition eq XValue 2 - geometry_depends_on { CONTENTS_OF 0.XValue } - aperture { VALUE_SET 0.XValue; VALUE_SET 0.X.c } - members { } -} -backtrack -remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } aperture { VALUE_SET 0.YKey; VALUE_SET 0.YValue } diff --git a/lib/DX/Proposition.pm b/lib/DX/Proposition.pm index 6c2d133..c32354d 100644 --- a/lib/DX/Proposition.pm +++ b/lib/DX/Proposition.pm @@ -1,5 +1,7 @@ package DX::Proposition; +use DX::Step::ConsiderProposition; + use DX::Class; has predicate => (is => 'ro', isa => Str, required => 1); @@ -32,4 +34,9 @@ sub resolve_for { return $predicate->resolution_step_for($self, @args); } +sub consider_step { + my ($self) = @_; + DX::Step::ConsiderProposition->new(proposition => $self); +} + 1; diff --git a/lib/DX/QueryState.pm b/lib/DX/QueryState.pm index ac247c1..4be7b1c 100644 --- a/lib/DX/QueryState.pm +++ b/lib/DX/QueryState.pm @@ -70,6 +70,15 @@ sub with_additional_proposition { ); } } + if ((my $next_step = $ss->next_step)->can('original_search_state')) { + $but{next_step} + = $seen{$next_step} + ||= $next_step->but( + original_search_state + => $next_step->original_search_state->$_munge + ); + } + $ss->but(%but); }; }; diff --git a/lib/DX/Step/Backtrack.pm b/lib/DX/Step/Backtrack.pm index a7c107b..865073a 100644 --- a/lib/DX/Step/Backtrack.pm +++ b/lib/DX/Step/Backtrack.pm @@ -4,6 +4,8 @@ use DX::Class; with 'DX::Role::Step'; +#has resolution_space => (is => 'ro', isa => ResolutionSpace, required => 1); + sub apply_to { my ($self, $ss) = @_; trace backtrack => [ statement => [ [ symbol => 'backtrack' ] ] ]; diff --git a/lib/DX/Step/CompleteResolution.pm b/lib/DX/Step/CompleteResolution.pm new file mode 100644 index 0000000..ef5a6f4 --- /dev/null +++ b/lib/DX/Step/CompleteResolution.pm @@ -0,0 +1,34 @@ +package DX::Step::CompleteResolution; + +use DX::Class; + +with 'DX::Role::Step'; + +has original_search_state => ( + is => 'ro', isa => SearchState, required => 1 +); + +has resolution_space => ( + is => 'ro', isa => ResolutionSpace, required => 1 +); + +sub apply_to { + my ($self, $old_ss) = @_; + my $orig_ss = $self->original_search_state; + my $ns = do { + if (my $prop = $orig_ss->next_proposition) { + $prop->consider_step + } else { + $old_ss->on_solution_step + } + }; + return $old_ss->but( + next_step => $ns, + decisions_taken => [ + [ $self->resolution_space, $orig_ss ], + @{$old_ss->decisions_taken} + ], + ); +} + +1; diff --git a/lib/DX/Step/ResolveProposition.pm b/lib/DX/Step/ResolveProposition.pm index 271e2c4..15ecf86 100644 --- a/lib/DX/Step/ResolveProposition.pm +++ b/lib/DX/Step/ResolveProposition.pm @@ -1,6 +1,7 @@ package DX::Step::ResolveProposition; use DX::Step::EnterRecheck; +use DX::Step::CompleteResolution; use DX::Step::Backtrack; use DX::Utils qw(expand_deps); @@ -55,21 +56,12 @@ sub apply_to { ] ], ] ] ] ]; - my $ns = do { - if (my $prop = $old_ss->next_proposition) { - DX::Step::ConsiderProposition->new( - proposition => $prop - ) - } else { - $old_ss->on_solution_step - } - }; + my $rspace = $self->resolution_space; my $ss = $old_ss->but( - next_step => $ns, - decisions_taken => [ - [ $self->resolution_space, $old_ss ], - @{$old_ss->decisions_taken} - ], + next_step => DX::Step::CompleteResolution->new( + original_search_state => $old_ss, + resolution_space => $rspace, + ) ); my $old_hyp = $old_ss->current_hypothesis; (my $hyp, my @recheck) = $old_hyp->with_resolution( @@ -82,7 +74,7 @@ sub apply_to { next_step => DX::Step::EnterRecheck->new( proposition_list => \@recheck, on_completion_step => $ss->next_step, - on_failure_step => DX::Step::Backtrack->new, + on_failure_step => $rspace->remaining_resolution_space->next_step, ), ); }