Commit Graph

664 Commits

Author SHA1 Message Date
Johnni Winther 931fd976c6 [cfe] Apply phase 2 macro results
Results of Phase 2 macros are now applied. The macro application code
has been refactored to support that Phase 1 can apply all macro
applications within a library in bulk, but Phase 2 can apply each
macro application in sequence.

The later is to prepare for making added member visible to subsequent
macro applications within Phase 2. This functionality has not been
completed yet.

Change-Id: Idaf2702e21bde75aedb1509d88e02f270196af5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233380
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-18 11:00:31 +00:00
Johnni Winther 2435848b13 [parser] Support 'augment' modifier on class declarations
This adds support for the 'augment' modifier on class declarations
needed for the static meta-programming prototype.

Change-Id: Iadd11f766a195076405f2803b2092199caf1ea8c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233180
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-18 09:39:23 +00:00
Jake Macdonald 621ea99c80 Work around windows test failures
This directory sometimes fails to delete due to files being still "in use".

If we have a better fix than just ignoring it let me know, but its just a temp dir used in a test.

Change-Id: I5c8e76192230cf2b033d9bcb4a86940ddf974517
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233522
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-17 22:27:41 +00:00
Jake Macdonald 7822eb9107 Add a macro executor which spawns and talks to a different process.
This also:

- Adds support to the bootstrap code to handle communicating via sendPort or stdio
- Refactors pretty heavily the isolate executor code such that it can be reused.
- Refactors the isolated executor test into a shared test for all executors
- Removes the mirror based executor entirely - I don't see a path forward with this one.
- Reorganizes all executor based files under macros/executor

Change-Id: I2fc6bb3e6ce56c8b331719f4dc08617b3a521398
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233200
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-02-17 20:40:21 +00:00
Chloe Stefantsova deba7fee1d [cfe] Report errors on implementors of 'Enum' declaring 'values'
Part of https://github.com/dart-lang/sdk/issues/47453

Closes https://github.com/dart-lang/sdk/issues/48388

Change-Id: I87d57407e16916a78864b9ce74b9250afc39958f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233304
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-02-17 10:29:00 +00:00
Johnni Winther f24c4fa919 [cfe] Add initial support for applying the phase 1 macro results
This adds support for the generating a synthesized augmentation
library for each library in which phase 1 macros were applied.
Current implementation piggybacks on the patch library support. The
intension is that both patches and augmentations are handled through
the same general mechanism. For now, the wording refers to augmentation
libraries as patch libraries where the implementation is shared.

Testing is extended to verify that the generated classes are
included in the resulting AST.

Change-Id: Ie0d4cfdc84b55ca87e0014794f14b38e442f08eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233101
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-16 09:19:49 +00:00
Jake Macdonald e6654814cc Make the serialization mode easily configurable (and required), and some other improvements.
- Support TransferableTypedData in the bootstrap code and IsolatedExecutor.
- Also removed the fake executor and conditional import. Mode will likely be chosen based on factors other than just the availability of `dart:isolate`.
- Run the tests in both serialization modes.

Change-Id: I5c731d192c0d3a8cdc5f7fb900dc07a32f4f4d51
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232981
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-02-15 16:16:20 +00:00
Chloe Stefantsova 6c8ad6a723 [cfe] Report errors on declared 'values' member in enums
Part of https://github.com/dart-lang/sdk/issues/47453

Closes https://github.com/dart-lang/sdk/issues/48389
Closes https://github.com/dart-lang/sdk/issues/48387

Change-Id: I8313e3f63122c85c91a9647ddaa53346591d7238
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232841
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-02-15 12:22:19 +00:00
Jake Macdonald 97176be3d4 add the local identifier type for parameters, add isStatic field to class members
Change-Id: I15d85fdc4a6b894e6ecda6716f9931e03a8278ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232961
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-15 11:49:50 +00:00
Alexander Thomas 30beab0f43 [infra] Add OWNERS to the Dart SDK
* Add team "groups" in tools/OWNERS_<group name>.
* Add top-level OWNERS as a fallback.
* Add OWNERS for all top-level directories.
* Add OWNERS to all packages.

For additional background information see go/dart-sdk-owners.

TEST=No op until code-owners is enabled.
Bug: b/200915407
Change-Id: I7fe6116cc599c749cd50ca16151d6d6a801d99d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229147
Reviewed-by: Jonas Termansen <sortie@google.com>
2022-02-14 14:06:34 +00:00
Johnni Winther 74a355c544 [cfe] Use buildAugmentationLibrary on phase 1 results
This CL add support for identifier resolution to use the
MacroExecutor.buildAugmentationLibrary for generating the code.

The CL updates the ResolvedIdentifier to have a nullable [uri] in
order to support built in identifiers, such as `void`.

Change-Id: I9436ea77c06cf5618f1977f4c9ac0490ff059587
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232623
Reviewed-by: Jake Macdonald <jakemac@google.com>
Auto-Submit: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-14 11:31:25 +00:00
Jake Macdonald 49d7f5056f Add a byteData serializer/deserializer implementation
With the optimizations suggested this does now equal or outperform the JSON serializer in all scenarios, the latest numbers from the benchmark are as follows:

Isolate.spawn + SerializationMode.jsonClient: 0:00:00.041666
Isolate.spawnUri + SerializationMode.jsonClient: 0:00:00.069551
Separate process + SerializationMode.jsonClient: 0:00:00.177171
Isolate.spawn + SerializationMode.byteDataClient: 0:00:00.040990
Isolate.spawnUri + SerializationMode.byteDataClient: 0:00:00.059319
Separate process + SerializationMode.byteDataClient: 0:00:00.080008

Change-Id: If5431513c7487d8b7af350381e794cbd61c1be42
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232027
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-02-11 23:35:27 +00:00
Johnni Winther 1a0e9f941d [cfe] Add macro api test
This adds an initial test for implementation of the macro api that
can be shared between implementations.

The test consists of a set of macros and a library of declarations that
apply these macros. When applied the macros work as unittest tests that
check that the macro api give the expected results for the various
declarations.

Change-Id: Id4183e8ac90fa96ef1ebc01b1c9f15cc413b6443
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232383
Auto-Submit: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-02-10 16:08:00 +00:00
Jake Macdonald 0c7bf4ba86 add ResolvedIdentifier class, return that instead of a Uri when building augmentation libraries, and use it to determine how to qualify identifiers
The main goal here is to be able to distinguish between instance members and static members, so we know what to prefix and with what.

Change-Id: I5189979cd218f1eba8b30cc39a95632edeaf9579
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231981
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-10 09:57:00 +00:00
Nate Bosch 33e174084a Replace Uri.scheme == with Uri.isScheme
Use `hasScheme` in place of comparing against the empty string, and
`isScheme` to compare against all other schemes.

TEST=No behavior changes.

Change-Id: Ifc9fd13c6cf37933ebd4a754c4b500dedbcb291b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231185
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
2022-02-08 21:38:57 +00:00
Jake Macdonald 5a99031028 Updates to the macro type instantiation apis based on feedback.
In general this moves in the direction of dealing more with Identifier instances instead of TypeAnnotation instances.

This ended up being a larger refactor than I had hoped, but at a high level it does the following:

- Adds the TypeAnnotationCode/NamedTypeAnnotationCode/FunctionTypeAnnotationCode classes
- Change the TypeResolver api to have a single 'resolve' method, which takes a TypeAnnotationCode argument
- Makes ParameterCode/TypeParameterCode take more structured arguments
- Update the CFE code to be able to resolve NamedTypeAnnotationCode instances instead of TypeAnnotation instances
- Also deletes some unnecessary Code classes.

Note that supporting FunctionTypeAnnotationCode instances looks like it will be some more work in the CFE.

