Skip to content
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

Trace back unification error #339

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MangoIV
Copy link
Collaborator

@MangoIV MangoIV commented Oct 27, 2024

  • see issue unifier error messages appear in the wrong place #338
  • add a very basic nix development environment
  • work in process of annotating the origin of an error
  • move the type error type into the heap to avoid warning
  • annotate ast with a bit more information what each of the nodes mean

@MangoIV MangoIV force-pushed the mangoiv/trace-back-unification-errors branch 3 times, most recently from 831c717 to 5314230 Compare October 27, 2024 12:28
Copy link
Collaborator

@timsueberkrueb timsueberkrueb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some nitpick comments, looking good so far, otherwise, thanks for contributing :)

flake.nix Outdated Show resolved Hide resolved
lang/parser/src/cst/exp.rs Outdated Show resolved Hide resolved
.envrc Outdated Show resolved Hide resolved
@MangoIV MangoIV force-pushed the mangoiv/trace-back-unification-errors branch 8 times, most recently from 1233624 to 46e7757 Compare October 28, 2024 13:13
@MangoIV MangoIV force-pushed the mangoiv/trace-back-unification-errors branch from 46e7757 to 1f1ea1d Compare November 7, 2024 10:37
@MangoIV
Copy link
Collaborator Author

MangoIV commented Nov 7, 2024

I rebased on main and now for some reason the output from check doesn't give me any description anymore:
image

@MangoIV
Copy link
Collaborator Author

MangoIV commented Nov 7, 2024

Ah no, it still does, but not on this example, however, on the smaller err.pol:
image

@MangoIV
Copy link
Collaborator Author

MangoIV commented Nov 7, 2024

ah! that's because they don't have labels. Please excuse the fuzz.

@MangoIV
Copy link
Collaborator Author

MangoIV commented Nov 7, 2024

image
I think I like this except due to the empty labels currently used in the macros the underlining of Type looks a bit sketchy.

@MangoIV MangoIV force-pushed the mangoiv/trace-back-unification-errors branch 2 times, most recently from 627f6d9 to c8a3963 Compare November 7, 2024 15:01
@MangoIV
Copy link
Collaborator Author

MangoIV commented Nov 7, 2024

image

Now there's a source span for (1) as well.

I wonder why the nix CI takes so long, the nix build doesn't use any caches... Maybe since the workflow is new it doesn't pick up the secret?

@BinderDavid
Copy link
Collaborator

Wow, the new error messages already look much better 👍

I wonder why the nix CI takes so long, the nix build doesn't use any caches... Maybe since the workflow is new it doesn't pick up the secret?

I remember something about GH Actions being different on PRs and main due to security reasons? I don't have a good mental model for what happens when you change the configuration of GitHub actions in PRs.

@MangoIV
Copy link
Collaborator Author

MangoIV commented Nov 7, 2024

Yeah me either and it somehow always manages to surprise me so it probably won’t emerge any time soon lol

@MangoIV
Copy link
Collaborator Author

MangoIV commented Nov 11, 2024

I'm currently verifying that the error messages actually make sense.

Here is the error message for 005.pol

image
I think it does make sense, but do you agree?

@MangoIV
Copy link
Collaborator Author

MangoIV commented Nov 11, 2024

Also in such situations, I'm not entirely sure whether we actually need the information to make sense of the error. Perhaps it should be hidden behind a flag?

image

@MangoIV MangoIV force-pushed the mangoiv/trace-back-unification-errors branch from c8a3963 to 31ef45a Compare November 11, 2024 12:40
@BinderDavid
Copy link
Collaborator

BinderDavid commented Nov 11, 2024

Also in such situations, I'm not entirely sure whether we actually need the information to make sense of the error. Perhaps it should be hidden behind a flag?

I think most people will primarily interact with the error messages via the LSP editor integration. And the important thing is that you fixed the location of the squiggly lines for that use case (I just checked this myself). Also we don't report multiple errors for the same file currently (cp #65), so there is also a smaller likelihood that users are swamped by pages and pages of error messages.

(LSP supports "related locations" for error messages. We could investigate in the future how well they work with these examples)

@MangoIV
Copy link
Collaborator Author

MangoIV commented Nov 11, 2024

(LSP supports "related locations" for error messages. We could investigate in the future how well they work with these examples)

that would be really nice!

@timsueberkrueb
Copy link
Collaborator

timsueberkrueb commented Nov 11, 2024

I think this is a great improvement.

If you allow me to dream up an ideal textual error message for this scenario it might look like this:

Error: T-002

Type mismatch in definition call between:

  │   1: Foo(False)    -- type of self argument
  │   2: Foo(True)     -- type of self parameter
  │ 
    ╭─[file:///home/tim/Dev/polarity-lang/polarity/test/suites/fail-check/002.pol:9:1]
  9 │     Bar : Foo(True),
 10 │     Baz : Foo(False),
    ·           ─────┬────
    ·                ╰── Source of (1)
 11 │ }
 12 │ 
 13 │ def Foo(True).foo() : Nat {
    ·     ────┬────
    ·         ╰── Source of (2)
 14 │     Bar() => Z,
 15 │     Baz() absurd,
 16 │ }
 17 │ 
 18 │ data Unit { Top }
 19 │ 
 20 │ def Unit.example : Nat {
 21 │     Top => Baz.foo
    ·            ─┬─ ─┬─
    ·             |   ╰── expected type (2)
    ·             ╰── got type (1)
 22 │ }
    ╰────

@MangoIV
Copy link
Collaborator Author

MangoIV commented Nov 15, 2024

Is there something you want me to do on this one? Otherwise I'd mark this as ready for review :)

- add an origin field to NotEq unification error
- add an origin field to CannotDecide unification error
- reuse the span emitted for a data constructor without type for its
  type
- Box the type error in Error to reduce the size of the enum
@MangoIV MangoIV force-pushed the mangoiv/trace-back-unification-errors branch from 31ef45a to c035ca5 Compare November 15, 2024 16:01
@MangoIV MangoIV marked this pull request as ready for review November 15, 2024 16:35
Copy link
Collaborator

@timsueberkrueb timsueberkrueb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a big improvement to our error messages, thank you!

I left some suggestions. Most of them are nitpicks. Please do check the comments on simplifying the test case, the reason field and whether to use the spans of (co)cases rather than (co)matches.

authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: Evaluate nix code
run: nix -Lv flake check
- name: build and run polarity using nix
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: build and run polarity using nix
- name: Build and run polarity using nix

run: nix -Lv flake check
- name: build and run polarity using nix
run: nix -Lv run .# -- --help
- name: build and run a static polarity exe
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: build and run a static polarity exe
- name: Build and run a static polarity exe

- your changes use existing nixpkgs infrastructure where possible
- your changes do not break any of the existing workflows and everything works as normal for non-nix users
- your changes do not require changes in regular non-nix development workflows
- your changes do not introduce any unnecessary IFD
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe link to a reference on what IFD is.

Copy link
Collaborator Author

@MangoIV MangoIV Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, I guess I will have to find one :P (https://nix.dev/manual/nix/2.25/language/import-from-derivation)

flake.nix Show resolved Hide resolved
meta = {
description = "A language with Dependendent Data and Codata Types";
homepage = "https://polarity-lang.github.io/";
licenses = with lib.licenses; [
Copy link
Collaborator

@timsueberkrueb timsueberkrueb Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the license field, the docs say:

If the license field is in the form of a list representation, then it means that parts of the package are licensed differently

Is the semantic of the licenses field different? Does this convey SPDX MIT OR Apache-2.0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look that up.

pub struct Fun {
pub span: Span,
pub from: Box<Exp>,
pub to: Box<Exp>,
}

#[derive(Debug, Clone)]
/// Lambda abstractions \x. e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Lambda abstractions \x. e
/// Lambda abstractions (syntactic sugar), e.g. \x. e

pub struct NatLit {
pub span: Span,
pub val: BigUint,
}

#[derive(Debug, Clone)]
/// Function arrow in syntax
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Function arrow in syntax
/// Function arrow (syntactic sugar), e.g. a -> b

@@ -35,6 +35,8 @@ pub enum TypeError {
lhs_span: Option<SourceSpan>,
#[label("Source of (2)")]
rhs_span: Option<SourceSpan>,
#[label("While elaborating")]
reason_span: Option<SourceSpan>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if there's a better term than reason to describe these fields. As far as I can see, this is always the span of the syntax tree node that is currently being elaborated.
I'm not sure I have a better term though; I've considered elab_origin_span, while_elaborating_span, ast_node_span.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I will probably take one of your options, I like while_elaborating_span best, for now :)

@@ -33,7 +33,7 @@ impl CheckToplevel for Def {

let ws = WithScrutinee { cases, scrutinee: self_param_nf.expect_typ_app()? };
ws.check_exhaustiveness(ctx)?;
let cases = ws.check_ws(ctx, &ret_typ_nf)?;
let cases = ws.check_ws(ctx, &ret_typ_nf, span)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the span of the definition or of the case here? The same applies to top-level codefinitions and local (co)matches.



codef ZipWith(n : Type, f : (CoNat -> CoNat -> CoNat), l1:CoList(n), l2: CoList(n)) : CoList(n) {
}
Copy link
Collaborator

@timsueberkrueb timsueberkrueb Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test case can be simplified. E.g. remove unnecessary (co)definitions, or create a simpler example that produces the same kind of error.

For instance:

data Foo {}

data Bar(f: Foo) {}

let bar(a: Type): Bar(a) { ? }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants