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
fasta: Support for metadata annotations on other objects than functions/classes #28434
Comments
Issue is still valid for fasta. |
Blocked on #29169 |
BTW, it's not just these blocked nodes, metadata is also allowed on local variable declarations and variable declarations in |
I've added "Annotations on VariableDeclaration" to #29169. |
Why is it blocked? |
@scheglov This is blocked because all the failures the OP mentioned require changes to kernel AST. But I can take a look at the missing parser support. Can you point me to the failing tests? |
OK, I see. There are more tests in analyzer, but most of them have not been moved yet to verify with Fasta. |
I got confused, this is still partially blocked, and it is not metadata in general (which @stereotype441 is working on). |
Is this still blocked? |
Kernel now supports these annotations, we need to start producing them. R=paulberry@google.com, sigmund@google.com Bug: Change-Id: I1b2732ddad2674688d562f3be3ca29140a5e9381 Reviewed-on: https://dart-review.googlesource.com/17863 Reviewed-by: Sigmund Cherem <sigmund@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Thank you, @scheglov. This is no longer blocked. |
We'll need this to switch DDC to kernel. (We'll need to support limited mirrors for some internal tests - those tests relying on mirrors to read parameter annotations.) |
@kmillikin @peter-ahe-google - is this doable this Q? |
Let me check. |
@vsmenon is it only annotations on parameters you're missing? |
That's the only thing we're aware of at the moment. @jmesserly - do you see anything else missing? |
Yeah, parameters are the only blocking thing that I'm aware of. Local variable annotations would be nice to have, but they aren't required/urgent. (DDC uses some local variable annotations in its private SDK impl code, to indicate non-null locals. But that can be refactored to use something else.) |
The fasta parser has supported metadata on formal method parameters for a while and it is plumbed through the AstBuilder to Analyzer. The BodyBuilder appears to ignore metadata on formal parameters. @jmesserly I'm not familiar with how DDC hooks into fasta. Is this what you need? |
DDC consumes the Kernel API. I'm not seeing parameter annotations filled in for the Kernel tree. Maybe it's BodyBuilder that hasn't implemented them yet? |
This patch appears to fix it, and the metadata shows up in the Kernel AST for DDC to use. But it may be incorrect because I haven't looked at this code before. --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -2096,7 +2096,7 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
}
bool isConst = (modifiers & constMask) != 0;
bool isFinal = (modifiers & finalMask) != 0;
- ignore(Unhandled.Metadata);
+ List annotations = pop();
VariableDeclaration variable;
if (!inCatchClause &&
functionNestingLevel == 0 &&
@@ -2124,6 +2124,12 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
variable.fileOffset = offsetForToken(name.token);
}
}
+ if (annotations != null) {
+ _typeInferrer.inferMetadata(this, annotations);
+ for (Expression annotation in annotations) {
+ variable.addAnnotation(annotation);
+ }
+ }
push(variable);
} |
Thank you, @jmesserly. @stefantsov will take this suggestion and add test cases. |
I believe the issue is about to be solved in CL 51840. I added a test case and updated a couple of existing ones. The most tricky part was to properly invoke the inference, so that it doesn't work on the same node twice. I don't expect serious issues with the CL, and I think it's ready for the review. In addition to variable declarations (that represent both variables and formal parameters), I handled the annotations on local functions. Each local function declaration already contains a variable declaration that represents this function declaration and that can hold the annotations. While working on this I also looked into annotations for type parameters. They are now handled if they are declared in local functions or function expressions. I hope to get to type parameters of classes, typedefs, and top-level functions soon. Until then I'm using references to #28981 in status files. |
The support for annotations on formals, local variables, and local function declarations is added in 0289071. |
0289071 had to be reverted :-( For some reason, the precomp bots aren't happy. The following test breaks:
Also, Flutter won't build :-( I'll investigate the reason next week and hope to get the patch back soon. |
I've just relanded the CL: fe3f87f. The annotations on all sorts of variable declarations, including formals of function nodes, should work. |
As far as I know we have annotations everywhere now. Reopen this issue if you discover that's not the case. |
There are a number of tests which test that it is possible to have metadata annotations on other objects than functions/classes, see
co19/Language/Metadata/*
./cc @kmillikin & #28263
The text was updated successfully, but these errors were encountered: