-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[compiler][trivial] fix type instantiation for receiver style syntax #16095
base: main
Are you sure you want to change the base?
Conversation
⏱️ 21m total CI duration on this PR
|
let translated = et.post_process_body(result.into_exp()); | ||
et.finalize_types(); |
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 is not looking right. Finalization has to happen before post processing since this needs to have the ground types, it is not place by accident in this order. Its also happening inside of post process for some special cases like here. Please look closer what is wrong here to find the right fix.
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.
The issue is that finalize_types
generated the error before running post_process_body
. I updated the code so that when finalize_types
is run before post_process_body
, error will not be generated.
a4aeca4
to
2331121
Compare
@@ -1573,8 +1573,9 @@ impl<'env, 'translator> ModuleBuilder<'env, 'translator> { | |||
} | |||
let access_specifiers = et.translate_access_specifiers(&def.access_specifiers); | |||
let result = et.translate_seq(&loc, seq, &result_type, &ErrorMessageContext::Return); | |||
et.finalize_types(); | |||
et.finalize_types(false); |
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.
Can you add a comment before this call, like "Run type inference finalization so post processing has all available type information, but do not report errors yet because receiver functions can add more type bindings."
Then add to the 2nd call "Run finalization again, this time with reporting errors."
Also look out in post-process and remove code, as we do not need to do the ad-hoc type specialization there any longer which I added to the receiver processing, since we run now finalization a 2nd time.
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.
done
2331121
to
5445e95
Compare
@@ -24,6 +24,5 @@ module 0x42::m { | |||
s.receiver_ref_mut(1u8); | |||
s.receiver_ref_mut::<u8>(1); | |||
s.receiver_ref_mut::<u8, u8>(1); | |||
s.receiver_needs_type_args(x) |
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.
Add this to a separate test case because this error will be hidden by previous ones.
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 is caused by removing adhoc finalize_type
in post_process_receiver_call
.
@@ -2139,12 +2141,8 @@ impl<'env, 'translator, 'module_translator> ExpTranslator<'env, 'translator, 'mo | |||
if ok { | |||
receiver_param_type = subs.specialize(&receiver_param_type); | |||
self.subs = subs; | |||
let inst = inst |
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.
Remove instantiation here because finalize_types
will be called later.
Description
This PR adds the logic to run
finalize_types
before and afterpost_process_body
and only generates error in the second time so that type can be instantiated in receiver style syntax before finalizing types.Close #16091
Close #16057
How Has This Been Tested?
Key Areas to Review
Type of Change
Which Components or Systems Does This Change Impact?
Checklist