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

QualifiedName should be able to reference top level members of libraries and members of interfaces #96

Open
jakemac53 opened this issue Oct 10, 2024 · 5 comments · May be fixed by #101

Comments

@jakemac53
Copy link
Contributor

It seems to me today that it can only reference Interfaces within a library, so we will have to figure out how it needs to change, and what the URI syntax of it should be (but, I think we will find this is hard to represent as a URI, fwiw).

We also need to be able to target whole libraries, so if we use QualifiedName to represent the "target" in macro APIs (as it does now), then they also need to be able to represent the library itself. But, if we move to specific URIs for each phase/target combo, we could just use a Uri instead as the target when running on a library.

@davidmorgan
Copy link
Contributor

Model doesn't actually have a place for top level members yet, we need to decide whether block declarations and members are part of the same union ... in which case top level members can just be referenced by name in the existing map ... or whether there is a special "top level" block declaration with members, which could either get its own field in the model or be in the existing Map and named the empty String ''.

If we choose to describe top level members as part of a block declaration called '' in every library then referring to it with a QualifiedName(name: '') sort of makes sense.

Taking a step back, though: it might make sense to introduce a new union type for "macro target"? Then we can certainly target all the different types of thing :)

@jakemac53
Copy link
Contributor Author

I am assuming that QualifiedName is the full replacement for Identifier, which would mean it also is what you use in code to emit references to things. That would also have the same requirements here of being able to reference any declaration at any scope.

So, I think we should figure out how to allow it to do that. Maybe adding a Scope instead of a Uri? I am not sure we should probably chat about it.

@davidmorgan
Copy link
Contributor

I do not have a clear idea the best way to go here :)

We have the capability to use any node in the Model for referring to things, so for example we can use Member and turn that into QualifiedName + member name.

Maybe what we are actually talking about is a path into Model? There is certainly a lot we can do there and have it be fully general and extensible, which is interesting :) ... for example I think we can generate metadata so that a path into the model acts as a union over all the types we have; you can ask it what type it is, and retrieve the actual value with that static type.

Given we are still free to refactor, it probably works okay all ways around: we could expand QualifiedName and later split it into more/different types; or start with new types and later combine them if they turn out to be unnecessary. And/or we can explore the possibilities around general paths.

@davidmorgan
Copy link
Contributor

A couple of notes from our chat:

  • Path isn't sufficient, since you can only refer to things that are already in Model; you might want to reference something you haven't generated yet.
  • We might usefully have two slightly different concepts: "the thing referred to by the name foo in Bar in xyz.dart" and "foo declared in Bar in xyz.dart", they both uniquely identify something, the second is the "canonical" version.

@jakemac53
Copy link
Contributor Author

jakemac53 commented Oct 11, 2024

Additionally we might want to distinguish between whether the URI refers to a scope in which to look up the name in the context of (as in look it up in the library scope and then import scope), or whether the name should be looked up in the export scope of the URI.

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 a pull request may close this issue.

2 participants