Git Product home page Git Product logo

Comments (5)

benreynwar avatar benreynwar commented on June 3, 2024

I'm trying to get my head around how a semantic pass might go.

  • Step through the AST of a design unit.

  • A DeclarativeRegion structure keeps track of what symbols have been declared in this region so far.

  • As we process declarations we add the new symbols to the Declarative Region.

  • As we process symbol uses we check if the symbols have already been declared in this region. If they haven't we check in parent regions recursively. If the declaration is present in this design unit we link the use of the symbol to it's declaration. If the declaration is not present we add it to a set of unresolved symbols along with the set of packages that were in scope at the time of use.

  • Step through all design units

  • Go back to each design unit and resolve the unresolved symbols. Identify circular dependencies. Link symbol uses with their declarations in appropriate packages. Identify ambiguous symbol uses.

Is this the general direction you were thinking?
At the moment it looks like the semantic analysis is making sure declarations are consistent with one another but hasn't worried about symbol uses yet. Is that correct?

from rust_hdl.

kraigher avatar kraigher commented on June 3, 2024

My current thinking is:

  • Traverse the entire AST and build DeclarativeRegions. The DeclarativeRegions only live temporarily in this pass and are thrown away afterwards. Public declarative regions such as in packages which might be saved for later use.
  • Desing units are only analyzed once and will be analyzed on-demand (See 2. in #7)
  • Check for duplicate declarations as you go.
    • DONE
  • Check some rules regarding protected type declaration/body deferred constant and incomplete type when a region is complete.
    • DONE
  • Check for missing declarations in all names and use clauses.
    • Partially done for use clauses, this is the next step

The there are two options to proceed:

  1. Annotate back to the AST (by mutating it) the multiple potential references for each name and perform type checking in a separate pass.
  2. Perform type checking in the same pass and write back to the AST the single resolved reference.

Also note that I use a Test-Driven-Development workflow which means I have an idea of where I want to go but I do not go ahead and build everything I think I will need without having tests that require it. Thus the current implementation may have shortcomings compared to my final intention since I have not defined the test cases that require the final intention. This is also the reason I have been holding off adding new fields to the AST since I want tests to require it and I do not want to make premature changes to the parsed AST (which is well understood by me) with semantic information (where I am stilll building my mental model of how it will work).

My strategy is also to develop the semantic analysis such that the example project always continues to work without errors. This means I will try not to implement partial solutions that will cause false errors but rather partial solutions that produce false positives. In this way the language server will never be unusable and provide incrementally more value until it is "complete".

from rust_hdl.

benreynwar avatar benreynwar commented on June 3, 2024

OK. So when we hit a "use work.mypkg.all", we pause the analysis of the design unit, and go and parse the appropriate package. Similarly if we hit a "myblah: entity work.blah" we pause the analysis, and go and parse that entity. This allows the semantic analysis to be done in a single pass, but reduces the possibility for parallelism. Is this implemented already? I didn't see it there.

from rust_hdl.

kraigher avatar kraigher commented on June 3, 2024

The on-demand analysis is implemented in my local repository. I will most likely push it today. This method will still allow enough parallelism. You can always start analysis for many design units in parallel and use locking to avoid duplicate analysis or race conditions. Only sequential dependencies would not get analysed in parallel due to locking but for large projects where parallel speed matters the dependency graph has high fan-out so there should be plenty of non-serial dependencies.

from rust_hdl.

kraigher avatar kraigher commented on June 3, 2024

I pushed the first version of the on-demand analysis now.

from rust_hdl.

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.