gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

Can't have two modules with the same filename #298

Open IsaacOscar opened 5 years ago

IsaacOscar commented 5 years ago

When I have two files, foo.grace:

import "folder/foo" as F
F.hello

And folder/foo.grace:

method hello { print("hello") }

It fails to compile on master (due to issue #295), but compiles on the branch for pull request #297.

However it causes a stack overflow at runtime:

RequestError: error on line 1 of module foo: Maximum call stack size exceeded
  raised at module initialization at line 1 of folder/foo
  requested from module initialization at line 1 of folder/foo
  ...

Change either of the file names fixes the issue.

apblack commented 5 years ago

Yes, this has to do with the way that the compiled code references modules. It's good to register it as an issue.

apblack commented 5 years ago

I flagged this as wontfix because allowing multiple modules with the same name would require a significant re-work of the way that the compiled code functions are named. At present, they are named gracecode_‹moduleName›. A possible fix would be to name them gracecode_‹moduleSHA›, where moduleSHA is a cryptographically-secure digest of the module source.