-
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?
Conversation
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.
I don't have much experience with the logic behind verify_attributes
, but I couldn't find any issue with this fix.
I wonder how hard it would be to store somewhere else the number of temporary variables, so that the WAM instructions don't need to be scanned for every attributed variable unification.
I do believe that the current method of modifying self.code
to eventually call verify_attr_interrupt
is iffy. It feels flimsy and it will make JIT impossible in its current form.
//println!("{}: {:?}", p, &self.code[p]); | ||
//println!("{} {:?}", arity, self.code[p]); |
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 :)
while p < self.code.len() | ||
&& current_pred_limit.map(|x| p < x).unwrap_or(true) |
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.
This can also work:
while p < self.code.len() | |
&& current_pred_limit.map(|x| p < x).unwrap_or(true) | |
let current_pred_limit = current_pred_limit.unwrap_or(self.code.len()); | |
while p < self.code.len() && p < current_pred_limit { |
I also think that both loops could be joined together, simplifying the logic a bit (or at least making it less imperative in nature):
- grab a slice of
self.code
:let predicate_instrs = &self.code[p..current_pred_limit.min(self.code.len())];
- find
p_interrupt
:let p_interrupt = p + predicate_instrs.partition_point(Instruction::is_head_instr);
- find the arity:
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I'm not sure if partition_point
can be used, since it does a binary search.
I think ideally this should all be done in the compilation step, although maybe the verify attributes interrupt really needs to be this dynamic. |
This fixes a bug in the current attributed variables implementation that creates a lot of strange bugs that seem like miscompilations.
Closes #2706, closes #2809, closes #2632.