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
Added ElementResolver to resolve namespace conflicts in CBN #3255
Added ElementResolver to resolve namespace conflicts in CBN #3255
Conversation
Adding @ikeough as reviewer |
@aparajit-pratap It's not entirely clear what you're asking for here. Are you esssentially looking for a design review on the API? |
@@ -255,7 +255,7 @@ public static bool TryLoadAssemblyIntoCore(Core core, string assemblyPath) | |||
/// </summary> | |||
/// <param name="parseParams"></param> | |||
/// <returns></returns> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please can you populate these /// comments whilst you're at it?
Thanks for this @aparajit-pratap it's good progress. I think the direction could use tweaking a little. I'd like to explore using an API that was less state based. So there would be a method which resolves a partial name to a full name without using a cache, and we make this sufficiently fast that we can do it directly in the replacement methods without adding more state. I guess the main challenge here is around the ClassTable structure that you're basing the translation off? |
Regarding these APIs you propose:
I think they are generally fine. Ideally we'd be able to yank them out of codegen and call them separately. |
/// </summary> | ||
public class ElementResolver | ||
{ | ||
private Dictionary<string, string> namespaceCache; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed resolutionMap
Hey Aparajit, Thanks for the discussion, to summarise:
I suspect we're going to end up wanting the UI to be able to query for lookups in other places in the code. thanks |
#region private methods | ||
|
||
// Initialize ResolutionMap from lookup table of strings | ||
private void InitializeNamespaceResolutionMap(string[] namespaceLookupMap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dict: String -> String
@@ -1,4 +1,6 @@ | |||
|
|||
using System.Collections.Generic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for clarity, would it still mean the same if I said ASTResolver and ASTRewiter?
Im not saying the name should be changed btw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Element
over here I guess mainly refers to namespace/class resolution. It was a term given by Luke. I'll just leave it at that.
Overall, the changes needed for the AST resolving look good. It conforms to what was discussed |
{ | ||
var elementRewriter = new ElementRewriter(elementResolver); | ||
|
||
for (int i = 0; i < astNodes.Count(); ++i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes multiple enumeration through the astNodes
, please move this out as var count = astNodes.Count();
, or better still, use foreach
(I think that's possible now that it is not an argument by ref
).
Hi @aparajit-pratap, first off my apology for not having time for this (it is large, and with each file added to review it feels heavier and heavier to review), but I manage to park some time for that today. I have made some comments for the things I would like changed (few optional). I still believe this PR can be broken down into small bits with corresponding tests, let's try to do that moving forward :) |
{ | ||
DfsTraverse(ref rightNode, ref classIdentifiers, ref resolvedNames); | ||
} | ||
if (!resolvedNames.Any()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
positive condition goes firstly :-)
@Benglin I'm done addressing your comments and adding test cases. Please review one final time. Thanks. |
Thanks for addressing those points, @aparajit-pratap. I have a look through, generally it LGTM. |
Added ElementResolver to resolve namespace conflicts in CBN
Overview
The objective here is to implement a strategy to handle namespace conflicts when there are multiple libraries loaded in Dynamo and to prevent breaking users' files as far as possible when they are opened in different Dynamo library environments. The approach here is to:
ElementResolver
object created when reading the file loads the information into its class resolution map (ResolutionMap
)ElementResolver
reads itsResolutionMap
and transforms the AST (obtained from parsing) by swapping its partial class names with the fully resolved names in theResolutionMap
. This happens in theResolveClassNamespace
method.ResolutionMap
, theElementResolver
updates it by relying on the compiler andclassTable
to resolve the namespace for a given partial class name. (If no unique class can be resolved, only then is a conflict warning generated for the user.)ResolutionMap
in theElementResolver
is persisted to the file.@lukechurch please review this first cut implementation. I would need @junmendoza to help me by providing the implementations of the core functions stubbed out below. These are mainly required by the
ElementResolver
to initially retrieve the fully resolved names from the compiler when there is no embedded information in the DYN file (i.e. when new code is typed in the CBN as well as migration of existing files). They are also needed to update the ASTs internally with the fully resolved class names which would be eventually sent to the VM.I need to implement embedding and reading of namespace information from DYN files. Currently I have added
TODO
placeholders for these calls. Also short name heuristics will come in subsequent submissions.