Commit Graph

1228 Commits

Author SHA1 Message Date
Johnni Winther 4b21f58d39 [cfe] Don't emit warnings on null-aware access on non-nullable
Change-Id: I94f3011f69330f5b2d8998f29eb9511517e1fffa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357301
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-03-20 14:04:29 +00:00
Jake Macdonald 17454cb118 make ConstructorMetadataAnnotation.type be a TypeAnnotation
Change-Id: I9013340307f6fa3a100b2263e0edaef69c05c437
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358500
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2024-03-19 16:22:52 +00:00
Srujan Gaddam 7685ec3e0e [dart:js_interop] Better error reporting for invalid external types
Closes https://github.com/dart-lang/sdk/issues/54320

Several improvements to the error reporting:

- Split errors to avoid parametrizing error strings.
- Use one error per member/toJS invocation.
- Highlight the invalid types in the signature.

Extra tests are added to get coverage for things like operators.

Change-Id: I6d8ac3cf0124730e7c2c0dab3a107da5d0263f7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347226
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-03-15 23:36:22 +00:00
Johnni Winther a7d5560ede [_fe_analyzer_shared] Compute multiple witnesses
This updates the exhaustive checking algorithm to produce a list of
witnesses instead of a single witness in case of a non-exhaustive error.

This is used to create a witness for each missing subtype when checking
"sealed static types", for instance enums and sealed classes.

The current error reporting isn't changed and only reports the first
witness. Use of the multiple witnesses in error messages and/or lints
must be done in the CFE and analyzer.

Change-Id: I950816f6a9eca16773f182d5d820929bdcb39684
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357160
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-03-14 08:36:28 +00:00
Paul Berry fb210554eb Enable feature inference-update-3.
In discussion with the language team, we've decided to ship this
feature in Dart 3.4. This CL contains a minimal CHANGELOG entry for
the feature; I plan to expand on it once I'm finished with the feature
specification document.

Change-Id: Iac86ebed322feb8e478bf5a6780d50adb433ed7f
Tested: trybots
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355900
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-03-13 22:04:23 +00:00
Johnni Winther c506bb80ba [macros] Remove Declaration from RecordField
This removes the Declaration from RecordFieldDeclaration and renames it
to RecordField. The fields of a record type are not declarations but
are similar to FormalParameter of a FunctionTypeAnnotation; they contain
part of the information for the RecordTypeAnnotation but are not
identifiable on their own.

Change-Id: Iaa9d95d49f2152096b970c6e2d24c524327f933e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355740
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2024-03-13 09:37:56 +00:00
Daco Harkes 8de00e2137 [vm] Introduce pragma vm:deeply-immutable
This CL introduces a way to mark all instances of a class as deeply
immutable.

In order to statically verify that all instances of a deeply immutable
class are immutable, a deeply immutable classes must have the following
properties:

1. All instance fields must
   1. have a deeply immutable type,
   2. be final, and
   3. be non-late.
2. The class must be `final` or `sealed`. This ensures no
   non-deeply-immutable subtypes are added by external code.
3. All subtypes must be deeply immutable. This ensures 1.1 can be
   trusted.
4. The super type must be deeply immutable (except for Object).

Note that instances of some classes in the VM are deeply immutable
while their class cannot be marked immutable.

* SendPort, Capability, RegExp, and StackTrace are not `final` and
  can be implemented by external code.
* UnmodifiableTypedDataViews do not have a public type. (It was
  recently deprecated.)

See runtime/docs/deeply_immutable.md for more details.

Use case:

This enables attaching a `Dart_FinalizableHandle` to a deeply immutable
object and the deeply immutable object with other isolates in the same
isolate group.

(Note that `NativeFinalizer`s live in an isolate, and not an isolate
group. So this should currently _not_ be used with `NativeFinalizer`s.
See https://github.com/dart-lang/sdk/issues/55062 for making a
`NativeFinalizer.shared(` that would live in an isolate group instead
of in an isolate.)

Implementation details:

Before this CL, the `ImmutableBit` in the object header was only ever
set to true for predefined class ids (and for const objects). After
this CL, the bit can also be set to true for non const instances of
user-defined classes. The object allocation and initialization code has
been changed to deal with this new case. The immutability of a class is
saved in the class state bits. On object allocation and initialization
the immutability bit is read from the class for non-predefined class
ids.

TEST=runtime/tests/vm/dart/isolates/fast_object_copy2_test.dart
TEST=runtime/vm/isolate_reload_test.cc
TEST=tests/lib/isolate/deeply_immutable_*

Bug: https://github.com/dart-lang/sdk/issues/55120
Bug: https://github.com/dart-lang/sdk/issues/54885
Change-Id: Ib97fe589cb4f81673cb928c93e3093838d82132d
Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-ubsan-linux-release-x64-try
Cq-Include-Trybots: dart-internal/g3.dart-internal.try:g3-cbuild-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354902
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-03-07 18:33:58 +00:00
Jake Macdonald f2e8464b98 add newline after doc comments, add tests for doc comments
Bug: https://github.com/dart-lang/sdk/issues/55128
Change-Id: I6897e33ad291093d460e28a0b0f374d6504418e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356260
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-03-07 16:58:00 +00:00
Johnni Winther 9293d2fc33 [cfe] Report errors on macro declaration/annotation in the same library cycle
Change-Id: Ia8b7b572f8947e7b82f3468331cd33e430ef8376
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356060
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-03-07 09:10:07 +00:00
Konstantin Shcheglov e9217c3b21 Legacy. Remove star types from shared FactorTypeTestMixin.
Change-Id: Ibb287b86aed21b296ddc646ce0db7f83c2c947d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355580
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-03-05 15:19:07 +00:00
David Morgan a4e15669ec [macros] Fix _checkForKernelRuntime.
The previous implementation always returns "true", making the PR a
no-op as it only does something for AOT runtimes. e2e test coverage
will land in
https://dart-review.googlesource.com/c/sdk/+/353100 to prevent such
mistakes in future.

R=johnniwinther@google.com

Change-Id: I8481187070a0af12a3f3bd77baa471f1a7d3256d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355682
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Morgan :) <davidmorgan@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
2024-03-05 13:05:16 +00:00
David Morgan b06edb3126 [macros] CFE can launch macros when run from AOT.
Switch to file-based serializer if needed because running from AOT.

Add `kernel_executor` that switches to launching a separate Dart process if
needed because running from AOT.

Add macro executor that picks how to run kernel.

R=jakemac@google.com, johnniwinther@google.com

Change-Id: I19f90969269c38f96d64652b41171a12d83d8a7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353263
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
2024-03-04 18:10:52 +00:00
Paul Berry b279238e48 Implement context-aware type analysis for conditional-like expressions.
In the following expression types, the static type is computed using
the least upper bound ("LUB") of their subexpressions (adjusted as
appropriate to account for the null-shorting behaviors of `??` and
`??=`):

- Conditional expressions (`a ? b : c`)
- If-null expressions (`a ?? b`)
- If-null assignments (`a ??= b`)
- Switch expressions (`switch (s) { p0 => e0, ... }`)

This can lead to problems since the LUB computation sometimes produces
a greater bound than is strictly necessary (for example if there are
multiple candidate bounds at the same level of the class hierarchy,
the LUB algorithm will walk up the class hierarchy until it finds a
level at which there is a unique result). For a discussion of the kind
of problems that can arise, see
https://github.com/dart-lang/language/issues/1618.

This change improves the situation by changing the analysis of these
four expression types so that after computing a candidate static type
using LUB, if that static type does not satisfy the expression's
context, but the static types of all the subexpressions *do* satisfy
the expression's context, then the greatest closure of the context is
used as the static type instead of the LUB. This is the algorithm
proposed in
https://github.com/dart-lang/language/issues/1618#issuecomment-1507241494.

This is theoretically a breaking change (since it can change code that
demotes a local variable into code that doesn't, and then the demotion
or lack of demotion can have follow-on effects in later code). So it
is implemented behind the `inference-update-3` experiment
flag. However, in practice it is minimally breaking; a test over all
of google3 found no test failures from turning the feature on.

Since one of these expression types (switch expressions) is
implemented in `package:_fe_analyzer_shared`, but the other three are
implemented separately in the `package:analyzer` and
`package:front_end`, this change required modifications to all three
packages. I've included tests for the new functionality, following the
testing style of each package. I've also included a comprehensive set
of language tests that fully exercises the feature regardless of how
it's implemented.

Since `package:front_end` has many different implementations of `??=`
depending on the form of the left hand side, I've tried to be quite
comprehensive in the language tests, covering each type of assignable
expression that might appear to the left of `??=`.

Change-Id: I13a6168b6edf6eac1e52ecdb3532985af19dbcdf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353440
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2024-03-04 17:19:00 +00:00
Lasse R.H. Nielsen 9d933d1281 Retire 3.3 experiments in the 3.4 release.
Tested: No new tests.
Change-Id: Idf19ce8b6743b221841e6cef6b2a80e8ab37860e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354260
Auto-Submit: Lasse Nielsen <lrn@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-03-04 16:09:31 +00:00
Johnni Winther f7434789d6 [cfe] Report error on macros applied to invalid targets
Closes #54658

Change-Id: I9a5aed969b0c9b4ec92fe97000512b63e4b49945
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354881
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-03-04 11:14:36 +00:00
Eli Geller 0766f7b83e typo fixes: its vs. it's
Closes https://github.com/dart-lang/sdk/pull/55023

GitOrigin-RevId: f9457aac2575780d5d712531d3694ccb38d3a5bd
Change-Id: I29357eac563d6423a78ec58bbfa6a1a72e3dadf7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354501
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Michael Thomsen <mit@google.com>
2024-02-29 11:07:40 +00:00
Chloe Stefantsova 3ef08e1ecd [analyzer][cfe] Expand TypeAnalyzerOperations. Part 1
This CL adds more of the type operations required in the subtype
constraint gathering algorithm into the shared type operation
class. The added operations are used in the constraint gathering
algorithms in the Analyzer and the CFE.

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

This is a reland of
https://dart-review.googlesource.com/c/sdk/+/346840

Change-Id: I99086cfc3cd56db40055e9bb8e23acec8bdf830b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354622
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-02-29 08:14:20 +00:00
Jake Macdonald 0bf9ef8076 add 'library augment <uri>'; to augmentation libraries
Bug: https://github.com/dart-lang/sdk/issues/54848
Change-Id: I5ec3cb01a76955e4cbe91a867277c9d91ce5c927
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353322
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-02-27 23:12:41 +00:00
Konstantin Shcheglov 5f6daed1e1 Augment. Parse 'augmentKeyword' for top-level variables.
Change-Id: If8f0cb6fc1af77fb91774952931db5da214142e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354520
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-02-27 16:48:18 +00:00
Konstantin Shcheglov 9018d41706 Macro. Support for TypeAliasDeclaration.
Change-Id: I4b85cfaf154591434729ba9ad5f94a6cfc2d1033
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354060
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2024-02-23 19:55:10 +00:00
Jake Macdonald 79bba81cd8 Use bit mask to serialize boolean fields on objects which have more than one.
Today, each boolean requires 1 byte. With this implementation all booleans on a class combined require between one and three bytes, depending on which ones are set.

This may or may not actually be worthwhile, please push back if you think it's not :). I can't tell much difference running real macros.

Change-Id: Ie9fac0497f0d4571c5f1314009ec9d7c474b073c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352562
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
2024-02-23 09:56:52 +00:00
Konstantin Shcheglov e0e72c9d3d Macro. Use empty function body, not empty block body for constructors.
Change-Id: I5bda2e1462fbfea97d2b6f7cd9f666373a88d1fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353585
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2024-02-22 17:20:59 +00:00
David Morgan e680eb4c4f [macros] Tweak diagnostic for unexpected macro implementation exception.
The only expected exceptions at this point are DiagnosticException and MacroException subtypes; everything else is a bug in the implementation.

