From 1125460f2e50b001315237702df7924b6c111681 Mon Sep 17 00:00:00 2001 From: Tess Strickland Date: Mon, 17 Nov 2025 06:56:33 -0800 Subject: [PATCH] [vm,dyn_modules] Allow desugared const constructors. The front end may desugar some const constructors into procedures, so be less strict with what is expected in the list of const constructors. Also updates SourceReport to check all Functions with is_const() true against the collected const constructor hits and not just Constructors. TEST=ci Fixes: https://github.com/dart-lang/sdk/issues/61947 Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try Change-Id: I092938eeeb0459de9b3d95400a538ec6528c43fe Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462442 Reviewed-by: Alexander Markov Commit-Queue: Tess Strickland --- pkg/dart2bytecode/lib/bytecode_generator.dart | 4 +++- runtime/vm/bytecode_reader.cc | 3 ++- runtime/vm/source_report.cc | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/dart2bytecode/lib/bytecode_generator.dart b/pkg/dart2bytecode/lib/bytecode_generator.dart index d48cb0236c3..2f8d2a6bde9 100644 --- a/pkg/dart2bytecode/lib/bytecode_generator.dart +++ b/pkg/dart2bytecode/lib/bytecode_generator.dart @@ -227,9 +227,11 @@ class BytecodeGenerator extends RecursiveVisitor { if (source == null) { final importUri = objectTable.getConstStringHandle(astSource.importUri.toString()); + // Use asMember instead of asConstructor because some const + // constructors from extension types are desugared to procedures. final coveredConstConstructors = astSource .constantCoverageConstructors - ?.map((r) => objectTable.getHandle(r.asConstructor)!) + ?.map((r) => objectTable.getHandle(r.asMember)!) .toList(); source = new SourceFile(importUri, coveredConstConstructors); bytecodeComponent.sourceFiles.add(source); diff --git a/runtime/vm/bytecode_reader.cc b/runtime/vm/bytecode_reader.cc index b2905c70926..ba70b736c65 100644 --- a/runtime/vm/bytecode_reader.cc +++ b/runtime/vm/bytecode_reader.cc @@ -334,7 +334,8 @@ void BytecodeReaderHelper::ReadCoveredConstConstructors(const Script& script, auto& function = Function::Handle(Z); for (intptr_t i = 0; i < len; i++) { function ^= ReadObject(); - ASSERT(function.IsConstructor() && function.is_const()); + // Const constructors from extension types can be desugared into procedures. + ASSERT(function.IsFunction() && function.is_const()); constant_coverage.SetAt(i, function); } script.set_collected_constant_coverage(constant_coverage); diff --git a/runtime/vm/source_report.cc b/runtime/vm/source_report.cc index 3824ff6dea9..947469620ba 100644 --- a/runtime/vm/source_report.cc +++ b/runtime/vm/source_report.cc @@ -341,7 +341,7 @@ void SourceReport::PrintCoverageData(JSONObject* jsobj, const Script& script = Script::Handle(zone(), function.script()); bool const_constructor_hit = false; - if (function.IsConstructor() && function.is_const()) { + if (function.IsFunction() && function.is_const()) { for (TokenPosition hit : script_table_entries_[script_index]->const_constructor_hits) { if (hit == begin_pos) {