Skip to content

rd: propose draft of MOD-1 - #458

Open
KyrylR wants to merge 1 commit into
masterfrom
rd/mod-1
Open

KyrylR wants to merge 1 commit into
masterfrom
rd/mod-1

Conversation

@KyrylR
KyrylR requested a review from apoelstra November 12, 2026 13:55
@KyrylR KyrylR self-assigned this Nov 12, 2026
@KyrylR
KyrylR requested a review from delta1 as a code owner November 12, 2026 13:55
@KyrylR
KyrylR force-pushed the rd/mod-1 branch 4 times, most recently from aae22b6 to c3fa46c Compare November 12, 2026 14:02
Comment thread doc/roadmap/README.md
is to define the DAG of dependencies so that we can understand what is blocking the high-priority
items.

| ID | Name | Description | Dependencies | Status | PRs |

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My MD formatted did this, if it does not conflict with others, let's keep it

Though it is annoying that it changed whole table

Comment thread doc/roadmap/MOD.md
Comment on lines +224 to +225
With `--debug`, debug symbols are numbered in the order in which analysis reaches the calls, so a reordered program can
get a different debug CMR, as moving a function already could on master.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This important point, about which I would like to hear your opinion

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to drop this sentence, and separately we should work on removing --debug in favor or something less invasive.

But I guess that's not on the critical path, and --debug is useful for now, so we'll probably keep it for a while. And in this case, the existing text sounds good to me.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should work on removing --debug in favor or something less invasive.

I can create a roadmap item for that

Comment thread doc/roadmap/MOD.md
Every module owns a directory for the files of its child modules:

- the crate root file `main.simf` owns the directory it is in;
- the module file `D/x.simf` owns `D/x/`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In c3fa46c:

Feel free to override me, but I have a mild preference for D/x/mod.simf rather than D/x.simf, because it makes it easier to tab-complete in the terminal if we don't have a x/ directory beside an x.simf file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below you mention this, say it's not allowed "for the time being". I think we should pick one and use that exclusively so we don't have style wars in every project.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should pick one and use that exclusively so we don't have style wars in every project.

Yeah, I had quite a dilemma regarding that

I like both variants in particular cases

I like x.simf in case when it does not have children, and I like D/x/mod.simf when it does have children mods

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After talk with @KyrylR I think we should just support both.

It feels a bit redundant, but unless we want to say "every single module is D/mod.simf even if it has no children", there will always be two possibilities for the no-children case. So we might as well have two possibilities for all cases.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 8931a27:

Updated the File layout section

And added these 2 sentences in the deps section:

Inside a dependency, each file is a module, and use alias::dir::file::item loads dir/file.simf.
So, dependencies keep this file-based form. use alias::dir::file::item loads only dir/file.simf.
Other form is responsibility of MOD-2 as well.

Comment thread doc/roadmap/MOD.md

The crate root in MOD-1 is defined by passing the file that is passed to `simc` for the compilation. `simc foo.simf`
makes `foo.simf` the root of the crate, whatever it's named.
In other words, the directory of the crate root file plays the role of that project root.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In c3fa46c:

In still other words, simc is equivalent to simc --project-root ./main.simf?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite, but yes

--project-root takes a directory, so the equivalent is simc main.simf --project-root .

Comment thread doc/roadmap/MOD.md Outdated
For example, `use math::arith::func;` (`func()` is called within the code), with `--dep math=libs/math` flag loads
`libs/math/arith.simf`.

`self` and `super` are reserved keywords. There are no glob imports and no qualified paths in expressions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In c3fa46c:

nit: should also say here that crate is reserved.

Comment thread doc/roadmap/MOD.md

#### Visibility

Items and modules are private unless marked `pub`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In c3fa46c:

Do we want to add pub(super) and pub(crate) here? Or punt on this for now?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would defer it to MOD-2 as, in a way, it is more relevant for it and I believe the time gap between MOD-1 and MOD-2 won't be too big

Comment thread doc/roadmap/MOD.md

Note regarding `unit_N`: with `--dep`, each dependency file is wrapped as `mod unit_N { ... }` at the top level, where N
is the file's source id.
It is a responsibility of MOD-2 to get rid of `unit_N`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In c3fa46c:

Yeah, I agree with this. I think we can do this in a fairly simple way but it'd still be too much scope for MOD-1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace unit_N with something like #unit_N though so that users can't directly refer to the module name or cause collisions with it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to this one: #458 (comment)

I would vote not to do it. IMO it is better to wait for MOD-2 and accept it as is as part of a "transition period"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About #unit_N, I don't think it helps. After flattening, the name is substituted into the use statements, so users could write the same thing with #. And if we didn't allow that, we would just break flattening

@LesterEvSe

Copy link
Copy Markdown
Collaborator

nit: I agree that a super keyword is useful. As for self, I think we could do without it, but it's fine to keep

Comment thread doc/roadmap/MOD.md
Comment on lines +241 to +249
#### Diagnostics

All of the above are collected without stopping at the first one.
A module whose file fails to load stays in the tree without items, so paths into it are not reported again.

Each import cycle is reported once, as one strongly connected component of the imports that stayed unresolved.
An import that could only import itself, such as `use crate::typo;` at the crate root, is reported as not found.

Analysis goes on after a failed import or a broken item, and reports the errors of the items that do not depend on them.

@LesterEvSe LesterEvSe Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In c3fa46c:

Let's model a tricky case:

mod a {
    pub mod foo {}
    pub fn foo() {}
    pub type foo = u32;
}

fn foo() {}
use crate::a::foo;
fn main() {}

Master accepts this, because resolve_processing_use_items_error returns Ok as soon as one namespace resolves and drops the other errors. So the RedefinedItem for fn foo is lost, and the local fn foo silently wins. Under this doc's rule (a local item never hides an import, E0255) it should be rejected, which I think is right. But then "same on master: yes" is not always right

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, master currently reports only the first import error in the AST phase and then stops. So, either we mention that this will be handled in the DIAG series, or, if you keep it here, you can reuse the code from #451

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything related to the diagnostics, should be handled in DIAG part

@LesterEvSe

Copy link
Copy Markdown
Collaborator

Despite that, LGTM!

@KyrylR

KyrylR commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

In 8931a27:

Updated list of reserved keywords and clarified the issue with D/x.simf and D/x/mod.simf

@canndrew

Copy link
Copy Markdown
Contributor

A lot of the wording here is kind awkard and confusing. I might do a PR to fix up some of it.

There are no glob imports

Horray! Although It might be nice to be able to specify a crate-wide prelude, but that's something we can always add later.

and no qualified paths in expressions.

How do you refer to things that need a qualified path then? Do we still want to support traits/methods at some point?

Items and modules are private unless marked pub.

I've mentioned this before but we should really avoid Rust's mistake here and have two seperate levels of pub-ness.

I'll call them defpub and sigpub for explanation's sake. The difference would be that defpub exposes the full definition of an item whereas sigpub only exposes its signature. eg. for a type, sigpub only exposes an opaque type with that name and not whether the type is a struct, an enum a type alias or whatever. For constants sigpub would expose an opaque constant which only unifies with itself whereas defpub would expose the actual value of the constant.

This also gives you nominal typing. For instance if you have something like:

mod stuff {
    sigpub type Foo = (U32, U32);

    sigpub fn foo_into_pair_of_u32(foo: Foo) -> (U32, U32) {
        foo
    }

    sigpub fn foo_from_pair_of_u32(x: U32, y: U32) -> Foo {
        (x, y)
    }
}

Then Foo is a type alias only within stuff (since it's the only module with defpub access to Foo). Whereas modules above stuff see foo as a nominal type.

A module binds a name at most once in each namespace .. So programs like below, will compile.

Do we actually want to have separate namespaces for modules, types and functions?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants