-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in finding arity for verify attributes #2812
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -566,7 +566,38 @@ impl Machine { | |||||||||
let mut p = self.machine_st.p; | ||||||||||
let mut arity = 0; | ||||||||||
|
||||||||||
self.indices.code_dir.sort_by(|_, a, _, b| a.cmp(b)); | ||||||||||
|
||||||||||
let predicate_idx = self | ||||||||||
.indices | ||||||||||
.code_dir | ||||||||||
.binary_search_by_key(&p, |_, x| x.get().p() as usize) | ||||||||||
.unwrap_or_else(|x| x - 1); | ||||||||||
|
||||||||||
let current_pred_limit = self | ||||||||||
.indices | ||||||||||
.code_dir | ||||||||||
.get_index(predicate_idx + 1) | ||||||||||
.map(|x| x.1.p() as usize); | ||||||||||
|
||||||||||
while self.code[p].is_head_instr() { | ||||||||||
//println!("{}: {:?}", p, &self.code[p]); | ||||||||||
//println!("{} {:?}", arity, self.code[p]); | ||||||||||
for r in self.code[p].registers() { | ||||||||||
//println!("reg {:?}", r); | ||||||||||
if let RegType::Temp(t) = r { | ||||||||||
arity = std::cmp::max(arity, t); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
p += 1; | ||||||||||
} | ||||||||||
|
||||||||||
let p_interrupt = p; | ||||||||||
|
||||||||||
while p < self.code.len() | ||||||||||
&& current_pred_limit.map(|x| p < x).unwrap_or(true) | ||||||||||
Comment on lines
+598
to
+599
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can also work:
Suggested change
I also think that both loops could be joined together, simplifying the logic a bit (or at least making it less imperative in nature):
let arity = predicate_instrs
.flat_map(Instruction::registers)
.flat_map(|r| {
match r {
RegType::Temp(t) => Some(t),
_ => None
}
})
.max()
.unwrap_or(0); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I'm not sure if |
||||||||||
{ | ||||||||||
for r in self.code[p].registers() { | ||||||||||
if let RegType::Temp(t) = r { | ||||||||||
arity = std::cmp::max(arity, t); | ||||||||||
|
@@ -577,14 +608,15 @@ impl Machine { | |||||||||
} | ||||||||||
|
||||||||||
let instr = std::mem::replace( | ||||||||||
&mut self.code[p], | ||||||||||
&mut self.code[p_interrupt], | ||||||||||
Instruction::VerifyAttrInterrupt(arity), | ||||||||||
); | ||||||||||
|
||||||||||
self.code[VERIFY_ATTR_INTERRUPT_LOC] = instr; | ||||||||||
self.machine_st.attr_var_init.cp = p; | ||||||||||
self.machine_st.attr_var_init.cp = p_interrupt; | ||||||||||
} | ||||||||||
&Instruction::VerifyAttrInterrupt(arity) => { | ||||||||||
//println!("VerifyAttr arity: {arity}"); | ||||||||||
// let (_, arity) = self.code[VERIFY_ATTR_INTERRUPT_LOC].to_name_and_arity(); | ||||||||||
// let arity = std::cmp::max(arity, self.machine_st.num_of_args); | ||||||||||
self.run_verify_attr_interrupt(arity); | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
% Issue 2706 | ||
:- use_module(library(atts)). | ||
:- use_module(library(lists)). | ||
:- use_module(library(iso_ext)). | ||
|
||
:- attribute a/1. | ||
|
||
verify_attributes(_,_, []). | ||
|
||
asdf([_|Xs], N) :- | ||
true, | ||
N1 is N - 1, | ||
asdf(Xs, N1). | ||
|
||
test_a :- | ||
put_atts(A, a(1)), | ||
call_with_inference_limit(asdf(A, 1), 1000, _). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
% Issue 2632 | ||
|
||
% Repro for cycle detection crash | ||
:- use_module(library(lists)). | ||
:- use_module(library(clpz)). | ||
:- use_module(library(error)). | ||
:- use_module(library(lambda)). | ||
:- use_module(library(debug)). | ||
|
||
clpz:monotonic. | ||
|
||
q_r(T/N, T:U) :- 0 #=< #T, 0 #=< #U, #N #= T + U. | ||
|
||
qs_Ts_Us(Qs, ΣTs, ΣUs) :- | ||
maplist(\Q^T^U^(q_r(Q, T:U)), Qs, Ts, Us), | ||
intlist_partsums(Ts, ΣTs), | ||
intlist_partsums(Us, ΣUs). | ||
|
||
%% Utility predicates used above: | ||
|
||
intlist_partsums([X|Xs], [X|Ss]) :- | ||
intlist_partsums_acc(Xs, Ss, X). | ||
|
||
intlist_partsums_acc([], [], _). | ||
intlist_partsums_acc([X|Xs], [S|Ss], A) :- | ||
#S #= #X + #A, | ||
intlist_partsums_acc(Xs, Ss, S). | ||
|
||
test_b :- | ||
once(qs_Ts_Us(_, [1,3], [5,9])). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
% Issue 2809 | ||
|
||
:- use_module(library(freeze)). | ||
|
||
main1 :- | ||
freeze(Minor,true), | ||
cbor_minor_value1(Minor, []). | ||
|
||
main2 :- | ||
freeze(Minor,true), | ||
cbor_minor_value2(Minor, []). | ||
|
||
cbor_minor_value1(24, S0) :- numbytes_number(1, S0). | ||
|
||
cbor_minor_value2(24, S0) :- S0=S1, numbytes_number(1, S1). | ||
|
||
numbytes_number(_, []). | ||
|
||
test_c :- main1. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
use_module(a), use_module(b), use_module(c). | ||
\+ \+ (test_a, test_b, test_c). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
true. | ||
true. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# issue 2706 | ||
args = ["-f", "--no-add-history"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot these in :)