fmease / lushui

The reference compiler of the Lushui programming language
Apache License 2.0
7 stars 0 forks source link

Crate system #14

Closed fmease closed 3 years ago

fmease commented 4 years ago

The package system of lushui.

fmease commented 3 years ago

Implementation sketch:

pub struct Session {
    options: Options, // compilation flags coming from CLI or similar: unstable options, etc.
    crates: IndexVec<CrateIndex, Crate>, // `Crate` formerly `CrateScope`, now also contains crate metadata (version, …)
    map: SourceMap, // maybe
    errors: RefCell<Diagnostics>, // maybe, depends on our error handling strategy here
    warnings: RefCell<Diagnostics>, // leave out for now
    lowering: LoweringSession, // or similar: parallel lexing, parsing and lowering: contains queue of SourceFiles
}

Also, I'd like to have methods/"queries" for Session which abstract a bit over the compiler passes so we can write more succinct code in main.rs like Session::front_end(…), Session::type_check(…), Session::document(…).

Additionally, I'd like to see a more centralized error handling infrastructure like an ErrorHandler/Communicator/Reporter inside of that session that controls the output of diagnostics (errors and maybe also warnings). This becomes increasingly important when we decide to implement allowing and denying of lints/warnings (those can update settings of the Reporter) and would like to support different error formats like short (for the use in a REPL or an IDE) or JSON. Kinda unrelated to this issue but I still regard it as useful since I'd like to architect this transition a bit more.

fmease commented 3 years ago

Since crates won't be compilation boundaries for now, crates are just a new kind of entity for the name resolver (not totally since we are going to use separate classes of indices for separate crates).

There's a good chance that the index examples above are very error-prone since parts of the name resolver might access and use the local index w/o checking the crate. I need to experiment with this. Of course, we could define the index as an u64 (or u128) and use some bytes of it for the crate index and some for the local part (with methods to abstract over this).