Commit Graph

3554 Commits

Author SHA1 Message Date
Ömer Ağacan 91374ffb12 [dart2wasm] Minify more errors
Transform front-end generated `throw` expressions (as indicated by the
kernel node's `forErrorHandling` flag) to error throwing functions that,
in minify mode, throw without details.

ACX demo sizes: (`-O2 --minify`)

- Before: 12,841,863 bytes
- After: 12,396,399 bytes
- Diff: -445,464 bytes, -3.46%

Issue: https://github.com/dart-lang/sdk/issues/60432
Change-Id: I3c0bfebd5a9cb460af312dafb63b5a0c9aeda22e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430380
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2025-05-23 03:31:36 -07:00
Johnni Winther 2b492a8d24 [cfe] Add UriOffsetLength
This adds a UriOffsetLength that passes uri, offset and length of a source locations. This is used to support
field/getter/setterUriOffset to prepare for getter/setter and final
field/setter pairs to be contained in the same builder object, while
still allowing messaging to point to the specific aspect.

UriOffsetLength is furthermore used on ClassMember which improves the
precision of messages from hierarchy checks.

Change-Id: I0776c8b66177164e326d3fb61e32a7620955f4c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429961
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-05-22 01:52:32 -07:00
Stephen Adams a2312f4776 [js_interop] Use stub for dart2js only when method has annotations
In order to support dart2js pragma annotations on external js_interop
methods, add the ability to generate stubs for getters, setters and
methods. Create stubs for dart2js only when the method has annotations.
Methods can only be handled by stubs when there are a fixed number of
positional arguments,

Move from using a `builder` to using a slightly more general
'treatement' that can also replace the Procedure's function body.

Issue: #60746
Change-Id: I7482f09d430448001d712dd4645d23f78910920d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429203
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2025-05-20 09:34:52 -07:00
Chloe Stefantsova ca694e46c1 [model] Remove nullability-related error messages in map literals
This is a follow-up to
https://dart-review.googlesource.com/c/sdk/+/428980

Change-Id: I7b6b3e2cc920f29b4ce4f409615efb7a858e9fe4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429360
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-05-19 05:06:42 -07:00
Chloe Stefantsova 617d0a8e96 [model] Remove more nullability-related assignability error messages
This is a preparation for removing the subtype checking procedure that
ignores the nullability in the input types.

Change-Id: I3c1db55abde0433e9059d949f1c98aaeb61e210c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428980
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-05-19 00:18:57 -07:00
Johnni Winther d56cabaf1f [cfe] Remove member/constructor iterators from NameSpace
This remove the iterators from the NameSpace interface and instead
collects the list of builders belonging to a library or declaration
directly inside these builders.

Adds ComputedNameSpace for import, export and prefix name spaces. This
allows for replacing a member and has a filteredIterator function. These name spaces are computed from import/exports and therefore need to be iterated through directly and replace builder when two builders collide.

Change-Id: Iec974656c5331498aa1cfca7973300ac6e044994
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428820
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2025-05-16 05:07:01 -07:00
Chloe Stefantsova bd92c25d53 [model] Remove nullability messaging in subtyping error messages
The subtype checking mode that ignores the nullability and is enabling
the nullability-related messaging is to be removed. This CL cleans up
the test expectations for that change.

Change-Id: I39e1fbf40192d1434b87e38cbe00eb68a965f0df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428782
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-05-16 00:58:00 -07:00
Johnni Winther 5087b62279 [cfe] Check NameSpace.addLocalMember
This adds assertions to NameSpaceImpl.addLocalMember to ensure that the name space entries are not overwritten unexpectedly.

The computations of library and declaration name spaces from dill are changed to exclude private members from other libraries which might otherwise replace exiting members.

To support private class members inherited from other libraries as
of the member hierarchy computation, the member builders in a dill
class builder are kept separately from the name space.

Change-Id: Ib6b24e539a838093a3a5a2abfc056dfc3883903c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427701
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2025-05-15 01:53:13 -07:00
Kallen Tu ecc6b93abd [cfe/analyzer] Dot shorthands: Abstract constructors can't be instantiated or torn off.
Adding a few errors on when we instantiate or tear off abstract constructors. Should be parallel to how we currently check for these errors in the CFE and analyzer.

Follow up to https://dart-review.googlesource.com/c/sdk/+/426682

Language test added, co19 test passing, and unit tests added.

Bug: https://github.com/dart-lang/sdk/issues/59758, https://github.com/dart-lang/sdk/issues/59835
Change-Id: I9b34e5f960856ce50aa969ca27e56907ae3a2a8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428201
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2025-05-13 10:10:51 -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
Johnni Winther 2455ace91b Revert "[model] Update handling of ?.length in constants"
This reverts commit b5e1ef4e14.

Reason for revert: Analyzer didn't report an error in all cases, so this is a breaking change.

Original change's description:
> [model] Update handling of ?.length in constants
>
> This adds reporting of an error in CFE for ?.length in constant expressions and improves the message for the analyzer in the same case. The error in the analyzer was previously the invalid claim that
>
>     The property 'length' can't be accessed on the type 'Null' in a constant expression.
>
> Closes #60509
>
> Change-Id: Ibbe0fa1ace3bea9d83efea2ccf3ea9716a125d74
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421841
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
> Commit-Queue: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>

Change-Id: I1bbe77b7abed5603dc062a235463bb4e0e755f23
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426860
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-05-07 05:16:59 -07:00
Johnni Winther 5874ba32e9 [cfe] Unify getter/setter/field references
This unifies the handling of getter/setter/field references into one object. The references for internal parts of the late lowering are removed. These are not need because the member are never accessed from outside the library and all uses are therefore created together with the reference objects.

Change-Id: I9a18d9f18fa379ee73a74ebadebd473dcb1649aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426800
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2025-05-06 01:47:40 -07:00
Johnni Winther b5e1ef4e14 [model] Update handling of ?.length in constants
This adds reporting of an error in CFE for ?.length in constant expressions and improves the message for the analyzer in the same case. The error in the analyzer was previously the invalid claim that

    The property 'length' can't be accessed on the type 'Null' in a constant expression.

Closes #60509

Change-Id: Ibbe0fa1ace3bea9d83efea2ccf3ea9716a125d74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421841
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-05-05 01:10:33 -07:00
Johnni Winther a077989c9d [cfe] Return LookupResult from NameSpace.lookupLocalMember
This prepares for having getters and setters in the same builder.

Change-Id: If800e7cccf1e71dbb7bca628a91a6ab48d8737c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426162
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2025-05-05 00:46:15 -07:00
Chloe Stefantsova 82960603a1 [model] Check setters of late lower fields in overrides
This CL includes the setters induced by late lower fields into the
override checks. Due to this change the erroneous overrides will be
marked as such.

Change-Id: Ie1ca9e6ab7e55c076c713b55dc85c6284af45ffe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426100
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-05-02 03:42:13 -07:00
Chloe Stefantsova 01d42a9357 [model] Only infer first required positional parameter in setters
This CL makes sure that only the first required positional parameter
is inferred in setters. Optional positional and named parameters,
which are erroneous in the case of setters, aren't inferred. That
prevents reporting of some cascading errors.

Change-Id: If89628adf542a325aa7320557c131abb7987a687
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426040
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-05-02 01:02:50 -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
Johnni Winther 7850078ce7 [cfe] Implement getter/setter aspect of fields through Getter/SetterDeclaration
This removes the parts of the FieldDeclaration interface dealing with the getter/setter aspects and instead uses the Getter/SetterDeclaration interfaces.

Change-Id: Ia807c085536c3132527d82491b17b796dfd745bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425521
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-04-30 06:05:17 -07:00
Johnni Winther f867dc7600 [cfe] Don't create ClassMember for internal implementation
Internal implementation members, like those used for the late lowering, are not real instance members on should not be part of the hierarchy member computation. These members are only called directly from within the members for which these are generated, so we don't need to add forwarders and stubs to handle calls from the outside.

Closes #49339

Change-Id: I4d87477243d4e015265c7bb200e1fb5431ae21f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424943
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-04-30 03:42:10 -07:00
Chloe Stefantsova f749040450 [model] Keep Let expressions intact in the verifier
Prior to this CL the CFE verifier would update the type of the
variable in Let expressions from `dynamic` to the computed static type
of the initializer. This CL removes the type update, making the
.expect files reflect the CFE output more accurately. Additionally, a
verification check is added to make sure the static type of the
initializer is assignable to the type of the Let variable.

Change-Id: I0b7b8f175bcb319678c323eb6440d93f1f384a85
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425500
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-04-30 03:25:50 -07:00
Johnni Winther 3c2f59da47 [cfe] Improve predicate helper for extension (type) members
This adds support for computing the qualified name for all extension and extension type members.

The `lowering_predicates_test.dart` is removed and testing is performed through `predicate_test.dart`.

Change-Id: I334bb85d48b6b1fd8fa01de6576f61168b3e96fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424443
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-04-29 03:22:54 -07:00
Chloe Stefantsova 496db5d366 [model] Mark constructors not initializing final fields as erroneous
Change-Id: I2f464ee708396cb916e420f0985cd39ca0bfe2f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424980
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-04-29 01:26:44 -07:00
Johnni Winther 7b10dc60ad [cfe] Use fileUri to determine when to create a FileUriExpression
This adds a fileUri property to MetadataBuilder and passes the fileUri of the annotated node

Change-Id: I8772ce012dc0c6f33be1f2a67e78ab6c34222405
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424941
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2025-04-28 04:31:32 -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
Alexander Markov 1c429e9f36 [dynamic modules] Add dart:core to dynamic interface by default
In order to simplify creating dynamic interface yaml files,
the following is added to dynamic interface by default:

callable: dart:core, pragma._
extendable: Object

TEST=pkg/dynamic_modules/test

CoreLibraryReviewExempt: no API changes, only adding pragmas
Change-Id: I925532c4c024ebbcf4972b00be0e0a080d5878fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422024
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-04-25 08:09:59 -07:00
Alexander Markov f75a80392e [dynamic modules] Fix dynamic interface validation of extension types
Instead of validating the erasure of an extension type,
validate that extension type declaration and type arguments
are specified as callable.

TEST=pkg/dynamic_modules/test/data/extension_type2

Fixes b/411433443

Change-Id: I063f0a622abd0d75594c4095573b29a7888f5afb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423882
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-04-24 07:58:33 -07:00
Johnni Winther 55dc02c2b1 [cfe] Remove Builder.isAugment
Change-Id: Idb8d5bb93d4cf8ae46d1d8d975a6c4987cd9b331
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424041
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-04-24 00:29:01 -07:00
Johnni Winther 5e6f501da5 [cfe] Clean up Builder properties
This cleans up and removes a lot of Builder properties in order to prepare for fields, getters and setters sharing the same PropertyBuilder object.

The PropertyBuilder interface is extended with field, getter and setter quality aspect to encode the various ways these can be declared.

Change-Id: I778ac9f2f8c288010beb00bea2525b89685a9df4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424060
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2025-04-24 00:29:01 -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
Ivan Inozemtsev 09f467b557 Update prebuilt Dart SDK to 3.9.0-3.0.dev
Revert changes to experimental_features.yaml.

Change-Id: Ic0ee592d8ceb72cf9c450b8bb898e01e93e6dbdb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421840
Commit-Queue: Alexander Thomas <athom@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Auto-Submit: Ivan Inozemtsev <iinozemtsev@google.com>
2025-04-10 09:50:11 -07:00
Johnni Winther a3953f12c7 [cfe] Include Procedure.isSynthetic in ast-to-text
In preparation for fixing #60490

TEST=existing

Change-Id: Iad3448a30de91e62f0d60bbaa9c425bc4706c799
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421100
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-04-10 00:59:49 -07:00
Johnni Winther b817b1b24e [cfe] Add test for exhaustiveness of != null
Change-Id: I04a34cf6f806a634a2290d8d3c68bbb724b7ebcc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421183
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-04-10 00:52:31 -07:00
Stephen Adams 3bedcdf1cf [js_interop] Use synthesized getter for static getters
The advantages of this approach:

- Annotations on the original getter are preserved, allowing any dart2js `@pragma` to be honored.
- An optimizing compiler (or user via a pragma) can decide to inline or not inline the getter, giving more control over code size.

Change-Id: I719b41640b75634fe00f6b87f95ebca1801cd159
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418880
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2025-04-09 13:36:34 -07:00
Ivan Inozemtsev 24120c84d0 [release] Bump version on main to 3.9
Change-Id: Id694e90aad9e0ca50e4e09e40c2795f210c60e3d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419700
Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Auto-Submit: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2025-04-08 11:16:58 -07:00
Johnni Winther 0dde212150 [cfe] Add LookupResult
This replaces the individual lookups of getables and setables in LookupScope and NameSpace with single lookup that returns a LookupResult holding both the getable and the setable. This prepares for having getter/setter pairs in the same SourcePropertyBuilder and avoids the need for AccessErrorBuilder for handling lookups of getters where only setters exist and vice versa.

Change-Id: I2b1e2477ed43506d9f94c48acd4b44277b490540
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420080
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-04-08 03:49:31 -07:00
Kallen Tu d3a0c152e4 [cfe] Dot Shorthands: Handle constructor tearoffs.
This CL adds support for constructor tearoffs in dot shorthands. If there's any type parameters on the tearoff and it's a constructor, we produce an error.

I also updated the expectations of existing tests due to an early return of `InvalidExpression`s and added language + cfe tests for the new behavior.

This CL fixes the following co19 tests and is a follow up to https://github.com/dart-lang/co19/issues/3122
co19/LanguageFeatures/Static-access-shorthand/constant_expression_A03_t01
co19/LanguageFeatures/Static-access-shorthand/constant_expression_A04_t01
co19/LanguageFeatures/Static-access-shorthand/semantics_A05_t01
co19/LanguageFeatures/Static-access-shorthand/constant_expression_A03_t02

Bug: https://github.com/dart-lang/sdk/issues/59758, https://github.com/dart-lang/co19/issues/3122
Change-Id: I1ea837342ad818cd3b1de9e422065f42e8a61d6b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419782
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2025-04-04 15:29:09 -07:00
Kallen Tu 59acc56966 [cfe] Dot shorthands: Static invocations are inferred.
Similar to constructor invocations, we infer the type parameters for the dot shorthand static member that we find.

Added language + cfe tests for this case.

This CL is a follow up to: https://dart-review.googlesource.com/c/sdk/+/417960/comment/90f32aed_8d1f6c01/

Bug: https://github.com/dart-lang/sdk/issues/59758
Change-Id: I96666ba9faa6ffaf42bd46e4d39175b88f7a353d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420283
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2025-04-04 10:47:39 -07:00
Chloe Stefantsova 001e0e6397 [model] Make null-guarded lowerings of cascades type safe
Change-Id: I035380abdb951a48110029ae93f965ad8bf83093
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420100
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-04-03 08:47:13 -07:00
Johnni Winther dced5e0482 [cfe] Add LocalTypeParameterScope
This cleans up the LocalScope interface and the handling of named function expressions.

Change-Id: Id0432910a9e65d8ae966dfab67c66248639d241a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419842
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-04-03 03:43:30 -07:00
Kallen Tu a94645962e [cfe] Dot shorthands: Constructor type parameters are inferred in the empty context.
Fixes https://github.com/dart-lang/co19/blob/master/LanguageFeatures/Static-access-shorthand/type_inference_A07_t01.dart and https://github.com/dart-lang/co19/blob/master/LanguageFeatures/Static-access-shorthand/type_inference_A07_t02.dart.

This CL changes the following behaviour according to the spec -- In case of a constructor invocation, the shorthand expression is inferred in the empty context.

Bug: https://github.com/dart-lang/sdk/issues/59758
Change-Id: Ia849888f1a810df7390a35e454a09f3fed458849
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417960
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2025-04-02 12:44:23 -07:00
Kallen Tu af51a0210b [cfe] Disallow '.new<int>' and type parameters on constructors for dot shorthands.
Adds errors for this part of the spec behaviour: `.new<typeArgs> and .new<typeArgs>(args) will always be compile-time errors because .new denotes a constructor which is not generic`

Bug: https://github.com/dart-lang/sdk/issues/59758
Change-Id: I76074d2314f40f60015324d4b01ece7477a8ffb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417880
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2025-03-27 12:15:57 -07:00
Kallen Tu 1d99738b04 [cfe] Add support for 'call()' methods in dot shorthands.
Any dot shorthand code in the form of `.id()` where `id` is a field or getter should resolve to the `call` method in the declaration of the type of `id`.

Normal static invocations already do this, and this CL adds the extra bit of `call()` resolution to the dot shorthands feature.

Bug: https://github.com/dart-lang/sdk/issues/59758
Change-Id: Ie8a22f251c3c80443e27d9fb307e7ef6b495315e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418141
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-03-27 09:05:46 -07:00
Johnni Winther 6526b26ddb [cfe] Convert extension_test into expectation tests
With the Builder model refactoring this test made less and less sense on its own. Removing the test enables the removal for properties that don't fit well with the new Builder model. The existing tests have been converted to expectation tests to preserve test coverage.

Change-Id: I0234a110321187870ad969236f58aae634f614cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418022
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2025-03-27 02:41:25 -07:00
Johnni Winther 60ea089c87 [cfe] Handle patch type parameters through fragments
Change-Id: I53bcab1b460737d756e9291ff7b3029c281ebb3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417742
Reviewed-by: Jens Johansen <jensj@google.com>
2025-03-26 01:41:15 -07:00
Kallen Tu ab778ef480 [cfe] Dot shorthands - Errors for invocations.
Adds `DotShorthandsUndefinedInvocation` error to handle unresolved method or constructor invocations.

Updates test expectations.

Bug: https://github.com/dart-lang/sdk/issues/59758
Change-Id: I004f989e2d6f460892964106ad72861fd3e49a5c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417084
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-03-25 08:28:24 -07:00
Kallen Tu caa192d24c [cfe] Dot Shorthands - Errors for getters and fields.
This CL adds two errors - 1 for having an invalid context type for resolving a dot shorthand and 1 for not finding a static getter/field in the declaration provided.

Bug: https://github.com/dart-lang/sdk/issues/59758
Change-Id: I9cc473adf82ca1f74f2370136ac8eec5e97fb23e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416881
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2025-03-25 07:29:02 -07:00
Sigurd Meldgaard 2fe05bd568 Reland "Migrate to use pub workspace"
This is a reland of commit b9b77058a9

Original change's description:
> Migrate to use pub workspace
>
> Use `pub get` to generate `.dart_tool/package_config.json` on gclient sync.
>
> All pkg/ (and a few third_party) packages that are developed inside the sdk repo are included in the workspace from the root `pubspec.yaml`.
>
> All dependencies that are pulled in via DEPS are added as path dependencies via `dependency_overrides` in the root `pubspec.yaml`.
>
> Bug: https://github.com/dart-lang/sdk/issues/56220
> Change-Id: I38c12b608c68da54c57821116cf9aa6696936746
> Tested: relies on CQ of existing tests. Should have no effect on functionality
> CoreLibraryReviewExempt: only core library change is adding a `// ignore:` comment. Should have no influence on functionality
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397164
> Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
> Reviewed-by: Alexander Thomas <athom@google.com>

Bug: https://github.com/dart-lang/sdk/issues/56220
Change-Id: I29afabade2d2447dea05121cb87ff50bb21a4b76
Cq-Include-Trybots: luci.dart.try:flutter-linux-try,flutter-web-try
Tested: relies on CQ of existing tests. Should have no effect on functionality
CoreLibraryReviewExempt: only core library change is adding a `//
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415561
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2025-03-20 06:19:16 -07:00
Johnni Winther 4aa7c8bca2 [cfe] Handle getter/setter patches through fragments
Change-Id: I93288a5518f2396df9783d45e9ebfadd80aaac51
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416600
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-03-20 03:43:08 -07:00
Jens Johansen 5ba5934201 [scanner] Specialized scanner recovery for missing end curly brace
*TL;DR*

This improves scanner recovery for a missing `}` in certain situations,
reducing the risk of an in-body change causing a (temporary) outline
change (which in turn could result in the analyzer becoming unresponsive
for "no reason").

*Details*

The behavior of IntelliJ is that when typing `{` it only inserts a
matching end brace `}` when hitting enter.

Imagine you are typing an if: `if (1 + 1 == 2) {`, where you don't hit
enter quickly enough and you trigger a re-analysis at this point.

What happens then is that every method below where you are typing looks
to be local function declarations and thus the outline change. When the
outline change the analyzer has to do a lot of work: everything
(transitively) depending on the file has to be recompiled, and every
strongly connected component is compiled "in one go" where the analyzer
can't respond to queries. So if you have one or more large strongly
connected components depending on the file, or the file itself is part
of such a chain, you will (or at least might) experience that the
analyzer is slow to respond, and it will be extra puzzling because
logically you're just doing an in-body change.

For some code the user might not even naturally hit enter, e.g. `var foo
= {"I'm", "a", "set"};`.

The recovery in the scanner has always been that - upon reaching the end
of the file - it sees that we're missing a `}` and it inserts it at the
end. This CL instead tries to figure out a better place to insert it,
and if successful, will rerun the scanner, instructing it to insert it
at the better place and (hopefully) avoiding a subsequent outline
change.

It does this by looking at the indentation - which is new for recovery -
and under the assumption that the indentation was correct before, will
find the position where the start curly brace was inserted. Note that if
it finds a position it will always be between the start curly brace (the
one missing the end curly brace) and the end of file, and inserting the
missing curly end brace there can't really be "more wrong" than
inserting it at the end (if the new place is not correct it's just
"still wrong").

In the benchmark added we see how quickly we can get completion after
having typed `if (1+1==2) {`, then adding `\n ge\n}` and requesting
completion on the `ge` part, i.e. a simulation of typing

```
if (1+1==2) {
  ge
}
```

and asking for completion at the `ge`.

The change in this CL - on cycles of size 1024 - caused the time to
completion response to come in between ~5 times faster (going from ~10.2
to ~2.1 seconds) to ~18 times faster (going from ~10.3 seconds to ~0.56
seconds):

`CodeType.ImportExportCycle` goes from:

```
+------+-----------+------------+
| Size |  Initial  | Completion |
+------+-----------+------------+
|   16 |  2.019581 |    0.97504 |
|   32 |  3.028976 |   1.031008 |
|   64 |  4.422884 |   1.198383 |
|  128 |  7.612125 |   1.597091 |
|  256 | 12.860864 |   2.906553 |
|  512 | 24.391894 |   5.017093 |
| 1024 | 48.390993 |  10.243085 |
+------+-----------+------------+
```

to

```
+------+-----------+------------+
| Size |  Initial  | Completion |
+------+-----------+------------+
|   16 |  2.107213 |   0.661066 |
|   32 |  3.012952 |    0.70554 |
|   64 |  4.682508 |   0.731176 |
|  128 |  7.508434 |   0.745501 |
|  256 | 13.105477 |   0.852413 |
|  512 | 24.520184 |   1.278403 |
| 1024 | 48.804348 |    2.11903 |
+------+-----------+------------+
```

and `CodeType.ImportExportChain` goes from:

```
+------+-----------+------------+
| Size |  Initial  | Completion |
+------+-----------+------------+
|   16 |  2.059196 |   0.892082 |
|   32 |  3.080717 |    0.93232 |
|   64 |  4.647163 |   1.240303 |
|  128 |  7.377035 |   1.674859 |
|  256 | 12.939432 |   2.705483 |
|  512 | 24.529501 |    5.02689 |
| 1024 | 47.713553 |  10.385469 |
+------+-----------+------------+
```

to

```
+------+-----------+------------+
| Size |  Initial  | Completion |
+------+-----------+------------+
|   16 |  2.020809 |   0.709643 |
|   32 |  3.106856 |   0.648818 |
|   64 |  4.503067 |   0.593152 |
|  128 |   7.45692 |   0.622423 |
|  256 | 13.140592 |   0.606948 |
|  512 | 24.933216 |   0.612687 |
| 1024 | 50.167541 |   0.567544 |
+------+-----------+------------+
```

Change-Id: I8dbefe215162d00a209206ae3db83b2b17505853
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415581
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2025-03-20 01:58:45 -07:00
Kallen Tu 9b116d047b [cfe] Dot shorthands - Const constructors
Parse and build dot shorthand invocations that are constant.
Added a new listener to handle and store the const-ness. It didn't feel right re-using any of the other `beginConstPattern` methods.

Added an error message if invoking a non-const constructor where we expected a const constructor.

Bug: https://github.com/dart-lang/sdk/issues/59758
Change-Id: I8551e3b8f71e89a69d090510bb64694d5e09247d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414660
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2025-03-19 08:52:23 -07:00