@@ -60,6 +60,7 @@ use smallvec::SmallVec;
6060use std:: collections:: { BTreeMap , VecDeque } ;
6161use std:: ops:: { Range , RangeTo } ;
6262use std:: { fmt, io, iter, mem, slice} ;
63+ use tracing:: { debug, error} ;
6364
6465// FIXME(eddyb) move this elsewhere.
6566struct FmtBy < F : Fn ( & mut fmt:: Formatter < ' _ > ) -> fmt:: Result > ( F ) ;
@@ -110,12 +111,10 @@ pub fn specialize(
110111 module : Module ,
111112 specialization : impl Specialization ,
112113) -> Module {
113- // FIXME(eddyb) use `log`/`tracing` instead.
114- let debug = opts. specializer_debug ;
115114 let dump_instances = & opts. specializer_dump_instances ;
116115
117116 let mut debug_names = FxHashMap :: default ( ) ;
118- if debug || dump_instances. is_some ( ) {
117+ if dump_instances. is_some ( ) {
119118 debug_names = module
120119 . debug_names
121120 . iter ( )
@@ -131,10 +130,7 @@ pub fn specialize(
131130
132131 let mut specializer = Specializer {
133132 specialization,
134-
135- debug,
136133 debug_names,
137-
138134 generics : IndexMap :: new ( ) ,
139135 int_consts : FxHashMap :: default ( ) ,
140136 } ;
@@ -188,27 +184,21 @@ pub fn specialize(
188184 // For non-"generic" functions, we can apply `replacements` right away,
189185 // though not before finishing inference for all functions first
190186 // (because `expander` needs to borrow `specializer` immutably).
191- if debug {
192- eprintln ! ( "non-generic replacements:" ) ;
193- }
187+ debug ! ( "non-generic replacements:" ) ;
194188 for ( func_idx, replacements) in non_generic_replacements {
195189 let mut func = mem:: replace (
196190 & mut expander. builder . module_mut ( ) . functions [ func_idx] ,
197191 Function :: new ( ) ,
198192 ) ;
199- if debug {
200- let empty = replacements. with_instance . is_empty ( )
201- && replacements. with_concrete_or_param . is_empty ( ) ;
202- if !empty {
203- eprintln ! ( " in %{}:" , func. def_id( ) . unwrap( ) ) ;
204- }
193+ let empty =
194+ replacements. with_instance . is_empty ( ) && replacements. with_concrete_or_param . is_empty ( ) ;
195+ if !empty {
196+ debug ! ( " in %{}:" , func. def_id( ) . unwrap( ) ) ;
205197 }
206198 for ( loc, operand) in
207199 replacements. to_concrete ( & [ ] , |instance| expander. alloc_instance_id ( instance) )
208200 {
209- if debug {
210- eprintln ! ( " {operand} -> {loc:?}" ) ;
211- }
201+ debug ! ( " {operand} -> {loc:?}" ) ;
212202 func. index_set ( loc, operand. into ( ) ) ;
213203 }
214204 expander. builder . module_mut ( ) . functions [ func_idx] = func;
@@ -537,9 +527,6 @@ struct Generic {
537527struct Specializer < S : Specialization > {
538528 specialization : S ,
539529
540- // FIXME(eddyb) use `log`/`tracing` instead.
541- debug : bool ,
542-
543530 // HACK(eddyb) if debugging is requested, this is used to quickly get `OpName`s.
544531 debug_names : FxHashMap < Word , String > ,
545532
@@ -1512,24 +1499,24 @@ impl InferError {
15121499 // FIXME(eddyb) better error reporting than this.
15131500 match self {
15141501 Self :: Conflict ( a, b) => {
1515- eprintln ! ( "inference conflict: {a:?} vs {b:?}" ) ;
1502+ error ! ( "inference conflict: {a:?} vs {b:?}" ) ;
15161503 }
15171504 }
1518- eprint ! ( " in " ) ;
1505+ error ! ( " in " ) ;
15191506 // FIXME(eddyb) deduplicate this with other instruction printing logic.
15201507 if let Some ( result_id) = inst. result_id {
1521- eprint ! ( "%{result_id} = " ) ;
1508+ error ! ( "%{result_id} = " ) ;
15221509 }
1523- eprint ! ( "Op{:?}" , inst. class. opcode) ;
1510+ error ! ( "Op{:?}" , inst. class. opcode) ;
15241511 for operand in inst
15251512 . result_type
15261513 . map ( Operand :: IdRef )
15271514 . iter ( )
15281515 . chain ( inst. operands . iter ( ) )
15291516 {
1530- eprint ! ( " {operand}" ) ;
1517+ error ! ( " {operand}" ) ;
15311518 }
1532- eprintln ! ( ) ;
1519+ error ! ( "" ) ;
15331520
15341521 std:: process:: exit ( 1 ) ;
15351522 }
@@ -1937,38 +1924,36 @@ impl<'a, S: Specialization> InferCx<'a, S> {
19371924 } ;
19381925
19391926 let debug_dump_if_enabled = |cx : & Self , prefix| {
1940- if cx. specializer . debug {
1941- let result_type = match inst. class . opcode {
1942- // HACK(eddyb) workaround for `OpFunction`, see earlier HACK comment.
1943- Op :: Function => Some (
1944- InferOperand :: from_operand_and_generic_args (
1945- & Operand :: IdRef ( inst. result_type . unwrap ( ) ) ,
1946- inputs_generic_args. clone ( ) ,
1947- cx,
1948- )
1949- . 0 ,
1950- ) ,
1951- _ => type_of_result. clone ( ) ,
1952- } ;
1953- let inputs = InferOperandList {
1954- operands : & inst. operands ,
1955- all_generic_args : inputs_generic_args. clone ( ) ,
1956- transform : None ,
1957- } ;
1927+ let result_type = match inst. class . opcode {
1928+ // HACK(eddyb) workaround for `OpFunction`, see earlier HACK comment.
1929+ Op :: Function => Some (
1930+ InferOperand :: from_operand_and_generic_args (
1931+ & Operand :: IdRef ( inst. result_type . unwrap ( ) ) ,
1932+ inputs_generic_args. clone ( ) ,
1933+ cx,
1934+ )
1935+ . 0 ,
1936+ ) ,
1937+ _ => type_of_result. clone ( ) ,
1938+ } ;
1939+ let inputs = InferOperandList {
1940+ operands : & inst. operands ,
1941+ all_generic_args : inputs_generic_args. clone ( ) ,
1942+ transform : None ,
1943+ } ;
19581944
1959- if inst_loc != InstructionLocation :: Module {
1960- eprint ! ( " " ) ;
1961- }
1962- eprint ! ( "{prefix}" ) ;
1963- if let Some ( result_id) = inst. result_id {
1964- eprint ! ( "%{result_id} = " ) ;
1965- }
1966- eprint ! ( "Op{:?}" , inst. class. opcode) ;
1967- for operand in result_type. into_iter ( ) . chain ( inputs. iter ( cx) ) {
1968- eprint ! ( " {}" , operand. display_with_infer_cx( cx) ) ;
1969- }
1970- eprintln ! ( ) ;
1945+ if inst_loc != InstructionLocation :: Module {
1946+ debug ! ( " " ) ;
1947+ }
1948+ debug ! ( "{prefix}" ) ;
1949+ if let Some ( result_id) = inst. result_id {
1950+ debug ! ( "%{result_id} = " ) ;
1951+ }
1952+ debug ! ( "Op{:?}" , inst. class. opcode) ;
1953+ for operand in result_type. into_iter ( ) . chain ( inputs. iter ( cx) ) {
1954+ debug ! ( " {}" , operand. display_with_infer_cx( cx) ) ;
19711955 }
1956+ debug ! ( "" ) ;
19721957 } ;
19731958
19741959 // If we have some instruction signatures for `inst`, enforce them.
@@ -1998,12 +1983,10 @@ impl<'a, S: Specialization> InferCx<'a, S> {
19981983 ) ,
19991984 } ;
20001985
2001- if self . specializer . debug {
2002- if inst_loc != InstructionLocation :: Module {
2003- eprint ! ( " " ) ;
2004- }
2005- eprintln ! ( " found {:?}" , m. debug_with_infer_cx( self ) ) ;
1986+ if inst_loc != InstructionLocation :: Module {
1987+ debug ! ( " " ) ;
20061988 }
1989+ debug ! ( " found {:?}" , m. debug_with_infer_cx( self ) ) ;
20071990
20081991 if let Err ( e) = self . equate_match_findings ( m) {
20091992 e. report ( inst) ;
@@ -2032,24 +2015,20 @@ impl<'a, S: Specialization> InferCx<'a, S> {
20322015 fn instantiate_function ( & mut self , func : & ' a Function ) {
20332016 let func_id = func. def_id ( ) . unwrap ( ) ;
20342017
2035- if self . specializer . debug {
2036- eprintln ! ( ) ;
2037- eprint ! ( "specializer::instantiate_function(%{func_id}" ) ;
2038- if let Some ( name) = self . specializer . debug_names . get ( & func_id) {
2039- eprint ! ( " {name}" ) ;
2040- }
2041- eprintln ! ( "):" ) ;
2018+ debug ! ( "" ) ;
2019+ debug ! ( "specializer::instantiate_function(%{func_id}" ) ;
2020+ if let Some ( name) = self . specializer . debug_names . get ( & func_id) {
2021+ debug ! ( " {name}" ) ;
20422022 }
2023+ debug ! ( "):" ) ;
20432024
20442025 // Instantiate the defining `OpFunction` first, so that the first
20452026 // inference variables match the parameters from the `Generic`
20462027 // (if the `OpTypeFunction` is "generic", that is).
20472028 assert ! ( self . infer_var_values. is_empty( ) ) ;
20482029 self . instantiate_instruction ( func. def . as_ref ( ) . unwrap ( ) , InstructionLocation :: Module ) ;
20492030
2050- if self . specializer . debug {
2051- eprintln ! ( "infer body {{" ) ;
2052- }
2031+ debug ! ( "infer body {{" ) ;
20532032
20542033 // If the `OpTypeFunction` is indeed "generic", we have to extract the
20552034 // return / parameter types for `OpReturnValue` and `OpFunctionParameter`.
@@ -2074,14 +2053,12 @@ impl<'a, S: Specialization> InferCx<'a, S> {
20742053 let ( i, param) = params. next ( ) . unwrap ( ) ;
20752054 assert_eq ! ( param. class. opcode, Op :: FunctionParameter ) ;
20762055
2077- if self . specializer . debug {
2078- eprintln ! (
2079- " %{} = Op{:?} {}" ,
2080- param. result_id. unwrap( ) ,
2081- param. class. opcode,
2082- param_ty. display_with_infer_cx( self )
2083- ) ;
2084- }
2056+ debug ! (
2057+ " %{} = Op{:?} {}" ,
2058+ param. result_id. unwrap( ) ,
2059+ param. class. opcode,
2060+ param_ty. display_with_infer_cx( self )
2061+ ) ;
20852062
20862063 self . record_instantiated_operand (
20872064 OperandLocation {
@@ -2133,13 +2110,11 @@ impl<'a, S: Specialization> InferCx<'a, S> {
21332110 }
21342111 }
21352112
2136- if self . specializer . debug {
2137- eprint ! ( "}}" ) ;
2138- if let Some ( func_ty) = self . type_of_result . get ( & func_id) {
2139- eprint ! ( " -> %{}: {}" , func_id, func_ty. display_with_infer_cx( self ) ) ;
2140- }
2141- eprintln ! ( ) ;
2113+ debug ! ( "}}" ) ;
2114+ if let Some ( func_ty) = self . type_of_result . get ( & func_id) {
2115+ debug ! ( " -> %{}: {}" , func_id, func_ty. display_with_infer_cx( self ) ) ;
21422116 }
2117+ debug ! ( "" ) ;
21432118 }
21442119
21452120 /// Helper for `into_replacements`, that computes a single `ConcreteOrParam`.
0 commit comments