Opened 8 years ago

Closed 7 years ago

#1376 closed defect (wontfix)

hide/block-global declaration doesn't hide exports

Reported by: megane Owned by:
Priority: minor Milestone: someday
Component: compiler Version: 5.0.0
Keywords: modules Cc:
Estimated difficulty: medium

Description

My understanding is that hide should be the opposite of the export declaration.

Here you can see both the macro foo and function bar get exported even when they are declared hidden:

(module
 m1
 *
 (import chicken scheme)
 (define-syntax (foo a b c) 1)
 (define (bar) 2)

 (declare (hide foo bar)))

(import m1)
(print (bar))
$ csc -J foo.scm && ./foo ; cat m1.import.scm
2
;;;; m1.import.scm - GENERATED BY CHICKEN 4.12.0 -*- Scheme -*-

(eval '(import chicken scheme))
(##sys#register-compiled-module
  'm1
  (list)
  '((bar . m1#bar))
  (list (cons 'foo (##sys#er-transformer (##core#lambda (a b c) 1))))
  (list))

;; END OF FILE

Change History (4)

comment:1 Changed 8 years ago by sjamaan

Estimated difficulty: medium
Priority: majorminor
Version: 5.0

Hide does not operate at the module level; it is a way to tell the compiler "you're free to inline this or drop the procedure altogether". It declares the procedure only needs to be visible from the current compilation unit. It is more like C's static function declaration than a module construct.

I guess the hide declaration sort of "conflicts" with a module export, because a module export declares that a procedure is a) visible outside the compilation unit and b) can be imported into a module's namespace. Basically, a procedure as hidden while at the same time trying to export it from a module is "nonsense".

Finally, the hide declaration is not scoped, so it should really read (declare (hide m1#foo m1#bar)) to have the "intended" effect. The hide declaration effectively ignores undefined variables.

Having said all that, I think we should either error/warn about this situation or attempt to indeed do what you think it would do: hide the procedure instead of exporting it (but that would require changing declarations so they respect module scope).

So unless you're interested in making a patch for this, I'm afraid it will probably be done sometime in the 5.2 or 5.3 release, or even later.

comment:2 in reply to:  1 Changed 8 years ago by evhan

Replying to sjamaan:

think we should either error/warn about this situation or attempt to indeed do what you think it would do

+1, it would be best to make declare "just work" for this case.

Finally, the hide declaration is not scoped, so it should really read (declare (hide m1#foo m1#bar)) to have the "intended" effect. The hide declaration effectively ignores undefined variables.

Unrelated to this ticket, but the hide declaration does actually respect module aliasing in this example, and in general.

comment:3 Changed 8 years ago by felix winkelmann

Sorry, but this is a non-problem. Visibility declarations should be completely unnecessary when modules are used and declarations are compile-time only. Moreover the hide declaration applies to value bindings only, IIRC.

If you want to make bindings non-visible from a module, then simply DO NOT EXPORT it.

comment:4 Changed 7 years ago by evhan

Resolution: wontfix
Status: newclosed

Wontfix per chicken-hackers.

However, see #1383.

Note: See TracTickets for help on using tickets.