@@ -13,7 +13,8 @@ use crate::{
13
13
ir,
14
14
proc:: { ConstantEvaluator , ConstantEvaluatorError , Emitter , U32EvalError } ,
15
15
valid:: {
16
- Capabilities , ModuleInfo , UnresolvedOverrides , ValidationError , ValidationFlags , Validator ,
16
+ Capabilities , FunctionInfo , ModuleInfo , UnresolvedOverrides , ValidationError ,
17
+ ValidationFlags , Validator ,
17
18
} ,
18
19
Arena , Block , Constant , Expression , FastHashMap , Function , Handle , Literal , Module , Override ,
19
20
Range , Scalar , Span , Statement , TypeInner , WithSpan ,
@@ -59,6 +60,26 @@ pub struct ProcessOverridesOutput<'a> {
59
60
pub unresolved : UnresolvedOverrides ,
60
61
}
61
62
63
+ /// Check the global usage in `fun_info` for any globals affected by unresolved
64
+ /// overrides.
65
+ ///
66
+ /// If any is found, returns `Some`, otherwise returns `None`.
67
+ fn check_for_unresolved_global_use < ' a > (
68
+ globals : impl Iterator < Item = ( Handle < ir:: GlobalVariable > , & ' a ir:: GlobalVariable ) > ,
69
+ unresolved : & UnresolvedOverrides ,
70
+ fun_info : & FunctionInfo ,
71
+ ) -> Option < Handle < Override > > {
72
+ for ( var_handle, _) in globals {
73
+ match unresolved. global_variables . get ( & var_handle) {
74
+ Some ( & o_handle) if !fun_info[ var_handle] . is_empty ( ) => {
75
+ return Some ( o_handle) ;
76
+ }
77
+ _ => { }
78
+ }
79
+ }
80
+ None
81
+ }
82
+
62
83
/// Replace overrides in `module` with constants.
63
84
///
64
85
/// If no changes are needed, this just returns `Cow::Borrowed`
@@ -325,11 +346,11 @@ pub fn process_overrides<'a>(
325
346
}
326
347
327
348
// Process functions, taking note of which ones require overrides that were
328
- // not specified. Like expressions, callees are guarenteed to appear before
349
+ // not specified. Like expressions, callees are guaranteed to appear before
329
350
// their callers.
330
351
let mut functions = mem:: take ( & mut module. functions ) ;
331
352
for ( f_handle, function) in functions. iter_mut ( ) {
332
- if let Some ( o_handle) = process_function (
353
+ let result = if let Some ( o_handle) = process_function (
333
354
& mut module,
334
355
& override_map,
335
356
& unresolved. functions ,
@@ -341,6 +362,15 @@ pub fn process_overrides<'a>(
341
362
function. name,
342
363
overrides[ o_handle] . name
343
364
) ;
365
+ Some ( o_handle)
366
+ } else {
367
+ check_for_unresolved_global_use (
368
+ module. global_variables . iter ( ) ,
369
+ & unresolved,
370
+ & module_info[ f_handle] ,
371
+ )
372
+ } ;
373
+ if let Some ( o_handle) = result {
344
374
unresolved. functions . insert ( f_handle, o_handle) ;
345
375
}
346
376
}
@@ -367,19 +397,11 @@ pub fn process_overrides<'a>(
367
397
{
368
398
Some ( o_handle)
369
399
} else {
370
- // See if we use any global variables that are missing overrides.
371
- let mut missing = None ;
372
- for ( var_handle, _) in module. global_variables . iter ( ) {
373
- let global_use = module_info. get_entry_point ( ep_index) [ var_handle] ;
374
- match unresolved. global_variables . get ( & var_handle) {
375
- Some ( & o_handle) if !global_use. is_empty ( ) => {
376
- missing = Some ( o_handle) ;
377
- break ;
378
- }
379
- _ => { }
380
- }
381
- }
382
- missing
400
+ check_for_unresolved_global_use (
401
+ module. global_variables . iter ( ) ,
402
+ & unresolved,
403
+ module_info. get_entry_point ( ep_index) ,
404
+ )
383
405
} ;
384
406
if let Some ( o_handle) = result {
385
407
// We found a missing override that is required by this entry point.
0 commit comments