Commit Graph

2055 Commits

Author SHA1 Message Date
Paul Berry 0850220ad5 Fix unreachable switch cases in standard_bounds.dart.
I'm currently working on a fix for
https://github.com/dart-lang/sdk/issues/56710 (Analyzer fails to
report UNREACHABLE_SWITCH_CASE when there is a when clause). In order
to avoid spurious warnings when I land the fix, I first need to fix
any existing locations in the SDK that would cause the warning to
fire.

One such place is in the `standard_bounds.dart` file.

Bug: https://github.com/dart-lang/sdk/issues/56710
Change-Id: Icc917c3289b76760d29b6d7386a3794030274807
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384861
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-09-12 12:31:49 +00:00
Chloe Stefantsova b6b375b2cb [cfe] Adjust type schema closures in UP and DOWN as per spec
See breaking change request
https://github.com/dart-lang/sdk/issues/56466

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

Change-Id: I7b04821da92b8b41cb8610e701fa7e7905ff2487
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375121
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-09-02 11:47:49 +00:00
Jens Johansen 0329ebfd99 [CFE et al] Lint for fields with StackTrace.current
This CL primarily adds a lint for fields with `StackTrace.current`
which is often useful for debugging, but shouldn't be left in.

* Add an ast visitor after the "explicit creation test",
  finding - for now - `StackTrace.current` calls in fields.
  This should have caught the left-in debug such in
  https://dart-review.googlesource.com/c/sdk/+/379281.
* Renamed explicit_creation to compile_and_lint
* Remove (for some time) unused "smoke_test_quick" files.
* Add kernel to the compile_and_lint suite, but ignore it for explicit
  creation (i.e. kernel will also be checked for fields
  with `StackTrace.current`).

Change-Id: Ib886d23a8945e7063dc673a7f99cbb3a6adc1139
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382361
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-08-28 09:46:08 +00:00
Chloe Stefantsova c9d7e3a4f3 [cfe] Use exhaustive switch in MORETOP and MOREBOTTOM
Change-Id: I9d0197fa0a51bd8a72cb8207f159ceff7076c3e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382161
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-08-26 12:36:48 +00:00
Chloe Stefantsova a02427fdf7 [cfe] Use exhaustive switch in isSubtypeOf
This CL uses exhaustive switch statement instead of chained if
statements in the implementation of isSubtypeOf. In addition to that,
all of the individual methods for computing isSubtypeOf for specific
pairs of DartTypes are inlined into the switch statement.

Change-Id: I425e8d415d07767313c6f1ff796f7715e35f10bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382000
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-08-26 06:11:21 +00:00
Chloe Stefantsova 3acd125e44 [analyzer][cfe] Implement types and type schemas as extension types
This CL removes Type and TypeSchema type variables from the abstract
classes with shared code between the CFE and the analyzer. Extension
types SharedTypeView and SharedTypeSchemaView are declared to replace
the type variables.

The update propagates the discipline of distinguishing between types
and type schemas into the clients of the shared code. Now the code in
the CFE and the Analyzer that uses the shared code needs to statically
specify the interpretation of their type objects as either types or
type schemas.

Another benefit of the update is SharedTypeView and
SharedTypeSchemaView being less opaque than the Type and TypeSchema
type variables, which removes the necessity for some code duplication
in abstract methods for types and type schemas.

Finally, the update enables some further changes in the shared code
between the Analyzer and the CFE.

Change-Id: I88e8cfcd47d4f721974b4f2612521e85bb54c30f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379302
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-08-23 08:10:09 +00:00
Chloe Stefantsova 531e4ca0ec [cfe] Provide a helper for computing interface member signature type
Change-Id: Iefad05b1a5e9b6f93f821ad29635af31e6c8926e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381642
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-08-22 15:55:39 +00:00
Johnni Winther 7e2aecb58e [cfe] Compute type variable nullability
This adds an explicit computation for the nullability of type variables
while taking cyclic dependencies into account. This removes the need
for post-processing of pending nullabilities.

Change-Id: Ic7c42eef8270610d3b4f1d27ea0067c80df88daa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381242
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-08-22 08:23:05 +00:00
Paul Berry 4f2a0e97ba Remove unreachable default clauses from type_checker.dart.
I'm currently working on a fix to the analyzer that will cause
unreachable default clauses to be properly flagged as a warning
(https://github.com/dart-lang/sdk/issues/54575). To avoid a bot
failure when the fix lands, these unreachable default clauses need to
be removed.

Bug: https://github.com/dart-lang/sdk/issues/54575
Change-Id: If97416de0f13bc66cf60a1da7df295838a8d18a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380962
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-08-19 14:17:08 +00:00
Chloe Stefantsova b9eefd2861 [cfe] Use exhaustiveness in the implementation of DOWN
Using exhaustive switch over type pairs ensures all combinations are
handled.

This is a follow-up to:
https://dart-review.googlesource.com/c/sdk/+/379800

Change-Id: I55c8f8bca70301c331898c259a7988eb2911b045
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381180
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-08-19 12:00:29 +00:00
Chloe Stefantsova 15b467f94e [cfe] Use exhaustiveness in the implementation of UP
Using exhaustive switch over type pairs ensures all combinations are
handled.

This is a follow-up to:
https://dart-review.googlesource.com/c/sdk/+/379800

Change-Id: Ia6c4279a42590b439388d9fdd8ec5a8c36dbe23a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380560
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-08-15 10:52:13 +00:00
Alexander Markov 531a4c8f62 Expose experimental dynamic modules API through package:dynamic_modules
Change-Id: I14963de5f6face564276955d21d63f4b038cf990
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378722
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-08-12 17:56:29 +00:00
Chloe Stefantsova 0d679017e1 [cfe] Handle StructuralParamtersType in UP
Closes https://github.com/dart-lang/sdk/issues/56420

Change-Id: I49104e0d021a7d85b458c7b74d6a9445710743e6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379800
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-08-09 14:00:39 +00:00
Chloe Stefantsova cf0e927a43 [analyzer][cfe] Make SharedType into a family of recursive types
SharedType and its subtypes now all declare one recursive type
variable Type with the bound SharedType<Type>. It allows to treate
SharedType and its subtypes as an abstract familty of types that has a
specific structure.

More specifically, the type variables Type and TypeSchema in the
abstract classes for shared algorithms between the Analyzer and the
CFE can now be defined recursively as extending SharedType<Type> and
SharedType<TypeSchema>, giving both types and type schemas the
structure of the family of types with the root at SharedType.

One of the benefits for that is that some abstract members become
unnecessary. For example, a type or type schema can now be tested for
having the shape of the type 'dynamic' with a direct is-check,
comparing them, correspondingly, with SharedType<Type> and
SharedType<TypeSchema>.

More importantly, having the family of recursive types lays the
foundation for further work on sharing the type structure between the
Analyzer and the CFE.

Change-Id: I67904f878668c035702092e8c21d3ce66f5ca469
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378700
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-08-09 07:10:42 +00:00
Stephen Adams e28c480e12 [dart2js] Use addUnused method for unused fields in proto shaker
The call to the new method has fewer arguments, which helps code size.

Change-Id: I50668e54bfba07ac34e8db99a748f7d83c6e5be4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378382
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-08-06 21:58:29 +00:00
Jens Johansen 9cfb44e053 [kernel] Introduce (and use) Substitution.fromSingleton
Turns out most things calling `Substitution.fromMap` first creates a map
of size 1, in which case a map doesn't seem like the right thing to use.

Also replace a few `growable: true` with `growable: false`.

When compiling the CFE with the CFE with an AOT snapshot, this CL:
instructions:u: -0.4582% +/- 0.0019% (-97936268.60 +/- 405215.88)

Change-Id: Ia1f5221cf84cd763139fcc5bd8518cbe7e575dfd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375503
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-07-31 06:34:17 +00:00
Alexander Markov 4e0b69fbd9 [vm/aot] Improve dynamic interface annotator
Dynamic interface annotator now automatically annotates classes and
members which are used implicitly:

* Targets of redirecting factories.
* Classes and members used in constants.
* Instance fields of classes used in instance constants or
  having a callable const constructor.
* Everything used in the bodies of extendable mixin declarations and
  mixin classes.
* Possible dispatch targets of instance calls
  (overrides/implementations).

Front-end server now also exposes '--dynamic-interface' option,
similar to gen_kernel tool.

Also, this change includes a couple of minor fixes:
* Typo in ast.dart.
* In the front-end server, additional dill file specified with
  '--import-dill' option is not ignored when '--link-platform' is
  also used.

TEST=pkg/vm/testcases/transformations/dynamic_interface_annotator

Change-Id: I705b64efb1834dec6e0bdc5873025607f3472139
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377761
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-07-30 16:24:51 +00:00
Johnni Winther 69bc1e86fb [kernel] Remove Extension.isExtensionTypeDeclaration flag
This was only used for an early extension types experiment.

TEST=existing

Change-Id: Icb85c744bc2ff48aae713ef01271719d3657b664
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376940
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-07-22 14:42:13 +00:00
Johnni Winther c4368b3cd7 [cfe] Stop passing local scope on the stack
This a LocalStack extension type for using a list as a typed stack and
uses this for local scopes in the body builder, instead of passing the
local scopes through the listener stack.

This also removes the need for LocalScope.parent

TEST=existing

Change-Id: I536c63258e4196a1582e9a1d73489adcfdaa6698
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376400
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-07-19 14:41:26 +00:00
Jens Johansen 90e1205750 [kernel] Don't call Substitution.fromMap twice with the same data in getFreshStructuralParametersFromTypeParameters
When compiling the CFE with the CFE with an AOT snapshot, this CL:
instructions:u: -0.5575% +/- 0.0037% (-119851086.80 +/- 799956.68)

Though probably mostly because
Scavenge(   new space) goes from 62 to 61

Change-Id: Ida0a834d6da34c8e09f521df3ff1490c6b6a875b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375522
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-07-12 15:55:29 +00:00
Jens Johansen 164c10a150 [kernel] Remove unused mixinInferrer in ClassHierarchy
Change-Id: Ib18715586f34db92a0764cdb621cb791085a4c15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374560
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-07-08 09:40:49 +00:00
Jake Macdonald 87b790b6d0 Bump version to 3.6
Change-Id: I1d096140adb8c01914e0b9d1c7cb2017204e7f0a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373940
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Kevin Chisholm <kevinjchisholm@google.com>
Reviewed-by: Kevin Chisholm <kevinjchisholm@google.com>
2024-07-02 00:02:19 +00:00
Jens Johansen a8314dac74 [kernel] Fix crash in dart_scope_calculator when all scopes are artificial
Fixes https://github.com/dart-lang/sdk/issues/55986

Change-Id: Icc7e6dbb4272613e838b0bd2ef9ac4764dd068f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373200
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-06-26 08:23:59 +00:00
Kallen Tu 9ead08f053 [cfe] Local functions named _ are not in scope.
Local functions named `_` are treated the same as local wildcard variables.
They cannot be referred to.
This CL changes that behaviour.

Bug: https://github.com/dart-lang/sdk/issues/55655
Change-Id: Idbbe2a4f5b406d4499602e808f6541af6451fb31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371480
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-06-14 22:31:48 +00:00
Kallen Tu 141bb5417b [kernel] Add isWildcard flag to VariableDeclaration.
Adds the `isWildcard` flag to variables. Will be using this for producing better errors.

TEST= Existing expectations tests for wildcards pass with new flag.
Bug: https://github.com/dart-lang/sdk/issues/55655
Change-Id: If2f7a5555e7cc26e84d1b1e63e4261c81a157d78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370062
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-06-10 19:33:39 +00:00
Johnni Winther c5cd8ff349 [cfe] Remove agnostic mode
The agnostic mode was added to allow the platform dill embedded in
the VM to support both weak and strong mode. Since weak mode is no
longer supported in the VM, the agnostic mode can new be deleted.

All uses of the agnostic in Dart and Flutter have been removed prior
to this change.

Change-Id: Iff0f69d9cd64e887e01cd7e7d336a97761bd6d4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366801
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-06-06 11:02:37 +00:00
Johnni Winther b2517e934f [cfe] Remove Env.isNonNullableByDefault
+ a few other references of 'isNonNullableByDefault'

Change-Id: Ifcd6bf5c2cc5dbbca7dda1576248fc4cd59eed5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369023
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-06-03 06:42:54 +00:00
Johnni Winther e3efaf2b66 [cfe] Remove isNonNullable from type_algebra et al.
Change-Id: Idcb55bcbc2cf42f4a6f49fb0751f9883a47ff66b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369041
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-06-03 06:42:54 +00:00
Johnni Winther ce12e3c8ac [cfe] Remove isNonNullableByDefault from class hierarchy
Change-Id: Ib5942357578a6481e8038dd090e4a9d9ff49f831
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369022
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-06-03 06:42:54 +00:00
Paul Berry 547307e554 Add SharedType.nullabilitySuffix getter.
This allows TypeAnalyzerOperations.getNullabilitySuffix to be removed,
and allows shared code to access nullability suffixes directly as
properties of a type, in the same way that the analyzer does.

Change-Id: I33ab90798b779534b5b0b111ec5137845b32f23b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368443
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-05-30 16:43:29 +00:00
Paul Berry b4a4075d5d Remove isNonNullableByDefault parameter from isTypeWithoutNullabilityMarker.
There is no functional change, because all callers were passing `true`.

Change-Id: I59a70e16b543023ee84657cf4e0d7ef3e0d4de8e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367420
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-05-30 16:37:47 +00:00
Johnni Winther 1315b3ab72 [kernel] Remove isNonNullableByDefault from checkBounds and instantiateToBounds
Change-Id: Ie1faa72cd1d9eaae65e1fb2fd44bf7a70b94a025
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368641
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-05-30 13:51:46 +00:00
Paul Berry 5bb928002e Remove isNonNullableByDefault parameters from methods in StandardBounds.
There is no functional change, because all callers were passing `true`.

Change-Id: I304b0694946565bd765d3fd10fc2a77bda201117
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368501
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-05-30 13:21:18 +00:00
Johnni Winther 1b9ccb9b08 [cfe] Remove isNonNullableByDefault from TypeSchemaEnvironment
Change-Id: Ife1951833bf5e6f5146e33734ae3b0cd3805bdc7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368640
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-05-30 12:34:59 +00:00
Johnni Winther 5d8d7941ac [cfe] Remove unnecessary use of Nullability.legacy
TEST=existing

Change-Id: I53b749c53e5f742d778c07571aafb7aff6325c9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368560
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-05-30 08:10:29 +00:00
Jens Johansen 8e168fc9f1 [kernel] ast-to-text: Print uri in more places
Constructors (say from a macro), typedefs (maybe from a part) and
FileUriExpression in general didn't write their file uri when different
from their surrounding container.

Change-Id: I70dc8cbb525a6fc2c1949e0d1fb1726ac19c6505
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368566
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-05-30 07:22:38 +00:00
Jens Johansen 727796e692 [kernel] Fix uri on some constants
Change-Id: I8b23563df3765bb076c851179bdbb02ad70671bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368402
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-05-29 14:01:32 +00:00
Jens Johansen f22752f661 [kernel] Give better error message if crashing on .location
In for instance https://github.com/flutter/flutter/issues/148668 we
crash on .location, but don't have anything to go on about why that is.
This CL adds more information (e.g. the url, and - in the particular
crash - it would also have added the name of the procedure it got the
uri from).

If this will actually be enough (once a crash comes in with this info)
to fix the issue, I'm don't know, but it should give us more to go on.

Change-Id: Iceab6f7841380d59aa39f26a728fd8fcad90ffb6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368303
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-05-28 07:28:59 +00:00
Ömer Sinan Ağacan 6f10e620fa [cfe] Remove unused Target.extraDeclaredVariables method
Change-Id: I9bf04e657657173a8fbb31a2bd081c3de02a6ba6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367920
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-05-23 11:06:48 +00:00
Jens Johansen 1eaa749e0e [kernel/CFE] Remove unneeded default in switches
This CL removes the "default" case when the switch must be exhaustive
and is exhaustive without the default. Found by modifying the CFEs
constant evaluator.

Change-Id: Iaba27864315875257502be8e74fc2ce34f6ce54d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367900
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-05-23 09:32:49 +00:00
Paul Berry bd7ef48815 Change SharedRecordType abstract getters to return lists.
Previously these abstract getters were typed as returning
iterables. Although in principle, changing the return types to lists
constrains the implementations more, in practice it makes no
difference because the only implementations are in the CFE, analzyer,
and the mini_types shared tests, and those implementations already
return lists anyhow.

Changing the abstact getters to return lists will simplify future work
by allowing code that interacts with the base SharedRecordType class
to index into the lists rather than having to iterate through them.

Change-Id: Ia257400dbb7c89aabc468be15a939e6baa36e191
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367500
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-05-22 14:27:51 +00:00
Johnni Winther ae03b57cbb [cfe] Remove .isNonNullableByDefault from package:kernel
This removes the .isNonNullableByDefault properties and similar from
the AST nodes in package:kernel. NNBD is now always enabled so these
properties are trivial.

TEST=existing

Change-Id: I75ca0551ac4b5910ea63530dd0c9c2e68bd01aff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366320
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-05-15 08:31:38 +00:00
Ömer Sinan Ağacan 9f94984af2 [kernel] Clarify what TreeNode.fileOffset indexes, some rephrasing
- Rephrase AssertStatement offset documentations to be consistent with
  the TreeNode.fileOffset documentation.

- Use a noun phrase in `TreeNode.fileOffsetsIfMultiple`, as per
  Effective Dart recommendation.

Change-Id: If3f8acb47a96effbda2526819badb943b6e6062f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366360
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-05-14 15:06:25 +00:00
Paul Berry 0d8bb0e7e7 Share more analyzer/CFE code related to types.
This commit builds on the work done in
https://dart-review.googlesource.com/c/sdk/+/362481, which established
the framework for sharing a class hierarchy between the analyzer and
CFE to represent types.

This commit introduces the following new classes:

- `SharedDynamicType`, which represents the common interface between
  the `DynamicType` classes in the analyzer and the CFE.

- `SharedInvalidType`, which represents the common interface between
  the `InvalidType` classes in the analyzer and the CFE.

- `SharedVoidType`, which represents the common interface between the
  `VoidType` classes in the analyzer and the CFE.

This allows 3 methods to be removed from the
`FlowAnalysisTypeOperations` class:

- `isDynamic`, which is no longer needed becasue `is
  SharedDynamicType` can be used instead.

- `isError`, which is no longer needed because `is SharedInvalidType`
  can be used instead.

- `isVoid`, which is no longer needed because `is SharedVoidType` can
  be used instead.

In addition, `getDisplayString` is removed from the
`TypeAnalyzerOperations` class, and replaced with a `getDisplayString`
method in `SharedType`. This does not increase the API surface area of
the analyzer, because the analyzer already has a
`DartType.getDisplayString` method.

Change-Id: Ib8d9d3a7699f3d1e8b9612ca9c8f4134fa19de77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365303
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-05-03 12:22:13 +00:00
Paul Berry 0c7585c907 Start building a shared class hierarchy for types.
This commit introduces the following new classes:

- SharedType, which represents the common interface between the
  DartType classes in the analyzer and the CFE.

- SharedRecordType, which represents the common interface between the
  RecordType classes in the analyzer and the CFE.

- SharedNamedType, which represents the common interface between the
  analyzer and CFE representations of a name/type pair.

- SharedUnknownType, which represents the common interface between the
  analyzer and CFE representations of the unknown type (`_`).

This allowed three methods to be removed from the
`TypeAnalyzerOperations` class:

- `areStructurallyEqual`, which is replaced by
  `SharedType.isStructurallyEqualTo`.

- `asRecordType`, which is no longer needed because `is
  SharedRecordType` can be used instead.

- `isUnknownType`, which is no longer needed because `is
  SharedUnknownType` can be used instead.

And one method to be removed from the `FlowAnalysisTypeOperations`
class:

- `isSameType`, which is replaced by `operator ==`. (Technically this
  could have been done even without introducing a shared class
  hierarchy, since `operator ==` is defined in the shared base class
  `Object`).

The long term goal is to fill out the shared class hierarchy to cover
other kinds of types (interface types, function types, void, etc.),
and to move most of the shared logic from the analyzer and CFE
DartType class hierarchies into shared code. This should reduce the
risk of implementation skew between the analyzer and CFE, and to
streamline the implementation of future features. Additionally, the
hope is to eventually remove, or drastically simplify, classes like
`TypeAnalyzerOperations`, so that the code in `_fe_analyzer_shared`
can be written in simpler and more straightforward way.

Change-Id: I5d3a929057959f77ccff8dbed5671f9bca6259c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362481
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-05-01 16:41:47 +00:00
Chloe Stefantsova 54c9b37b8a [cfe] Implement full subtyping rules for extension types vs FutureOr
Closes https://github.com/dart-lang/sdk/issues/55578

Change-Id: Id344e9057f42b3fc19a6ff83ce000775aec5789a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364720
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-04-29 12:02:08 +00:00
Chloe Stefantsova 54031e2752 [cfe] Ensure default values in synthesized function nodes
Closes https://github.com/dart-lang/sdk/issues/55529

Change-Id: Ic4738e9b8abc333a39ec52b642bbf844128ef61b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364325
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Chloe Stefantsova <cstefantsova@google.com>
2024-04-26 14:06:30 +00:00
Alexander Markov c9e386fe16 [kernel] Cleanup legacy types from kernel type checker
Change-Id: Iea66efe173d0f342e4257fe1976f7baaf14ff524
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364523
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-04-26 13:52:00 +00:00
Jens Johansen a9f684e624 [CFE/kernel/VM] Fix for crash when compiling after a reject in face of unnamed extension
In https://dartbug.com/55357 a crash is reported happening after a hot
restart (not reload!) with a compilation error. This causes a "reject"
call, which means we create a new incremental compiler, initializing it
from the component of the previous good world.

World 1: Initial state.
World 2: The library is new, but (most) references are reused because
         of advanced invaidation. References of unnamed extensions are
         not reused. Instead the canonical names are unbound (so they
         can successfully be bound to the new reference).
         We now have:
           * ref1 (from world1) pointing to no canonical name.
           * ref2 (from world2) pointing to the canonical name.
           * The canonical name pointing to ref2.
         This world is rejected.
World 3: We start from the world 1 state, but because world 2 *did*
         happen and that only most references (i.e. not references for
         unnamed extensions) were reused, when about to unbind the
         unnamed extenesion we are looking at ref1 and have nothing
         to unbind.
         Compiling creates ref3 (from world 3).
         Upon attempt to serialize we try to bind the canonical name to
         "ref3", but it is already bound to "ref2" and we crash.

The main problem here is that not only `Reference`s are reused,
but because `Reference`s point to `CanonicalName`s these are reused too.

This CL clears the canonical name in the references in the libraries that are reused, meaning that a whole new canonical name tree for those
libraries will be created. This is more in line with what the
non-advanced-invalidation does (by it not reusing references and
naturally getting a whole new canonical name tree).
In my opinion it even makes more sense --- and the fact that the
canonical names were reused was probably more me not thinking about it,
than it was a deliberate design decision.

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

Change-Id: I90bd579984f4aefad78243e8366ac0ab91a905bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363563
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-04-22 14:08:20 +00:00
Chloe Stefantsova 8aa400bf5f [analyzer][cfe] Share the implementation of the Variance class
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: Ie406b59baf3efdeaac577f5181320b28c5076068
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361781
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-04-10 13:08:55 +00:00