@@ -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 ,
@@ -62,6 +63,26 @@ pub struct ProcessOverridesOutput<'a> {
62
63
pub unresolved : UnresolvedOverrides ,
63
64
}
64
65
66
+ /// Check the global usage in `fun_info` for any globals affected by unresolved
67
+ /// overrides.
68
+ ///
69
+ /// If any is found, returns `Some`, otherwise returns `None`.
70
+ fn check_for_unresolved_global_use < ' a > (
71
+ globals : impl Iterator < Item = ( Handle < ir:: GlobalVariable > , & ' a ir:: GlobalVariable ) > ,
72
+ unresolved : & UnresolvedOverrides ,
73
+ fun_info : & FunctionInfo ,
74
+ ) -> Option < Handle < Override > > {
75
+ for ( var_handle, _) in globals {
76
+ match unresolved. global_variables . get ( & var_handle) {
77
+ Some ( & o_handle) if !fun_info[ var_handle] . is_empty ( ) => {
78
+ return Some ( o_handle) ;
79
+ }
80
+ _ => { }
81
+ }
82
+ }
83
+ None
84
+ }
85
+
65
86
/// Replace overrides in `module` with constants.
66
87
///
67
88
/// If no changes are needed, this just returns `Cow::Borrowed`
@@ -328,11 +349,11 @@ pub fn process_overrides<'a>(
328
349
}
329
350
330
351
// Process functions, taking note of which ones require overrides that were
331
- // not specified. Like expressions, callees are guarenteed to appear before
352
+ // not specified. Like expressions, callees are guaranteed to appear before
332
353
// their callers.
333
354
let mut functions = mem:: take ( & mut module. functions ) ;
334
355
for ( f_handle, function) in functions. iter_mut ( ) {
335
- if let Some ( o_handle) = process_function (
356
+ let result = if let Some ( o_handle) = process_function (
336
357
& mut module,
337
358
& override_map,
338
359
& unresolved. functions ,
@@ -344,6 +365,15 @@ pub fn process_overrides<'a>(
344
365
function. name,
345
366
overrides[ o_handle] . name
346
367
) ;
368
+ Some ( o_handle)
369
+ } else {
370
+ check_for_unresolved_global_use (
371
+ module. global_variables . iter ( ) ,
372
+ & unresolved,
373
+ & module_info[ f_handle] ,
374
+ )
375
+ } ;
376
+ if let Some ( o_handle) = result {
347
377
unresolved. functions . insert ( f_handle, o_handle) ;
348
378
}
349
379
}
@@ -370,19 +400,11 @@ pub fn process_overrides<'a>(
370
400
{
371
401
Some ( o_handle)
372
402
} else {
373
- // See if we use any global variables that are missing overrides.
374
- let mut missing = None ;
375
- for ( var_handle, _) in module. global_variables . iter ( ) {
376
- let global_use = module_info. get_entry_point ( ep_index) [ var_handle] ;
377
- match unresolved. global_variables . get ( & var_handle) {
378
- Some ( & o_handle) if !global_use. is_empty ( ) => {
379
- missing = Some ( o_handle) ;
380
- break ;
381
- }
382
- _ => { }
383
- }
384
- }
385
- missing
403
+ check_for_unresolved_global_use (
404
+ module. global_variables . iter ( ) ,
405
+ & unresolved,
406
+ module_info. get_entry_point ( ep_index) ,
407
+ )
386
408
} ;
387
409
if let Some ( o_handle) = result {
388
410
// We found a missing override that is required by this entry point.
0 commit comments