-
Notifications
You must be signed in to change notification settings - Fork 50
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: avoid node overriding and re-instantiate a same function #198
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.
Looks good!
Left a couple of comments as it's not clear to me the usage of the mapping
src/mast/mod.rs
Outdated
..expr.clone() | ||
}; | ||
// check if this function is already monomorphized | ||
if ctx.functions_instantiated.contains_key(&old_qualified) { |
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.
Shouldn't this be checked to contain the new signature as a key? I think in the code below the zip
function is monomorphized two times, even if the LEN parameter is the same. Though, maybe I'm missing the point of the PR 😄
fn zip(a1: [Field; LEN], a2: [Field; LEN]) -> [[Field; 2]; LEN] {
let mut result = [[0; 2]; LEN];
for index in 0..LEN {
result[index] = [a1[index], a2[index]];
}
return result;
}
fn main(pub arr: [Field; 3]) -> Field {
let expected = [1, 2, 3];
for pair in zip(arr, expected) {
assert_eq(pair[0], pair[1]);
}
for pair in zip(arr, expected) {
assert_eq(pair[0], pair[1]);
}
return arr[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.
Oh yeah, indeed. It should always check the monomorphized name.
I have just pushed a fix that also includes a refactor to better encapsulate the resolutions for the generic values and types. This refactor makes it always resolves the types so as to get the monomorphized qualified name, without having to re-instantiate a function.
src/mast/mod.rs
Outdated
// check if this function is already monomorphized | ||
if ctx | ||
.methods_instantiated | ||
.contains_key(&(struct_qualified.clone(), method_name.value.clone())) |
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.
Same as before
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.
LGTM now! Also very nice refactoring 😃
Changes:
Since every functions need to be instantiated, the
ctx.generic_func_scope
is not necessary for determining whether it needs to generate new node id. Thus,ctx.generic_func_scope
is removed to avoid unexpected behavior in terms of handling the node ids at mast phase.A fix to avoid re-instantiate a same function.