Skip to content

Commit ca525fc

Browse files
authored
Merge branch 'master' into fix-c-type-doc-references
2 parents ed86425 + 19946f9 commit ca525fc

32 files changed

Lines changed: 350 additions & 448 deletions

‎DEPS‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ vars = {
5555
# updated revision list of existing dependencies. You will need to
5656
# gclient sync before and after update deps to ensure all deps are updated.
5757
# updated revision list of existing dependencies.
58-
'dart_revision': 'e2fcf6d538c8016561b2deb2e70573497f5d3af1',
58+
'dart_revision': '4c572fafd0565ed3bb31ee3b9c68870e3d05bb87',
5959

6060
# WARNING: DO NOT EDIT MANUALLY
6161
# The lines between blank lines above and below are generated by a script. See create_updated_flutter_deps.py
@@ -70,7 +70,7 @@ vars = {
7070
'dart_protobuf_rev': 'a73edc98c98fb25152aa3f12c1b9db91594c1369',
7171
'dart_pub_rev': '0382a52acba89ff0080d559bb22f4017962bbd1d',
7272
'dart_sync_http_rev': '6666fff944221891182e1f80bf56569338164d72',
73-
'dart_tools_rev': 'd22cfa54dc71cc9d9d38556e6e8c695741640113',
73+
'dart_tools_rev': '1b0c3bbacef984b9d8278eb5cf0f96a06c6f2850',
7474
'dart_vector_math_rev': 'cf3b5db7340d317dd3489e5a35434b408020a852',
7575
'dart_web_rev': 'e5c6c028da66688a2295557757850a1599ec392e',
7676
'dart_webdriver_rev': '8e5c611ea242efdc9f597a8a37c38a9c586120ee',
@@ -830,7 +830,7 @@ deps = {
830830
'packages': [
831831
{
832832
'package': 'fuchsia/sdk/core/linux-amd64',
833-
'version': 'zGeeR7JORNm-Un1vfYM7l_q7WlcrsIDjGGWBExsOLOkC'
833+
'version': 'uoIfEEWvgUEIbiXH_USmSJS2CxP-RJrNf0Fx2ub6YzMC'
834834
}
835835
],
836836
'condition': 'download_fuchsia_deps and not download_fuchsia_sdk',

‎dev/flutter_analyzer_plugin/README.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This plugin replaces legacy regex-based and manual AST scripts (previously locat
2626
- [`no_bad_imports_in_flutter`](#no_bad_imports_in_flutter)
2727
- [`protect_public_state_subtypes`](#protect_public_state_subtypes)
2828
- [`render_box_intrinsics`](#render_box_intrinsics)
29-
- [`null_initialized_debug_expensive_fields`](#null_initialized_debug_expensive_fields)
29+
- [`lazy_initialized_debug_expensive_fields`](#lazy_initialized_debug_expensive_fields)
3030
- [Testing Rules](#testing-rules)
3131
- [`skip_test_comments`](#skip_test_comments)
3232
- [`integration_test_timeouts`](#integration_test_timeouts)
@@ -103,7 +103,7 @@ The analyzer requires all `analysis_options.yaml` files referencing `flutter_ana
103103
| [`no_bad_imports_in_flutter`](#no_bad_imports_in_flutter) | `ERROR` | Enabled | `packages/flutter/lib/src/` | Enforce layer hierarchy, prevent cycles, and forbid meta imports outside foundation. |
104104
| [`protect_public_state_subtypes`](#protect_public_state_subtypes) | `ERROR` | Enabled | `packages/flutter` | Require `@protected` on overridden lifecycle methods in public `State` classes. |
105105
| [`render_box_intrinsics`](#render_box_intrinsics) | `ERROR` | Enabled | `packages/flutter/lib/src/rendering/` | Disallow calling `compute*` intrinsic methods directly (use `get*`). |
106-
| [`null_initialized_debug_expensive_fields`](#null_initialized_debug_expensive_fields) | `ERROR` | Enabled | `packages/flutter` | Require `@_debugOnly` fields to be conditionally initialized via `kDebugMode ? <value> : null;`. |
106+
| [`lazy_initialized_debug_expensive_fields`](#lazy_initialized_debug_expensive_fields) | `ERROR` | Enabled | `packages/flutter` | Require `@_debugOnly` fields to be lazy initialized (declared as `late final` with an initializer). |
107107
| [`skip_test_comments`](#skip_test_comments) | `ERROR` | Enabled | Test files | Require justification comments (e.g. `// [intended]` or issue link) for skipped tests. |
108108
| [`integration_test_timeouts`](#integration_test_timeouts) | `ERROR` | Enabled | `test_driver/` files | Require integration test files under `test_driver/` to set `timeout: Timeout.none`. |
109109

@@ -317,11 +317,11 @@ final double width = child.getMinIntrinsicWidth(height);
317317

318318
---
319319

320-
#### `null_initialized_debug_expensive_fields`
320+
#### `lazy_initialized_debug_expensive_fields`
321321
- **Severity**: `ERROR`
322322
- **Scope**: `packages/flutter`
323-
- **Description**: Requires all fields annotated with `@_debugOnly` to be conditionally initialized via `kDebugMode ? <value> : null;`.
324-
- **Rationale**: Expensive diagnostic objects and debug trackers must not allocate heap memory or execute costly initialization logic in profile and release builds. Initializing them with `kDebugMode ? <value> : null` enables the compiler and tree-shaker to eliminate both the field and its initializer in release builds.
323+
- **Description**: Requires all non-static fields annotated with `@_debugOnly` to be lazy initialized (declared as `late` with an initializer).
324+
- **Rationale**: Expensive debug fields must not allocate heap memory or execute costly initialization logic in profile and release builds. Declaring them as `late` ensures lazy evaluation on first read (which can happen only in `assert(...)` blocks).
325325

326326
```dart
327327
// BAD:
@@ -330,7 +330,7 @@ List<StackTrace> _creationStackTraces = <StackTrace>[];
330330
331331
// GOOD:
332332
@_debugOnly
333-
List<StackTrace>? _creationStackTraces = kDebugMode ? <StackTrace>[] : null;
333+
late List<StackTrace> _creationStackTraces = <StackTrace>[];
334334
```
335335

336336
---

‎dev/flutter_analyzer_plugin/lib/main.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import 'src/rules/deprecation_syntax.dart';
1010
import 'src/rules/golden_test_tags.dart';
1111
import 'src/rules/integration_test_timeouts.dart';
1212
import 'src/rules/issue_link_syntax.dart';
13+
import 'src/rules/lazy_initialized_debug_expensive_fields.dart';
1314
import 'src/rules/no_bad_imports_in_flutter.dart';
1415
import 'src/rules/no_double_clamp.dart';
1516
import 'src/rules/no_runtimetype_in_tostring.dart';
1617
import 'src/rules/no_stopwatches.dart';
1718
import 'src/rules/no_sync_async_star.dart';
1819
import 'src/rules/no_test_imports.dart';
19-
import 'src/rules/null_initialized_debug_expensive_fields.dart';
2020
import 'src/rules/protect_public_state_subtypes.dart';
2121
import 'src/rules/render_box_intrinsics.dart';
2222
import 'src/rules/repository_link_syntax.dart';
@@ -45,7 +45,7 @@ class FlutterAnalyzerPlugin extends Plugin {
4545
..registerLintRule(NoDoubleClamp())
4646
..registerLintRule(NoRuntimeTypeInToString())
4747
..registerLintRule(NoStopwatches())
48-
..registerLintRule(NullInitializedDebugExpensiveFields())
48+
..registerLintRule(LazyInitializedDebugExpensiveFields())
4949
..registerLintRule(ProtectPublicStateSubtypes())
5050
..registerLintRule(RenderBoxIntrinsicCalculationRule());
5151
}

dev/flutter_analyzer_plugin/lib/src/rules/null_initialized_debug_expensive_fields.dart renamed to dev/flutter_analyzer_plugin/lib/src/rules/lazy_initialized_debug_expensive_fields.dart

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ import 'package:analyzer/error/error.dart';
1111

1212
import '../flutter_analysis_rule.dart';
1313

14-
/// An analysis rule that verifies that debug expensive fields annotated with @_debugOnly are null initialized.
15-
class NullInitializedDebugExpensiveFields extends FlutterAnalysisRule {
16-
NullInitializedDebugExpensiveFields()
14+
/// An analysis rule that verifies that debug expensive fields annotated with @_debugOnly
15+
/// are lazily initialized (declared as a late or static field).
16+
class LazyInitializedDebugExpensiveFields extends FlutterAnalysisRule {
17+
LazyInitializedDebugExpensiveFields()
1718
: super(
1819
name: code.name,
19-
description: 'Verify that debug expensive fields are null initialized.',
20+
description: 'Verify that debug expensive fields are lazily initialized.',
2021
);
2122

2223
static const LintCode code = LintCode(
23-
'null_initialized_debug_expensive_fields',
24-
'Fields annotated with @_debugOnly must null initialize.',
25-
correctionMessage: 'Initialize with: field = kDebugMode ? <DebugValue> : null;',
24+
'lazy_initialized_debug_expensive_fields',
25+
'Non-static fields annotated with @_debugOnly must be lazily initialized.',
26+
correctionMessage: 'Declare with: @_debugOnly late final <Type> field = <DebugValue>;',
2627
severity: DiagnosticSeverity.ERROR,
2728
);
2829

@@ -47,32 +48,11 @@ class _Visitor extends SimpleAstVisitor<void> {
4748
final bool hasDebugOnly = node.metadata.any(
4849
(Annotation annotation) => annotation.name.name == '_debugOnly',
4950
);
50-
if (!hasDebugOnly) {
51-
return;
52-
}
53-
54-
for (final VariableDeclaration variable in node.fields.variables) {
55-
if (!_isCorrectInitializer(variable.initializer)) {
56-
rule.reportAtNode(variable);
57-
}
58-
}
59-
}
6051

61-
bool _isCorrectInitializer(Expression? initializer) {
62-
if (initializer case ConditionalExpression(
63-
:final Expression condition,
64-
elseExpression: NullLiteral(),
65-
)) {
66-
var unwrappedCondition = condition;
67-
while (unwrappedCondition is ParenthesizedExpression) {
68-
unwrappedCondition = unwrappedCondition.expression;
69-
}
70-
return switch (unwrappedCondition) {
71-
SimpleIdentifier(name: 'kDebugMode') => true,
72-
PrefixedIdentifier(identifier: SimpleIdentifier(name: 'kDebugMode')) => true,
73-
_ => false,
74-
};
52+
// A field is lazy when it's static or late.
53+
final bool eagerlyInitialized = hasDebugOnly && !(node.isStatic || node.fields.isLate);
54+
if (eagerlyInitialized) {
55+
rule.reportAtNode(node);
7556
}
76-
return false;
7757
}
7858
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:analyzer/src/lint/registry.dart';
6+
import 'package:analyzer_testing/analysis_rule/analysis_rule.dart';
7+
import 'package:analyzer_testing/src/analysis_rule/pub_package_resolution.dart';
8+
import 'package:flutter_analyzer_plugin/src/rules/lazy_initialized_debug_expensive_fields.dart';
9+
import 'package:test_reflective_loader/test_reflective_loader.dart';
10+
11+
@reflectiveTest
12+
class LazyInitializedDebugExpensiveFieldsTest extends AnalysisRuleTest {
13+
@override
14+
void setUp() {
15+
Registry.ruleRegistry.registerLintRule(LazyInitializedDebugExpensiveFields());
16+
super.setUp();
17+
}
18+
19+
@override
20+
String get analysisRule => LazyInitializedDebugExpensiveFields.code.name;
21+
22+
static const String source = '''
23+
class GoodClass {
24+
@_debugOnly
25+
late final int _foo = 1;
26+
}
27+
28+
class GoodClassStatic {
29+
@_debugOnly
30+
static int _foo = 1;
31+
}
32+
33+
class BadClass {
34+
@_debugOnly
35+
final int _foo = 1;
36+
}
37+
38+
const _debugOnly = Object();
39+
''';
40+
41+
// ignore: non_constant_identifier_names
42+
Future<void> test_lazy_initialized() async {
43+
await assertDiagnostics(source, <ExpectedDiagnostic>[lint(145, 33)]);
44+
}
45+
}
46+
47+
void main() {
48+
defineReflectiveSuite(() {
49+
defineReflectiveTests(LazyInitializedDebugExpensiveFieldsTest);
50+
});
51+
}

‎dev/flutter_analyzer_plugin/test/null_initialized_debug_expensive_fields_test.dart‎

Lines changed: 0 additions & 79 deletions
This file was deleted.

‎engine/src/flutter/ci/builders/mac_unopt.json‎

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -263,71 +263,6 @@
263263
}
264264
]
265265
},
266-
{
267-
"cas_archive": false,
268-
"properties": {
269-
"$flutter/osx_sdk": {
270-
"runtime_versions": [
271-
"ios-26-2_17c52"
272-
],
273-
"sdk_version": "17c52"
274-
}
275-
},
276-
"drone_dimensions": [
277-
"device_type=none",
278-
"os=Mac-15.7",
279-
"cpu=x86"
280-
],
281-
"gclient_variables": {
282-
"download_android_deps": false,
283-
"use_rbe": true
284-
},
285-
"gn": [
286-
"--ios",
287-
"--runtime-mode",
288-
"debug",
289-
"--simulator",
290-
"--no-lto",
291-
"--unoptimized",
292-
"--rbe",
293-
"--no-goma",
294-
"--xcode-symlinks",
295-
"--target-dir",
296-
"ci/ios_debug_unopt_sim"
297-
],
298-
"name": "ci/ios_debug_unopt_sim",
299-
"description": "Builds a debug mode engine for x64 iOS simulator. Runs unit tests and the scenario app tests.",
300-
"ninja": {
301-
"config": "ci/ios_debug_unopt_sim",
302-
"targets": [
303-
"flutter/testing/ios_scenario_app",
304-
"flutter/shell/platform/darwin/ios:ios_test_flutter"
305-
]
306-
},
307-
"tests": [
308-
{
309-
"language": "python3",
310-
"name": "Tests for ios_debug_unopt_sim",
311-
"script": "flutter/testing/run_tests.py",
312-
"parameters": [
313-
"--variant",
314-
"ci/ios_debug_unopt_sim",
315-
"--type",
316-
"objc",
317-
"--engine-capture-core-dump",
318-
"--ios-variant",
319-
"ci/ios_debug_unopt_sim"
320-
]
321-
},
322-
{
323-
"name": "Scenario App Integration Tests",
324-
"parameters": [
325-
"ci/ios_debug_unopt_sim"
326-
],
327-
"script": "flutter/testing/ios_scenario_app/run_ios_tests.sh"
328-
}
329-
]
330-
},
331266
{
332267
"cas_archive": false,
333268
"drone_dimensions": [

‎engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,17 +1024,23 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
10241024

10251025
final locales = <ui.Locale>[];
10261026
for (final String language in languages) {
1027-
final domLocale = DomLocale(language);
1028-
locales.add(
1029-
ui.Locale.fromSubtags(
1030-
languageCode: domLocale.language,
1031-
scriptCode: domLocale.script,
1032-
countryCode: domLocale.region,
1033-
),
1034-
);
1027+
try {
1028+
final domLocale = DomLocale(language);
1029+
locales.add(
1030+
ui.Locale.fromSubtags(
1031+
languageCode: domLocale.language,
1032+
scriptCode: domLocale.script,
1033+
countryCode: domLocale.region,
1034+
),
1035+
);
1036+
} catch (_) {
1037+
// Skip tags Intl.Locale rejects (e.g. en-US@posix on Linux).
1038+
}
10351039
}
10361040

1037-
assert(locales.isNotEmpty);
1041+
if (locales.isEmpty) {
1042+
return const <ui.Locale>[_defaultLocale];
1043+
}
10381044
return locales;
10391045
}
10401046

0 commit comments

Comments
 (0)