-
Notifications
You must be signed in to change notification settings - Fork 59
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
Adding a check to verify that functions names do not conflict when translated to assembly labels #1067
Conversation
9dd611a
to
b86a6e7
Compare
The issue only arises for export function. Is it necessary to also fail when one of the functions is internal or inline? |
With this variant of original issue example :
generated assembly code is :
We can see that I didn't found any bug using inline functions, and I don't expect one since inline dissapears before printasm. I will update the pull request to raise an error only if the function is not inline. |
b220b93
to
e70a1fa
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.
I think it will be nicer to not modify the type Env.env.
Write a checker that given a list gfunc ensure that this clash of name do not occurs.
We can call it when we want, maybe at the end of pretyping.
I agree with your proposition, but this will require deeper work. For the moment, I will qualify this PR as draft so we can find a suitable (and reusable) solution. |
e70a1fa
to
ff94257
Compare
I released a new version applying your suggestion @bgregoir. I think it is ready for review now. |
ff94257
to
bd5a829
Compare
compiler/src/label_check.ml
Outdated
Check if functions have conflicting names when translated to their assembly label names. | ||
Raise `DuplicateLabelError` if a conflict is found between two non inline functions (because inline function are substituted before assembly traduction). | ||
*) | ||
let check_labels (prog: ('len,'info,'asm) gprog) = |
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 should return the list of conflicts instead of failing early.
compiler/src/main_compiler.ml
Outdated
@@ -134,6 +134,13 @@ let main () = | |||
exit 0 | |||
end; | |||
|
|||
ignore ( |
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 ignore
is fishy.
compiler/src/main_compiler.ml
Outdated
ignore ( | ||
try Label_check.check_labels pprog with | ||
| Label_check.DuplicateLabelError (loc, code) -> | ||
hierror ~loc:(Lone loc) ~kind:"label error" |
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.
Also, a warning
might be more appropriate.
c3833f8
to
72d23ea
Compare
I did changes as suggested by @vbgl . Since It only print warning now, I didn't saw the interested or returning error list (at least in the current version of error handling). If you think it is better, I can add it. |
72d23ea
to
5c389fa
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.
- Please add a
label_check.mli
- What is the purpose of the test case?
5c389fa
to
9812715
Compare
9812715
to
3a7fbca
Compare
I rewrote error type to be simpler to understand and change the error message to be more clear. I think it is ready to merge now. |
type function_label = { | ||
loc : L.t; | ||
fname : string; | ||
} |
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 about type function_label = string L.located
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 like it but it is also a good type. 'a L.located
should only represent located object in my opinion. But I can make the change if you prefer
…n translated to assembly labels. Inline functions are not affected by this change
3a7fbca
to
4fb6b55
Compare
Issue
Assembly generation use
PrintCommon.escape
function to build labels which can creates names conflicts because of namespaces. see (#993).Solution
We introduce a map in
pretyping.ml
environment that check if a label is already used by another function.