Commit Graph

362 Commits

Author SHA1 Message Date
Chloe Stefantsova 87032377ee [cfe] Use ExpressionVariable in ForInStatement and similar nodes
Part of https://github.com/dart-lang/sdk/issues/61572

Change-Id: I4f02718dc292b0e18f1fb4858ee31b4c645597a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467360
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-12-11 01:38:24 -08:00
Chloe Stefantsova 95df731257 [cfe] Use VariableInitialization in ForStatement and similar nodes
This change is similar to
https://github.com/dart-lang/sdk/commit/c97e2554ee3b21b0b0146ca41be969dd8531986d,
where ExpressionVariable was used in VariableGet and VariableSet.

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

Change-Id: Id9fa5302adcf8c773cec8478a31948b54c8393b6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466720
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-12-08 04:56:51 -08:00
Chloe Stefantsova 6209d8dd0b [cfe] Implement trivial context allocation strategy for local variables
Part of https://github.com/dart-lang/sdk/issues/61572

Change-Id: I7569168e6595e88e2bda25a122f3b238c188b381
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466080
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-12-05 06:59:29 -08:00
Johnni Winther 4338105c13 [kernel] Make InvalidExpression.message non-nullable
Change-Id: I0b88dfa01a8e2caae8631266310aa3b0a5f5e0bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464685
Reviewed-by: Jens Johansen <jensj@google.com>
2025-11-27 05:15:04 -08:00
Johnni Winther 5bc2037cb0 [kernel] Implement InvalidInitializer
This updates the Initializer classes such that InvalidInitializer has a message and will throw at runtime, similar to InvalidExpression. All initializers have positions and only FieldInitializer and SuperInitializer have an isSynthetic field.

TEST=pkg/front_end/testcases/general/invalid_initializer.dart

Change-Id: Ic444bb1dc273b433ac70249240527d115deaa332
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/463661
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2025-11-27 01:53:23 -08:00
Chloe Stefantsova c94482a3b5 [cfe] Add text serialization for VariableInitialization
This is a step towards better visualisation of the new variable nodes
emitted by the CFE.

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

Change-Id: If39f609627044b97967ed82683bbf49bb02edd5d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464182
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-11-26 03:11:52 -08:00
Nate Biggs 52be04e90a [dart2wasm][vm] Fix deferred loading with mixin deduplication.
Now moves mixin applications into their own libraries that can be
imported separately from the rest of the code in the originating
library.

Then adds an import to the new library containing the mixin application
to any libraries that use it.

This ensures the import graph is accurate while only making sure it
remains minimal.

TEST=Added case to pkg/vm testcases.

Bug: https://github.com/dart-lang/sdk/issues/43089
Change-Id: I56b6ea1db8261e0d0508c2d7e62d0c13fbe9678b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457260
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2025-11-21 10:29:51 -08:00
Chloe Stefantsova a4d6787112 [cfe] Start emititng new variable nodes when the experiment is on
As a part of this CL, the following was changed:

* Instead of `VariableInitialization` implementing `VariableDeclaration`, `VariableDeclaration` now implements `VariableInitialization`.
* `InternalLocalVariable` now implements `LocalVariable`. It delegates most of its members to the variable it wraps around, and the implementations of the `TreeNode` members are throwing.
* Some tests in the bytecode generator under the experimental type started to fail and are skipped.

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

Change-Id: I06b391cc762d5935f528d208ff5e27eccf311a47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462981
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-11-20 01:33:37 -08:00
Chloe Stefantsova cb559f1870 [cfe] Introduce InternalExpressionVariable
`VariableDeclarationImpl` is re-defined in terms of
`InternalExpressionVariable` and `InternalExpressionVariableMixin`.
`InternalLocalVariable` is introduced similarly.

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

Change-Id: I5cb16828687a715cf0f9049338bf461e5ff67f1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462422
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-11-18 03:18:33 -08:00
Chloe Stefantsova c97e2554ee [cfe] Make VariableGet and VariableSet abstract interfaces
This change is similar to
https://dart-review.googlesource.com/c/sdk/+/456620 and
https://dart-review.googlesource.com/c/sdk/+/458520 and prepares the
CFE to emit new variable nodes when the experimental flag is on.

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

Change-Id: I78cff188c3a94de337d7114c7496552733b2e208
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461421
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-11-14 03:09:49 -08:00
Chloe Stefantsova 63b34b2e1f [cfe] Implement VariableDeclarations on the new nodes
The nodes that now conform to VariableDeclarations are Variable,
LocalVariable, SyntheticVariable, ThisVariable, FunctionParameter,
PositionalParameter, NamedParameter, and VariableStatement.

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

Change-Id: I6b38d2756662b5bd729d65158621f56791dce829
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460840
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-11-10 06:26:34 -08:00
Chloe Stefantsova 756dbcde19 [cfe] Make TypeParameter an abstract interface
The concrete implementation is named `NominalTypeParameter`. The
change is needed as a transition step to the new encoding for
variables in Kernel.

This change is similar to
https://dart-review.googlesource.com/c/sdk/+/456620

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

Change-Id: I9e4107b50a0790008d65a5ee94a4ff06a1b48052
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/458520
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-10-30 09:01:30 -07:00
Chloe Stefantsova dc2a0aae7d [cfe] Always query for ranked superclass info in least upper bound
Previously, the info was inconsistently queried, leading to
nondeterministic behaviors.

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

Change-Id: I5d47d0f29b0e78d2834ae3c5793fd05171cf9156
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457360
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Chloe Stefantsova <cstefantsova@google.com>
2025-10-29 03:10:46 -07:00
Johnni Winther 6d70657fad [kernel] Add RedirectingFactoryInvocation
This adds an internal wrapper expression for redirecting factory invocations. This holds a reference to the original redirecting factory constructor along with the resulting invocation of the generative or factory constructor. The node is removed during constant evaluation and only available to backends through the pre-modular transformations.

TEST=existing

Change-Id: I35c19766117ab2942aefddb4ccebcd2df66babf3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454820
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-10-28 03:03:44 -07:00
Chloe Stefantsova 06e54c8c24 [cfe] Make VariableDeclaration an abstract interface
The concrete implementation is named `VariableStatement`. The change
is needed as a transition step to the new encoding for variables in
Kernel.

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

Change-Id: Ib333f28e9998f2e758a18e4ad4b0a3cf4d642013
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456620
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-10-22 23:11:39 -07:00
Chloe Stefantsova cad0aae004 [cfe] Introduce Kernel AST node for the closure expreiment
Part of https://github.com/dart-lang/sdk/issues/61572

Change-Id: Iee3c2a223f4c44f5528016082cf3a068b401d87d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454061
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-10-17 02:16:25 -07:00
Chloe Stefantsova a478a4418c [cfe] Add experimental visitor mixins and experimental type
This CL reduces the noise of future CFE experiments in the
backends. Whenever new nodes will be added as an experiment, the
related exception-throwing implementations will be added to the
mixins, eliminating the need to add the visit methods to the backend
code directly. The experimental type addresses a similar issue in
exhaustive switch statements and expressions.

TEST=existing

Change-Id: I1a021e11a159a992500c42287cbe6ef027bf54a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455080
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2025-10-17 02:16:25 -07:00
Paul Berry bea092d844 [kernel/_fe_analyzer_shared] Share demangleMixinApplicationName.
It's not necessary for `package:kernel` and
`package:_fe_analyzer_shared` to have duplicate implementations of
this method. `package:kernel` depends on
`package:_fe_analyzer_shared`, so they can share one definition.

Change-Id: I6a6a696462a0e22a2ea818c42f58187c45821afc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447842
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-09-02 07:51:58 -07:00
Chloe Stefantsova 1a7e1134ab [model] Share implementation of chooseTypes between Analyzer and CFE
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: I7b83f7634940d24ba4406c476f9cd63dcfafff57
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446660
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-08-26 00:41:33 -07:00
Jens Johansen abfa152cfc [kernel/DDC] DDC shouldn't crash when trying to translate line/column to offset for expresion compilation
Follow-up to https://dart-review.googlesource.com/c/sdk/+/446042.

Change-Id: Icfbaa763a6d6089a74f62088602c07c478520741
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446420
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-08-24 23:50:07 -07:00
Jens Johansen 9b157b67e3 Format {_fe_analyzer_shared,front_end,kernel}/lib; update generated files to match package version
For the generated files (e.g. codes) we had gotten into a scenario
where the auto generated files was forced to be formatted as short
style, but if asking the dart formatter to format the
_fe_analyzer_shared file it would be formatted in long style because the
minimum version for _fe_analyzer_shared is now 3.7.

This CL updates the generators for the generated files to pass the
language version from the package config to the formatter.

Change-Id: I986ce1b5ff65244499ab5a277e78124f372ee46d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444300
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-08-07 06:07:21 -07:00
Jens Johansen dfba8a7ca9 [CFE] Remove more allocation from iterators
These are from `_Array.iterator` whereas the previous ones was from,
iirc, `List.iterator`.

* 7.41mb Import.finalizeImports
* 1.13mb FindTypeVisitor.visitInterfaceType
* 856.39kb new NamedTypeBuilderImpl
* 815.92kb BodyBuilder.createSuperParametersAsArguments

(values from uprobe)

When compiling the CFE with the CFE I get this:

```
msec task-clock:u: -5.6347% +/- 0.5257% (-321.96 +/- 30.04) (5713.89 -> 5391.92)
page-faults:u: 5.9842% +/- 0.0970% (6310.26 +/- 102.33) (105449.48 -> 111759.74)
cycles:u: -6.0829% +/- 0.5338% (-1447602857.06 +/- 127036484.81) (23797839542.02 -> 22350236684.96)
instructions:u: -4.9550% +/- 0.0008% (-1364113249.40 +/- 214444.14) (27529935457.16 -> 26165822207.76)
branch-misses:u: -5.7909% +/- 2.2880% (-5395643.76 +/- 2131857.44) (93173948.12 -> 87778304.36)
seconds time elapsed: -5.6275% +/- 0.5257% (-0.32 +/- 0.03) (5.72 -> 5.40)
seconds user: -6.0582% +/- 0.5861% (-0.33 +/- 0.03) (5.47 -> 5.13)
Scavenge(   new space) goes from 63 to 61
Evacuate(store buffer) goes from 2 to 3
MarkSweep(   old space) goes from 1 to 0
```

As before the changes here are mostly "bogus" and likely caused by the
GC being weird, see also
https://dart-review.googlesource.com/c/sdk/+/438722 and
https://dart-review.googlesource.com/c/sdk/+/438681.

It does seem to consistently change the number of new space GCs though
(65 -> 63 -> (here) 61).

Change-Id: I18ef712394c1d98b8ed15c7fe6c4ac32fa9bc2e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438682
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2025-07-31 01:52:02 -07:00
Johnni Winther f49d92aba9 [cfe] Use LookupResult for constructor lookup
This adds `LookupResult.isInvalidLookup` to the handle invalid lookup
results and uses this to avoid a lot of cascading error messages.

This is a step towards removing ProblemBuilder, AmbiguousBuilder and
reliance on `NamedBuilder.isDuplicate` in lookups.

Change-Id: Ia9d558ce55b45567607282295dd1e54e6187f9c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441880
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2025-07-29 04:41:21 -07:00
Jens Johansen 84e279d279 [CFE] Remove ~19 mb of allocations caused by iterators etc
* Remove ~2.8mb of iterators in SourceMethodBuilder
* Remove ~0.7mb of iterators in calculateBounds
* Remove ~1.7 mb of iterators in ClassMembersNodeBuilder.build
* Remove ~1.9mb of iterators in BuilderFactory.computeBuildersByName
* Remove ~3mb of iterables and iterators in findRecordUseAnnotation
* Remove ~3mb of allocations from List.iterator in InferenceVisitorBase._inferInvocation
* Another ~6.3mb of iterables in various places in chunks of ~100-800kb.

Running a benchmark of the CFE compiling the CFE I get this:

```
msec task-clock:u: -5.9719% +/- 0.3845% (-342.77 +/- 22.07) (5739.61 -> 5396.84)
page-faults:u: -2.6307% +/- 0.0630% (-2951.12 +/- 70.63) (112178.18 -> 109227.06)
cycles:u: -6.1751% +/- 0.3921% (-1471343183.50 +/- 93434420.74) (23827045867.84 -> 22355702684.34)
instructions:u: -5.0116% +/- 0.0006% (-1385443477.90 +/- 176957.44) (27644543467.86 -> 26259099989.96)
branch-misses:u: -6.0357% +/- 1.7661% (-5562845.14 +/- 1627775.60) (92165665.40 -> 86602820.26)
seconds time elapsed: -5.9868% +/- 0.3830% (-0.34 +/- 0.02) (5.75 -> 5.40)
seconds user: -6.0365% +/- 0.4515% (-0.33 +/- 0.02) (5.47 -> 5.14)
seconds sys: -4.6542% +/- 3.6415% (-0.01 +/- 0.01) (0.27 -> 0.26)
Scavenge(   new space) goes from 64 to 63
MarkSweep(   promotion) goes from 9 to 8
Evacuate(store buffer) goes from 2 to 1
```

Worth noticing, though, is that the before numbers (e.g. 5739.61 ms
task-clock:u) is very close to the before numbers from
https://dart-review.googlesource.com/c/sdk/+/438681 (5767.31 ms) and not
the after numbers on that cl (5478.56 ms) --- so something weird is
going on here.

Change-Id: I67248bbde47900435ababcb1a2d5ecff2dde5c13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438722
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-07-04 05:59:12 -07:00
Chloe Stefantsova 7b541da59b [cfe] Use exhaustiveness in computing nullability of intersection
This is a follow-up for
https://dart-review.googlesource.com/c/sdk/+/436620/comment/cddbbd38_1d23184c/

Change-Id: Ib473db14c6088ceb99034a6762ec75edccb4b5c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438723
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-07-04 05:19:14 -07:00
Chloe Stefantsova 433c0998d0 [cfe] Remove Nullability.legacy
TEST=existing

Change-Id: Id924e4ef64ddabc1986cb885f558382ff139b481
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436620
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-07-02 23:50:12 -07:00
Chloe Stefantsova 150e8cbe97 [cfe] Upate pre-Null Safe naming in the CFE
Change-Id: I45e8dc703ce7810e6df5a328b3829dc86a128792
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436241
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-06-23 03:17:42 -07:00
Chloe Stefantsova b5cb488278 [cfe] Remove IsSubtypeOf.onlyIfIgnoringNullabilities
Change-Id: I584e079c273e48a007590fd63575321fe49f4b6a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434060
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-06-13 02:02:54 -07:00
Chloe Stefantsova 39810ffbe4 [cfe] Cleanup interface of subtype queries
Under the hood, there is no difference between
`isSubtypeWhenUsingNullabilities` and
`isSubtypeWhenIgnoringNullabilities` by now. This CL makes the
corresponding renames and removals in the CFE and its clients.

TEST=existing

Change-Id: I22060c29834179c30ba62562aa254146b1d7530d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433480
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-06-13 02:02:54 -07:00
Chloe Stefantsova c542a1e82f [model] Remove support for subtype checks ignoring nullability
Change-Id: I4a43e09094d79c7b5e59eb03cbe7eb676808a5f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426121
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-06-04 06:52:57 -07:00
Chloe Stefantsova 1117dce94d [model] Mark erroneously initialized optional parameters as such
This adds the flag isErroneouslyInitialized to the VariableDeclaration
AST node in Kernel. The flag is set to true whenever it is concluded
during compilation that the initializer contains errors is erroneous
for the parameter in any other way, for exaple, due to a type mismatch.

Change-Id: I1b3c9c662974fb9537ab4f89b58dd004979feebe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431862
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-06-02 02:14:27 -07:00
Chloe Stefantsova e535e812be [model] Update instructions for generating benchmark data in CFE
Change-Id: I505390321f8ca26391503dd4645b56a208108fc7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429661
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-05-21 01:45:11 -07:00
Johnni Winther 94c9dff1c5 [cfe] Add isInternalImplementation to Extension(Type)MemberDescriptor
This adds a flag to the member descriptors that allow us to skip these when building the name space for extensions and extension types from dill.

The late lowering of fields in dart2js is fixed to support lookup from dill.

Change-Id: Iacbd6451ac234767036dfe8f818c3ecbb693ced8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427720
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-05-12 00:26:25 -07:00
Chloe Stefantsova 40d52d54af [model] Enable checks in redirecting factories of extension types
This CL enables the same checks in the redirecting factories of
extension types as in redirecting factories of classes. Additionally,
this CL marks all of those erroneous constructors, in classes and in
extension type declarations, as erroneous.

Change-Id: Ic270324f05b6a8424c1ab9fbe9fe4f1d0b22a3fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425860
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-05-01 06:05:34 -07:00
Chloe Stefantsova b7aaf90246 [model] Mark erroneous constructors as such in the CFE
This allows to skip some apriori failing checks and avoid cascading
errors. Aditionally it instructs the verifier to not check the
erroneous constructors.

Change-Id: Ie96bbe84d02a96567b3deab65e15e0780a625d19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424820
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-04-26 07:38:44 -07:00
Chloe Stefantsova 669bcef1a6 [model] Introduce isErroneous flag on Members in Kernel
The flag is used to signal known issues with members, so that the
verifier could skip on checking assumptions for well-formed programs.

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

TEST=existing

Change-Id: I7cf1983035d26105ccfe2e7a844a9ba3108bfda2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420760
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-04-23 01:15:43 -07:00
Paul Berry c67a80f3f5 Stop using NullabilitySuffix in fe/analyzer shared code.
The getter `SharedType.nullabilitySuffix` is replaced by
`SharedType.isQuestionType`, which returns a boolean.

The method `TypeAnalyzerOperations.withNullabilitySuffixInternal` is
replaced by `SharedType.setNullabilitySuffix`, which accepts a
boolean.

Support for `*` types has been removed from `mini_types.dart`.

A few test cases in `flow_analysis_test.dart` previously used `*`
types as a way of exercising corner cases involving types that were
mutual subtypes of each other. These tests have been changed to take
advantage of the fact that `dynamic` and `Object?` are mutual
subtypes.

Change-Id: Id9904f9570fc738b388192db8536848204af03e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414581
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-03-19 11:24:21 -07:00
Johnni Winther 06d938046f [kernel] Remove NonNullableByDefaultCompiledMode
and TargetFlags.soundNullSafety

TEST=existing

Change-Id: I5e28d3d187b0f84fa23130c042fd3c55b89c687c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413460
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-03-19 01:37:07 -07:00
Johnni Winther 1ebf3df920 [kernel] Add tool for checking AST equivalence
Change-Id: Ie06776203080e91346582534af2d56c24581bd54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413200
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-03-04 03:54:48 -08:00
Johnni Winther 0060b0f665 [cfe] Remove nnbd mode
TEST=existing

Change-Id: I30bbadb74e81c7f4aaa444d1e2f6f5ffc2005d4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412881
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-03-04 01:46:51 -08:00
Chloe Stefantsova d8c48032bb [cfe] Remove legacy raw types from CoreTypes
Change-Id: I9d920cc00ce22900429fd38b6c452483438f94d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397161
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-02-28 00:50:40 -08:00
Chloe Stefantsova dcd410efd4 [analyzer][cfe] Remove TypeStructure variable from shared classes
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: Ia70f2afd321e9b4a4762b6ed860611dee1399d87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404622
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-01-20 01:58:43 -08:00
Paul Berry 9a472930e5 [_fe_analyzer_shared] Renames to prepare for analyzer refactoring.
The following shared getters are renamed so that their names are
distinct from the corresponding getters in the analyzer:

- `SharedFunctionTypeStructure.positionalParameterTypes` is renamed to
  `positionalParameterTypesShared` to be distinct from the analyzer's
  public getter `FunctionType.positionalParameterTypes`.*

