-
Notifications
You must be signed in to change notification settings - Fork 124
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
Enhancement: vfs
is needed to uniformly manage KCL's current interaction with the file system during compilation.
#966
Comments
[WIP] KCL Virtual File SystemFeature
Workflowfile/code ---> VFS + SourceFiles ---> Parser/Resolver/Codegen
Parts
PkgPathPkgPath is the unified path style for VFS. struct PkgPath {
pkgpath: String, // the path in VFS, like "a.b.c.d"
extension: Option<String>, // the file extension, default is "k"
root: Option<String>, // the root path, default is "${KCL_MOD}"
} Implement the VFSVFS is the virtual file system. pub trait VFS{
// Load the local file path from `path` into VFS.
fn load(path: String) -> Self;
// If the `pkgpath` is loaded into VFS.
fn exists(pkgpath: PkgPath) -> bool;
// If return the `SourceFile` by `PkgPath`
fn get_source_files_by_pkgpath(pkgpath: PkgPath) -> Vec<SourceFile>;
// Add a specified file into VFS
fn insert_source_file_by_pkgpath(pkgpath: PkgPath);
}
let vfs = VFS::load("/usr/local/main.k");
If it is a dir, vfs.exists(PkgPath::new("usr.local"));
vfs.exists(PkgPath::new("usr.local.main"));
vfs.exists(PkgPath::new_with_extension("usr.local.main", Some("k")));
let pkgpath = PkgPath::new("usr.local");
let sfs: Vec<SourceFile> = vfs.get_source_files_by_pkgpath(pkgpath);
let pkgpath = PkgPath::new_with_extension("usr.local.main", Some("k"));
let sfs: Vec<SourceFile> = vfs.get_source_files_by_pkgpath(pkgpath); SourceFileAt present, the struct SourceFile {
// Still use the `SourceFile` in rustc.
sf: rustc::SourceFile
// `PkgPath` is used to associate `SourceFile` with `a.b.c.d` style path.
pkgPath: PkgPath
} |
Enhancement
The KCL compiler has some technical implementation problems in the process of interacting with the file system.
The Parse stage has a messy process of reading entry for compilation, either from the file system or from incoming code snippets, because it does not have a
vfs
, causing some work that requiresvfs
to be written directly to the parser. The resolver also relies directly on the local file system.Some apis that directly compile code snippets and the code snippets import each other, independent of local file system, and require a
vfs
to organize the associations between virtual code snippets.The text was updated successfully, but these errors were encountered: