Giter VIP home page Giter VIP logo

Comments (6)

LouisJenkinsCS avatar LouisJenkinsCS commented on September 28, 2024

@mppf mentioned that compilerError has an errorDepth overload that will do what I want. Perhaps Debug.badArgs can take an argument with a similar argument that defaults to 2. Will verify that this works before closing issue.

from chgl.

LouisJenkinsCS avatar LouisJenkinsCS commented on September 28, 2024

@mppf I am having a bit of an issue here because technically the errorDepth is a bit dynamic, but easily provable at compile time. Lets say that each time a function is called a compile-time counter is incremented and when a function exits it gets decremented. This would be enough to obtain the errorDepth, but it seems that this isn't possible? Whenever I attempt to make a global param and then use it in a function I get a 'used before defined' compiler error. The function I am trying to use can be seen below...

proc badArgs(bad, type good...?n) param {
compilerError("Expected argument of type to be in ", good : string, " but received argument of type ", bad.type : string);
}

It does not include the dynamic compile-time counter yet as it will not compile. Any assistance with this? The ability to provide custom errors for the user was actually one of the highlights we made for the language (in the paper and presentation on CHGL), it would be nice to have this ability back.

from chgl.

mppf avatar mppf commented on September 28, 2024

I am having a bit of an issue here because technically the errorDepth is a bit dynamic, but easily provable at compile time.

Can you say what the actual issue here is?

Lets say that each time a function is called a compile-time counter is incremented and when a function exits it gets decremented.

You can't modify a param variable.

from chgl.

LouisJenkinsCS avatar LouisJenkinsCS commented on September 28, 2024

Can you say what the actual issue here is?

We describe vertices and edges via a wrapper (record that contains a type which determines whether the wrapper refers to a vertex or edge), but we also allow implicit type conversions for integers of the same width and signed-ness. Hence we perform type-checking a bit late, sometimes after multiple function calls (a function f can call g which calls h which finally does type-checking) which would need to propagate the type error down to where the user invoked the original function (f in this example).

The issue is that since we have internal functions calling other functions, which may vary in depth, it wouldn't be correct to hard-code the actual errorDepth (for example, the sequence f -> g -> h is valid but so is g -> h or even just h). I suppose one way to resolve this would be to perform type-checking of these implicit casts early or add explicit types (rather than inferred) to enforce a more predictable type-checking from the compiler, but since we allow conversions between integers and their wrappers, if we had N arguments, we'd need to make 2^N + 1 overloads... Example...

     proc hasInclusion(v : vIndexType, e : eIndexType) {                                                                                                                                                  
       const vDesc = toVertex(v);                                                                                                                                                                         
       const eDesc = toEdge(e);                                                                                                                                                                           
                                                                                                                                                                                                          
       return getVertex(vDesc).hasNeighbor(eDesc);                                                                                                                                                        
     }                                                                                                                                                                                                    
                                                                                                                                                                                                          
     proc hasInclusion(vDesc : vDescType, e : eIndexType) {                                                                                                                                               
       const eDesc = toEdge(e);                                                                                                                                                                           
       return getVertex(vDesc).hasNeighbor(eDesc);                                                                                                                                                        
     }                                                                                                                                                                                                    
                                                                                                                                                                                                          
     proc hasInclusion(v : vIndexType, eDesc : eDescType) {                                                                                                                                               
       const vDesc = toVertex(v);                                                                                                                                                                         
       return getVertex(vDesc).hasNeighbor(eDesc);                                                                                                                                                        
     }                                                                                                                                                                                                    
                                                                                                                                                                                                          
     proc hasInclusion(vDesc : vDescType, e : eDescType) {                                                                                                                                                
       return getVertex(vDesc).hasNeighbor(eDesc);                                                                                                                                                        
     }                                                                                                                                                                                                    
                                                                                                                                                                                                          
     proc hasInclusion(v, e) {                                                                                                                                                                            
       Debug.badArgs((v, e), ((vIndexType, eIndexType), (vDescType, eDescType), (vIndexType, eDescType), (vDescType, eIndexType)));                                                                       
     } 

Why do we have Debug.badArgs to begin with if the compiler can emit its own error?

The compiler's default errors are ambiguous and vague at times, and very frustrating to work with at times. Custom and tailored error messages like this make it much easier to figure out what is wrong.

Let me know if I was unclear in any way.

Edit: I should mention that toVertex and toEdge does its own type-checking as well as bounds-checking (if enabled).

from chgl.

github-actions avatar github-actions commented on September 28, 2024

This issue is stale and should either be closed or eventually resolved.

from chgl.

mppf avatar mppf commented on September 28, 2024

I wonder if it'd be sufficient to have something like compilerError that reported the line number at the module boundary (so ignored functions within the module with the compilerError).

from chgl.

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.