-
Notifications
You must be signed in to change notification settings - Fork 247
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
Refactor check_unique
to Checked{Graph,Node}
#668
base: kkysen/pfb/unique-checking/check-unique-refactor
Are you sure you want to change the base?
Refactor check_unique
to Checked{Graph,Node}
#668
Conversation
328afba
to
449a7e3
Compare
34bc78f
to
7510aec
Compare
…d running `.check_unique()`. It also preserves the Rust source code in debug info.
449a7e3
to
ee941dd
Compare
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.
Not sure this is really necessary, but it certainly doesn't hurt
|
||
let a = g.mk_addr_of_local("let mut a = 0", false, 0_u32); | ||
let b1 = g.mk_copy("let b = &mut a", false, a); | ||
g.mk_store_addr("*b = 0", false, b1); |
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.
How about let _b2 = g.mk_store_addr(...)
, so the name b2
is visible here for matching with the graph above?
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.
Sure, I can add them back and just _
-prepend them.
fn mk_node( | ||
&mut self, | ||
stmt: &'static str, | ||
unique: bool, |
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.
nit pick: i think i'd rather this be an enum than a bool
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.
optional change, just my two cents
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.
What's the advantage of an enum
? If we're calling them Unique
and NonUnique
, I'm not sure there's an advantage over a bool
. One is just non the other. Plus, then we should just change the unique
field in NodeInfo::unique
to the same enum
.
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.
Plus, then we should just change the unique field in NodeInfo::unique to the same enum.
I agree that should be done. My preference is because I don't like relying on IDEs to tell me what the bool represents. A type Unique
or NonUnique
is very clear, despite it being semantically the same as a bool
. In cases where functions take more than one bool (not the case here), it prevents mixing argument order by making things type safe.
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.
Okay, that makes sense. Plus we could change it to Unique
and Aliases
if we want, too. I do think we should save that for a later PR, though.
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.
that sounds okay
This refactors
check_unique
toChecked{Graph,Node}
.CheckedNode
stores not just theNodeId
like as passed to the previouscheck_unique
, but also if it should be unique (thus we ensure we don't forget to check anyNode
s (we did)), as well as the Rust source code statement for thatNode
as debug info.Then
CheckedGraph
stores aGraph
and aVec<CheckedNode>
. When.mk_*
methods are called on it, it adds theCheckedNode
to theVec
, and then when.check_unique()
is called at the end, it uses all theseCheckedNode
s.The benefits of this are:
unique
value is right next to the call that creates thatNode
Node
s have to be markedunique
or not, so we don't forget any (we did)assert!
ion fails and we print theNodeId
andGraphs
, we also print the Rust source code as the debug info (previously this was left blank).