Skip to content

Commit

Permalink
Version 3.5.0-292.0.dev
Browse files Browse the repository at this point in the history
Merge 755d4e0 into dev
  • Loading branch information
Dart CI committed Jun 22, 2024
2 parents 56c98c7 + 755d4e0 commit 8f4cebd
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 20 deletions.
8 changes: 7 additions & 1 deletion pkg/analyzer/lib/src/generated/resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ import 'package:analyzer/src/generated/variable_type_provider.dart';
import 'package:analyzer/src/task/inference_error.dart';
import 'package:analyzer/src/util/ast_data_extractor.dart';

/// Function determining which source files should have inference logging
/// enabled.
///
/// By default, no files have inference logging enabled.
bool Function(Source) inferenceLoggingPredicate = (_) => false;

typedef SharedMatchContext = shared.MatchContext<AstNode, Expression,
DartPattern, DartType, PromotableElement>;

Expand Down Expand Up @@ -2186,7 +2192,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>

@override
void visitCompilationUnit(CompilationUnit node) {
conditionallyStartInferenceLogging();
conditionallyStartInferenceLogging(dump: inferenceLoggingPredicate(source));
try {
NodeList<Directive> directives = node.directives;
int directiveCount = directives.length;
Expand Down
38 changes: 20 additions & 18 deletions pkg/analyzer/lib/src/summary2/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -533,18 +533,6 @@ class LibraryBuilder with MacroApplicationsContainer {
return;
}

var mergedUnit = performance.run(
'mergedUnit',
(performance) {
performance.getDataInt('length').add(augmentationCode.length);
return kind.file.parseCode(
code: augmentationCode,
errorListener: AnalysisErrorListener.NULL_LISTENER,
performance: performance,
);
},
);

kind.disposeMacroAugmentations(disposeFiles: true);

// Remove import for partial macro augmentations.
Expand Down Expand Up @@ -636,12 +624,26 @@ class LibraryBuilder with MacroApplicationsContainer {
unitElement: unitElement,
augmentation: augmentation,
).perform(updateConstants: () {
MacroUpdateConstantsForOptimizedCode(
libraryElement: element,
unitNode: mergedUnit,
codeEdits: optimizedCodeEdits,
unitElement: unitElement,
).perform();
if (optimizedCodeEdits.isNotEmpty) {
var mergedUnit = performance.run(
'mergedUnit',
(performance) {
performance.getDataInt('length').add(augmentationCode.length);
return kind.file.parseCode(
code: augmentationCode,
errorListener: AnalysisErrorListener.NULL_LISTENER,
performance: performance,
);
},
);

MacroUpdateConstantsForOptimizedCode(
libraryElement: element,
unitNode: mergedUnit,
codeEdits: optimizedCodeEdits,
unitElement: unitElement,
).perform();
}
});

// Set offsets the same way as when reading from summary.
Expand Down
47 changes: 47 additions & 0 deletions pkg/analyzer/tool/type_inference_log.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/src/generated/resolver.dart';
import 'package:args/args.dart';
import 'package:path/path.dart';

/// This program analyzes a single source file with type inference logging
/// enabled, and prints out the resulting log.
Future<void> main(List<String> args) async {
var argParser = ArgParser();
var argResults = argParser.parse(args);
var paths = argResults.rest;
if (paths.length != 1) {
print('Exactly one path must be specified.');
exit(1);
}
var filePath = normalize(absolute(paths.single));
var contextCollection = AnalysisContextCollection(
includedPaths: [filePath],
);
inferenceLoggingPredicate = (source) => source.fullName == filePath;
var result = await contextCollection
.contextFor(filePath)
.currentSession
.getResolvedUnit(filePath);
if (result is! ResolvedUnitResult) {
print('Failed to resolve `$filePath`: ${result.runtimeType}');
exit(1);
}
if (!result.exists) {
print('File does not exist: `$filePath`');
exit(1);
}
var errors = result.errors;
if (errors.isNotEmpty) {
print('${errors.length} errors found:');
for (var error in errors) {
print(' $error');
}
}
}
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 3
MINOR 5
PATCH 0
PRERELEASE 291
PRERELEASE 292
PRERELEASE_PATCH 0

0 comments on commit 8f4cebd

Please sign in to comment.