Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 1 addition & 43 deletions rhombus-lib/rhombus/private/amalgam/module.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

(provide (for-space rhombus/decl
(rename-out
[rhombus:module module]))
pragma)
[rhombus:module module])))

(module+ for-module-begin
(provide (for-space rhombus/decl
Expand Down Expand Up @@ -179,44 +178,3 @@
(car (syntax-e orig)))])
(loop (syntax-track-origin stx orig id-stx)
(cdr origs))))))])))

;; ----------------------------------------

(begin-for-syntax
(define-splicing-syntax-class :pragma
#:attributes (kw [parsed 1])
(pattern (~seq (~and kw #:unsafe))
#:with (parsed ...) (list #'kw))
(pattern (~seq (~and kw #:empty_evaluator))
#:with (parsed ...) (list #'#:empty-namespace))
;; TODO: allow, but then disable `#:realm` added by `rhombus`:
#;
(pattern (~seq (~and kw #:realm) id:identifier)
#:with (parsed ...) (list #'kw #'id))
;; not possible, so far:
#;
(pattern (~seq (~and kw #:cross_phase_persistent))
#:with (parsed ...) (list #'#:cross-phase-persistent)))

;; Also module-local:
(define-values (pragmas-box) (make-hasheq)))

(define-syntax pragma
(declaration-transformer
(lambda (stx)
(define (check kw-stxes)
(for ([kw (in-list (syntax->list kw-stxes))])
(when (hash-ref pragmas-box (syntax-e kw) #f)
(raise-syntax-error #f "duplicate use of keyword" stx kw))
(hash-set! pragmas-box (syntax-e kw) #t)))
(unless (eq? 'module (syntax-local-context))
(raise-syntax-error #f "allowed only within a module body" stx))
(syntax-parse stx
#:datum-literals (group)
[(_ p::pragma)
(check #'(p.kw))
#`((#%declare p.parsed ...))]
[(_ (_::block (group p::pragma ...)
...))
(check #'(p.kw ... ...))
#`((#%declare p.parsed ... ... ...))]))))
8 changes: 5 additions & 3 deletions rhombus/rhombus/scribblings/model/static-overview.scrbl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#lang rhombus/scribble/manual
@(import:
"common.rhm" open)
"common.rhm" open
meta_label:
rhombus/unsafe.use_unsafe)

@title(~style: #'toc, ~tag: "static-info"){Type Model}

Expand All @@ -13,8 +15,8 @@ object's class. The main distinction between this capability and a
statically typed language, at least in the usual sense, is that Rhombus
offers only limited guarantees that static predictions about values will
be correct. Rhombus is a safe language,@margin_note{Although Rhombus is
safe by default, unsafe facilities or the use of
@rhombus(pragma ~unsafe, ~decl) can opt into unsafe mode.} because
safe by default, unsafe facilities or the use of an
@rhombus(use_unsafe) declaration can opt into unsafe mode.} because
run-time checks will enforce predictions where the compiler cannot prove
that they will hold, but limited guarantees mean that the checks can
fail.
Expand Down
29 changes: 0 additions & 29 deletions rhombus/rhombus/scribblings/reference/module.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,6 @@ different than the enclosing (sub)module.

}

@doc(
~nonterminal:
module_path: import ~defn

decl.macro 'pragma $decl'
decl.macro 'pragma:
$decl ...
...'

grammar decl
| ~unsafe
| ~empty_evaluator
){

Controls properties of a module's compilation:

@itemlist(

@item{@as_indexed{@rhombus(~unsafe)} compiles the module in unsafe mode,
where annotation failures trigger unspecified behavior.}

@item{@as_indexed{@rhombus(~empty_evaluator)} disables the use of the
module's content for interactive evaluation, which can avoid overhead
for the module.}

)

}

@doc(
decl.macro '#%module_block:
$body
Expand Down