Skip to content

Allow spelling out a C type in the convention attribute. #28479

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

Merged
merged 2 commits into from
Dec 10, 2019
Merged

Allow spelling out a C type in the convention attribute. #28479

merged 2 commits into from
Dec 10, 2019

Conversation

varungandhi-apple
Copy link
Contributor

Once this PR + the #27479 PR land, I will land a third PR that includes the StringRef <-> Clang Type conversions. For now, we treated the string literal containing the type as some opaque data.

Q. Should we special-case the "c" and "block" calling conventions for the cType key (I am doing that right now)? It feels like a layering violation; the parser shouldn't know what string corresponds to C conventions vs Swift conventions. I implemented it this way because it seemed easy.

@varungandhi-apple

This comment has been minimized.

1 similar comment
@varungandhi-apple

This comment has been minimized.

@varungandhi-apple
Copy link
Contributor Author

Kinda' neat that the difference in numbers between this PR and the clang function types in AST PR is exactly 100.

consumeToken(tok::identifier);

// TODO: (Varun) The parser should probably not know about what conventions
// might have Clang types :(.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's unreasonable, but you can certainly parse it unconditionally if you want and then diagnose if it's provided multiple times.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand what you mean by "provided multiple times". The change I had in mind here was to get rid of the convention.Name checks.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you're going to parse generically, you should probably accept an arbitrary list of <identifier> : <expression> pairs and then complain about the ones you see multiple times or which you don't understand. I guess you don't have to, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, but one advantage of diagnosing this here rather than in Sema is that you can easily suppress follow-on diagnostics from Sema about a missing cType: clause by just dropping the attribute entirely.

Copy link
Contributor Author

@varungandhi-apple varungandhi-apple Dec 3, 2019

Choose a reason for hiding this comment

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

If you're going to parse generically

That is something I was trying to avoid. We can do that when we need it, instead of right now.

you can easily suppress follow-on diagnostics from Sema about a missing cType: clause by just dropping the attribute entirely

Not sure why we would diagnose if cType: is missing. We don't expect users to write the cType: -- would this be a diagnostic specific to new swiftinterfaces?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should at least require it in SIL types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok... but isn't the parser the wrong place to be doing a "error only if the convention is this or that and we are parsing SIL"? It seems convenient but...

Copy link
Contributor

Choose a reason for hiding this comment

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

That should definitely be delayed until Sema.

For example, one may write a calling convention like

  convention(c, cType: "void *(void)")

for a procedure that takes no arguments.
@varungandhi-apple
Copy link
Contributor Author

@swift-ci please test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

Okay, LGTM

@varungandhi-apple
Copy link
Contributor Author

Thanks! Just re-running tests in case:

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 9, 2019

Build failed
Swift Test OS X Platform
Git Sha - 7d297bc

@varungandhi-apple
Copy link
Contributor Author

@swift-ci please clean test macOS platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 7d297bc

@varungandhi-apple
Copy link
Contributor Author

Merging because it was only the Python linter which was failing, which has since been fixed.

@varungandhi-apple varungandhi-apple merged commit 3cc452e into swiftlang:master Dec 10, 2019
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.

3 participants