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

[Documentation]: Module Initialization Order spec section could be clearer about submodules #24985

Open
mppf opened this issue May 3, 2024 · 0 comments

Comments

@mppf
Copy link
Member

mppf commented May 3, 2024

Consider this program:

module Main {
  writeln("initializing Main");

  module Submodule {
    writeln("initializing Main.Submodule");
    proc foo() { }
  }

  proc main() {
    import this.Submodule;
    Submodule.foo();
  }
}

At present, compiling and running this program produces this output:

initializing Main.Submodule
initializing Main

However, the language specification's description of module initialization order could be clearer about this being the result. One might interpret the statement

For nested modules, the parent module and its uses are initialized before the nested module and its uses or imports.

to indicate a constraint that requires parent modules are always initialized first, but this is not the case.

I think that what is actually happening is that Main starts initialization first, but the initialization process for Main causes Main.Submodule to be initialized.

The language specification is close to describing this in

Starting from the module that defines the main procedure, the modules named in its use and import statements are visited depth-first and initialized in post-order. If a use or import statement names a module that has already been visited, it is not visited a second time. Thus, infinite recursion is avoided.

Maybe this is clear enough? I think it's a bit subtle to interpret the "visited depth-first" as a separate operation from being initialized in post-order.

What to do about this?

  • add an example
  • clarify the "parent modules initialized first" part to indicate parent modules begin initialization first
  • while there, clarify that an except clause does not count as "naming" a module
@mppf mppf added the area: Docs label May 3, 2024
@mppf mppf changed the title [Documentation]: Module Initialization Order spec section is not clear about used submodules [Documentation]: Module Initialization Order spec section could be clearer about submodules May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant