-
Notifications
You must be signed in to change notification settings - Fork 210
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
Building more than one target causes InconsistentAnalysisException
#2634
Comments
cc @natebosch I think we got another report of this recently as well. also cc @scheglov for analyzer perspective here. |
From the analyzer POV, when |
Yes, this also came up in gitter, also about package:reflectable https://gitter.im/dart-lang/build?at=5e555d19fa9f20553b4e7e02 |
Interesting, I wonder why we are only seeing this for reflectable? |
Simon Binder mentioned So I tried to change the reflectable code generator such that it awaits |
any update on the InconsistentAnalysisException problem @eernstg? Would rolling back to an older version of source_gen or build work, if so what version could I try? My CI keeps failing! Thank you |
one strange thing is that if I rename the file then it sometimes works again, the exception mentions the word cache in the output so possibly there might be a way of clearing something to get it to work??? |
@atreeon wrote:
No. I suspect that it is caused by the build framework (perhaps the build_runner) running many code generation steps in an overlapping fashion (because it's asynchronous). The exception is then thrown when However, I've performed experiments where the reflectable code generator performs all invocations of The only thing that really works is to force code generation to run with exactly one target (one "program"). The latest version of reflectable before the one that needed to introduce all these asynchronous operations was v2.0.12. However, that version depends on analyzer version |
ah ok, thank you for the reply, yup, v0.35 won't work! I don't understand the internal workings of the code generator but renaming the files seems to overcome the problem...temporarily (but often it reappears when a new file is added or an existing file is changed). |
@atreeon wrote:
OK, then I'd like to know: Which files are being renamed? Are you generating code for a single entry point, that is, does the end result contain exactly one file named |
so I have something like This is the error I get, and if I rename
|
It looks like we never updated this issue - I am going to close it because there is nothing that we can do from our end, but I will describe the problem and workaround: The problemCalls to The workaroundAny direct usage of an // where `resolver` came from something like `var resolver = await buildStep.resolver;`,
// and `existingLibraryElement` is some library element that you have and want to grab
// a session from.
var newLibraryElement =
await resolver.libraryFor(await resolver.assetIdForElement(existingLibraryElement));
var session = newLibraryElement.session; This is unfortunately verbose and slow but we don't have other solutions at this time. Note that in between any async calls that session could theoretically be invalidated, so you may even want to add some retry logic. Generally, avoid using the analysis session at all if you can, and if you do use it you will have to be aware of these issues. |
This PR changes reflectable to to obtain a fresh resolved library at each invocation of `getResolvedLibraryByElement`, thus eliminating the `InconsistentAnalysisException` which was reported in #198 and dart-lang/build#2634.
👋 Is there an easy way to know what is causing the invalidation? I am not calling |
That's pretty interesting. How reliably can you reproduce this? What version of |
Locally I am unable to reproduce it, but the CI fails relatively often https://github.com/rrousselGit/river_pod/runs/1366244210?check_suite_focus=true And many users of the code-generator have complained about this exception.
Latest, so 1.4.3 |
I think I have pinpointed the issue. Is it expected? By understanding is that this method returns the already parse result, rather than parsing it again. So I am not sure why that would invalidate the analysis I don't fully understand why I do not have this exception locally either. Since the code is synchronous, there shouldn't be concurrency issues. |
The method is called Regardless of what the method does, |
In that case, is there a way to access the AstNode of an Element without invalidating the previously obtained results in the process? The only reason I have this exception is because I do: AstNode astNodeForElement(Element element) {
return element.session
.getParsedLibraryByElement(element.library)
?.getElementDeclaration(element)?.node;
} But this line forces me to use the workaround after every call to this function, which I run in a loop, so it's very unideal |
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Use workaround for dart-lang/build#2634 by @eernstg
Working on package reflectable, I performed a
pub upgrade
which changed versions of build related packages as follows:The package test_reflectable contains a set of tests that are used to test reflectable. After the above changes they are all failing, for instance:
However, if I edit the file build.yaml such that it only specifies a
generate_for:
property matching a single entry point library then code generation succeeds, and the test runs as expected.This behavior might be associated with
AnalysisDriver.changeFile
being invoked by the getterBuildStepImpl.inputLibrary
that theBuilder
in reflectable is using to get access to the input library, and subsequently to all other entities from the analyzer.Did one of the build packages change recently (
build_runner
?) in such a way that it is not possible to build more than one target? Or in such a way that it is now required to do something extra in the case where multiple targets are given, in order to avoidInconsistentAnalysisException
?Here is a scenario that gives rise to the failures:
The make command runs
pub get
,pub run build_runner build test
, asmake -n
shows.The text was updated successfully, but these errors were encountered: