Skip to content

Dedupliate library elements #3838

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

Merged
merged 1 commit into from
Aug 21, 2024
Merged

Conversation

srawlins
Copy link
Member

@srawlins srawlins commented Aug 20, 2024

Fixes #3748. Work towards #2021.

This change removes duplication of elements that are declared in one library and exported in another.

The main change that deduplicates library elements is splitting Library.exportedAndLocalElements into Library._localElements and Library._exportedElements, and then Library._elementsOfType into Library._localElementsOfType and Library._exportedElementsOfType. These two lists are separated so that the ModelElements can be instantiated or fetched from the package graph with the "correct" enclosing library. _localElementsOfType fetches elements via getModelFor(e, this), and exportedElementsOfType fetches elements via getModelFor(e, packageGraph.getModelForElement(library)).

Other changes to support this:

  • Use an element's canonicalLibrary instead of library in many places, like in each override of filePath, and in GeneratorFrontEnd.
  • There is no longer a distinction between an element's library and its defining library. ModelElement.definingLibrary is removed.
  • Introduce a canonicalizedQualifiedName to use when creating index.json, which is the same as fullyQualifiedName but using the element's canonical library.
  • The global map of all elements was keyed on a 3-element key, which can now be a 2-element key (ConstructedModelElementsKey).
  • Remove an assert in Inheritable that no longer makes sense with this new model.

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

The main change that deduplicates library elements is splitting
`Library.exportedAndLocalElements` into `Library._localElements` and
`Library._exportedElements`, and then `Library._elementsOfType` into
`Library._localElementsOfType` and `Library._exportedElementsOfType`. These two
lists are separated so that the ModelElements can be instantiated or fetched
from the package graph with the "correct" enclosing library.
`_localElementsOfType` fetches elements via `getModelFor(e, this)`, and
`exportedElementsOfType` fetches elements via `getModelFor(e,
packageGraph.getModelForElement(library))`.

Other changes to support this:

* Use an element's `canonicalLibrary` instead of `library` in many places, like
  in each override of `filePath`, and in GeneratorFrontEnd.
* There is no longer a distinction between an element's library and its
  _defining_ library. `ModelElement.definingLibrary` is removed.
* Introduce a `canonicalizedQualifiedName` to use when creating `index.json`,
  which is the same as `fullyQualifiedName` but using the element's canonical
  library.
* The global map of all elements was keyed on a 3-element key, which can now be
  a 2-element key (ConstructedModelElementsKey).
* Remove an assert in Inheritable that no longer makes sense with this new
  model.
@srawlins srawlins force-pushed the no-dupe-libraries-2 branch from dc05cd4 to 2515ab8 Compare August 20, 2024 19:57
@srawlins
Copy link
Member Author

Ready for review, @dart-lang/analyzer-team

@srawlins srawlins merged commit d629e1e into dart-lang:main Aug 21, 2024
9 checks passed
@srawlins srawlins deleted the no-dupe-libraries-2 branch August 21, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All exported elements are duplicated in dartdoc's model
2 participants