@@ -60,6 +60,7 @@ use smallvec::SmallVec;
60
60
use std:: collections:: { BTreeMap , VecDeque } ;
61
61
use std:: ops:: { Range , RangeTo } ;
62
62
use std:: { fmt, io, iter, mem, slice} ;
63
+ use tracing:: { debug, error} ;
63
64
64
65
// FIXME(eddyb) move this elsewhere.
65
66
struct FmtBy < F : Fn ( & mut fmt:: Formatter < ' _ > ) -> fmt:: Result > ( F ) ;
@@ -110,12 +111,10 @@ pub fn specialize(
110
111
module : Module ,
111
112
specialization : impl Specialization ,
112
113
) -> Module {
113
- // FIXME(eddyb) use `log`/`tracing` instead.
114
- let debug = opts. specializer_debug ;
115
114
let dump_instances = & opts. specializer_dump_instances ;
116
115
117
116
let mut debug_names = FxHashMap :: default ( ) ;
118
- if debug || dump_instances. is_some ( ) {
117
+ if dump_instances. is_some ( ) {
119
118
debug_names = module
120
119
. debug_names
121
120
. iter ( )
@@ -131,10 +130,7 @@ pub fn specialize(
131
130
132
131
let mut specializer = Specializer {
133
132
specialization,
134
-
135
- debug,
136
133
debug_names,
137
-
138
134
generics : IndexMap :: new ( ) ,
139
135
int_consts : FxHashMap :: default ( ) ,
140
136
} ;
@@ -188,27 +184,21 @@ pub fn specialize(
188
184
// For non-"generic" functions, we can apply `replacements` right away,
189
185
// though not before finishing inference for all functions first
190
186
// (because `expander` needs to borrow `specializer` immutably).
191
- if debug {
192
- eprintln ! ( "non-generic replacements:" ) ;
193
- }
187
+ debug ! ( "non-generic replacements:" ) ;
194
188
for ( func_idx, replacements) in non_generic_replacements {
195
189
let mut func = mem:: replace (
196
190
& mut expander. builder . module_mut ( ) . functions [ func_idx] ,
197
191
Function :: new ( ) ,
198
192
) ;
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( ) ) ;
205
197
}
206
198
for ( loc, operand) in
207
199
replacements. to_concrete ( & [ ] , |instance| expander. alloc_instance_id ( instance) )
208
200
{
209
- if debug {
210
- eprintln ! ( " {operand} -> {loc:?}" ) ;
211
- }
201
+ debug ! ( " {operand} -> {loc:?}" ) ;
212
202
func. index_set ( loc, operand. into ( ) ) ;
213
203
}
214
204
expander. builder . module_mut ( ) . functions [ func_idx] = func;
@@ -537,9 +527,6 @@ struct Generic {
537
527
struct Specializer < S : Specialization > {
538
528
specialization : S ,
539
529
540
- // FIXME(eddyb) use `log`/`tracing` instead.
541
- debug : bool ,
542
-
543
530
// HACK(eddyb) if debugging is requested, this is used to quickly get `OpName`s.
544
531
debug_names : FxHashMap < Word , String > ,
545
532
@@ -1512,24 +1499,24 @@ impl InferError {
1512
1499
// FIXME(eddyb) better error reporting than this.
1513
1500
match self {
1514
1501
Self :: Conflict ( a, b) => {
1515
- eprintln ! ( "inference conflict: {a:?} vs {b:?}" ) ;
1502
+ error ! ( "inference conflict: {a:?} vs {b:?}" ) ;
1516
1503
}
1517
1504
}
1518
- eprint ! ( " in " ) ;
1505
+ error ! ( " in " ) ;
1519
1506
// FIXME(eddyb) deduplicate this with other instruction printing logic.
1520
1507
if let Some ( result_id) = inst. result_id {
1521
- eprint ! ( "%{result_id} = " ) ;
1508
+ error ! ( "%{result_id} = " ) ;
1522
1509
}
1523
- eprint ! ( "Op{:?}" , inst. class. opcode) ;
1510
+ error ! ( "Op{:?}" , inst. class. opcode) ;
1524
1511
for operand in inst
1525
1512
. result_type
1526
1513
. map ( Operand :: IdRef )
1527
1514
. iter ( )
1528
1515
. chain ( inst. operands . iter ( ) )
1529
1516
{
1530
- eprint ! ( " {operand}" ) ;
1517
+ error ! ( " {operand}" ) ;
1531
1518
}
1532
- eprintln ! ( ) ;
1519
+ error ! ( "" ) ;
1533
1520
1534
1521
std:: process:: exit ( 1 ) ;
1535
1522
}
@@ -1937,38 +1924,36 @@ impl<'a, S: Specialization> InferCx<'a, S> {
1937
1924
} ;
1938
1925
1939
1926
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
+ } ;
1958
1944
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) ) ;
1971
1955
}
1956
+ debug ! ( "" ) ;
1972
1957
} ;
1973
1958
1974
1959
// If we have some instruction signatures for `inst`, enforce them.
@@ -1998,12 +1983,10 @@ impl<'a, S: Specialization> InferCx<'a, S> {
1998
1983
) ,
1999
1984
} ;
2000
1985
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 ! ( " " ) ;
2006
1988
}
1989
+ debug ! ( " found {:?}" , m. debug_with_infer_cx( self ) ) ;
2007
1990
2008
1991
if let Err ( e) = self . equate_match_findings ( m) {
2009
1992
e. report ( inst) ;
@@ -2032,24 +2015,20 @@ impl<'a, S: Specialization> InferCx<'a, S> {
2032
2015
fn instantiate_function ( & mut self , func : & ' a Function ) {
2033
2016
let func_id = func. def_id ( ) . unwrap ( ) ;
2034
2017
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}" ) ;
2042
2022
}
2023
+ debug ! ( "):" ) ;
2043
2024
2044
2025
// Instantiate the defining `OpFunction` first, so that the first
2045
2026
// inference variables match the parameters from the `Generic`
2046
2027
// (if the `OpTypeFunction` is "generic", that is).
2047
2028
assert ! ( self . infer_var_values. is_empty( ) ) ;
2048
2029
self . instantiate_instruction ( func. def . as_ref ( ) . unwrap ( ) , InstructionLocation :: Module ) ;
2049
2030
2050
- if self . specializer . debug {
2051
- eprintln ! ( "infer body {{" ) ;
2052
- }
2031
+ debug ! ( "infer body {{" ) ;
2053
2032
2054
2033
// If the `OpTypeFunction` is indeed "generic", we have to extract the
2055
2034
// return / parameter types for `OpReturnValue` and `OpFunctionParameter`.
@@ -2074,14 +2053,12 @@ impl<'a, S: Specialization> InferCx<'a, S> {
2074
2053
let ( i, param) = params. next ( ) . unwrap ( ) ;
2075
2054
assert_eq ! ( param. class. opcode, Op :: FunctionParameter ) ;
2076
2055
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
+ ) ;
2085
2062
2086
2063
self . record_instantiated_operand (
2087
2064
OperandLocation {
@@ -2133,13 +2110,11 @@ impl<'a, S: Specialization> InferCx<'a, S> {
2133
2110
}
2134
2111
}
2135
2112
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 ) ) ;
2142
2116
}
2117
+ debug ! ( "" ) ;
2143
2118
}
2144
2119
2145
2120
/// Helper for `into_replacements`, that computes a single `ConcreteOrParam`.
0 commit comments