give importers the private macros a pub one expands into

Only pub macros crossed, so one built on a private macro expanded in
the importer into a call of a C function nothing defines.
This commit is contained in:
2026-10-16 17:04:20 +03:00
parent 54a79ee75e
commit b5f9089bf1
4 changed files with 42 additions and 3 deletions

View File

@@ -118,7 +118,39 @@
(interface-forms raw-forms))))
(define (interface-forms raw-forms)
(reverse (fold process-public-interface-form (list) raw-forms)))
(let ((helpers (helper-macros raw-forms)))
(reverse (fold (lambda (form acc)
(if (memq form helpers)
(cons form acc)
(process-public-interface-form form acc)))
(list)
raw-forms))))
;;; The private macros a pub one expands into, and the ones those do:
;;; the importer expands them all, the way a C header that defines a
;;; macro has to define what it uses too
(define (helper-macros raw-forms)
(let* ((macro-name (lambda (form)
(match form
(('defmacro (name . _) . _) name)
(('pub 'defmacro (name . _) . _) name)
(_ #f))))
(private (filter (lambda (form) (and (macro-name form) (not (pub-form? form))))
raw-forms))
(mentions (lambda (form name)
(let walk ((x (cdr form)))
(or (eq? x name) (and (pair? x) (or (walk (car x)) (walk (cdr x)))))))))
(let grow ((needed (list))
(users (filter (lambda (form) (and (macro-name form) (pub-form? form)))
raw-forms)))
(let ((more (filter (lambda (form)
(and (not (memq form needed))
(any (lambda (user) (mentions user (macro-name form)))
users)))
private)))
(if (null? more)
needed
(grow (append needed more) more))))))
;;; What importers can see of a module's types
;;;