-
Notifications
You must be signed in to change notification settings - Fork 237
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 issue on specialize 'this_type(interface)' #5970
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 want to get better understanding why IRThisType can appear as the parameter type of an actual function, this seems wrong to me.
// case in maybeSpecializeGeneric() because we the concrete type of the | ||
// 'this_type(interface_type)' is not known at that time. So we have to handle this case | ||
// here. | ||
if (auto thisType = as<IRThisType>(firstParam->getDataType())) |
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.
Should we just check for ThisType in the loop above at line 1316?
|
||
// Replace the first parameter of the function type with the | ||
// concrete type. | ||
auto functionType = calleeFunc->getDataType(); |
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.
firstParamType->replaceUsesWith() is dangerous/incorrect, because there may still be other uses of the type (e.g. outside the function we are processing), and they shouldn't be replaced.
If the intention here is just to create a new IRFuncType and set it to calleeFunc, you can just call fixupFuncType before returning.
@@ -1328,7 +1328,52 @@ struct SpecializationContext | |||
// If we never found a parameter or return type worth specializing, we should bail out. | |||
// | |||
if (!returnTypeNeedSpecialization && !argumentNeedSpecialization) | |||
{ | |||
auto firstParam = calleeFunc->getFirstParam(); |
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 am not understanding the underlying issue we are trying to fix here.
How can a param type of the callee end up being an ThisType? IIRC ThisType
is only used when declaring an interface requirement, and should never appear in any actual methods. I am very confused why the callee here can have its first param type being an IRThisType. They should only just be IRInterfaceType and be handled with the existing code.
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.
call specialize(base, this_type(interface_type), witness_table) (xxx)
for above IR, maybeSpecializeGeneric()
will evaluate specialize
, and this will generate a specialized function with this_type(interface_type)
as the input parameter.
Let's say the function is named func
, then this IR will be
call func(xxx)
, and the function will be
void func(this_type(interface_type))
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.
Based on what you said, you mean
call specialize(base, this_type(interface_type), witness_table) (xxx)
this_type(interface_type)
should never appear in specialize
call?
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 know about that.
But if this is the case, then the bug is in more previous stage.
The PR should also include a regression test for the issue we are fixing. |
Yea, I will add. |
I did some investigation here, and it appears that the IR for It is something like:
The This usually occurs when the front-end produces wrong DeclRef to |
I drafted an attempt to fix this issue in the front-end here: #5971 It may still not be 100% correct, but this is the direction we should be exploring. |
It makes sense to me that we should fix the front-end if the |
close issue #5900