From: Matt S Trout Date: Mon, 16 Apr 2018 02:38:01 +0000 (+0000) Subject: show dependencies before backtracking X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4db57c0455eccf4cb7ac0b89abdc1969add73685;p=scpubgit%2FDX.git show dependencies before backtracking --- diff --git a/fragment.output/btdemo b/fragment.output/btdemo index f42caa6..33df4d0 100644 --- a/fragment.output/btdemo +++ b/fragment.output/btdemo @@ -126,10 +126,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { actions { SetValue 0.X {{ a 1 b 2 c 3 }} } depends_on { CONTENTS_OF 0.X } } - backtrack + backtrack because { CONTENTS_OF 0.X } fail_recheck } -backtrack +backtrack because { CONTENTS_OF 0.XValue } remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } @@ -184,10 +184,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { actions { SetValue 0.X {{ a 1 b 2 c 3 }} } depends_on { CONTENTS_OF 0.X } } - backtrack + backtrack because { CONTENTS_OF 0.X } fail_recheck } -backtrack +backtrack because { CONTENTS_OF 0.XValue } remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } @@ -239,10 +239,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { actions { SetValue 0.X {{ a 1 b 2 c 3 }} } depends_on { CONTENTS_OF 0.X } } - backtrack + backtrack because { CONTENTS_OF 0.X } fail_recheck } -backtrack +backtrack because { CONTENTS_OF 0.XValue } remaining resolution_space { proposition member_at X ?XKey ?XValue geometry_depends_on { INDICES_OF 0.X; TYPE_OF 0.XKey; TYPE_OF 0.XValue } @@ -328,10 +328,10 @@ recheck eq ?Y {{ d 1 e 2 f 3 }} { actions { SetValue 0.Y {{ d 1 e 2 f 3 }} } depends_on { CONTENTS_OF 0.Y } } - backtrack + backtrack because { CONTENTS_OF 0.Y } fail_recheck } -backtrack +backtrack because { CONTENTS_OF 0.YValue } remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } @@ -429,10 +429,10 @@ recheck eq ?Y {{ d 1 e 2 f 3 }} { actions { SetValue 0.Y {{ d 1 e 2 f 3 }} } depends_on { CONTENTS_OF 0.Y } } - backtrack + backtrack because { CONTENTS_OF 0.Y } fail_recheck } -backtrack +backtrack because { CONTENTS_OF 0.YValue } remaining resolution_space { proposition member_at X ?XKey ?XValue geometry_depends_on { INDICES_OF 0.X; TYPE_OF 0.XKey; TYPE_OF 0.XValue } @@ -505,10 +505,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { actions { SetValue 0.X {{ a 1 b 2 c 3 }} } depends_on { CONTENTS_OF 0.X } } - backtrack + backtrack because { CONTENTS_OF 0.X } fail_recheck } -backtrack +backtrack because { CONTENTS_OF 0.XValue } remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } @@ -563,10 +563,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { actions { SetValue 0.X {{ a 1 b 2 c 3 }} } depends_on { CONTENTS_OF 0.X } } - backtrack + backtrack because { CONTENTS_OF 0.X } fail_recheck } -backtrack +backtrack because { CONTENTS_OF 0.XValue } remaining resolution_space { proposition member_at Y ?YKey ?YValue geometry_depends_on { INDICES_OF 0.Y; TYPE_OF 0.YKey; TYPE_OF 0.YValue } @@ -618,10 +618,10 @@ recheck eq ?X {{ a 1 b 2 c 3 }} { actions { SetValue 0.X {{ a 1 b 2 c 3 }} } depends_on { CONTENTS_OF 0.X } } - backtrack + backtrack because { CONTENTS_OF 0.X } fail_recheck } -backtrack +backtrack because { CONTENTS_OF 0.XValue } {{ X {{ a 1 b 2 c 3 }} XKey 'b' diff --git a/lib/DX/Step/Backtrack.pm b/lib/DX/Step/Backtrack.pm index 9a92677..06d1986 100644 --- a/lib/DX/Step/Backtrack.pm +++ b/lib/DX/Step/Backtrack.pm @@ -1,16 +1,33 @@ package DX::Step::Backtrack; +use DX::DependencyMap; +use DX::Utils qw(format_deps); use DX::Class; with 'DX::Role::Step'; -#has resolution_space => (is => 'ro', isa => ResolutionSpace, required => 1); +has resolution_space => (is => 'ro', isa => ResolutionSpace, required => 1); sub apply_to { my ($self, $ss) = @_; - trace backtrack => [ statement => [ [ symbol => 'backtrack' ] ] ]; + my $rspace = $self->resolution_space; + trace backtrack => [ statement => [ + [ symbol => 'backtrack' ], + [ statement => [ + [ symbol => 'because' ], + format_deps($rspace->geometry_depends_on) + ] ] + ] ]; + my $dmap = DX::DependencyMap->new_empty + ->with_dependencies_for( + backtrack => $rspace->geometry_depends_on + ); + foreach my $adj (@{$ss->decisions_taken}) { my ($rspace_was, $ss_was) = @$adj; + $dmap = $dmap->with_dependencies_for( + backtrack => $rspace_was->geometry_depends_on + ); next unless @{$rspace_was->remaining_resolution_space->members}; trace rspace => [ statement => [ [ symbol => 'remaining' ], diff --git a/lib/DX/Utils.pm b/lib/DX/Utils.pm index b52119d..2bef078 100644 --- a/lib/DX/Utils.pm +++ b/lib/DX/Utils.pm @@ -11,7 +11,7 @@ my @const = ( our @EXPORT_OK = ( @const, (my @builders = qw(rspace rstrat res string number dict proposition)), - 'deparse', '*trace', 'expand_deps', + 'deparse', '*trace', 'expand_deps', 'format_deps', ); our %EXPORT_TAGS = ( @@ -56,6 +56,15 @@ sub expand_deps { [ map _expand_dep($_), @{$_[0]} ] } +sub format_deps { + [ block => [ + map [ statement => [ + [ symbol => (split '::', ${$_->[0]})[-1] ], + [ value_path => [ @{$_}[1..$#$_] ] ] + ] ], @{$_[0]} + ] ] +} + sub rspace { require DX::ResolutionSpace; DX::ResolutionSpace->new(@_);