Skip to content

Extensions: fix lowering of implicit conversion on receiver in pattern-based scenarios #78685

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented May 22, 2025

This is a follow-up on #78480, which didn't properly handle the lowering of some more complex implicit conversions (implicit span or implicit tuple conversions).

Relates to test plan #76130

@jcouv jcouv self-assigned this May 22, 2025
@jcouv jcouv added Area-Compilers Feature - Extension Everything The extension everything feature labels May 22, 2025

mixableArguments.Free();
escapeValues.Free();
return valid;

void inferDeclarationExpressionValEscape()
void inferDeclarationExpressionValEscape(ImmutableArray<BoundExpression> argsOpt, SafeContext localScopeDepth, ArrayBuilder<EscapeValue> escapeValues)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 I was debugging in this area as part of this PR and noticed we're doing some captures

Debug.Assert(Conversions.IsValidExtensionMethodThisArgConversion(this.Compilation.Conversions.ClassifyConversionFromType(receiver.Type, extensionParameter.Type, isChecked: false, ref discardedUseSiteInfo)));
#endif

return this.Convert(extensionParameter.Type, receiver);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 the problem was that this produces a BoundConversion. That's okay (can be handled by the emit layer) for simple conversions, but for more complex conversions we need to produce lowered nodes (see MakeConversionNode).

@jcouv
Copy link
Member Author

jcouv commented May 22, 2025

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jcouv jcouv force-pushed the extensions-conversions2 branch from 71f0783 to 2109823 Compare May 23, 2025 07:42
@jcouv jcouv marked this pull request as ready for review May 23, 2025 07:43
@jcouv jcouv requested a review from a team as a code owner May 23, 2025 07:43
Debug.Assert(Conversions.IsValidExtensionMethodThisArgConversion(this._compilation.Conversions.ClassifyConversionFromType(receiver.Type, extensionParameter.Type, isChecked: false, ref discardedUseSiteInfo)));
#endif

return MakeConversionNode(receiver, extensionParameter.Type, @checked: false, acceptFailingConversion: false, markAsChecked: true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markAsChecked: true

I do not see any corresponding changes in binding, therefore, I am not certain whether we really can pass true here. The contract is, we can pass true only if this conversion was actually checked during binding. This is achieved by calling CreateConversion helper and actually attempting to create BoundConversion node (there are plenty examples for this). In addition, it is preferred to not drop the created BoundConversion node, but preserve it in the tree and use it during rewrite in order to actually produce its lowered form. There is a small set of cases when we do not preserve the node given too much complexity of the bound node structure, but we still "check" conversion during binding for those cases.

Debug.Assert(Conversions.IsValidExtensionMethodThisArgConversion(this._compilation.Conversions.ClassifyConversionFromType(receiver.Type, extensionParameter.Type, isChecked: false, ref discardedUseSiteInfo)));
#endif

return MakeConversionNode(receiver, extensionParameter.Type, @checked: false, acceptFailingConversion: false, markAsChecked: true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@checked: false

This looks suspicious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Extension Everything The extension everything feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants