~ chicken-core (chicken-5) /manual/Declarations
Trap1[[tags: manual]]
2[[toc:]]
3
4
5== Declarations
6
7
8Declarations can be used to control compiler settings directly inside
9the compiled code and are always global in scope. In many (but not
10all) cases an associated command-line option exists. When in conflict,
11declarations override command-line options. When multiple declarations
12conflict, the one appearing textually last overrides any previous one.
13
14Declarations can be used to improve performance and to give entities
15like procedures and variables special properties that can result in
16better performing code. Most of these declarations subtly change the
17semantics of standard Scheme code with respect to the declared
18entities, so care must be taken when using them.
19
20Declarations are always ignored in {{csi}} (the interpreter) or in evaluated code.
21
22
23=== declare
24
25<macro>(declare DECLSPEC ...)</macro>
26
27Process declaration specifiers. Declarations always override
28any command-line settings. Declarations are valid for the whole
29compilation-unit (source file), the position of the declaration in
30the source file can be arbitrary. Declarations are ignored in the interpreter
31but not in code evaluated at compile-time (by {{eval-when}} or in
32syntax extensions loaded via {{require-extension}}).
33{{DECLSPEC}} may be any of the following:
34
35
36=== always-bound
37
38 [declaration specifier] (always-bound IDENTIFIER ...)
39
40Declares that the given variables are always bound and
41accesses to those have not to be checked.
42
43
44=== block
45
46 [declaration specifier] (block)
47
48Assume global variables are never redefined. This is the same as
49specifying the {{-block}} option.
50
51
52=== block-global
53=== hide
54
55 [declaration specifier] (block-global IDENTIFIER ...)
56 [declaration specifier] (hide IDENTIFIER ...)
57
58Declares that the toplevel bindings for {{IDENTIFIER ...}}
59should not be accessible from code in other compilation units or by
60{{eval}}. Access to toplevel bindings declared as block global is
61also more efficient. {{(declare (hide))}} is equivalent to {{(declare (block))}}.
62
63
64=== bound-to-procedure
65
66 [declaration specifier] (bound-to-procedure IDENTIFIER ...)
67
68Declares that the given identifiers are always bound to procedure values.
69
70
71=== enforce-argument-types
72
73 [declaration-specifier] (enforce-argument-types IDENTIFIER ...)
74
75Declares that the toplevel procedures listed check the type of their arguments
76(either explicitly or by calling other enforcing procedures) and so a successfull
77invocation will indicate the arguments are of the types declared.
78
79
80=== export
81
82 [declaration specifier] (export IDENTIFIER ...)
83
84The opposite of {{hide}}. All given identifiers will be exported and all toplevel variables
85not listed will be hidden and not be accessible outside of this compilation unit.
86
87
88=== emit-external-prototypes-first
89
90 [declaration specifier] (emit-external-prototypes-first)
91
92Emit prototypes for callbacks defined with {{define-external}} before any
93other foreign declarations. Equivalent to giving the {{-emit-external-prototypes-first}}
94option to the compiler.
95
96
97=== disable-interrupts
98
99 [declaration specifier] (disable-interrupts)
100
101Disable timer-interrupts checks in the compiled program. Threads can
102not be preempted in main- or library-units that contain this declaration.
103
104
105=== emit-import-library
106
107 [declaration specifier] (emit-import-library MODULENAME | (MODULENAME FILENAME) ...)
108
109Declares that any following definition of a module named {{MODULENAME}} should be written to
110an external file (either a specified one or a file named {{"MODULENAME.import.scm"}}).
111The compiler option {{-emit-import-library}} may also be used instead.
112
113Note that the import library is only generated if it cannot be found in the current
114directory, or if it exists but is not equal to the one that would be generated.
115
116
117=== emit-types-file
118
119 [declaration specifier] (emit-types-file [FILENAME])
120
121Enables generation of a types file for the current compilation unit, which will
122be written to the specified {{FILENAME}} or to {{<source-filename>.types}} in the
123current directory. This filename can be overridden with the {{-emit-types-file}}
124command line flag, which takes precedence over this declaration.
125
126
127=== inline
128
129 [declaration specifier] (inline)
130 [declaration specifier] (not inline)
131 [declaration specifier] (inline IDENTIFIER ...)
132 [declaration specifier] (not inline IDENTIFIER ...)
133
134If given without an identifier-list, inlining of known procedures is enabled (this is equivalent to the {{-inline}}
135compiler option). When an identifier-list is given, then inlining is enabled only for the specified global procedures.
136The negated forms {{(not inline)}} and {{(not inline IDENTIFIER)}} disable global inlining, or inlining for
137the given global procedures only, respectively.
138
139
140=== inline-global
141
142 [declaration specifier] (inline-global)
143 [declaration specifier] (not inline-global)
144 [declaration specifier] (inline-global IDENTIFIER ...)
145 [declaration specifier] (not inline-global IDENTIFIER ...)
146
147Declare that then given toplevel procedures (or all) are subject to
148cross-module inlining. Potentially inlinable procedures in the current
149compilation unit will be written to an external
150{{<source-filename>.inline}} file in the current directory. Globally
151inlinable procedures from other compilation units referred to via
152{{(declare (uses ...))}} or {{require-extension}} are loaded from
153{{.inline}} files (if available in the current include path) and inlined
154in the current compilation unit.
155
156Enabling global inlining implies {{(declare (inline))}}.
157
158
159=== inline-limit
160
161 [declaration specifier] (inline-limit THRESHOLD)
162
163Sets the maximum size of procedures which may potentially be inlined. The default threshold is {{20}}.
164
165
166=== unroll-limit
167
168 [declaration specifier] (unroll-limit LIMIT)
169
170Sets the maximum number of times a self-recursive call is inlined and
171so effectively "unrolled". The default limit is 1.
172
173
174=== keep-shadowed-macros
175
176 [declaration specifier] (keep-shadowed-macros)
177
178Normally, when a toplevel variable is assigned or defined that has the same name as a macro, the macro-definition
179will be removed (in addition to showing a warning). This declaration will disable the removal of the macro.
180
181
182=== local
183
184 [declaration specifier] (local)
185 [declaration specifier] (local IDENTIFIER ...)
186
187Declares that the listed (or all) toplevel variables defined in the
188current compilation unit are not modified from code outside of this
189compilation unit. See also the documentation for the {{-local}}
190compiler option about the implications of this.
191
192
193=== no-argc-checks
194
195 [declaration specifier] (no-argc-checks)
196
197Disables argument count checking.
198
199
200=== no-bound-checks
201
202 [declaration specifier] (no-bound-checks)
203
204Disables the bound-checking of toplevel bindings.
205
206
207=== no-procedure-checks
208
209 [declaration specifier] (no-procedure-checks)
210
211Disables checking of values in operator position for being of procedure type.
212
213
214=== no-procedure-checks-for-usual-bindings
215
216 [declaration specifier] (no-procedure-checks-for-usual-bindings)
217
218Disables checking of procedures for the default standard- and extended toplevel bindings.
219
220
221=== no-procedure-checks-for-toplevel-bindings
222
223 [declaration specifier] (no-procedure-checks-for-toplevel-bindings)
224
225Disables checking of procedures for calls to procedures referenced via a toplevel variable
226(calls to explicitly named procedures).
227
228
229=== predicate
230
231 [declaration specifier] (predicate (IDENTIFIER TYPE) ...)
232
233Marks the global procedure {{IDENTIFIER}} as a predicate on {{TYPE}}.
234
235
236=== profile
237
238 [declaration specifier] (profile IDENTIFIER ...)
239
240Enable profiling exclusively for given identifiers. Normally the compiler
241enables profiling decorations for all globally defined procedures. With
242this declaration, profiling can be enabled for selected procedures.
243
244
245=== pure
246
247 [declaration specifier] (pure IDENTIFIER ...)
248
249Declares the procedures with the names {{IDENTIFIER ...}} as
250referentially transparent, that is, as not having any side
251effects. This can help the compiler to remove non-side-effecting
252expressions.
253
254
255=== number-type
256=== fixnum-arithmetic
257
258 [declaration specifier] ([number-type] TYPE)
259 [declaration specifier] (fixnum-arithmetic)
260
261Declares that only numbers of the given type are used. {{TYPE}}
262may be {{fixnum}} or {{generic}} (which is
263the default).
264
265
266=== compile-syntax
267
268 [declaration specifier] (compile-syntax)
269
270Equivalent to the compiler option of the same name - macros defined in the compiled code are also made available at
271runtime.
272
273
274=== safe-globals
275
276 [declaration specifier] (safe-globals)
277
278Assumes variables assigned in the current compilation unit are always bound and
279that any calls to these variables can always be assumed to be calls to proper
280procedures.
281
282
283=== specialize
284
285 [declaration specifier] (specialize)
286
287Enables specialization. This is equivalent to passing the {{-specialize}} option to the compiler.
288
289
290=== standard-bindings
291
292 [declaration specifier] (standard-bindings IDENTIFIER ...)
293 [declaration specifier] (not standard-bindings IDENTIFIER ...)
294
295Declares that all given standard procedures (or all if no symbols are
296specified) are never globally redefined. If {{not}} is specified,
297then all but the given standard bindings are assumed to be never
298redefined.
299
300
301=== strict-types
302
303 [declaration specifier] (strict-types)
304
305Declares that the type of variables is not changed by assignment. Equivalent to giving the {{-strict-types}} compiler option.
306
307
308=== type
309
310 [declaration specifier] (type (IDENTIFIER TYPE) ...)
311
312Declares toplevel procedures to have a specific type for
313scrutiny. {{IDENTIFIER}} should name a toplevel variable and {{TYPE}}
314should be a type specification. A type-declaration overrides any
315previous declaration for the same identifier. See also [[Types]] for
316more information about using types, the syntax of type-specifiers and
317a more convenient type-declaration syntax ({{:}}).
318
319
320=== extended-bindings
321
322 [declaration specifier] (extended-bindings IDENTIFIER ...)
323 [declaration specifier] (not extended-bindings IDENTIFIER ...)
324
325Declares that all given non-standard and CHICKEN-specific procedures (or all if no symbols are specified) are never globally redefined.
326If {{not}} is specified, then all but the given extended bindings
327are assumed to be never redefined.
328
329
330=== usual-integrations
331
332 [declaration specifier] (usual-integrations IDENTIFIER ...)
333 [declaration specifier] (not usual-integrations IDENTIFIER ...)
334
335Declares that all given standard and extended bindings (or all if no
336symbols are specified) are never globally redefined. If {{not}}
337is specified, then all but the given standard and extended bindings are
338assumed to be never redefined. Note that this is the default behaviour,
339unless the {{-no-usual-integrations}} option has been given.
340
341
342=== unit
343
344 [declaration specifier] (unit IDENTIFIER)
345
346Specify compilation unit-name (if this is a library)
347
348
349=== unsafe
350
351 [declaration specifier] (unsafe)
352 [declaration specifier] (not safe)
353
354Do not generate safety-checks. This is the same as specifying the
355{{-unsafe}} option. Also implies
356
357
358 (declare (no-bound-checks) (no-procedure-checks) (no-argc-checks))
359
360
361=== unused
362
363 [declaration specifier] (unused IDENTIFIER ...)
364
365Disables any warnings when the global variable {{IDENTIFIER}} is not defined but used,
366or defined but never used and not exported.
367
368
369=== uses
370
371 [declaration specifier] (uses IDENTIFIER ...)
372
373Gives a list of used library-units. Before the toplevel-expressions
374of the main-module are executed, all used units evaluate their
375toplevel-expressions in the order in which they appear in this
376declaration. If a library unit A uses another unit B, then B's toplevel
377expressions are evaluated before A's. Furthermore, the used symbols
378are registered as features during compile-time, so {{cond-expand}}
379knows about them.
380
381
382---
383Previous: [[Types]]
384
385Next: [[Extensions]]