actonlang / acton

The Acton Programming Language
https://www.acton-lang.org/
BSD 3-Clause "New" or "Revised" License
80 stars 7 forks source link

Intermittent compilation error to find function in module dependency #1957

Closed plajjan closed 3 weeks ago

plajjan commented 3 weeks ago

When trying to build a project that has a dependency, on the very first build, actonc doesn't find a function that is in an moduled imported from the dependency project.

kll@Kristians-MacBook-Air orchestron % acton build
Copying yang from zig global cache
Copying /Users/kll/.cache/acton/zig-global-cache/p/122093fc7009207f33da3c71cba1391c3797e97481f3b943751d4c1be6fb66283dbb to /Users/kll/orchestron/.build/deps/yang
Building dependencies:
 - yang
Building project in /Users/kll/orchestron/.build/deps/yang
  Compiling yang/syntax.act for release
   Finished compilation in   0.005 s
  Compiling yang/schema.act for release
   Finished compilation in  21.976 s
  Compiling yang/parser.act for release
   Finished compilation in   0.475 s
  Compiling yang/gdata.act for release
   Finished compilation in   0.659 s
  Compiling yang/adata.act for release
   Finished compilation in   0.004 s
  Compiling yang.act for release
   Finished compilation in   0.049 s
  Compiling test_yang.act for release
   Finished compilation in   0.414 s
  Compiling rfc.act for release
   Finished compilation in   0.055 s
  Compiling rfcgen.act for release
   Finished compilation in   0.833 s
  Final compilation step
   Finished final compilation step in   2.130 s
Dependency yang built successfully
All dependencies built, building main project
Building project in /Users/kll/orchestron
  Compiling ttt.act for release
   Finished compilation in   0.055 s
  Compiling ttt_gen.act for release
   Finished compilation in   0.069 s
  Compiling rfc.act for release
   Finished compilation in   0.078 s
  Compiling rfcgen.act for release
   Finished compilation in   0.625 s
  Compiling orchestron/build.act for release

ERROR: Error when compiling orchestron.build module: Compilation error

   |
28 |        layer_src = yang.compile(models)
   |                         ^^^^^^^
Module yang does not export compile

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Error building project Building project in /Users/kll/orchestron
  Compiling ttt.act for release
   Finished compilation in   0.055 s
  Compiling ttt_gen.act for release
   Finished compilation in   0.069 s
  Compiling rfc.act for release
   Finished compilation in   0.078 s
  Compiling rfcgen.act for release
   Finished compilation in   0.625 s
  Compiling orchestron/build.act for release

ERROR: Error when compiling orchestron.build module: Compilation error

   |
28 |        layer_src = yang.compile(models)
   |                         ^^^^^^^
Module yang does not export compile

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

kll@Kristians-MacBook-Air orchestron % 

running acton build again and it just works:

kll@Kristians-MacBook-Air orchestron % acton build
Building dependencies:
 - yang
Building project in /Users/kll/orchestron/.build/deps/yang
  Compiling yang/syntax.act for release
   Already up to date, in    0.000 s
  Compiling yang/schema.act for release
   Already up to date, in    0.007 s
  Compiling yang/parser.act for release
   Already up to date, in    0.000 s
  Compiling yang/gdata.act for release
   Already up to date, in    0.000 s
  Compiling yang/adata.act for release
   Already up to date, in    0.000 s
  Compiling yang.act for release
   Already up to date, in    0.001 s
  Compiling test_yang.act for release
   Already up to date, in    0.000 s
  Compiling rfc.act for release
   Already up to date, in    0.000 s
  Compiling rfcgen.act for release
   Already up to date, in    0.000 s
  Final compilation step
   Finished final compilation step in   0.173 s
Dependency yang built successfully
All dependencies built, building main project
Building project in /Users/kll/orchestron
  Compiling ttt.act for release
   Already up to date, in    0.000 s
  Compiling ttt_gen.act for release
   Already up to date, in    0.000 s
  Compiling rfc.act for release
   Already up to date, in    0.000 s
  Compiling rfcgen.act for release
   Already up to date, in    0.000 s
  Compiling orchestron/build.act for release
   Finished compilation in   0.060 s
  Final compilation step
   Finished final compilation step in  17.213 s
kll@Kristians-MacBook-Air orchestron %

It's not really intermittent, this really only happens the first time we try to build. I think if there are subsequent updates to some files, it can also show up but I don't know the details.

I don't understand how this can happen. The way we build a project with dependencies, we will first go and build each dependency project, so all files in there should already be compiled and the back in the main project we find the relevant .ty file and use it.

I have not been able to reproduce this on other projects, although I haven't tried that hard. I guess first step would be to instrument the compiler enough to like dump the content of the .ty file so we can check what we've actually read in.

Reproduction

Reproduction steps:

Troubleshooting

After wiping the problematic output from the yang dependency, I tried building, got the error and then inspected the .ty file, which looks good!

kll@Kristians-MacBook-Air orchestron % rm -rf .build/deps/yang/out
kll@Kristians-MacBook-Air orchestron % acton build
Building dependencies:
 - yang
Building project in /Users/kll/orchestron/.build/deps/yang
  Compiling yang/syntax.act for release
   Finished compilation in   0.004 s
... snip snip
Building project in /Users/kll/orchestron
  Compiling ttt.act for release
   Finished compilation in   0.058 s
  Compiling ttt_gen.act for release
   Finished compilation in   0.103 s
  Compiling rfc.act for release
   Already up to date, in    0.000 s
  Compiling rfcgen.act for release
   Already up to date, in    0.000 s
  Compiling orchestron/build.act for release

ERROR: Error when compiling orchestron.build module: Compilation error

   |
28 |        layer_src = yang.compile(models)
   |                         ^^^^^^^
Module yang does not export compile

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
... snip snip ...
kll@Kristians-MacBook-Air orchestron % actonc .build/deps/yang/out/types/yang.ty 

#################################### Interface:
import yang.schema
import yang.parser

compile : mut(yang_sources: list[str]) -> yang.schema.DRoot
kll@Kristians-MacBook-Air orchestron % 

it has a compile function in the yang module!!

Now building it again, it works OK and looking at the .ty file, it has the exact same content!

kll@Kristians-MacBook-Air orchestron % actonc .build/deps/yang/out/types/yang.ty

#################################### Interface:
import yang.schema
import yang.parser

compile : mut(yang_sources: list[str]) -> yang.schema.DRoot
kll@Kristians-MacBook-Air orchestron %
plajjan commented 3 weeks ago

Hmm, okay, so I started looking into this and have found some things that appear to be broken.... so no need for anyone else to look right now. I'll post updates.

plajjan commented 3 weeks ago

Fixed by #1961