- `SharedFunctionTypeStructure.returnType` is renamed to
  `returnTypeShared` to be distinct from the analyzer's public getter
  `FunctionType.returnType`.

- `SharedNamedFunctionParameterStructure.type` is renamed to
  `typeShared` to be distinct from the analyzer's public getter
  `FormalParameterElement.type`.

- `SharedNamedTypeStructure.type` is renamed to `typeShared` to be
  distinct from the analyzer's public getter
  `RecordTypeNamedField.type`.

- `SharedRecordTypeStructure.positionalTypes` is renamed to
  `positionalTypesShared` to be distinct from the analyzer's public
  getter `RecordType.positionalTypes`.*

- `SharedRecordTypeStructure.sortedNamedTypes` is renamed to
  `sortedNamedTypesShared` to be distinct from the analyzer's public
  getter `RecordType.sortedNamedTypes`.

- `SharedTypeParameterStructure.bound` is renamed to `boundShared` to
  be distinct from the analyzer's public getter
  `TypeParameterElement2.bound`.

*Note that `FunctionType.positionalParameterTypes`,
 `RecordType.positionalTypes`, and `RecordType.sortedNamedTypes` were
 unintentionally exposed as part of the analyzer's public API. In a
 previous CL I marked them as deprecated.

These renames pave the way for changing the analyzer's `DartType`
class so that it implements `SharedTypeStructure<TypeImpl>` rather
than `SharedTypeStructure<DartType>` (without the renames, the public
getters mentioned above would all have to be changed to have type
`TypeImpl`, and that in turn would expose `TypeImpl` through the
analyzer public API, which we don't want to do).

Once `DartType` implements `SharedTypeStructure<TypeImpl>`, that will
allow all the other uses of `SharedTypeStructure<DartType>` in the
analyzer to be gradually migrated to
`SharedTypeStructure<TypeImpl>`. Once that is done, `DartType` can be
changed so that it no longer implements
`SharedTypeStructure<TypeImpl>` at all (`TypeImpl` will implement
`SharedTypeStructure<TypeImpl> instead). This will free us up to make
future changes to the `SharedTypeStructure` base class without
inadvertently exposing those changes through the analyzer public API.

This is part of a larger arc of work to change the analyzer's use of
the shared code so that the type parameters it supplies are not part
of the analyzer public API. See
https://github.com/dart-lang/sdk/issues/59763.

Change-Id: I0686fdeae304f8948484516f0249841b79e7da6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403625
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-01-10 14:32:47 -08:00
Jens Johansen b022ecae70 [CFE] Fix crash in _computeOnClause
If a mixin refers to a non-existing class (or Function) it doesn't get
the otherwise expected number of implementedTypes and crashes.

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

Change-Id: I482e997751b36c5d62d2151b31bd58875d86ebf3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403602
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-01-09 23:13:11 -08:00
Chloe Stefantsova 3393befc99 [cfe] Remove constructors for alpha renaming
In this CL methods StructuralParameterType.forAlphaRenaming,
StructuralParameterType.forAlphaRenamingFromTypeParameter,
TypeParameterType.forAlphaRenaming, and
TypeParameterType.forAlphaRenamingFromStructuralParameter are removed,
and their call sites are replaced with invocations of other
constructors of StructuralParameterType and TypeParameterType. The
reason for this change is call sites having more information for
correct computing of type nullabilities.

In addition to the primary update, the following related changes are
made in this CL.

* Method StructuralParameterType.computeDefaultNullabilityForLibrary
  is renamed into StructuralParameterType.computeDefaultNullability,
  and TypeParameterType.computeDefaultNullabilityForLibrary is renamed
  into TypeParameterType.computeDefaultNullability. The parameter
  `library` is removed from both methods, since it's no longer needed.
* The static methods named `computeNullabilityFromBound` are removed
  from `StructuralParameterType` and `TypeParameterType` and
  re-introduced as instance members in classes `StructuralParameter`
  and `TestParameter` respectively

TEST=existing

Change-Id: I26cccf17ccc9bda1e8b750196f427325b544a7ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402820
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-01-07 01:16:48 -08:00
Paul Berry a8b8df2e45 [_fe_analyzer_shared] Renames to prepare for analyzer refactoring.
The following shared getters are renamed so that their names are
distinct from the corresponding getters in the analyzer:

- `SharedFunctionTypeStructure.sortedNamedParameters` is renamed to
  `sortedNamedParametersShared` to be distinct from the analyzer's
  getter `FunctionTypeImpl.sortedNamedParameters`.

- `SharedFunctionTypeStructure.typeFormals` is renamed to
  `typeParametersShared` to be distinct from the analyzer's getter
  `FunctionTypeImpl.typeFormals`.

- `SharedNamedFunctionParameterStructure.name` is renamed to
  `nameShared` to be distinct from the analyzer's getter
  `ParameterElement.name`.

- `SharedNamedTypeStructure.name` is renamed to `nameShared` to be
  distinct from the analyzer's getter `RecordTypeNamedFieldImpl.name`.

These renames pave the way for switching the analyzer's use of these
shared types over to the new element model. They're necessary because
when the analyzer switches over to the new element model:

- `FunctionTypeImpl.sortedNamedParameters` will no longer have the
  correct type to override
  `SharedFunctionTypeStructure.sortedNamedParameters`; instead, it
  will be necessary to convert each named parameter to a corresponding
  element in the new element model (`FormalParameterElementImpl` or
  `ParameterMember`).

- `FunctionTypeImpl.typeFormals` will no longer have the correct type
  to override `SharedFunctionTypeStructure.typeParametersShared`;
  instead, it will be necessary to use
  `FunctionTypeImpl.typeParameters` (which is a list of
  new element model type parameters).

- `ParameterElementMixin` will no longer implement
  `SharedNamedFunctionParameterStructure`; instead,
  `FormalParameterElementImpl` and `ParameterMember` (which are
  classes in the new element model) will implement it. The class
  `FormalParameterElementImpl` deliberately doesn't have a `name`
  getter; instead it has a `name3` getter, with slightly different
  semantics (it returns `null` rather than the empty string when there
  is no name).

Change-Id: I629e45b6fc588e6a86f7590aab853064e31ab661
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402220
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-01-06 06:12:22 -08:00
Alexander Markov 8c1fa6d05b [tfa,aot,dart2wasm] Allow tree-shaking of extension type members independently of their tear-offs
ExtensionTypeMemberDescriptor.memberReference and
ExtensionMemberDescriptor.memberReference are now nullable.

TFA-based tree shaker can now set them to null when extension type
member is not used and removed but corresponding lowered tear-off is
still used and retained.

Front-end never sets them to null and requires non-null memberReferences
when consuming kernel.

TEST=pkg/vm/testcases/transformations/type_flow/transformer/regress_flutter155624.dart
Fixes https://github.com/flutter/flutter/issues/155624

Change-Id: I71f98c02f4659ff72a8c1d7fc6c578e8b8e26d82
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401382
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-12-18 06:10:31 -08:00
Jens Johansen 66d8d8d6b3 [kernel/CFE] Mark when a VariableDeclaration is a super initializing formal
Tested: Existing tests.
Change-Id: I3d5ccba75c346c7e0cf743b3c2d151428a6bca80
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399662
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-12-10 13:59:10 +00:00
Jens Johansen bce3dd4fe7 [CFE/shared] Make formatting more consistent by specifying DartFormatter.latestShortStyleLanguageVersion
Autogenerated files was formatted with the new style, so if one for
instance formatted the file via the IDE or by saying
`out/ReleaseX64/dart-sdk/bin/dart format pkg/front_end/lib/` we'd get
*a lot* of changes which isn't great.
This CL sets the formatter version for the auto-generated files,
hopefully avoiding such things.

Change-Id: I4f92aafde7c77e7c78179f78bf821979a25ec12c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398884
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-12-05 08:50:30 +00:00
Jens Johansen 1674217277 [CFE] Do less duplicate calls
Change-Id: Ifb373449ed01b2aa66c6d0a71a5cf04bbf372690
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398401
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-12-03 11:28:00 +00:00