@@ -128,14 +128,14 @@ fn always_valid<T>(_: &T) -> bool {
128
128
/// This type allows us to store some metadata for the option. To get the value of an option,
129
129
/// you can simply dereference it (for example, *options.threads).
130
130
#[ derive( Clone ) ]
131
- pub struct MMTKOption < T : Debug + Clone > {
131
+ pub struct MMTKOption < T : Debug + Clone + FromStr > {
132
132
/// The actual value for the option
133
133
value : T ,
134
134
/// The validator to ensure the value is valid.
135
135
validator : fn ( & T ) -> bool ,
136
136
}
137
137
138
- impl < T : Debug + Clone > MMTKOption < T > {
138
+ impl < T : Debug + Clone + FromStr > MMTKOption < T > {
139
139
/// Create a new MMTKOption
140
140
pub fn new ( value : T , validator : fn ( & T ) -> bool ) -> Self {
141
141
// FIXME: We should enable the following check to make sure the initial value is valid.
@@ -164,7 +164,7 @@ impl<T: Debug + Clone> MMTKOption<T> {
164
164
}
165
165
166
166
// Dereference an option to get its value.
167
- impl < T : Debug + Clone > std:: ops:: Deref for MMTKOption < T > {
167
+ impl < T : Debug + Clone + FromStr > std:: ops:: Deref for MMTKOption < T > {
168
168
type Target = T ;
169
169
170
170
fn deref ( & self ) -> & Self :: Target {
@@ -177,7 +177,14 @@ macro_rules! options {
177
177
options!( $( #[ $outer] ) * $( $name: $type [ $validator] = $default) ,* ) ;
178
178
] ;
179
179
( $( $( #[ $outer: meta] ) * $name: ident: $type: ty [ $validator: expr] = $default: expr) ,* ) => [
180
- /// MMTk command line options.
180
+ /// Options for an MMTk instance. It affects many aspects of the behavior of the MMTk
181
+ /// instance, including the number of GC worker threads, the GC plan to use, etc.
182
+ ///
183
+ /// Options are set by the VM binding before creating an instance of MMTk. The VM binding
184
+ /// usually parses command line options, environment variables, configuration files, etc.,
185
+ /// to determine the options. MMTk also provides the [`Options::read_env_var_settings`]
186
+ /// method which reads environment variables of the form `MMTK_*` and set options. It can
187
+ /// be convenient in the early development stage of a VM binding.
181
188
#[ derive( Clone ) ]
182
189
pub struct Options {
183
190
$( $( #[ $outer] ) * pub $name: MMTKOption <$type>) ,*
@@ -209,16 +216,16 @@ macro_rules! options {
209
216
}
210
217
}
211
218
}
212
-
213
- impl Default for Options {
214
- /// By default, `Options` instance is created with built-in default settings.
215
- fn default ( ) -> Self {
216
- Self :: new( )
217
- }
218
- }
219
219
]
220
220
}
221
221
222
+ impl Default for Options {
223
+ /// By default, `Options` instance is created with built-in default settings.
224
+ fn default ( ) -> Self {
225
+ Self :: new ( )
226
+ }
227
+ }
228
+
222
229
impl Options {
223
230
/// Set an option by name and value as strings. Returns true if the option is successfully set;
224
231
/// false otherwise.
@@ -228,13 +235,12 @@ impl Options {
228
235
///
229
236
/// ```rust
230
237
/// let mut builder = MMTKBuilder::new();
231
- ///
232
- /// // Set values directly
233
238
/// builder.options.threads.set(4);
234
239
/// builder.options.plan.set(PlanSelector::GenImmix);
235
240
///
236
- /// // or convert strings to values.
237
- /// builder.options.stress_factor.set(user_input.parse());
241
+ /// // All `T` in `MMTKOption<T>` implement `FromStr`.
242
+ /// builder.options.plan.set(user_input1.parse()?);
243
+ /// builder.options.thread_affinity.set(user_input2.parse()?);
238
244
/// ```
239
245
///
240
246
/// Only use this method if the option name is also provided as strings, e.g. from command line
@@ -780,8 +786,6 @@ mod gc_trigger_tests {
780
786
}
781
787
}
782
788
783
- // Currently we allow all the options to be set by env var for the sake of convenience.
784
- // At some point, we may disallow this and all the options can only be set by command line.
785
789
options ! {
786
790
/// The GC plan to use.
787
791
plan: PlanSelector [ always_valid] = PlanSelector :: GenImmix ,
0 commit comments