-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[AST][Sema] Typed throws implementation #33653
base: main
Are you sure you want to change the base?
Conversation
|
Developers are welcome in order to get this implementation going forward (as it is needed for a review process). |
|
I think some of the problems building the stdlib are from a lot of diagnostic noise when trying to parse a type and failing. That's straightforward to fix--you can do something like when the DiagnosticSuppression goes out of scope the diagnostics go back on. I added that locally and got some improvement. The one that's generating a lot of noise compiling the stdlib is If you take that out, then stdlib compiles, but obviously that defeats the purpose of the whole thing. I want to make sure I understand that one though. If the current token is an arrow, haven't we moved past anything like |
|
The new syntax is as you said |
|
You can call |
|
As it was an optional token @theblixguy, I chose to get the type if was present or null in other case scenario. With |
lib/Parse/ParsePattern.cpp
Outdated
| ASTContext &Ctx = SF.getASTContext(); | ||
| DiagnosticSuppression SuppressedDiags(Ctx.Diags); | ||
| backtrackingScope.cancelBacktrack(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the backtrack for searching of my previous word was a keyword and if it was the throws keyword, but maybe there's some other way to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what you should do is something like:
bool hasType = false;
{
BacktrackingScope backtrack(*this);
hasType = canParseType();
}
// Parser backtracks after end of scope above
if (hasType) {
ParserResult<TypeRepr> result = parseType();
throwsType = result.getPtrOrNull();
}as canParseType() consumes some tokens IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is good for consuming the type token! Thank you! But I'm unable to check that the previous token was tok::throws
|
ok, working through that in is skipping the important part--we already consumed the 'throws' and the active token is the throw type. We should try to parse the type immediately, and not look for |
|
If we don't check for |
I think the order of elements should be good--we don't need to check for The stdlib won't build after my change so it needs something else. I'm interpreting what's happening after ParsePattern.cpp:840 as:
I think where the problem is after my change is that |
|
I got it working, I just delay a step the token being consumed in order to check that there's a type or not just after it 😄 |
|
Could we make a quick testrun and a source compatibility on the CI? (tests are passing locally) Altough I cannot make stdlib to compile, lots of errors (unrelated), to the changes being made (?) |
What are the errors like? I am having problems compiling in |
|
Things like: |
|
Now I'm only getting: Only |
|
is that in |
|
I'm getting a hard time with Deserialization, I'll push what I have but I does not compile, I cannot find a way to get from the deserialized func to a The Protocols are running into issues all as you said, could you take a look at them? |
* Added parsing of 'throws (Type)' syntax.
New diagnostic if the parsing fails. Logic to parse an optional
parenthesized type identifier after the 'throws' keyword.
This will not compile the standard library right now because it cannot
parse the pattern
`func f(_ body: (T) throws -> U) rethrows -> U {return try body(t)}`
That pattern is really common in the standard library for things like
`withUnsafeBufferPointer`. I'm not sure what the problem is right now there.
* Added Parser::parseThrowsType.
Edited Parse/errors.swift test to include
some throws (SomeError) entries. Parse/errors.swift passes in this form.
Stdlib compiles. Parse/async.swift, Syntax/Parser/tree.swift and
incrParse/incrementalTransfer.swift fail right now. Also I think I need to set
a SourceLoc for the throwsType explicitly.
* [Parse] Parse type after throws correctly in function declarations
* [Parse] Parse type after throws correctly in function types
* Improve documentation of new parsing functions
Co-authored-by: Josef Zoller <josef@walterzollerpiano.com>
Update typed throws implementation
|
This is all parsing done. |
|
@swift-ci please smoke test |
|
@swift-ci please compatibility test |
|
cc @theblixguy ? |
|
You need commit access to trigger CI. I’ll do it for you. |
|
@swift-ci please smoke test |
|
@swift-ci please test source compatibility |
|
and how do I get with those permissions? as we're working on a proposal implementation and will need it sometimes, do I ask you? |
|
Jenkins died before the smoke test even started on OS X |
|
You can run the tests locally. If you have any problems with that, then I can run CI for you if you ping me. |
|
@swift-ci please smoke test macOS |
|
Looks like there’s an infrastructure problem preventing smoke tests on macOS. Let’s wait for it to be resolved. |
|
Yeah we always test locally before updating the PR but as the CI is the source of truth we want to make sure we didn't screw up anything locally. |
|
Two questions @theblixguy, why the compat may fail in debug and not in release? which the difference? on the other hand, the smoke tests have failed, it seems, for unrelated things to the changes made, is it possible to repeat them? |
|
Debug failure is known (been failing for others as well) and is unrelated to your changes, so I wouldn’t worry about it. @swift-ci please smoke test |
|
@swift-ci please smoke test cc @theblixguy |
|
Let’s just run python lint as that failed last time. @swift-ci please python lint |
|
first time see that command |
This PR adds a basic implementation for adding a type after the
throwskeyword as discussed in the following thread: https://forums.swift.org/t/typed-throws/39660This is a draft
Todo: