Skip to content
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

Translate generic math calls using the existing Math translators #31322

Merged
merged 1 commit into from
Jul 25, 2023

Conversation

bricelam
Copy link
Contributor

Resolves #30916

@bricelam bricelam requested a review from a team July 20, 2023 17:51
/// </summary>
public class CallForwardingExpressionVisitor : ExpressionVisitor
{
private static readonly IReadOnlyDictionary<MethodInfo, MethodInfo> _forwardedMethods = new Dictionary<MethodInfo, MethodInfo>
Copy link
Contributor Author

@bricelam bricelam Jul 20, 2023

Choose a reason for hiding this comment

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

Note, I didn't include any methods with ValuTuple, IntPtr, or out since it seems unlikely that a provider will ever support those.

@@ -47,12 +47,8 @@ public class SqliteMathTranslator : IMethodCallTranslator
{ typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(long) })!, "sign" },
{ typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(sbyte) })!, "sign" },
{ typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(short) })!, "sign" },
{ typeof(MathF).GetMethod(nameof(MathF.Abs), new[] { typeof(float) })!, "abs" },
{ typeof(MathF).GetMethod(nameof(MathF.Max), new[] { typeof(float), typeof(float) })!, "max" },
{ typeof(MathF).GetMethod(nameof(MathF.Min), new[] { typeof(float), typeof(float) })!, "min" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are now redirected to the float overloads on Math. In the end, they still get translated.

{ typeof(double).GetRuntimeMethod(nameof(double.Exp), new[] { typeof(double) })!, typeof(Math).GetRuntimeMethod(nameof(Math.Exp), new[] { typeof(double) })! },
{ typeof(double).GetRuntimeMethod(nameof(double.Floor), new[] { typeof(double) })!, typeof(Math).GetRuntimeMethod(nameof(Math.Floor), new[] { typeof(double) })! },
{ typeof(double).GetRuntimeMethod(nameof(double.FusedMultiplyAdd), new[] { typeof(double), typeof(double), typeof(double) })!, typeof(Math).GetRuntimeMethod(nameof(Math.FusedMultiplyAdd), new[] { typeof(double), typeof(double), typeof(double) })! },
{ typeof(double).GetRuntimeMethod(nameof(double.Ieee754Remainder), new[] { typeof(double), typeof(double) })!, typeof(Math).GetRuntimeMethod(nameof(Math.IEEERemainder), new[] { typeof(double), typeof(double) })! },
Copy link
Member

Choose a reason for hiding this comment

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

We are missing tests for many of these

Copy link
Contributor Author

@bricelam bricelam Jul 20, 2023

Choose a reason for hiding this comment

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

Not all of them are actually translated. Should I test all the ones that are on SQL Server? We get coverage that this works by the MathF tests for the methods removed from the translators.

Adding a unit tests felt a bit silly since it's really just a dictionary lookup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that Math and MathF are no longer evolving so this list won't change. New methods will be added using the generic math pattern with no corresponding Math method. Providers will need to translate those directly (as I did in PR #31301)

@bricelam bricelam merged commit dd17dec into dotnet:main Jul 25, 2023
2 of 7 checks passed
@bricelam bricelam deleted the gmath branch July 25, 2023 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Translate generic math methods to SQL
3 participants