Giter Club home page Giter Club logo

Comments (6)

danelkhen avatar danelkhen commented on August 30, 2024

Hi,
Any news / updates regarding this issue?

Thanks!

from nrefactory.

danelkhen avatar danelkhen commented on August 30, 2024

Hi,

I've modified a very small piece of code, which totally resolves this issue, please consider it:

class CSharpResolver
{
    static ResolveResult DynamicResult { get { return new ResolveResult(SpecialType.Dynamic); } }

}

The previous code had a single const object for this.
This code will create a new resolve result object for every dynamic object expression, which helps resolving back to the original expression.

from nrefactory.

dgrunwald avatar dgrunwald commented on August 30, 2024

Yes, I guess we'll need to stop reusing ResolveResults. This is not only a problem for dynamic, there are a couple of other cases where ResolveResults are cached (member lookup cache, voidResult, maybe more).

from nrefactory.

danelkhen avatar danelkhen commented on August 30, 2024

Yes, this might be an issue, although from all the code I've tested, most of the other cached ResolveResults are pretty harmless. My issue happens when I begin resolving an expression, then I have a whole new tree to visit (ResolveResult tree), most of the time, I can perform all calculations directly on ResolveResults, but in some cases (lambda expressions, delegates, dynamics), I must have the original expression back. During this time I'm so deep inside ResolveResults, that the only way to resolve it back is using the dictionary. So, only then, if I have more than one expression for a resolve result, I can't continue.

BTW: I've implemented two ResolveResult visitors, for both Core and CSharp namespaces, I saw some people asking for it, so if you want to integrate it, let me know and I'll send it to you.

from nrefactory.

dgrunwald avatar dgrunwald commented on August 30, 2024

Well, the others might be harmless for your usecase, but it would be nice to have the ResolveResult -> AST mapping work in general.

I'm not sure if the visitor pattern is a good idea for ResolveResults.

  1. The separation into language-independent and C#-specific results is a bit messy.
  2. ResolveResults derive from other non-abstract ResolveResults.
    E.g. VisitInvocationResolveResult() wouldn't get called for all invocations, as the CSharpInvocationResolveResult would call another visit method. (for the AST, we've taken care to derive only from abstract node types)
  3. It's possible that we add additional ResolveResults in the future to represent cases that currently only return a general ResolveResult. Implementing the visitor pattern makes every such addition a breaking change.

We've written some ResolveResult-traversing code using dynamic in SharpDevelop, and I think I'm preferring that approach over the visitor pattern.
https://github.com/icsharpcode/SharpDevelop/blob/newNR/src/AddIns/Debugger/Debugger.AddIn/NRefactory/ExpressionEvaluationVisitor.cs

from nrefactory.

danelkhen avatar danelkhen commented on August 30, 2024

Regarding ResolveResult mapping:
Cool, a general solution will be great, thanks!

Regarding Visitor pattern:
Got it, thank you for the example, since I need a performance critical solution, I'll keep using the visitor pattern myself, I don't mind refactoring when breaking changes are made.

Thank you for your swift and detailed answer.
Cheers!

from nrefactory.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.