Tweak the diagnostic to explain that it's due to a bug in the macro. Add the exception message and stack trace as a context message, and a fix hint to contact the author.

Add a language test.

Retry landing with updates to `pkg/analyzer/test/summary/macro_test`.

R=jensj@google.com, scheglov@google.com, sigmund@google.com

Change-Id: Iebc3df784922dcb6ef112ba8d023d5388516373b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352361
Reviewed-by: Jake Macdonald <jakemac@google.com>
Auto-Submit: Morgan :) <davidmorgan@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-02-22 13:53:20 +00:00
Jake Macdonald af17bedd44 optimize Edit.applyList to use a StringBuffer
This is about 30% faster in my tests even on a small library, and ultimately makes it linear instead of n*m or so.

Change-Id: Ia368766a1ee9b06cc7a1b93f0f130e2356a3d7d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353542
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2024-02-21 23:59:26 +00:00
Chloe Stefantsova 91c54ff06a [analyzer,cfe] Share classes representing type constraints
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: Ic441a582bcc43fb5d909ca70f101160512f11afe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352222
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-02-21 12:03:14 +00:00
David Morgan 93b7791c0c [macros] Fix flakiness on Windows related to add during flush and timeouts.
R=jakemac@google.com

Change-Id: I48f5829613ca2999caf23a485648054b920596a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352907
Reviewed-by: Jake Macdonald <jakemac@google.com>
Auto-Submit: Morgan :) <davidmorgan@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2024-02-20 15:47:10 +00:00
Chloe Stefantsova aa043e90a4 Revert "[analyzer][cfe] Expand TypeAnalyzerOperations. Part 1"
This reverts commit a8cf0a0825.

Reason for revert: The CL broke a few places in google3.

Original change's description:
> [analyzer][cfe] Expand TypeAnalyzerOperations. Part 1
>
> This CL adds more of the type operations required in the subtype
> constraint gathering algorithm into the shared type operation
> class. The added operations are used in the constraint gathering
> algorithms in the Analyzer and the CFE.
>
> Part of https://github.com/dart-lang/sdk/issues/54902
>
> Change-Id: Ia895fc84bd7ab666330a4ab32b6e759f0977e750
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346840
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Paul Berry <paulberry@google.com>
> Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>

Change-Id: Ibf75bb6dda4a4f5f36a2265036703977b28a4333
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353160
Auto-Submit: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-02-20 09:14:00 +00:00
David Morgan 859e359266 [macros] Cleanup after exception changes.
Add `RequestChannelException`, remove unused `RemoteExcepion`, update
some doc comments.

R=jakemac@google.com

Change-Id: Id51d2a9d16e7d4599703470b5c974c2bd438c55e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352911
Auto-Submit: Morgan :) <davidmorgan@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-02-20 09:07:29 +00:00
Jens Johansen b25ebda686 [macro] Add 'isClosed' to ExternalMacroExecutorBase and throw if using it after
E.g. running
```
out/ReleaseX64/dart pkg/_fe_analyzer_shared/test/macros/executor/executor_test.dart
```

(which is apparently the wrong executable) fails after 12 minutes (!)
with "TimeoutException after 0:12:00.000000: Test timed out after 12
minutes."

With this instead it runs in a few seconds because the stuff that makes
it wait forever throws instead.

Change-Id: Idd8be08438863511769b4cace1a492d613cadb03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352301
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-02-20 08:19:18 +00:00
Johnni Winther a765ffc540 [cfe] Generate merged augmentation library for macros
This adds support for generating the merged augmentation library in the
CFE. In order to get the right file offsets in the generated AST the
MacroExecutor.buildArgumentationLibrary function is extended to compute
a list of spans the describe what each segment of the generated source
code contains. These spans are used to compute the offset relation
between the intermediate augmentation libraries and the merged
augmentation libraries.

Change-Id: Ie5b9c23130da67ac874fb824b82827bfd6b88880
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349864
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2024-02-19 12:35:22 +00:00
Chloe Stefantsova a8cf0a0825 [analyzer][cfe] Expand TypeAnalyzerOperations. Part 1
This CL adds more of the type operations required in the subtype
constraint gathering algorithm into the shared type operation
class. The added operations are used in the constraint gathering
algorithms in the Analyzer and the CFE.

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

Change-Id: Ia895fc84bd7ab666330a4ab32b6e759f0977e750
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346840
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-02-19 10:41:00 +00:00
David Morgan 4be3368d73 [macros] Fix flakiness on socket macro executor shutdown.
There is a race between closing the socket and killing the process that
causes the socket close to fail ~1% of the time on my machine.

R=jakemac@google.com

Change-Id: I16d337534956194a11cc46f29cb722ac1bda5538
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352905
Auto-Submit: Morgan :) <davidmorgan@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2024-02-16 16:50:08 +00:00
Jake Macdonald 1e0223e6d8 Clean up VariableDeclaration and MemberDeclaration APIs.
- Adds hasInitializer and hasConst to VariableDeclaration.
- Renames isStatic to hasStatic to be consistent with other members.
- Improves serialization tests by randomizing some values, which
  should help to catch ordering errors in serialization.

Change-Id: I44199b1b058444510b9fa55afe0611187b90fc95
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352540
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
2024-02-16 07:42:53 +00:00
Parker Lougheed d1553ffda6 [cfe] Focus nullable subtype error messages
Now that the types in the message were recently adjusted to include the '?', I think it's beneficial to focus on what the underlying problem is rather than the syntax.

Change-Id: I7e59ea3cc2ce618fe46052a9c5e04a973a5f6ab9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349581
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-02-14 13:22:29 +00:00
Jake Macdonald 2624743bdd handle deserializing metadata diagnostic targets
Change-Id: I47f747baf48d6fc3a0e04871990d0743dbbb41e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352560
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
2024-02-14 00:03:35 +00:00
Morgan :) 6d57fe5a1c Revert "[macros] Tweak diagnostic for unexpected macro implementation exception."
This reverts commit 093271880a.

Reason for revert: Breaks some analyzer tests.

Original change's description:
> [macros] Tweak diagnostic for unexpected macro implementation exception.
>
> The only expected exceptions at this point are DiagnosticException and MacroException subtypes; everything else is a bug in the implementation.
>
> Tweak the diagnostic to explain that it's due to a bug in the macro. Add the exception message and stack trace as a context message, and a fix hint to contact the author.
>
> Add a language test.
>
> R=jakemac@google.com
>
> Change-Id: Ieaa6bedb3bc1646e4be61b384619152cc173b7e0
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351040
> Auto-Submit: Morgan :) <davidmorgan@google.com>
> Reviewed-by: Jens Johansen <jensj@google.com>
> Commit-Queue: Morgan :) <davidmorgan@google.com>
> Reviewed-by: Jake Macdonald <jakemac@google.com>

Change-Id: Ia64c112aad79fdcdd1f6e1a4b800616632107fc2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352260
Auto-Submit: Morgan :) <davidmorgan@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-02-13 12:38:14 +00:00
David Morgan 093271880a [macros] Tweak diagnostic for unexpected macro implementation exception.
The only expected exceptions at this point are DiagnosticException and MacroException subtypes; everything else is a bug in the implementation.

Tweak the diagnostic to explain that it's due to a bug in the macro. Add the exception message and stack trace as a context message, and a fix hint to contact the author.

Add a language test.

R=jakemac@google.com

Change-Id: Ieaa6bedb3bc1646e4be61b384619152cc173b7e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351040
Auto-Submit: Morgan :) <davidmorgan@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2024-02-13 10:31:11 +00:00
Paul Berry acc74df9f1 Use _ to refer to the unknown type schema in _fe_analyzer_shared.
Change-Id: If06e0bb05e285bd53d924a791c36d461f00750e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352100
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-02-12 21:21:18 +00:00
Konstantin Shcheglov 716d8ccbf8 Macro. Code optimizer. Enough implementation to handle JsonSerializable result.
Previous attempt to use AST and builder was removed.

Also, after talk with Brian, removed scopes, and replaced with more
course grained, but simpler collision detection. If there is a declaration with the same name as prefixed, the name stays prefixed. Similarly, if there is an unprefixed invocation.


Change-Id: If2b0ce530ac81482e5bfd066d6df43e1a5d34799
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350683
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-02-12 20:23:20 +00:00
Jake Macdonald 22264a24c8 add TypeParameter interface, for function type parameters which are not Declarations
Bug: https://github.com/dart-lang/language/issues/3559
Change-Id: I98d20e9f3b84d89c985fddb10ed1dc5e7c651b7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346640
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
2024-02-09 08:35:28 +00:00
Jake Macdonald 94fb9c9f2c support custom JSON keys for fields
Change-Id: I72c2a4f09b012c4100fe9286967d182831507160
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350740
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2024-02-07 16:48:38 +00:00
Ben Konyi d9797db9ea [ VM ] Inherit system isolate property on child isolate spawn
This prevents --pause-isolates-on-start and --pause-isolates-on-exit
from impacting isolates spawned from system isolates. This should be
revisited to determine if:

- Inheriting the system isolate property is actually what we want to do
  in general
- Isolate.spawn* APIs should instead include a parameter to specify an
  isolate as a system isolate

Fixes https://github.com/dart-lang/sdk/issues/54729

TEST=Manual testing

Change-Id: Ibacdea845db6344148c11bebf001e4cac3377a62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348460
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2024-02-06 23:38:53 +00:00
Paul Berry 650c3cb917 Use records instead of MapPatternTypeArguments and NamedType.
These classes served no function but to wrap around two values; the
code that used them is clearer if it just uses record types instead.

Change-Id: I202dab727f27173489556ca1208e409e6a91fabd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350340
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-02-06 21:01:01 +00:00
Konstantin Shcheglov 5234dfb838 Macro. Extend MacroIntrospectionCycleExceptionImpl and use to store cycled applications instead of ID hack.
Change-Id: Icfbfbd49696b0b744a45d1e0973c3b166f04b3ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350643
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-02-06 19:53:19 +00:00
Konstantin Shcheglov 8672f63387 Macro. Code optimizer. Update import directives.
Change-Id: I5599f243fd4ddcda046934b1584612b209d69815
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350406
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-02-06 18:13:59 +00:00
David Morgan f367d1e107 [macros] Add DiagnosticException that macro implementations can throw to report a diagnostic.
R=jakemac@google.com

Change-Id: I7546aa84f3e0b8423465dcb49d90a89df9231b84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350302
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Morgan :) <davidmorgan@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
2024-02-06 17:32:14 +00:00
Konstantin Shcheglov 0d3910fca3 Macro. Code optimizer. Consider library declarations, pass ScannerConfiguration.
Change-Id: Ibe9ef926d6c2527493e7f3729c1e29e4cc6b3f3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350405
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-02-06 17:03:18 +00:00
David Morgan 402f85662d [macros] Report MacroException thrown during macro execution separately from diagnostics.
Change-Id: I2abf846e98479cf4d5d317127bbfe387393b142a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349482
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
2024-02-06 09:55:28 +00:00
Konstantin Shcheglov 05d7c407cf Macro. Code optimizer. Verify the stack, handle more shadowing or not.
Change-Id: Idd8447ca5f42c7fbb55f20eb4d75c3f0159be09d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350401
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-02-05 22:41:01 +00:00
Konstantin Shcheglov 8d1a8ada6b Macro. Code optimizer, 0-th version.
I don't try to be even close to be correct here, but this is the base
on top of which I'd like to build the full implementation.

The idea is that we scan, and implement parser listener that builds
prefixed name in scopes. We fill scope with declarations as we find them. Using these scopes we can decide which import prefixes can be removed.

As usually for shared code, clients will implement abstract methods in the client specific way.

We might get a hierarchy of `Edit` objects, such as `RemoveImportPrefix` and `RemoveImportDirective` because at least in the analyzer we might need to apply some changes to the element models (metadata, constants).

Change-Id: I153259d87a09ab070f37192ae64ccd8da36e2d41
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350260
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-02-05 18:50:10 +00:00