Opened 7 months ago

Closed 5 months 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
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 follow-up: Changed 7 months ago by sjamaan

  • Estimated difficulty set to medium
  • Priority changed from major to minor
  • Version set to 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 6 months 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 6 months ago by felix

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 5 months ago by evhan

  • Resolution set to wontfix
  • Status changed from new to closed

Wontfix per chicken-hackers.

However, see #1383.

Note: See TracTickets for help on using tickets.