Skip to content

Commit

Permalink
[ddc] Delete defineLazy with legacy semantics
Browse files Browse the repository at this point in the history
This is no longer used since support for legacy code < 2.12
has been dropped.

Change-Id: Id0e67445407c9b110218625d8e3a7ad5230d75cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386966
Reviewed-by: Mark Zhou <[email protected]>
Commit-Queue: Nicholas Shahan <[email protected]>
  • Loading branch information
nshahan authored and Commit Queue committed Sep 27, 2024
1 parent 30a57b2 commit 32d2b53
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 74 deletions.
7 changes: 3 additions & 4 deletions pkg/dev_compiler/lib/src/kernel/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>

if (_constLazyAccessors.isNotEmpty) {
var constTableBody = _runtimeStatement(
'defineLazy(#, { # }, false)', [_constTable, _constLazyAccessors]);
'defineLazy(#, { # })', [_constTable, _constLazyAccessors]);
_moduleItems.insert(_constTableInsertionIndex, constTableBody);
_constLazyAccessors.clear();
}
Expand Down Expand Up @@ -2762,8 +2762,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
}
_currentUri = savedUri;

return _runtimeStatement(
'defineLazy(#, { # }, #)', [objExpr, accessors, js.boolean(false)]);
return _runtimeStatement('defineLazy(#, { # })', [objExpr, accessors]);
}

js_ast.Fun _emitStaticFieldInitializer(Field field) {
Expand Down Expand Up @@ -3610,7 +3609,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
.add(js.statement('const # = Object.create(null);', [_constTable]));

constTable.add(_runtimeStatement(
'defineLazy(#, { # }, false)', [_constTable, _constLazyAccessors]));
'defineLazy(#, { # })', [_constTable, _constLazyAccessors]));

constTable.addAll(_constTableCache.emit());
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/dev_compiler/lib/src/kernel/compiler_new.dart
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>

if (_constLazyAccessors.isNotEmpty) {
var constTableBody = _runtimeStatement(
'defineLazy(#, { # }, false)', [_constTable, _constLazyAccessors]);
'defineLazy(#, { # })', [_constTable, _constLazyAccessors]);
_moduleItems.insert(_constTableInsertionIndex, constTableBody);
_constLazyAccessors.clear();
}
Expand Down Expand Up @@ -2892,8 +2892,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
}
_currentUri = savedUri;

return _runtimeStatement(
'defineLazy(#, { # }, #)', [objExpr, accessors, js.boolean(false)]);
return _runtimeStatement('defineLazy(#, { # })', [objExpr, accessors]);
}

js_ast.Fun _emitStaticFieldInitializer(Field field) {
Expand Down Expand Up @@ -3690,7 +3689,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
.add(js.statement('const # = Object.create(null);', [_constTable]));

constTable.add(_runtimeStatement(
'defineLazy(#, { # }, false)', [_constTable, _constLazyAccessors]));
'defineLazy(#, { # })', [_constTable, _constLazyAccessors]));

constTable.addAll(_constTableCache.emit());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,16 +1049,9 @@ void setDynamicModuleLoader(Object loaderFunction, Object entrypointHelper) {
}

/// Defines lazy statics.
///
/// TODO: Remove useOldSemantics when non-null-safe late static field behavior is
/// deprecated.
void defineLazy(to, from, bool useOldSemantics) {
void defineLazy(to, from) {
for (var name in getOwnNamesAndSymbols(from)) {
if (useOldSemantics) {
defineLazyFieldOld(to, name, getOwnPropertyDescriptor(from, name));
} else {
defineLazyField(to, name, getOwnPropertyDescriptor(from, name));
}
defineLazyField(to, name, getOwnPropertyDescriptor(from, name));
}
}

Expand Down Expand Up @@ -1124,63 +1117,6 @@ defineLazyField(to, name, desc) => JS('', '''(() => {
return ${defineProperty(to, name, desc)};
})()''');

/// Defines a lazy static field with pre-null-safety semantics.
defineLazyFieldOld(to, name, desc) => JS('', '''(() => {
const initializer = $desc.get;
let init = initializer;
let value = null;
// Tracks if these local variables have been saved so they can be restored
// after a hot restart.
let savedLocals = false;
$desc.get = function() {
if (init == null) return value;
let f = init;
init = $throwCyclicInitializationError;
if (f === init) f($name); // throw cycle error
// On the first (non-cyclic) execution, record the field so we can reset it
// later if needed (hot restart).
if (!savedLocals) {
$resetFields.push(() => {
init = initializer;
value = null;
savedLocals = false;
});
savedLocals = true;
}
// Try to evaluate the field, using try+catch to ensure we implement the
// correct Dart error semantics.
try {
value = f();
init = null;
return value;
} catch (e) {
init = null;
value = null;
throw e;
}
};
$desc.configurable = true;
let setter = $desc.set;
if (setter != null) {
$desc.set = function(x) {
if (!savedLocals) {
$resetFields.push(() => {
init = initializer;
value = null;
savedLocals = false;
});
savedLocals = true;
}
init = null;
value = x;
setter(x);
};
}
return ${defineProperty(to, name, desc)};
})()''');

/// Checks for null or undefined and returns [val].
///
/// Throws a [TypeError] when [val] is null or undefined and the option for
Expand Down

0 comments on commit 32d2b53

Please sign in to comment.