Skip to content

Calculate what extensions could apply with an extension tree #2061

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

Closed
wants to merge 5 commits into from

Conversation

jcollins-g
Copy link
Contributor

More groundwork for #2021 and #2033.

This is more accurate than #2050 and should have more scalable performance. In particular it fixes some bugs in the tests that were verifying incorrect output.

@googlebot googlebot added the cla: yes Google CLA check succeeded. label Nov 7, 2019
/// instantiation of that type where the extension would be applicable if
/// made accessible in the namespace per:
/// https://github.com/dart-lang/language/blob/master/accepted/2.6/static-extension-members/feature-specification.md#implicit-extension-member-invocation
class ExtensionNode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that a tree structure is adequate, given that it appears to follow the type hierarchy but the type hierarchy is a graph structure. If the declarations look like

class A {}
class B extends A {}

then, as I understand it, there would be a node for A and a node for B that is a child of the node for A. But if the declarations look like

class A {}
class B {}
class C implements A, B {}

then there would be nodes for A, B, and C, and C would need to be a child of both the node for A and the node for B, which a tree doesn't allow.

In analyzer we just compute a list of the extensions visible within a single library, then recompute the set of applicable extensions based on a given type without trying to build a graph of extensions. I think that's a cleaner approach, but ymmv.


/// The set of seen [ModelElement]s backing [extendedType]s in this tree.
/// Only valid at the root.
Set<ModelElement> _seen;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by "Only valid at the root.". If you mean that only the node at the root of the tree will have a value for this field and other nodes will have null values, then consider either creating a subclass such as ExtensionRootNode that's only used for the root node that defines this field, or create an ExtensionTree that holds both this field and the root node. The space savings will probably be minimal, but it will allow you to make this a non-nullable field in the future. Ditto for _genericsInserted.

Set<ModelElement> _genericsInserted;

/// The type all [extensions] are extending.
final DefinedElementType extendedType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the purposes of dartdoc, could this just be the element associated with the extended type?


/// The [PackageGraph] associated with the tree; must be the same for all
/// nodes.
final PackageGraph packageGraph;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do have a tree / root node, then this field can be moved there as well and a getter added to walk up the parent chain to find it. That would ensure that it's the same for all nodes.


/// Merge from [other] node into [this], unconditionally.
void _merge(ExtensionNode other) {
//assert(other.extendedType.type == extendedType.type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment or remove?

documentedPackages.toList().forEach((package) {
package._libraries.forEach((library) {
for (Extension e in library.extensions) {
ExtensionNode returned = _extensions.addExtension(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to filter out private extensions?

@jcollins-g jcollins-g removed request for pq and scheglov November 7, 2019 16:18
@jcollins-g
Copy link
Contributor Author

withdrawing for now. @bwilkerson is right in that a tree structure is likely inadequate.

@jcollins-g jcollins-g closed this Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants