Code Monkey home page Code Monkey logo

Comments (7)

Alasdair avatar Alasdair commented on August 24, 2024 1

Good timing, I was just working on improving the overload errors yesterday! I just added a heuristic that prefers other errors other the unify errors (which I also changed to 'type mismatch' and added more location info.

This is another good heuristic, so I will add it as well

from sail.

Alasdair avatar Alasdair commented on August 24, 2024 1

Yes, in the scheme I described that would cause us to stop immediately on the second bullet point.

from sail.

Timmmm avatar Timmmm commented on August 24, 2024

which I also changed to 'type mismatch'

Ah yeah I was going to suggest that too. I assume "unify" is some standard PL theory term, and it's kind of clear from the context what it means but it did confuse me for a second! Type mismatch is much clearer.

from sail.

Alasdair avatar Alasdair commented on August 24, 2024

I think maybe the way to go is to do the following when we encounter an overload:

  • Construct an 'overload tree' of subexpressions
  • (Partially) infer the type of any obvious leaves, where obvious leaves are things like identifiers, function calls, etc
  • Use those partial types to rule out any overloads that cannot apply, pruning the tree down to a smaller set of possibilities.

If we checked overloads like that, we'd essentially get this heuristic for free just from the way the typing rule worked. It would also be a performance optimisation, because we would rule out impossible cases earlier and not waste time exploring them.

from sail.

Timmmm avatar Timmmm commented on August 24, 2024

Maybe I'm being dumb, but when you get to an identifier and try to figure out what it is and you don't find any definitions for that identifier or any type (variable, function, etc), can't you immediately stop?

I wouldn't be surprised if the error is more confusing if that item exists but is the wrong type (e.g. trying to call a variable) but if literally no item exists with the name it seems like you could do an early stop and report that very clearly.

I have never written a compiler though (does a WASM to TCL transpiler count? 😄), let alone a fancy dependently typed one so sorry if I am spewing nonsense!

from sail.

Alasdair avatar Alasdair commented on August 24, 2024

With #526 the following:

default Order dec

$include <prelude.sail>

val main : unit -> unit

function main() = {
    let bv: bits(32) = 0xFFFF_FFFF;
    let _ = bv | bv | bv | bv | b;
    ()
}

now prints:

Type error:
test.sail:9.32-33:
9 |    let _ = bv | bv | bv | bv | b;
  |                                ^
  | Identifier b is unbound. Did you mean bv?

whereas before it printed:

Type error:
test.sail:9.12-33:
9 |    let _ = bv | bv | bv | bv | b;
  |            ^-------------------^ (operator |)
  | No overloading for (operator |), tried:
  | * or_vec
  |   test.sail:9.17-33:
  |   9 |    let _ = bv | bv | bv | bv | b;
  |     |                 ^--------------^ checking function argument has type bitvector(32)
  |     | No overloading for (operator |), tried:
  |     | * or_vec
  |     |   test.sail:9.22-33:
  |     |   9 |    let _ = bv | bv | bv | bv | b;
  |     |     |                      ^---------^ checking function argument has type bitvector(32)
  |     |     | No overloading for (operator |), tried:
  |     |     | * or_vec
  |     |     |   test.sail:9.27-33:
  |     |     |   9 |    let _ = bv | bv | bv | bv | b;
  |     |     |     |                           ^----^ checking function argument has type bitvector(32)
  |     |     |     | No overloading for (operator |), tried:
  |     |     |     | * or_vec
  |     |     |     |   test.sail:9.32-33:
  |     |     |     |   9 |    let _ = bv | bv | bv | bv | b;
  |     |     |     |     |                                ^ checking function argument has type bitvector(32)
  |     |     |     |     | Identifier b is unbound. Did you mean bv?
  |     |     |     | 
  |     |     |     | Also tried or_bool
  |     |     | 
  |     |     | Also tried or_bool
  |     | 
  |     | Also tried or_bool
  | 
  | Also tried or_bool
  | This seems less likely, use --explain-all-overloads to see full details

from sail.

Timmmm avatar Timmmm commented on August 24, 2024

Much better, thanks!

from sail.

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.