-
Notifications
You must be signed in to change notification settings - Fork 447
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
[#4661] Do not unconditionally mark extern method calls as compile-time constants. #4726
Conversation
This is kind-of ugly with |
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 the correct fix might be to add a check in at line 3844 to only mark the expression as constant if the extern method has an @pure annotation (and all the args are constants).
if (auto ef = mi->is<ExternFunction>()) {
if (constArgs && ef->method->getAnnotation(IR::Annotation::pureAnnotation)) {
@ChrisDodd I don't think |
But I don't really understand why we would want to mark extern method calls as compile-time constants when all args are const (or when there exist no args). Isn't it up to a backend to decide whether a given extern method can be evaluated at compile-time or not? |
Yes, precisely -- and the backend should mark the extern as The other place this In both places, a function of no arguments should be considered to be a function with all arguments constant (thus the |
4a844de
to
6b0b71f
Compare
@ChrisDodd The code on line 3844 is also needed for factory methods (and |
Yes, using I now can't recall why were adding these experimental factory-style functions -- someone probably wanted them, but I'm not sure why. We could hack in a flag when the return type is an extern type, but that isn't nice either. These testcases never made it into any "real" backend as far as I can see. |
@fruffy @ChrisDodd Do you know what is wrong with my DCO remediation commit? |
Hmm maybe because there is Kyle Cripps and kfcripps as signers? I do not thnk there is a way to configure DCO to ignore this. Btw DCO isn't mandatory yet until kinks like that are sorted out. |
but in #4762, I also signed off as "Kyle Cripps" and it worked :( |
I don't think it is safe to assume that a |
@vlstill Are you saying we should replace |
This is the actual implementation: It might be a mismatch between commit author and signoff. Unclear to me. It might be easier just to amend and rebase... |
Basically what I am saying is that if we want this behaviour (compiler-evaluated call to extern with constant args), we should have a specific annotation for that. I'm not sure if the "factory" is the only use case we have for these. On a second thought, these two things are not even one extension of another. It is possible that a compiler will be able to constant-evaluate an extern that is not pure! For example, one can imagine a What do you think, @ChrisDodd? |
Yes, they're not the same. |
@ChrisDodd, we could borrow https://en.cppreference.com/w/cpp/language/consteval
Would this be something to propose to the spec first? |
05bacf0
to
02813bd
Compare
@vlstill @ChrisDodd For now, I have modified the check to mark extern function call results as compile-time constants only if:
This is an improvement from the I believe adding a new annotation goes beyond the fix for #4726 and is out of scope of my intended changes. |
Signed-off-by: kfcripps <kyle@pensando.io>
…constants Signed-off-by: kfcripps <kyle@pensando.io>
Signed-off-by: kfcripps <kyle@pensando.io>
Signed-off-by: kfcripps <kyle@pensando.io>
…lls as compile-time constants Signed-off-by: kfcripps <kyle@pensando.io>
…pe_Extern Signed-off-by: kfcripps <kyle@pensando.io>
I set DCO to pass, it's not yet required anyway. |
Thanks @fruffy |
see below discussionconstArgs
is used to indicate whether all of an extern function call's arguments are constant, in which case the call is marked as a compile-time constant. TheconstArgs
calculation doesn't consider extern functions that have 0 arguments.Fixes #4661.