Skip to content

Commit

Permalink
cgen: fix chained ./v -usecache -o v cmd/v (and all other V program…
Browse files Browse the repository at this point in the history
…s that use maps)
  • Loading branch information
spytheman committed Dec 29, 2021
1 parent cc577e1 commit cb34309
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ jobs:
- name: usecache
run: |
./v -usecache examples/hello_world.v && examples/hello_world
# ./v -o v2 -usecache cmd/v
# ./v2 -o v3 -usecache cmd/v
# ./v3 -usecache examples/tetris/tetris.v
./v -o v2 -usecache cmd/v
./v2 -o v3 -usecache cmd/v
./v3 -o tetris -usecache examples/tetris/tetris.v
- name: Test symlink
run: ./v symlink
# - name: Set up pg database
Expand Down
13 changes: 12 additions & 1 deletion vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -5008,7 +5008,18 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) {
}
}
else {
if g.pref.build_mode != .build_module {
// NB: -usecache uses prebuilt modules, each compiled with:
// `v build-module vlib/module`
// combined with a top level program, that is compiled with:
// `v -usecache toplevel`
// For it to work, the consts optimisations should be identical, because
// only the top level program will have the const initialisation code for
// all the modules.
// TODO: encapsulate const initialisation for each module in a separate function,
// that is just called by the top level program in _vinit, instead of generating
// all the code inside _vinit for each module.
use_cache_mode := g.pref.build_mode == .build_module || g.pref.use_cache
if !use_cache_mode {
if ct_value := field.comptime_expr_value() {
if g.const_decl_precomputed(field.mod, name, ct_value, field.typ) {
continue
Expand Down

0 comments on commit cb34309

Please sign in to comment.