Change-Id: I84712aa1c29634cd0a93d245171b3591f69be927
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231327
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-02-04 21:54:59 +00:00
Jake Macdonald 3b1710506c drop defaultValue and initializer getters
Change-Id: Ifec4928946392b5140adda781a8be1c3a439915f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231525
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-02-04 16:33:59 +00:00
Jake Macdonald 984ec03a80 Add support for operator functions, fix a few other small things
- Fixes mostly just include outputting raw names instead of identifiers where we don't want prefixing to happen.

Change-Id: I99c349fd742be2b027290ed02daea57002f152e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231041
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-01 06:51:25 +00:00
Chloe Stefantsova 5f0433afcf [cfe] Report more errors on forbidden enum constructor calls
This CL also adds support for redirecting enum factories.

Part of https://github.com/dart-lang/sdk/issues/47453

Change-Id: Idd16598316a52ac6122a47f4c12f82ab5750d8f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230661
Auto-Submit: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-01-31 11:45:04 +00:00
Jens Johansen a066e2c83e [parser] Don't be overly aggressive when parsing 'on' in 'try'
Fixes https://github.com/dart-lang/sdk/issues/47541

Change-Id: Idb25f86801b14f75fe7bc06e5496c6fdd2cbe971
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230243
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-01-31 09:09:35 +00:00
Jake Macdonald e60aafc5be s/by/with
Change-Id: I060ab53e40be3dea3c92c374894859f052f30185
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230780
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
2022-01-28 18:23:42 +00:00
Johnni Winther c8775427f0 add a name argument to declareType, to make it easier for implementations to know the names of new types
Change-Id: Ie2c2200b5cc845c95a74d9472fa64580fba4bb42
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230500
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-01-28 16:25:02 +00:00
Chloe Stefantsova 999f267d0e [cfe] Add more compiler-time errors for incorrect enum constructors
Additionaly this CL moves the arguments checks for redirecting and
super initializer invocations from the early stage of their creation
to a later stage of their addition to the list of constructor
initializers, after the possible modifications to the arguments of the
invocation are performed.

