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

fasta: Support for metadata annotations on other objects than functions/classes #28434

Closed
mkustermann opened this issue Jan 18, 2017 · 26 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-fasta front-end-kernel P2 A bug or feature request we're likely to work on
Milestone

Comments

@mkustermann
Copy link
Member

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

@mraleph
Copy link
Member

mraleph commented Mar 27, 2017

Issue is still valid for fasta.

@mraleph mraleph changed the title dartk: Support for metadata annotations on other objects than functions/classes fasta: Support for metadata annotations on other objects than functions/classes Mar 27, 2017
@peter-ahe-google peter-ahe-google added the status-blocked Blocked from making progress by another (referenced) issue label Mar 27, 2017
@peter-ahe-google
Copy link
Contributor

Blocked on #29169

@scheglov
Copy link
Contributor

scheglov commented Apr 3, 2017

BTW, it's not just these blocked nodes, metadata is also allowed on local variable declarations and variable declarations in for loops.

@peter-ahe-google
Copy link
Contributor

I've added "Annotations on VariableDeclaration" to #29169.

@scheglov
Copy link
Contributor

scheglov commented Apr 4, 2017

Why is it blocked?
Nothing blocks you from implementing it in the parser.
Kernel is not the only client.
There are failing tests in analyzer that require parser support for these annotations.

@peter-ahe-google
Copy link
Contributor

@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?

@scheglov
Copy link
Contributor

scheglov commented Apr 4, 2017

OK, I see.
Still, there are more than one client that needs to pass these tests.

There are more tests in analyzer, but most of them have not been moved yet to verify with Fasta.
These two have.

@peter-ahe-google peter-ahe-google removed the status-blocked Blocked from making progress by another (referenced) issue label Jun 1, 2017
@peter-ahe-google peter-ahe-google added the status-blocked Blocked from making progress by another (referenced) issue label Jun 1, 2017
@peter-ahe-google
Copy link
Contributor

I got confused, this is still partially blocked, and it is not metadata in general (which @stereotype441 is working on).

@sigmundch sigmundch added area-front-end Use area-front-end for front end / CFE / kernel format related issues. and removed area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels Oct 4, 2017
@scheglov
Copy link
Contributor

scheglov commented Nov 1, 2017

Is this still blocked?
#30035 was fixed, it is not possible to represent annotations of local variables and parameters.

whesse pushed a commit that referenced this issue Nov 1, 2017
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>
@peter-ahe-google peter-ahe-google removed the status-blocked Blocked from making progress by another (referenced) issue label Nov 2, 2017
@peter-ahe-google
Copy link
Contributor

Thank you, @scheglov. This is no longer blocked.

@kmillikin kmillikin added this to Incoming in Dart Front End Jan 3, 2018
@jensjoha jensjoha added the P2 A bug or feature request we're likely to work on label Jan 9, 2018
@jensjoha jensjoha moved this from Incoming Untriaged to Triaged in Dart Front End Jan 9, 2018
@vsmenon
Copy link
Member

vsmenon commented Apr 17, 2018

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.)

@vsmenon vsmenon added this to the Dart2Stable milestone Apr 17, 2018
@vsmenon
Copy link
Member

vsmenon commented Apr 17, 2018

@kmillikin @peter-ahe-google - is this doable this Q?

@peter-ahe-google
Copy link
Contributor

Let me check.

@peter-ahe-google
Copy link
Contributor

@danrubel @bwilkerson

@peter-ahe-google
Copy link
Contributor

@vsmenon is it only annotations on parameters you're missing?

@vsmenon
Copy link
Member

vsmenon commented Apr 17, 2018

That's the only thing we're aware of at the moment.

@jmesserly - do you see anything else missing?

@jmesserly
Copy link

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.)

@danrubel
Copy link

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?

@jmesserly
Copy link

@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?

@jmesserly
Copy link

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);
   }

@peter-ahe-google
Copy link
Contributor

Thank you, @jmesserly. @stefantsov will take this suggestion and add test cases.

@chloestefantsova
Copy link
Contributor

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.

@chloestefantsova
Copy link
Contributor

The support for annotations on formals, local variables, and local function declarations is added in 0289071.

@chloestefantsova
Copy link
Contributor

0289071 had to be reverted :-( For some reason, the precomp bots aren't happy. The following test breaks:

python tools/test.py -m release -c dartkp -r dart_precompiled --strong language_2/metadata_test

Also, Flutter won't build :-( I'll investigate the reason next week and hope to get the patch back soon.

@chloestefantsova
Copy link
Contributor

I've just relanded the CL: fe3f87f. The annotations on all sorts of variable declarations, including formals of function nodes, should work.

@kmillikin
Copy link

As far as I know we have annotations everywhere now. Reopen this issue if you discover that's not the case.

@kmillikin kmillikin moved this from Triaged to Done in Dart Front End May 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-fasta front-end-kernel P2 A bug or feature request we're likely to work on
Projects
Development

No branches or pull requests