cucapra / filament

Fearless hardware design

Home Page:http://filamenthdl.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filament `Imports` can pollute parent namespace.

UnsignedByte opened this issue · comments

If we import some file a.fil in main.fil, and that file internally imports b.fil, we can use the modules in b.fil in main.fil.

This could be unwanted because we can do something like the following:

// main.fil
import "a.fil";

comp main<'G: 1>(...) -> (...) {
    calc := new Calc<'G>(...);
}
// a.fil
import "b.fil";

// define some other components
// b.fil
comp Calc<'G: 1>(
    ['G, 'G+1] in: 1,
) -> (
    ['G, 'G+1] out: 1,
) {
    out = in;
}

This would be confusing to debug, for example, as it would be difficult to find where components come from in larger projects, and would make it much harder to debug, for example, if multiple files define some component with the same name.

I did some testing with defining a component named Calc in main.fil, and FWIW filament uses the right Calc, so we are unlikely to have weird bugs with redefnining components leading to inconsistent behavior.

Yeah, this is a problem because we import everything into the same global namespace. A better solution would require thinking about modules (#118) and explicitly reasoning about the bindings that are visible in a particular file.