anoma / juvix

A language for intent-centric and declarative decentralised applications
https://docs.juvix.org
GNU General Public License v3.0
457 stars 53 forks source link

Weird Compiler Error on Import Cycles #3161

Closed mariari closed 4 days ago

mariari commented 1 week ago

Describe the bug A clear and concise description of what the bug is.

Desktop (please complete the following information):

To Reproduce Steps to reproduce the behavior:

https://github.com/anoma/juvix-stdlib/tree/mariari/show-bad-error

check out the branch above and run juvix typecheck

% juvix typecheck
juvix: Impossible: Could not find edge between
/home/taichi/Documents/Work/Repo/anoma-repos/juvix-stdlib/ : "Stdlib/Data/String/Base.juvix"
and
/home/taichi/Documents/Work/Repo/anoma-repos/juvix-stdlib/ : "Stdlib/Debug/Fail.juvix"
Available Edges:
[ import Stdlib.Data.Fixity
, import Juvix.Builtin.V1.String
, import Stdlib.Function
, import Stdlib.Data.List.Base ]
CallStack (from HasCallStack):
  error, called at src/Juvix/Prelude/Base/Foundation.hs:510:9 in juvix-0.6.6-63HcRSLJPON7XBeV31D9oO:Juvix.Prelude.Base.Foundation
  error, called at src/Juvix/Compiler/Pipeline/Loader/PathResolver/ImportTree.hs:139:11 in juvix-0.6.6-63HcRSLJPON7XBeV31D9oO:Juvix.Compiler.Pipeline.Loader.PathResolver.ImportTree

If I change the import cycle to be more direct:

module Stdlib.Trait.Partial;

import Stdlib.Data.String.Base open;
-- import Juvix.Builtin.V1.String open;
import Stdlib.Debug.Fail as Debug;

trait
type Partial := mkPartial@{fail : {A : Type} -> String -> A};

open Partial public;

runPartial {A} (f : {{Partial}} -> A) : A := f {{mkPartial Debug.failwith}};

to

module Stdlib.Trait.Partial;

-- import Stdlib.Data.String.Base open;
import Juvix.Builtin.V1.String open;
import Stdlib.Debug.Fail as Debug;

trait
type Partial := mkPartial@{fail : {A : Type} -> String -> A};

open Partial public;

runPartial {A} (f : {{Partial}} -> A) : A := f {{mkPartial Debug.failwith}};

then we get

% juvix typecheck
/home/taichi/Documents/Work/Repo/anoma-repos/juvix-stdlib/Stdlib/Data/List/Base.juvix:9:0-28: error:
There is an import cycle:
  import Stdlib.Trait.Partial (at /home/taichi/Documents/Work/Repo/anoma-repos/juvix-stdlib/Stdlib/Data/List/Base.juvix:9:0-28)
  ⇓
  import Stdlib.Debug.Fail (at /home/taichi/Documents/Work/Repo/anoma-repos/juvix-stdlib/Stdlib/Trait/Partial.juvix:4:0-25)
  ⇓
  import Stdlib.Data.String.Base (at /home/taichi/Documents/Work/Repo/anoma-repos/juvix-stdlib/Stdlib/Debug/Fail.juvix:2:0-31)
  ⇓
  import Stdlib.Data.List.Base (at /home/taichi/Documents/Work/Repo/anoma-repos/juvix-stdlib/Stdlib/Data/String/Base.juvix:3:0-29)
  ⇓
  import Stdlib.Trait.Partial (at /home/taichi/Documents/Work/Repo/anoma-repos/juvix-stdlib/Stdlib/Data/List/Base.juvix:9:0-28)

I assume there is a bug in the compiler that doesn't transform the first to this error message

janmasrovira commented 1 week ago

I can't reproduce the error. Perhaps the state of .juvix-build was corrupted.

I've run:

git clone git@github.com:anoma/juvix-stdlib.git bug
cd bug
git checkout origin/mariari/show-bad-error
juvix typecheck
mariari commented 1 week ago

@janmasrovira can you give me your ref?

juvix/mariari/show-bad-error 1abf52b141b3ae752cf5d052e285bd225e30a7d7

Is the ref.

I'm trying it now on the v0.6.7 compiler and I still get the error

% LANG=en_US.UTF-8 git show --oneline -q
1abf52b (HEAD -> mariari/show-bad-error, juvix/mariari/show-bad-error) Bad Error Time
% juvix typecheck
juvix: Impossible: Could not find edge between
/home/taichi/Documents/Work/Repo/anoma-repos/juvix-stdlib/ : "Stdlib/Data/String/Base.juvix"
and
/home/taichi/Documents/Work/Repo/anoma-repos/juvix-stdlib/ : "Stdlib/Debug/Fail.juvix"
Available Edges:
[ import Stdlib.Data.Fixity
, import Juvix.Builtin.V1.String
, import Stdlib.Function
, import Stdlib.Data.List.Base ]
CallStack (from HasCallStack):
  error, called at src/Juvix/Prelude/Base/Foundation.hs:510:9 in juvix-0.6.7-50u9D51IVst7yCAZvJwESf:Juvix.Prelude.Base.Foundation
  error, called at src/Juvix/Compiler/Pipeline/Loader/PathResolver/ImportTree.hs:139:11 in juvix-0.6.7-50u9D51IVst7yCAZvJwESf:Juvix.Compiler.Pipeline.Loader.PathResolver.ImportTree