From 86862d6a94baca43efd5bfe5eb38e6b8ae50cd03 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 1 Jun 2020 17:39:24 +0300 Subject: [PATCH] checker: remove mod_file_cacher exception --- vlib/v/builder/builder.v | 3 ++- vlib/v/checker/checker.v | 5 +---- vlib/v/parser/comptime.v | 3 ++- vlib/v/scanner/scanner.v | 3 ++- vlib/v/vmod/vmod.v | 9 ++++++--- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 1f96326ce6..40039de4f3 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -197,7 +197,8 @@ fn module_path(mod string) string { pub fn (b Builder) find_module_path(mod, fpath string) ?string { // support @VROOT/v.mod relative paths: - vmod_file_location := vmod.mod_file_cacher.get_by_file(fpath) + mcache := vmod.get_cache() + vmod_file_location := mcache.get_by_file(fpath) mod_path := module_path(mod) mut module_lookup_paths := []string{} if vmod_file_location.vmod_file.len != 0 && vmod_file_location.vmod_folder !in b.module_search_paths { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 8684a8a2c2..5c964a3e28 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -583,10 +583,7 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) { c.error('`$it.name` is immutable, declare it with `mut` to make it mutable', it.pos) } - } else if it.name in c.const_names { - if it.name .contains('mod_file_cacher') { - return - } + } else if it.name in c.const_names { c.error('cannot modify constant `$it.name`', it.pos) } } diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index 16f3abeca7..4b1247519c 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -15,7 +15,8 @@ const ( ) fn (mut p Parser)resolve_vroot(flag string) string { - vmod_file_location := vmod.mod_file_cacher.get_by_folder(p.file_name_dir) + mcache := vmod.get_cache() + vmod_file_location := mcache.get_by_folder(p.file_name_dir) if vmod_file_location.vmod_file.len == 0 { // There was no actual v.mod file found. p.error('To use @VROOT, you need' + ' to have a "v.mod" file in ${p.file_name_dir},' + diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 17fd49b1ac..572c22b86f 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -807,7 +807,8 @@ pub fn (mut s Scanner) scan() token.Token { } if name == 'VMOD_FILE' { if s.vmod_file_content.len == 0 { - vmod_file_location := vmod.mod_file_cacher.get_by_file( s.file_path ) + mcache := vmod.get_cache() + vmod_file_location := mcache.get_by_file( s.file_path ) if vmod_file_location.vmod_file.len == 0 { s.error('@VMOD_FILE can be used only in projects, that have v.mod file') } diff --git a/vlib/v/vmod/vmod.v b/vlib/v/vmod/vmod.v index 655c7cdfb6..eba7b09fc5 100644 --- a/vlib/v/vmod/vmod.v +++ b/vlib/v/vmod/vmod.v @@ -33,6 +33,7 @@ pub: vmod_folder string } +[ref_only] pub struct ModFileCacher { mut: cache map[string]ModFileAndFolder @@ -155,6 +156,8 @@ fn (mut mcache ModFileCacher) get_files(cfolder string) []string { return files } -pub const ( - mod_file_cacher = new_mod_file_cacher() // used during lookup for v.mod to support @VROOT -) +// used during lookup for v.mod to support @VROOT +const ( private_file_cacher = new_mod_file_cacher() ) +pub fn get_cache() &ModFileCacher { + return private_file_cacher +}