Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnalysisDriver.getSourceKind can return outdated data #40546

Closed
simolus3 opened this issue Feb 8, 2020 · 5 comments
Closed

AnalysisDriver.getSourceKind can return outdated data #40546

simolus3 opened this issue Feb 8, 2020 · 5 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@simolus3
Copy link
Contributor

simolus3 commented Feb 8, 2020

In AnalysisDriver, getSourceKind appears to return outdated data after calling changeFile. This is causing issues with the build system in the following scenario

  1. A builder runs on a file, say /a/input.dart, which has the following content. At this point, neither /a/input.a.dart or /a/input.b.dart exist.
part 'input.a.dart';
part 'input.b.dart';
  1. That builder creates input.a.dart with the content part of 'input.dart';
  2. Another builder runs on input.a.dart. build_resolvers will call changeFile('/a/input.a.dart') on the driver
  3. getSourceKind('/a/input.a.dart') returns SourceKind.LIBRARY.

I'd expect that the last step should return SourceKind.PART, since the file has since been created and contains a part of statement. Adding a file.refresh() before this line fixes this problem, but I'm not sure if it's correct to make that change. Maybe AnalysisDriver doesn't properly invalidate the FileSystemState after calling changeFile?

This is causing https://github.com/dart-lang/source_gen/issues/447. @jakemac53 wrote a smaller test that can be used to reproduce this behavior: dart-lang/build#2620. I'm using analyzer version 0.39.4.

@simolus3 simolus3 changed the title AnalysisDriver.getSourceKind can return oudated data AnalysisDriver.getSourceKind can return outdated data Feb 8, 2020
@bwilkerson
Copy link
Member

@scheglov

@vsmenon vsmenon added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Feb 9, 2020
@scheglov scheglov self-assigned this Feb 10, 2020
@scheglov
Copy link
Contributor

dart-bot pushed a commit that referenced this issue Feb 10, 2020
R=brianwilkerson@google.com

Bug: #40546
Change-Id: I68b3e0610960bfbad05d6d132d534cea9cfe5925
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135100
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
@jakemac53
Copy link
Contributor

jakemac53 commented Feb 10, 2020

Hmm, I am still seeing this in the test I had added. Looking into it a bit more.

Nevermind I forgot I need to update the package version of the analyzer and not rebuild the sdk :D.

I have confirmed it fixes the issue if I pin the analyzer dep.

@scheglov
Copy link
Contributor

This change causes internal build failures when getSourceKind() is invoked for a path that is in a provided summary, so not all data structures are filled for it.

NoSuchMethodError: The method 'toList' was called on null.
Receiver: null
Tried calling: toList()
dart:core                                                         Object.noSuchMethod
package:analyzer/src/dart/analysis/file_state.dart 905:51         FileSystemState.getFilesForPath
package:analyzer/src/dart/analysis/file_tracker.dart 227:40       FileTracker.verifyApiSignature.<fn>
package:analyzer/src/dart/analysis/performance_logger.dart 34:15  PerformanceLog.run
package:analyzer/src/dart/analysis/file_tracker.dart 223:20       FileTracker.verifyApiSignature
package:analyzer/src/dart/analysis/driver.dart 834:37             AnalysisDriver.getSourceKind
package:_bazel_codegen/src/resolver/resolvers.dart 93:32          AnalysisResolver.isLibrary
package:build/src/builder/build_step_impl.dart 193:25             _DelayedResolver.isLibrary

@scheglov scheglov reopened this Feb 11, 2020
@scheglov
Copy link
Contributor

dart-bot pushed a commit that referenced this issue Feb 11, 2020
…maries.

R=brianwilkerson@google.com

Bug: #40546
Change-Id: I06f99175c9aee127e71b99ff7f0e70066965d6f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135280
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

5 participants