Skip to content

Commit ce9c581

Browse files
author
Anna Gringauze
authored
Validate only needed summaries in expression_compiler_service (#1920)
* Validate only needed summaries in expression_compiler_service * Make webdev tests use sound null safe fixtures * Updated changelog
1 parent a347fa0 commit ce9c581

File tree

6 files changed

+168
-2
lines changed

6 files changed

+168
-2
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Return error on expression evaluation if expression evaluator stopped.
2020
- Update SDK constraint to `>=3.0.0-134.0.dev <4.0.0`.
2121
- Update `package:vm_service` constraint to `>=10.1.0 <12.0.0`.
22+
- Fix expression compiler throwing when weak SDK summary is not found.
2223

2324
**Breaking changes**
2425
- Include an optional param to `Dwds.start` to indicate whether it is running

dwds/lib/src/services/expression_compiler_service.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ class _Compiler {
7171
List<String> experiments,
7272
bool verbose,
7373
) async {
74-
sdkConfiguration.validate();
74+
sdkConfiguration.validateSdkDir();
75+
if (soundNullSafety) {
76+
sdkConfiguration.validateSoundSummaries();
77+
} else {
78+
sdkConfiguration.validateWeakSummaries();
79+
}
7580

7681
final librariesUri = sdkConfiguration.librariesUri!;
7782
final workerUri = sdkConfiguration.compilerWorkerUri!;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
3+
<head>
4+
<script defer src="scopes_main.dart.js"></script>
5+
</head>
6+
7+
</html>
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// An example with more complicated scope
6+
import 'dart:async';
7+
import 'dart:collection';
8+
9+
final libraryPublicFinal = MyTestClass();
10+
11+
final _libraryPrivateFinal = 1;
12+
Object? libraryNull;
13+
var libraryPublic = <String>['library', 'public', 'variable'];
14+
var notAList = NotReallyAList();
15+
16+
var _libraryPrivate = ['library', 'private', 'variable'];
17+
18+
var identityMap = <String, int>{};
19+
20+
var map = <Object, Object>{};
21+
22+
void staticFunction(int formal) {
23+
print(formal); // Breakpoint: staticFunction
24+
}
25+
26+
void main() async {
27+
print('Initial print from scopes app');
28+
var local = 'local in main';
29+
var intLocalInMain = 42;
30+
var testClass = MyTestClass();
31+
Object? localThatsNull;
32+
identityMap['a'] = 1;
33+
identityMap['b'] = 2;
34+
map['a'] = [1, 2, 3];
35+
map['b'] = 'something';
36+
notAList.add(7);
37+
38+
String nestedFunction<T>(T parameter, Object aClass) {
39+
var another = int.tryParse('$parameter');
40+
return '$local: parameter, $another'; // Breakpoint: nestedFunction
41+
}
42+
43+
dynamic nestedWithClosure(String banana) {
44+
return () => '$local + $banana';
45+
}
46+
47+
Timer.periodic(const Duration(seconds: 1), (Timer t) {
48+
var ticks = t.tick;
49+
// ignore: unused_local_variable, prefer_typing_uninitialized_variables
50+
var closureLocal;
51+
libraryPublicFinal.printCount();
52+
staticFunction(1);
53+
print('ticking... $ticks (the answer is $intLocalInMain)');
54+
print(nestedFunction('$ticks ${testClass.message}', Timer));
55+
print(localThatsNull);
56+
print(libraryNull);
57+
var localList = libraryPublic;
58+
print(localList);
59+
localList.add('abc');
60+
var f = testClass.methodWithVariables();
61+
print(f('parameter'));
62+
});
63+
64+
print(_libraryPrivateFinal);
65+
print(_libraryPrivate);
66+
print(nestedFunction(_libraryPrivate.first, Object));
67+
print(nestedWithClosure(_libraryPrivate.first)());
68+
}
69+
70+
String libraryFunction(String arg) {
71+
print('calling a library function with $arg');
72+
var concat = 'some constant plus $arg plus whatever';
73+
print(concat);
74+
return concat;
75+
}
76+
77+
class MyTestClass<T> {
78+
final String message;
79+
80+
late String notFinal;
81+
82+
MyTestClass({this.message = 'world'}) {
83+
myselfField = this;
84+
tornOff = toString;
85+
}
86+
87+
String hello() => message;
88+
89+
String Function(String) methodWithVariables() {
90+
var local = '$message + something';
91+
print(local);
92+
return (String parameter) {
93+
// Be sure to use a field from this, so it isn't entirely optimized away.
94+
var closureLocalInsideMethod = '$message/$local/$parameter';
95+
print(closureLocalInsideMethod);
96+
return closureLocalInsideMethod; // Breakpoint: nestedClosure
97+
};
98+
}
99+
100+
//ignore: avoid_returning_this
101+
MyTestClass get myselfGetter => this;
102+
103+
late MyTestClass myselfField;
104+
105+
var count = 0;
106+
107+
// An easy location to add a breakpoint.
108+
void printCount() {
109+
print('The count is ${++count}');
110+
libraryFunction('abc'); // Breakpoint: printMethod
111+
}
112+
113+
final _privateField = 'a private field';
114+
115+
// ignore: unused_element
116+
String privateMethod(String s) => '$s : $_privateField';
117+
118+
@override
119+
String toString() => 'A test class with message $message';
120+
121+
bool equals(Object other) {
122+
if (other is MyTestClass) return message == other.hello();
123+
return false;
124+
}
125+
126+
Function closure = someFunction;
127+
128+
late String Function() tornOff;
129+
}
130+
131+
Function? someFunction() => null;
132+
133+
// ignore: unused_element
134+
int _libraryPrivateFunction(int a, int b) => a + b;
135+
136+
class NotReallyAList extends ListBase {
137+
final List<Object?> _internal;
138+
139+
NotReallyAList() : _internal = [];
140+
141+
@override
142+
Object? operator [](x) => _internal[x];
143+
144+
@override
145+
operator []=(x, y) => _internal[x] = y as Object?;
146+
147+
@override
148+
int get length => _internal.length;
149+
150+
@override
151+
set length(x) => _internal.length = x;
152+
}

webdev/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
to the build runner and the expression compiler service.
55
- Update SDK constraint to `>=3.0.0-134.0.dev <4.0.0`.
66
- Update `package:vm_service` constraint to `>=10.1.0 <12.0.0`.
7+
- Make all tests use sound null safety fixtures.
78

89
**Breaking changes**
910

webdev/test/daemon/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Future<String> waitForAppId(TestProcess webdev) async {
3939

4040
Future<String> prepareWorkspace() async {
4141
var exampleDirectory =
42-
p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSmoke'));
42+
p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSoundSmoke'));
4343

4444
var process = await TestProcess.start(dartPath, ['pub', 'upgrade'],
4545
workingDirectory: exampleDirectory, environment: getPubEnvironment());

0 commit comments

Comments
 (0)