Skip to content

Commit f6a36c9

Browse files
committed
allow configuration via :COALTON-CONFIG symbol-plist
1 parent 6ff46c9 commit f6a36c9

File tree

1 file changed

+83
-26
lines changed

1 file changed

+83
-26
lines changed

src/settings.lisp

Lines changed: 83 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,54 @@
1818

1919
(in-package #:coalton-impl/settings)
2020

21+
;;; Configuration reaches the Coalton compiler in 3 ways.
22+
;;;
23+
;;; 1. When Coalton is compiled, several environment variables are
24+
;;; inquired. These are
25+
;;;
26+
;;; - COALTON_ENV: Whether to be in development or release mode.
27+
;;;
28+
;;; - COALTON_DISABLE_SPECIALIZATION: Whether to disable
29+
;;; function specialization.
30+
;;;
31+
;;; - COALTON_HEURISTIC_INLINING: Whether to enable automatic
32+
;;; inlining.
33+
;;;
34+
;;; 2. When Coalton is compiled, configuration on properties of the
35+
;;; :COALTON-CONFIG symbol are inquired. These are secondary to the
36+
;;; environment variables.
37+
;;;
38+
;;; 3. When the Coalton compiler is run, several special variables
39+
;;; control how the code is compiled. The values of the special
40+
;;; variables are affected by the aforementioned configuration.
41+
42+
(eval-when (:compile-toplevel :load-toplevel :execute)
43+
(defvar *config-keys*
44+
'(:compiler-mode ; [string] compiler mode
45+
:print-unicode ; [boolean] print unicode?
46+
:perform-specialization ; [boolean] use specializations?
47+
:perform-inlining ; [boolean] automatic inlining?
48+
:emit-type-annotations ; [boolean] emit type annotations?
49+
:print-types ; [boolean] print types when compiling?
50+
)
51+
"Valid configuration keys that can be (SETF GET) on the user configuration variable :COALTON-CONFIG.")
52+
53+
(defun config (key &key (default nil defaultp))
54+
"Get the user configuration associated with the key KEY. If it's not
55+
found, return DEFAULT instead."
56+
(assert defaultp () "A default must be supplied to CONFIG.")
57+
(cond
58+
((member key *config-keys*)
59+
(get ':coalton-config key default))
60+
(t
61+
(warn "Unknown Coalton configuration key: ~A" key)
62+
default))))
63+
64+
65+
;;; Compiler and runtime configuration
66+
2167
(declaim (type boolean *coalton-print-unicode*))
22-
(defvar *coalton-print-unicode* t
68+
(defvar *coalton-print-unicode* (config ':print-unicode :default t)
2369
"Whether to print coalton info using unicode symbols")
2470

2571
(defun coalton-release-p ()
@@ -33,43 +79,54 @@ not support redefinition.
3379
3480
Development mode is the default.
3581
36-
Enable release mode either by setting the UNIX environment variable COALTON_ENV to \"release\", or by pushing
37-
`:coalton-release' into `*features*'. Either of these must be done before loading Coalton.
38-
"
39-
(uiop:featurep :coalton-release))
82+
Enable release mode either by setting the UNIX environment variable COALTON_ENV to \"release\", by
4083
41-
(when (string-equal (uiop:getenv "COALTON_ENV") "release")
42-
(pushnew :coalton-release *features*))
84+
(setf (get ':coalton-config ':compiler-mode) \"release\")
4385
44-
(when (coalton-release-p)
45-
(format t "~&;; COALTON starting in release mode~%"))
86+
or by pushing `:coalton-release' into `*features*'. Any of these must be done before loading Coalton."
87+
(uiop:featurep ':coalton-release))
4688

47-
(declaim (type boolean *coalton-disable-specialization*))
48-
(defvar *coalton-disable-specialization* nil)
89+
(when (or (string-equal (uiop:getenv "COALTON_ENV") "release")
90+
(string-equal (config ':compiler-mode :default nil) "release"))
91+
(pushnew ':coalton-release *features*))
4992

50-
(when (find (uiop:getenv "COALTON_DISABLE_SPECIALIZATION")
51-
'("t" "true" "1")
52-
:test #'string-equal)
53-
(format t "~&;; COALTON starting with specializations disabled~%")
54-
(setf *coalton-disable-specialization* t))
93+
(declaim (type boolean *coalton-disable-specialization*))
94+
(defvar *coalton-disable-specialization*
95+
(cond
96+
((find (uiop:getenv "COALTON_DISABLE_SPECIALIZATION")
97+
'("t" "true" "1")
98+
:test #'string-equal)
99+
t)
100+
(t
101+
;; NOT because this variable disables specializations.
102+
(not (config ':perform-specialization :default t)))))
55103

56104
(declaim (type boolean *coalton-heuristic-inlining*))
57-
(defvar *coalton-heuristic-inlining* nil)
58-
59-
(when (find (uiop:getenv "COALTON_HEURISTIC_INLINING")
60-
'("t" "true" "1")
61-
:test #'string-equal)
62-
(format t "~&;; COALTON starting with heuristic inlining enabled~%")
63-
(setf *coalton-heuristic-inlining* t))
105+
(defvar *coalton-heuristic-inlining*
106+
(cond
107+
((find (uiop:getenv "COALTON_HEURISTIC_INLINING")
108+
'("t" "true" "1")
109+
:test #'string-equal)
110+
t)
111+
(t
112+
(config ':perform-inlining :default nil))))
64113

65-
;; Configure the backend to remove type annotations from the generated code
66114
(declaim (type boolean *emit-type-annotations*))
67-
(defvar *emit-type-annotations* t)
115+
(defvar *emit-type-annotations* (config ':emit-type-annotations :default t)
116+
"Configure the backend to insert or remove type annotations from the generated code.")
68117

69118
(declaim (type boolean *compile-print-types*))
70-
(defvar *compile-print-types* nil
119+
(defvar *compile-print-types* (config ':print-types :default nil)
71120
"Print types of definitions to standard output on compile.")
72121

73122
(defvar *coalton-optimize* '(optimize (speed 3) (safety 0)))
74123

75124
(defvar *coalton-optimize-library* '(optimize (speed 3) (safety 1)))
125+
126+
127+
;;; Print (some of) the configuration
128+
129+
(format t "~&;; COALTON starting in ~:[development~;release~] mode~%" (coalton-release-p))
130+
(format t "~&;; COALTON starting with specializations ~:[enabled~;disabled~]~%" *coalton-disable-specialization*)
131+
(format t "~&;; COALTON starting with heuristic inlining ~:[disabled~;enabled~]~%" *coalton-heuristic-inlining*)
132+
(format t "~&;; COALTON will~:[ not~;~] emit type annotations~%" *emit-type-annotations*)

0 commit comments

Comments
 (0)