Skip to content

Generate libSyntax API #10926

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
Jul 26, 2017
Merged

Conversation

harlanhaskins
Copy link
Contributor

@harlanhaskins harlanhaskins commented Jul 13, 2017

This patch replaces the hand-rolled implementation of libSyntax’s APIs with a set of Python definitions that drive a set of gyb templates.

The Node definitions are incomplete, and they will be filled out incrementally.

@harlanhaskins harlanhaskins requested a review from bitjammer July 13, 2017 02:01
@harlanhaskins harlanhaskins changed the title [WIP] Generate libSyntax API from JSON definitions Generate libSyntax API from JSON definitions Jul 13, 2017
@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test

@CodaFi CodaFi mentioned this pull request Jul 13, 2017
@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test

@harlanhaskins harlanhaskins force-pushed the json-born branch 3 times, most recently from f586b70 to 14b88c7 Compare July 14, 2017 18:28
@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test

@moiseev
Copy link
Contributor

moiseev commented Jul 16, 2017

I have a question. Why mix JSON and gyb? gyb is already Python, and all the structures can be described in Python as well as in JSON. I think...

@harlanhaskins
Copy link
Contributor Author

They can, but it feels a little weird describing the entire AST structure directly in python...it feels more like the job of a declarative language.

@moiseev
Copy link
Contributor

moiseev commented Jul 16, 2017

Think about the benefits. You can compile your grammar definitions and even write tests for it! Just thinking out loud…

@harlanhaskins harlanhaskins changed the title Generate libSyntax API from JSON definitions Generate libSyntax API Jul 17, 2017
@harlanhaskins harlanhaskins removed the request for review from DougGregor July 17, 2017 22:26
@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test and merge

@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

I took a quick look at the cmake changes that you added. I have a question.

@@ -1759,6 +1767,7 @@ function(add_swift_library name)
SDK ${sdk}
ARCHITECTURE ${arch}
DEPENDS ${SWIFTLIB_DEPENDS}
GYB_DEPENDS ${SWIFTLIB_GYB_DEPENDS}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed? Why doesn't the normal depends just work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The normal DEPENDS won't regenerate gyb files if they're changed. This is actually no longer necessary for this PR, so I can remove it.

@@ -574,6 +574,9 @@ endfunction()
# FILE_DEPENDS
# Additional files this library depends on.
#
# GYB_DEPENDS
# Additional files .gyb sorce files depend on.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo. sorce -> source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

@gottesmm
Copy link
Contributor

Also, generally we have not used gyb in the compiler itself. We have used it in the standard library. From what I remember adding gyb dependencies to the compiler is controversial. Can you bring this up for discussion on swift-dev? If we are going to add such a large dependency, we should make sure that no one has objections about it.

My main feeling with gyb is if it is possible to not gyb we should.

@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test

@gottesmm
Copy link
Contributor

Harlan and I talked about this offline.

@harlanhaskins harlanhaskins force-pushed the json-born branch 2 times, most recently from 7bdea02 to a30ce39 Compare July 20, 2017 20:45
Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

LGTM

@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 95b32accc3e7242b267853881b00832cd4c31dfe
Test requested by - @harlanhaskins

This patch removes the hand-rolled libSyntax API and replaces it with an
API that's entirely automatically generated. This means the API is
guaranteed to be internally stylistically and functionally consistent.
@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test and merge

@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test

@harlanhaskins
Copy link
Contributor Author

@harlanhaskins harlanhaskins merged commit a5098e6 into swiftlang:master Jul 26, 2017
@@ -0,0 +1,11 @@
set(SWIFT_GYB_FLAGS
--line-directive "''")
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't understand why you'd disable line directives like this; the result would be that any compilation errors point into the generated file instead of the original one, with the typical result that maintainers edit the wrong file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh yes sorry about that. I turned line directives off while initially writing the gyb templates because it made it harder to see what the template instantiation was doing. That said, they should have been re-enabled before merging. I’ll re-enable them in a patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that I'm looking, these are for the C++ bindings. gyb's line directive code emits Swift-style line directives -- clang will just ignore them. The patch for this would need to teach gyb how and when to emit C-style line directives, which wouldn't be too difficult.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, those aren't swift-style line directives, which are broken for this purpose because they are only valid in certain syntactic positions. These are just comments that get post-processed by the line-directive tool. For error messages, it doesn't matter that clang would ignore them because the output of clang would get passed through the line-directive tool just like the output of Swift does. However, generating real #line directives should also allow you to debug in the .gyb source rather than in the generated .cpp

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.

8 participants