Change-Id: I87a3710c885926a74c844288bdf266e7127a9c40
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229967
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-01-28 15:07:02 +00:00
Johnni Winther 61e491c413 Add the AugmentationLibraryBuilder to build augmentation libraries
Removes the `imports` field from MacroExecutionResult (we don't know them since identifiers arent resolved yet).

Adds a callback function when creating the library to convert an identifier to its library import Uri.

Change-Id: I7f4345f41aa24d18aa7872a226fcfce32166ea6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230400
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-01-28 10:40:21 +00:00
Jens Johansen c2b2aa5b9a [parser] Add beforeSynthetic to Synthetic*
Follow-up to https://dart-review.googlesource.com/c/sdk/+/205799

Change-Id: I620bf4548095d0597b89e4b6305c2301bcbed144
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230242
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-01-28 08:54:13 +00:00
Jake Macdonald 1307a78707 ensure macro identifier ids are unique across macro isolates by passing it in from the server
Change-Id: I7e7c7026c177ee2ca74882d3a2b08579951b4f4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230320
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-01-28 08:48:52 +00:00
Jake Macdonald fa4ffe3a1d Add Identifier class and replace most TypeAnnotation uses with it.
- The only public member on Identifier is `String get name`, but implementations should tie these back to the original AST nodes they came from. These can't be created by users, only given to them.
- Replaces most name getters with Identifier identifier getters.
- Updates many apis to take an Identifier instead of a TypeAnnotation. This definitely cleans things up some as TypeAnnotation was weird for a lot of these apis that don't care about type arguments etc, only the name of the type.
- Replaces the instantiate API on TypeDeclaration with two new apis on TypeResolver:
  - `Future<StaticType> instantiateType(TypeAnnotation typeAnnotation);`
  - `Future<StaticType> instantiateCode(ExpressionCode code);`
    - This one might be a bit weird, but it allows for a fairly intuitive way of constructing any arbitrary type (like function types with required params, etc).
- Removes the ability to pass TypeAnnotations to Code objects, now you can pass Identifiers instead. You can however call the convenience `Code get code` getter on TypeAnnotation, and pass that to a Code object. We could implicitly invoke this if wanted to, and allow passing TypeAnnotations directly again, 🤷‍♂️ .
- Removes the IdentifierCode class, it is confusing to have both. We already have ExpressionCode which can be used instead.
- We no longer expect setters to have a trailing = on the name - since names are no longer used to disambiguate, it is OK for two identifiers to have the same name they can be disambiguated by the AST node the originated from.


Bug: https://github.com/dart-lang/language/issues/2072
Change-Id: Ibb012d91de3da9a699b7d22fbe2bae00be9b023e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230180
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-01-27 18:03:12 +00:00
Chloe Stefantsova 13713c2232 [cfe] Make _Enum type pre-created similarly to built-in types
Part of https://github.com/dart-lang/sdk/issues/47453

Change-Id: I046fc14b76513b6b1b3f3606b4c1bd299abca50a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229963
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-01-27 09:32:40 +00:00
Jake Macdonald 5f7a49979b Add shouldExecute and supportsDeclarationKind apis to MacroInstanceIdentifier.
Ideally this would be on MacroClassIdentifier but it isn't very feasible to do, at least not without using mirrors.

Change-Id: I543461fc677da3daeec4172489d1c7d846901382
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229945
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-01-26 11:19:30 +00:00
Jake Macdonald 577ba62516 Macro cleanup/simplifications plus some additional tests and fixes
- Added the ClassMemberDeclaration interface to simplify some things and unify builder implementations.
- Adds tests for running macros on top level declarations
- Update the code for executing macros to allow function/variable macros to be ran on methods and fields.
- Other general cleanup and some minor bug fixes

Change-Id: I9bc60740c1b583e39179238cdcd68a78c110c3dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229621
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-01-25 16:27:32 +00:00
Jake Macdonald b0d9dc4192 add support for type phase macros
Change-Id: I6bd786853760bb0eaf087eae5bc42f7532e190b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229323
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-01-24 17:34:36 +00:00
Chloe Stefantsova 0ff6340598 [cfe] Error on type arguments without value arguments in enum elements
Part of https://github.com/dart-lang/sdk/issues/47453

Change-Id: Icf8b5a58d991c4fb693fd41e9b49dc326269c9fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229153
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-01-24 13:48:47 +00:00
Jake Macdonald aa54fea1e6 implement the remaining definition phase macros, as well as all declaration phase macros
Change-Id: I8ad1625d102cfbdafed020a7a1b88220e4e6a6bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229000
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-01-21 16:16:00 +00:00
Johnni Winther 2bc20bcc09 [cfe] Support TypeResolver and StaticType in macro implementation
This adds initial support for TypeResolver.resolve and
StaticType.isExactly and StaticType.isSubtypeOf.

Change-Id: Iaa147a6fc3c8c9eee8940aa9bcf4a01b51819ddc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228860
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-01-21 14:37:40 +00:00
Johnni Winther 5b8386489a [cfe] Reinsert comments
These comments were accidentally removed in the landing of
https://dart-review.googlesource.com/c/sdk/+/224953

Change-Id: Iafdeef3e2c96c70c6840106babef3f69cad5f840
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229141
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-01-20 09:43:56 +00:00
Konstantin Shcheglov 75247601ef Prepare to publish analyzer 3.2.0 and _fe_analyzer_shared 34.0.0
Change-Id: Iceaeeb8e12e5de779f87b6c8b8a1ef56fbfaefd6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228981
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-01-19 23:00:36 +00:00
Jake Macdonald 26d9cb5146 Add support for ClassIntrospector and TypeDeclarationsResolver forwarding
Change-Id: If897fe6f1eef2f3976986935bd90fbc0417a8be6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228724
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-01-19 07:47:17 +00:00
Chloe Stefantsova df0f476177 [cfe] Allow abstract classes to implement and extend Enum
Part of https://github.com/dart-lang/sdk/issues/47453

Change-Id: I6782b4a9f13f95f626f41c311c05ce949649c828
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228562
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-01-18 13:52:34 +00:00
Johnni Winther 9b7be8d117 [cfe] Call MacroExecutor for phase 3 macros
This CL adds capability for calling MacroExecutor to apply phase 3
macros to function declarations.

Change-Id: I1ab5bf33c8d9c6ce0c6706fe2bcafe2298ff292b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227720
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-01-17 16:24:55 +00:00
Johnni Winther 65e8b3f59e finish serialization implementations for all declaration types, and add tests for them
I also refactored some of the existing deserialization code to make it shorter, and to unify the patterns.

Change-Id: I4407027800d66957464cc2603e85113297367bd1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228260
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-01-17 14:45:24 +00:00
Konstantin Shcheglov e8098caeab Field formal parameter identifier is a declaration.
Change-Id: I70bdf7af8f2663a056b8b9be65f5ea23a105d2f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-01-15 20:37:53 +00:00
Jake Macdonald 2a31ee5530 get TypeResolver and StaticType interfaces working
Change-Id: I7cebff43f1079679525bd11c1622d277b55c1501
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228060
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-01-14 16:49:21 +00:00
Jake Macdonald 1756bb0802 Add RemoteInstance class, which most objects extend.
Each request is now ran in its own zone, with its own cache of remote instances by ID. Requests and responses have a zone identifier to know which zone they should be serialized/deserialized in.

Refactor to express most internal objects in terms of Impl classes which are serializable directly, instead of using extensions.

Moved the `kind` enums to the general `RemoteInstanceKind` enum, which all `RemoteInstance`s must have.

Change-Id: I0264fe2b8cd2c2717787fa8e6318e725f63b29d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227902
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-01-13 17:43:00 +00:00
Konstantin Shcheglov 878ce55edb Prepare to publish analyzer 3.1.0 and _fe_analyzer_shared 33.0.0
Change-Id: Iebc52d41b1b5c4ff36fc356569020f13d43ff53e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227860
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-01-12 20:24:32 +00:00
Lasse R.H. Nielsen 06f8981460 Remove "Interpreted this as package URI" warning.
Bug: https://github.com/dart-lang/sdk/issues/37978
Change-Id: I0635f6e5da2186df73ceb24afcaa40126413a11a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224525
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2022-01-12 16:56:43 +00:00
Paul Berry 4775fa3857 Flow analysis: ensure that not-yet-declared variables aren't marked as captured.
In certain error recovery situations, it's possible for code to refer
to a variable whose declaration has been lost by error recovery
mechanisms.  To prevent flow analysis from crashing when this
happened, it assumed that any reference to a variable whose
declaration had not yet been seen was valid, and implicitly added that
variable to the flow analysis state.

This created a subtle problem: if a function contained a closure that
declared (and assigned to) a local variable, at the time the closure
was entered, flow analysis would get confused and temporarily put the
variable in the "write captured" state (because it hadn't yet seen the
declaration of the variable, so it didn't realize it was local to the
closure).  Then, a boolean variable might capture that incorrect
state.  Later, upon seeing the declaration of the variable, it would
fix the incorrect state, however it was possible that a later
reference to the boolean variable would re-vivify the old incorrect
state.  This is precisely what happened in issue #47991.

This CL fixes the problem by giving flow analysis the ability to
detect, at the time the FlowAnalysis object is constructed, all
variables that are referred to but not explicitly declared, and add
them to the flow analysis state.  This allows it to safely assume that
any variables that are not yet in the flow analysis state haven't been
declared yet (and hence can be ignored), so no variable is every
erroneously placed into the "write captured" state.

Fixes #47991.

Bug: https://github.com/dart-lang/sdk/issues/47991
Change-Id: I8d84fab96fad063f1d3ade3b8b9a6e9af88c3737
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227361
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-01-11 15:42:04 +00:00
Paul Berry fccc5fc4d5 Flow analysis: add assertions to verify that API is used correctly
This change adds assertions to ensure that the first phase of flow
analysis (calls to the AssignedVariables class) is complete before the
FlowAnalysis class is created.  It also calls AssignedVariables.finish
(which does additional assertions) from the FlowAnalysis constructor
(if the client hasn't done so already).

Adding these assersions exposed a few minor (but benign) bugs in the
usage of the flow analysis API.

- The flow analysis unit tests were failing to call
  AssignedVariables.declare.  This should have been caught by
  AssignedVariables.finish, but the flow analysis unit tests were
  failing to call that as well.

- Several flow analysis unit tests failed to declare the variables
  they were using (or in one case, the declaration was at the wrong
  location).

- In the CFE, DeclaredSourceConstructorBuilder.buildOutlineExpressions
  was failing to set up scopes properly when compiling a const
  constructor.

- In the CFE, SourceLoader.buildExpression was failing to call
  AssignedVariables.declare for variables in scope.

- In the CFE, the TypeInferrerImpl constructor was constructing the
  FlowAnalysis object eagerly, even though the AssignedVariables phase
  often hadn't completed yet.  I've fixed this by constructing
  FlowAnalysis lazily.

A follow-up CL will take advantage of the invariants checked by these
assertions to introduce the logic necessary to fix issue #47991.

Change-Id: Id680020dcd525632afa0820bc49c7b966b1ea534
Bug: https://github.com/dart-lang/sdk/issues/47991
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227320
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-01-11 15:06:04 +00:00
Johnni Winther 8510f27d37 [cfe] Change encoding of supported dart: libraries
This CL changes the way dart: libraries are considered supported when
used in conditional imports or bool.fromEnvironment constant using
the "dart.library.*" values.

Library nodes now has an isUnsupported flag which is set according to
the "supported" property in the libraries specification. Furthermore
the Target now supplies a DartLibrarySupport interface that allows
targets to override whether dart: libraries are unsupported.

This allows the JIT/AOT to use the same platform file but still
consider dart:mirrors unsupported in AOT mode, and dart2js to consider
the internal library `dart:_dart2js_runtime_metrics` supported.

Furthermore, the internal handling is changed so that condition imports
and bool.fromEnvironments constants are computed through the same logic
for "dart.library.*" values, avoiding the need for passing these values
through the environment.

TEST=pkg/front_end/testcases/general/supported_libraries/main

Closes https://github.com/dart-lang/sdk/issues/48057
Closes https://github.com/dart-lang/sdk/issues/47814
Closes https://github.com/dart-lang/sdk/issues/47243
Closes https://github.com/dart-lang/sdk/issues/32657
Closes https://github.com/dart-lang/sdk/issues/36460

Change-Id: Ie8f8dff99167de64ced51b71d89918bf0f3bbd13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227020
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2022-01-11 14:52:38 +00:00
Jake Macdonald f362e1e350 Create a macro executor that runs in a separate isolate group with a precompiled dill.
Also gets a start on the serialization protocol and implements a chunk of it.

Change-Id: Ia16136351a868858d679fe4bae96318d9126d3a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226966
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-01-11 04:49:27 +00:00
Chloe Stefantsova 384aeb3533 [cfe] Add support for factories and methods in enums
Part of https://github.com/dart-lang/sdk/issues/47453

Closes https://github.com/dart-lang/sdk/issues/48084

Change-Id: If96b17220df63b5f0089e302322fad2735354d5f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226687
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-01-10 11:59:49 +00:00