@@ -120,6 +120,46 @@ macro optlevel(n::Int)
120
120
return Expr (:meta , :optlevel , n)
121
121
end
122
122
123
+ """
124
+ Experimental.@compiler_options optimize={0,1,2,3} compile={yes,no,all,min} infer={yes,no}
125
+
126
+ Set compiler options for code in the enclosing module. Options correspond directly to
127
+ command-line options with the same name, where applicable. The following options
128
+ are currently supported:
129
+
130
+ * `optimize`: Set optimization level.
131
+ * `compile`: Toggle native code compilation. Currently only `min` is supported, which
132
+ requests the minimum possible amount of compilation.
133
+ * `infer`: Enable or disable type inference. If disabled, implies [`@nospecialize`](@ref).
134
+ """
135
+ macro compiler_options (args... )
136
+ opts = Expr (:block )
137
+ for ex in args
138
+ if isa (ex, Expr) && ex. head === :(= ) && length (ex. args) == 2
139
+ if ex. args[1 ] === :optimize
140
+ push! (opts. args, Expr (:meta , :optlevel , ex. args[2 ]:: Int ))
141
+ elseif ex. args[1 ] === :compile
142
+ a = ex. args[2 ]
143
+ a = # a === :no ? 0 :
144
+ # a === :yes ? 1 :
145
+ # a === :all ? 2 :
146
+ a === :min ? 3 : error (" invalid argument to \" compile\" option" )
147
+ push! (opts. args, Expr (:meta , :compile , a))
148
+ elseif ex. args[1 ] === :infer
149
+ a = ex. args[2 ]
150
+ a = a === false || a === :no ? 0 :
151
+ a === true || a === :yes ? 1 : error (" invalid argument to \" infer\" option" )
152
+ push! (opts. args, Expr (:meta , :infer , a))
153
+ else
154
+ error (" unknown option \" $(ex. args[1 ]) \" " )
155
+ end
156
+ else
157
+ error (" invalid option syntax" )
158
+ end
159
+ end
160
+ return opts
161
+ end
162
+
123
163
# UI features for errors
124
164
125
165
"""
0 commit comments