gfngfn / SATySFi

A statically-typed, functional typesetting system
GNU Lesser General Public License v3.0
1.16k stars 82 forks source link

Identifiers in packages not imported are sometimes visible #248

Open na4zagin3 opened 3 years ago

na4zagin3 commented 3 years ago

Modules defined in another package that is not imported are visible while they should not be.

Reproducible example

This example consist of three satyg packages and one saty file.

Dependency graph

test.saty 
     |
     +------------+------------+
     |            |            |
     v            v            |
test1.satyg  test2.satyg       |
     |            |            v
     +------------+------> set.satyg 

Files

File set.satyg:

module Set : sig
  type 'a t
  val empty : 'a t
  val eq : 'a t -> 'a t -> bool
end = struct
  type 'a t = 'a list
  let empty = []
  let eq s1 s2 = true
end

File test1.satyg:

@import: set

let s1 = Set.empty

File test2.satyg:

% This package does not import set package
%@import: set

% Set.empty should not be visible
let s1 = Set.empty

File test.satyg:

@require: stdjabook

@import: set
@import: test1
@import: test2

document (|
  title = {test};
  author = {\code(`@na4zagin3`);};
  show-title = Set.eq s1 s2;
  show-toc = false;
|) '<
  +p {
    test
  }
>

Execution result

$ satysfi test.saty
 ---- ---- ---- ----
  target file: 'test.pdf'
  dump file: 'test.satysfi-aux' (will be created)
  parsing 'test.saty' ...
  parsing 'stdjabook.satyh' ...
  parsing 'pervasives.satyh' ...
  parsing 'gr.satyh' ...
  parsing 'geom.satyh' ...
  parsing 'list.satyg' ...
  parsing 'option.satyg' ...
  parsing 'math.satyh' ...
  parsing 'code.satyh' ...
  parsing 'color.satyh' ...
  parsing 'vdecoset.satyh' ...
  parsing 'annot.satyh' ...
  parsing 'footnote-scheme.satyh' ...
  parsing 'set.satyg' ...
  parsing 'test1.satyg' ...
  parsing 'test2.satyg' ...
 ---- ---- ---- ----
  type checking 'option.satyg' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'pervasives.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'color.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'set.satyg' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'test2.satyg' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'list.satyg' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'geom.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'test1.satyg' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'gr.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'annot.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'footnote-scheme.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'math.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'vdecoset.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'code.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'stdjabook.satyh' ...
  type check passed.
 ---- ---- ---- ----
  type checking 'test.saty' ...
  type check passed. (document)
  evaluating 'option.satyg' ...
  preprocessing 'pervasives.satyh' ...
  preprocessing 'color.satyh' ...
  preprocessing 'set.satyg' ...
  preprocessing 'test2.satyg' ...
  evaluating 'list.satyg' ...
  preprocessing 'geom.satyh' ...
  preprocessing 'test1.satyg' ...
  preprocessing 'gr.satyh' ...
  preprocessing 'annot.satyh' ...
  preprocessing 'footnote-scheme.satyh' ...
  preprocessing 'math.satyh' ...
  preprocessing 'vdecoset.satyh' ...
  preprocessing 'code.satyh' ...
  preprocessing 'stdjabook.satyh' ...
  preprocessing 'test.saty' ...
  evaluating 'pervasives.satyh' ...
  evaluating 'color.satyh' ...
  evaluating 'set.satyg' ...
  evaluating 'test2.satyg' ...
  evaluating 'geom.satyh' ...
  evaluating 'test1.satyg' ...
  evaluating 'gr.satyh' ...
  evaluating 'annot.satyh' ...
  evaluating 'footnote-scheme.satyh' ...
  evaluating 'math.satyh' ...
  evaluating 'vdecoset.satyh' ...
  evaluating 'code.satyh' ...
  evaluating 'stdjabook.satyh' ...
 ---- ---- ---- ----
  evaluating texts ...
  evaluation done.
 ---- ---- ---- ----
  breaking contents into pages ...
  needs another trial for solving cross references...
 ---- ---- ---- ----
  evaluating texts (2nd trial) ...
  evaluation done.
 ---- ---- ---- ----
  breaking contents into pages ...
  all cross references were solved.
 ---- ---- ---- ----
  embedding fonts ...
 ---- ---- ---- ----
  writing pages ...
 ---- ---- ---- ----
  output written on 'test.pdf'.

Expected behavior

It shouldn't compile.

Environment

SATySFi 4e8ea2147f66b8c26a494067b3011e480be6526e (0.0.5+dev2020.09.05 at Satyrographos Repo)

