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

aliases don't round trip #5357

Open
ceedubs opened this issue Sep 19, 2024 · 3 comments · May be fixed by #5360
Open

aliases don't round trip #5357

ceedubs opened this issue Sep 19, 2024 · 3 comments · May be fixed by #5360

Comments

@ceedubs
Copy link
Contributor

ceedubs commented Sep 19, 2024

Describe and demonstrate the bug

The pretty-printer takes into account two names being aliases when picking the shortest non-ambiguous suffix for a name, but the parser/type-checker does not. This leads to aliases not round-tripping.

Input:

```unison
util.ignore : a -> ()
util.ignore _ = ()

foo : ()
foo =
  ignore 3
  ignore 4
```

```ucm
scratch/main> add
```

```unison
lib.base.ignore : a -> ()
lib.base.ignore _ = ()
```

```ucm
scratch/main> add
scratch/main> edit.namespace
scratch/main> load
```

Output:

``` unison
util.ignore : a -> ()
util.ignore _ = ()

foo : ()
foo = ignore 3
```

``` ucm

  Loading changes detected in scratch.u.

  I found and typechecked these definitions in scratch.u. If you
  do an `add` or `update`, here's how your codebase would
  change:
  
    ⍟ These new definitions are ok to `add`:
    
      foo         : ()
      util.ignore : a -> ()

```
``` ucm
scratch/main> add

  ⍟ I've added these definitions:
  
    foo         : ()
    util.ignore : a -> ()

```
``` unison
lib.base.ignore : a -> ()
lib.base.ignore _ = ()
```

``` ucm

  Loading changes detected in scratch.u.

  I found and typechecked these definitions in scratch.u. If you
  do an `add` or `update`, here's how your codebase would
  change:
  
    ⍟ These new definitions are ok to `add`:
    
      lib.base.ignore : a -> ()
        (also named util.ignore)

```
``` ucm
scratch/main> add

  ⍟ I've added these definitions:
  
    lib.base.ignore : a -> ()
      (also named util.ignore)

scratch/main> edit.namespace

  ☝️
  
  I added 2 definitions to the top of scratch.u
  
  You can edit them there, then run `update` to replace the
  definitions currently in this namespace.

scratch/main> load

  Loading changes detected in scratch.u.

  I couldn't figure out what ignore refers to here:
  
      2 | foo = ignore 3
  
  The name ignore is ambiguous. Its type should be: ##Nat ->
  #00nv2kob8f
  
  I found some terms in scope that have matching names and
  types. Maybe you meant one of these:
  
  util.ignore : a -> #00nv2kob8f
  util.ignore : a -> #00nv2kob8f

```



🛑

The transcript failed due to an error in the stanza above. The error is:


  I couldn't figure out what ignore refers to here:
  
      2 | foo = ignore 3
  
  The name ignore is ambiguous. Its type should be: ##Nat ->
  #00nv2kob8f
  
  I found some terms in scope that have matching names and
  types. Maybe you meant one of these:
  
  util.ignore : a -> #00nv2kob8f
  util.ignore : a -> #00nv2kob8f

Environment (please complete the following information):

@ceedubs
Copy link
Contributor Author

ceedubs commented Sep 19, 2024

Note that there is another issue here in that it says:

Maybe you meant one of these:
  
  util.ignore : a -> #00nv2kob8f
  util.ignore : a -> #00nv2kob8f

Those are the same thing, ucm!

@aryairani
Copy link
Contributor

Some notes @mitchellwrosen and my discussion of this:

Current logic of “suffixify by hash”:

  • Do all names matching suffix baz refer to #xxx? If yes, use name baz
    • Proposed change
      • Actually look at those names that end in baz.
      • Do they look like this?
        • foo.bar.baz
        • lib.base.whatever.baz
      • If so, “yay!”, we only have one name in here (not 2+) that we are worried might end up in scratch file (foo.bar.baz)
        • So we use suffix baz
      • Do they look like this?
        • foo.bar.baz
        • qux.baz
      • Oh no! 2+ local names. Fall back to suffixify-by-name strategy
  • Else, do all names matching suffix bar.baz refer to #xxx? If yes, use name bar.baz

What about alias directives in the file

question/example:

what if you have aliases foo and bar and you say edit foo and then later say edit bar?

option 1: you get this

bar = 3

— fold

foo = 3

— fold

option 2: you get this

foo = 3
alias bar = foo

— fold

foo = 3
alias bar = foo

—

option 3: ???

@aryairani
Copy link
Contributor

Plan: tweak the suffixify by hash logic as outlined in the previous comment

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

Successfully merging a pull request may close this issue.

3 participants