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

Fix #141: Improve type inference for macros, in particular handle type arguments. #178

Conversation

ciechowoj
Copy link
Contributor

The commit learns dstep to infer the signature of the macro basing on usage. It is still quite rudimentary implementation but it handles the cases that were wrong before anyway. Example:

assertTranslates(q"C
#define BAR(x, y, z) x * y * sizeof(z)

#define BAZ BAR(0, 1, float)
C", q"D
extern (C):

extern (D) auto BAR(z, T0, T1)(auto ref T0 x, auto ref T1 y)
{
    return x * y * z.sizeof;
}

enum BAZ = BAR!float(0, 1);
D");

More examples in unit tests.

@ciechowoj ciechowoj force-pushed the feature-infer-param-types-from-usage branch 2 times, most recently from f5aa6a4 to 9654914 Compare October 21, 2017 19:32
auto result = ExpressionContext.make(context);
result.params = params;
return result;
}
Copy link
Owner

Choose a reason for hiding this comment

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

Is there a reason why constructors are not used?

Copy link
Contributor Author

@ciechowoj ciechowoj Oct 22, 2017

Choose a reason for hiding this comment

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

Yes, you cannot create (allocate on the heap) the associative array in the constructor.

@ciechowoj
Copy link
Contributor Author

@jacob-carlborg What about making a little review : ) ?

@jacob-carlborg
Copy link
Owner

Yes, sorry. I've been busy with non-D related things.


extern (D) auto FOO(T)(auto ref T x)
{
return BAR(int);
Copy link
Owner

Choose a reason for hiding this comment

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

This is translated like this because at this point we don't know what BAR is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, do you think BAR!int() is better?

Copy link
Owner

Choose a reason for hiding this comment

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

Well, BAR(int); doesn't compile, regardless if BAR is defined in the D code or not. So yes I think BAR!int() is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that it isn't that trivial to change it (more than 1h of work), can we merge it as is for now? I don't have time to fix it right now. Maybe I'll manage after winter...

Copy link
Owner

Choose a reason for hiding this comment

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

Sure, can you rebase please.

Copy link
Contributor Author

@ciechowoj ciechowoj Mar 16, 2018

Choose a reason for hiding this comment

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

Do you remember what you meant by rebase? There is no merge conflict after all.

Copy link
Owner

Choose a reason for hiding this comment

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

No. The only thing I can think of is perhaps it's behind master.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rebased.

@ciechowoj ciechowoj force-pushed the feature-infer-param-types-from-usage branch from 9654914 to 37b4dcf Compare March 16, 2018 15:40
@ciechowoj ciechowoj force-pushed the feature-infer-param-types-from-usage branch from 37b4dcf to 8dae476 Compare March 16, 2018 17:45
@jacob-carlborg jacob-carlborg merged commit 41c0f99 into jacob-carlborg:master Mar 18, 2018
@jacob-carlborg
Copy link
Owner

Thanks.

@ciechowoj ciechowoj deleted the feature-infer-param-types-from-usage branch March 18, 2018 22:16
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.

None yet

2 participants