$ opam list -i --columns=name,version
# Packages matching: installed
# Name                          # Version
angstrom                        0.15.0
astring                         0.8.5
base                            v0.14.0
base-bigarray                   base
base-bytes                      base
base-threads                    base
base-unix                       base
base_bigstring                  v0.14.0
base_quickcheck                 v0.14.0
batteries                       3.2.0
bigarray-compat                 1.0.0
bigstringaf                     0.7.0
bin_prot                        v0.14.0
biniou                          1.2.1
bos                             0.2.0
camlimages                      5.0.4
camlpdf                         2.3.1+satysfi
camomile                        1.0.2
charInfo_width                  1.1.0
cmdliner                        1.0.4
conf-m4                         1
conf-pkg-config                 1.3
core                            v0.14.0
core_kernel                     v0.14.1
cppo                            1.6.6
csexp                           1.3.2
ctypes                          0.17.1
depext                          transition
dot-merlin-reader               3.4.2
dune                            2.7.1
dune-configurator               2.7.1
easy-format                     1.3.2
fieldslib                       v0.14.0
fileutils                       0.6.3
fmt                             0.8.9
fpath                           0.7.3
integers                        0.4.0
jane-street-headers             v0.14.0
jbuilder                        1.0+beta20.2
js_of_ocaml-compiler            3.8.0
json-derivers                   1.0.0
jst-config                      v0.14.0
lambda-term                     3.1.0
logs                            0.7.0
lwt                             5.3.0
lwt_log                         1.1.1
lwt_react                       1.1.3
menhir                          20200624
menhirLib                       20200624
menhirSdk                       20200624
merlin                          3.4.2
mew                             0.1.0
mew_vi                          0.5.0
mmap                            1.1.0
num                             1.4
ocaml                           4.11.1
ocaml-base-compiler             4.11.1
ocaml-compiler-libs             v0.12.3
ocaml-config                    1
ocaml-migrate-parsetree         1.8.0
ocaml-syntax-shims              1.0.0
ocamlbuild                      0.14.0
ocamlfind                       1.8.1
ocamlgraph                      2.0.0
ocp-indent                      1.8.1
ocplib-endian                   1.1
octavius                        1.2.2
omake                           0.10.3
omd                             1.3.1
opam-core                       2.0.7
opam-depext                     1.1.5
opam-file-format                2.1.0
opam-format                     2.0.7
opam-repository                 2.0.7
opam-state                      2.0.7
otfm                            0.3.7+satysfi
parsexp                         v0.14.0
posixat                         v0.14.0
ppx_assert                      v0.14.0
ppx_base                        v0.14.0
ppx_bench                       v0.14.1
ppx_bin_prot                    v0.14.0
ppx_cold                        v0.14.0
ppx_compare                     v0.14.0
ppx_custom_printf               v0.14.0
ppx_derivers                    1.2.1
ppx_deriving                    5.1
ppx_deriving_yojson             3.6.1
ppx_enumerate                   v0.14.0
ppx_expect                      v0.14.0
ppx_fields_conv                 v0.14.1
ppx_fixed_literal               v0.14.0
ppx_hash                        v0.14.0
ppx_here                        v0.14.0
ppx_inline_test                 v0.14.1
ppx_jane                        v0.14.0
ppx_js_style                    v0.14.0
ppx_let                         v0.14.0
ppx_module_timer                v0.14.0
ppx_optcomp                     v0.14.0
ppx_optional                    v0.14.0
ppx_pipebang                    v0.14.0
ppx_sexp_conv                   v0.14.1
ppx_sexp_message                v0.14.0
ppx_sexp_value                  v0.14.0
ppx_stable                      v0.14.1
ppx_string                      v0.14.1
ppx_tools                       6.2
ppx_typerep_conv                v0.14.1
ppx_variants_conv               v0.14.1
ppxfind                         1.4
ppxlib                          0.15.0
re                              1.9.0
react                           1.2.1
result                          1.5
rresult                         0.6.0
satyrographos                   0.0.2.8
satysfi                         0.0.5+dev2020.09.05
satysfi-base                    1.3.0
satysfi-dist                    0.0.5+dev2020.09.05
satysfi-fonts-bodoni-star       2.3+satysfi0.0.5
satysfi-fonts-dejavu            2.37+satysfi0.0.4
satysfi-fonts-junicode          1.0002+satysfi0.0.5
satysfi-fss                     0.1.0
satysfi-fss-doc                 0.1.0
satysfi-fss-fontset-bodoni-star 2.3
satysfi-sss                     0.1.0
satysfi-zrbase                  0.4.0
seq                             base
sexplib                         v0.14.0
sexplib0                        v0.14.0
shexp                           v0.14.0
spawn                           v0.13.0
splittable_random               v0.14.0
stdio                           v0.14.0
stdlib-shims                    0.1.0
stringext                       1.6.0
time_now                        v0.14.0
timezone                        v0.14.0
topkg                           1.0.3
trie                            1.0.0
typerep                         v0.14.0
uchar                           0.0.2
uri                             4.0.0
uri-sexp                        4.0.0
utop                            2.6.0
uutf                            1.0.2
variantslib                     v0.14.0
yaml                            2.1.0
yojson                          1.7.0
yojson-with-position            1.4.2+satysfi
zed                             3.1.0
na4zagin3 commented 3 years ago

According to @gfngfn, this is expected since all packages are incrementally compiled with the shared global namespace. He has a plan to change the name resolution rule so that every external identifiers are explicitly introduced by either @require or @import.