You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a main issue for a number of issues we need to fix.
Enforcing allowed imports
First, I can import anything I want here:
use something::that_doesnt_exist;
and it will work. This is because the name resolution pass doesn't seem to be aware of dependencies that are allowed. The Noname.toml file related to the code being compiled should dictate which dependencies are accessible. Some standard modules should be accessible as well (not std::builtins which is included by default, but std::crypto or std::bits)
Scope of imports
Second, it seems to me that we aren't really keeping track of what dependencies a function has access to as we traverse the AST. This is because we build one main TAST with all the fully-qualified functions (or exported structs or constants) in its functions: HashMap<FullyQualified, FnInfo<B>> field when we compile all dependencies in cmd_build_and_check.rs:produce_all_asts():
for dep in dep_graph.from_leaves_to_roots(){let path = path_to_package(&dep);let lib_file = path.join("src").join("lib.no");let code = std::fs::read_to_string(&lib_file).into_diagnostic().wrap_err_with(|| format!("could not read file `{path}`"))?;let lib_file_str = lib_file.to_string();
node_id = typecheck_next_file(&mut tast,Some(dep),&mut sources,
lib_file_str.clone(),
code,
node_id,)?;}
This means that if we have the following chain of imports a -> b -> c then a will be able to call c's functions. Worst, even parts of the dependency graph might have access to their neighboring parts if they are parsed after. I think we should keep a dependency graph on the side AND go through it as we go through different modules, so that we can keep track of what other modules are accessible to us.
I'm wondering if this could be done in the name resolution phase as explained in the previous section (so basically I might be repeating the same stuff here).
This is a main issue for a number of issues we need to fix.
Enforcing allowed imports
First, I can import anything I want here:
and it will work. This is because the name resolution pass doesn't seem to be aware of dependencies that are allowed. The
Noname.toml
file related to the code being compiled should dictate which dependencies are accessible. Some standard modules should be accessible as well (notstd::builtins
which is included by default, butstd::crypto
orstd::bits
)Scope of imports
Second, it seems to me that we aren't really keeping track of what dependencies a function has access to as we traverse the AST. This is because we build one main TAST with all the fully-qualified functions (or exported structs or constants) in its
functions: HashMap<FullyQualified, FnInfo<B>>
field when we compile all dependencies incmd_build_and_check.rs:produce_all_asts()
:This means that if we have the following chain of imports
a -> b -> c
thena
will be able to callc
's functions. Worst, even parts of the dependency graph might have access to their neighboring parts if they are parsed after. I think we should keep a dependency graph on the side AND go through it as we go through different modules, so that we can keep track of what other modules are accessible to us.I'm wondering if this could be done in the name resolution phase as explained in the previous section (so basically I might be repeating the same stuff here).
Move to declaring stdlib modules in noname files!
#155
The text was updated successfully, but these errors were encountered: