Commit Graph

271 Commits

Author SHA1 Message Date
Paul Berry b9ed13c76f Rework flow analysis API for operator == and identical.
In order to address https://github.com/dart-lang/language/issues/731
(improved inference for fold etc.) I'm going to need to sometimes
change the order in which the resolution process visits invocation
arguments.  As a preparatory step, this change reworks the flow
analysis API so that it doesn't depend on the order in which arguments
to `identical` are visited.

Bug: https://github.com/dart-lang/language/issues/731
Change-Id: Ic886bb44537523a1cab75762925e62d46e33f290
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237933
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-03-22 22:49:10 +00:00
Johnni Winther e50b7e77b8 [macro] Support fresh names in MacroExecutor.buildAugmentationLibrary
This adds support for generating truly unique fresh names when building
augmentation library code. The synthesized names are used for import
prefixes and as placeholders for not-yet-inferred omitted type
annotations.

Change-Id: I6fe9bc37b39a243c93187f561ee32e07237341f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237823
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-03-22 16:30:08 +00:00
Jake Macdonald ded8936d35 Add TypeInferrer interface, this is what macro authors will use to infer real types from OmittedTypeAnnotations.
Bug:https://github.com/dart-lang/language/issues/2154
Change-Id: I00484ddbd09a3c2371b96e540b9926144d80c832
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237844
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-03-21 16:19:47 +00:00
Jake Macdonald 8d2c630052 add OmittedTypeAnnotation and support in code objects
Bug: https://github.com/dart-lang/language/issues/2154
Change-Id: Ie48d308a822798da22ea38954774e393f81e2e2a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237740
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-03-18 14:30:07 +00:00
Johnni Winther e86a1140aa [cfe] Implement TypeDeclarationResolver
This implements TypeDeclarationResolver for the CFE. Adds a test to
the macro api test, which includes support for throwing and catching
the ArgumentError required by the api.

Change-Id: I5bb7948064ba5a2c215289915fc10314fd28aa1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237020
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-03-15 16:35:02 +00:00
Johnni Winther e7d708558f [cfe] Add test for member lookup in ClassIntrospector
This adds tests for `fieldsOf`, `methodsOf` and `constructorsOf` of
the `ClassIntrospector` interface in the macro api test.

Change-Id: I79ef7ce01d00cda2c8277342e4b7c17e91266b5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/236884
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-03-15 15:17:59 +00:00
Johnni Winther 29fc2e7802 [cfe] Support ClassIntrospector.interfacesOf and ClassIntrospector.mixinsOf
This adds support for [interfacesOf] and [mixinsOf] of the
[ClassIntrospector] interface. To support this, the mixed in
[ClassHierarchyNode] is now included in the [ClassHierarchyNode] for
a mixin application.

Change-Id: I30cef4b462b1b2b52acf1bd286d82ebc1c5caa4e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/236883
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-03-15 12:42:20 +00:00
Johnni Winther 2c430537c6 add IdentifierResolver api, which allows you to get identifiers for a
given symbol in a given library

Change-Id: I665b3bd2fa6fe7bb64375873e9ae9343e7922a3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234904
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-03-03 16:51:50 +00:00
Johnni Winther c16d5f01bd [cfe] Use macro_api_test to test ClassIntrospector.superclassOf
Change-Id: I0d74773c27e1fce0d84243c507af7cb2d32a1aa9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234160
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-25 07:25:44 +00:00
Jake Macdonald fb5503960f Add a map of class name to augmentations in MacroExecutionResults to assist with merging.
There should now only be a single `augment class` declaration (per augmented class) in a given augmentation library.

Change-Id: I32a56baef63a0658df23b3c52e398597c09f8ba2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234106
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-02-24 17:31:21 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
Paul Berry 241ef0dfac Sort declarations in flow_analysis_test.dart
Change-Id: Ic7addf569b2fe734d3007b463ab602c5ebdc2e79
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226760
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-01-06 21:29:15 +00:00
Johnni Winther b4cd3a844b [dart2js] Use 'include' to share lib spec between dart2js and dart2js_server
This CL uses the recently added 'include' tag in libraries
specification to share common library definitions between targets
'dart2js' and 'dart2js_server' through the "private" target
'_dart2js_common'.

Change-Id: I12f85d0d71803c6adcb94e37385ba837f7cdc9ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224953
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2022-01-05 13:25:22 +00:00
Johnni Winther 4e283a7e08 [_fe_analyzer_shared] Support 'include' tag in libraries specification
This adds support for an 'include' tag in libraries specifications
that enable composite declarations. With this, we can avoid relying on
copied portions of (other) specifications.

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

Change-Id: I694d5c006741e6625feb7cdd5898946cc6caee50
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224952
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2022-01-05 08:13:23 +00:00
Jake Macdonald 459c66f13e add a _FakeMacroExecutor class and a general purpose MacroExecutor.start method which returns a platform specific implementation (or Fake)
Bug:b/211377847
Change-Id: I0b3a66a6732d8a9a60bee62a1672b829df191d18
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226260
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2022-01-04 20:12:41 +00:00
Jake Macdonald 8784f9682d Move macro apis to _fe_analyzer_shared from the language repo.
I could do a separate package if you think that would be better, but putting it here I think makes things simpler.

Change-Id: I4e62bc18dcd9d3bb84a7aceb8f4e2821c84d1361
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224280
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-12-16 19:10:21 +00:00
Paul Berry b0b1534f3e Make checkUnassigned easier to debug in flow analysis tests.
This change adds a stack trace so that if the check fails, the user
sees the stack trace of the call to `checkUnassigned` prior to the
stack trace from the process of visiting the mini-AST.  Usually teh
stack trace from the call to `checkUnassigned` is much more useful in
debugging, since it allows the user to see the location of the problem
relative to the code being analyzed.

Change-Id: I125b4059ec740850919798cfa66bf7e8c7490213
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217283
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-10-19 19:49:03 +00:00
Paul Berry e5e8f84927 Rework how final and late are represented in flow analysis tests.
The fields `isFinal` and `isLate` are moved to the `Var` class.  This
should allow greater flexibility when experimenting with possible
changes in promotion behavior for final and late variables.

Bug: https://github.com/dart-lang/language/issues/1721
Change-Id: I3a328566b4a55244ca76c41da6e362066118d283
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217261
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-10-19 18:18:52 +00:00
Sam Rawlins 228e1062ee Move front_end's libraries.json parser to _fe_analyzer_shared
Bug: https://github.com/dart-lang/sdk/issues/35081
Change-Id: Idd1c68a871ace37e45970e5452a59fd655445fd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216100
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2021-10-11 17:59:43 +00:00
Paul Berry b65a18f54f Add a flow analysis ID test of new constructor-tearoffs behaviors.
These behaviors were introduced during the fix for
https://github.com/dart-lang/language/issues/1785, and at the time
they were tested using both unit tests and language tests.  But it was
not possible to write ID tests for them, because ID tests don't
support turning on experimental language feature flags.

Now that the "constructor-tearoffs" feature has been turned on we can
test these behaviors using ID tests.

Change-Id: I6e1ccda4b5837ab61de80f15d2f31a82a90b4a22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212265
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-09-07 21:39:46 +00:00
Konstantin Shcheglov b12724b7c6 Issue 47026. Use simple subtype check for combining signatures.
Bug: https://github.com/dart-lang/sdk/issues/47026
Change-Id: Id6999e0eaab03ffa0caa63c97b708526d22a8d97
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211605
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2021-08-30 16:38:39 +00:00
Paul Berry 1b18e8f5ac Flow analysis: account for initializers of implicitly typed variables.
Previously, initializers of implicitly typed variables did not
contribute to the SSA tracking performed by flow analysis (see
https://github.com/dart-lang/language/issues/1785).  This change fixes
the bug, however the fix is conditioned on the "constructor tearoffs"
language feature to avoid compatibility issues (we don't want someone
to publish a package taking advantage of the fix, without realizing
that it makes their package unusable on older SDKs).

TEST=standard trybots
Bug: https://github.com/dart-lang/language/issues/1785
Change-Id: I1143440c7a9795b059e8f4b84e3f4125cd80732c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211306
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-08-27 15:01:15 +00:00
Paul Berry e1f0d03ec5 Flow analysis: rework analyzer/CFE handling of initialized variables.
Previously, the analyzer and CFE were responsible for two pieces of
logic that arguably should be in the shared flow analysis engine:

- Deciding whether or not it's necessary to tell flow analysis about
  initializer expressions.

- Deciding whether or not to promote the variable at the time of
  initialization (we do this when the variable is implicitly typed,
  and the initializer is a promoted type variable type).

It's better to just always tell flow analysis about the initializer
expression and let it decide what to do about it.

This paves the way for fixing
https://github.com/dart-lang/language/issues/1785 (which results from
initializer expressions sometimes being ignored when they shouldn't
be), by consolidating the broken logic into the flow_analysis library,
where it will be easy to unit test the fix.

Bug: https://github.com/dart-lang/language/issues/1785
Change-Id: Iec832e92995eb4f8d0c1fbd4e9be6c897e0917b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211180
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-08-27 14:53:06 +00:00
Paul Berry d2b313227d Flow analysis: Pin down initialization behaviors before fixing #1785.
https://github.com/dart-lang/language/issues/1785 has a wide enough
impact that its fix will have to be bundled in with a language version
(i.e. future versions of Dart will have to reproduce the old buggy
behavior for code that's not opted in to the latest language version).
Therefore, we'll have to maintain tests of the behavior both before
and after the fix.  This CL is the first step in that process, adding
tests that validate the current (buggy) behavior.

Bug: https://github.com/dart-lang/language/issues/1785
Change-Id: I78f17999ac1cbc096a312ef977db24654e06a263
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210400
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-08-25 20:32:02 +00:00