[logging] Introduce a function to call arbitrary function with subsequent logs written in an indended way.
Summary: The problem: you want to log "as much as possible" so you rarely need to debug your stuff. But you are worried that logs will become not readable because it will be hard to follow the logic of the program. Solution: Indentation! If everything what is happening inside the function is indended, it won't hurt readability: the overall flow of the whole program will be easy to comprehend. Intended usage of this new helper: if the function is complex enough that does something nontrivial inside (e.g. calls other complex functions), wrap it in `d_with_indent` at top level. This diff also uses this function in several top-level places of Nullsafe. Follow up diffs will include more logging in nullsafe. Example of log: ``` before: &bad -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &codetoanalyze.java.nullsafe_default.NullFieldAccess_codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &this -> [this] StrictNonnull codetoanalyze.java.nullsafe_default.NullFieldAccess* ----------------------------- Typecking instr: n$1=*&bad:java.lang.Object* [line 45] Executing typecheck_expr: Expr: &bad Result of typecheck_expr: Typ: java.lang.Object*; Nullability: Nullable Executing convert_complex_exp_to_pvar: Result of convert_complex_exp_to_pvar: Exp: &bad; Typestate: &bad -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &codetoanalyze.java.nullsafe_default.NullFieldAccess_codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &this -> [this] StrictNonnull codetoanalyze.java.nullsafe_default.NullFieldAccess* Executing typecheck_expr: Expr: &bad Result of typecheck_expr: Typ: java.lang.Object*; Nullability: Nullable Setting Nullable to Id n$1: Sil.Load New state: n$1 -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &bad -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &codetoanalyze.java.nullsafe_default.NullFieldAccess_codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &this -> [this] StrictNonnull codetoanalyze.java.nullsafe_default.NullFieldAccess* ----------------------------- Typecking instr: _=*n$1:java.lang.Object*(root java.lang.Object) [line 45] Executing typecheck_expr: Expr: n$1 Result of typecheck_expr: Typ: java.lang.Object*; Nullability: Nullable Executing convert_complex_exp_to_pvar: Result of convert_complex_exp_to_pvar: Exp: &bad; Typestate: n$1 -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &bad -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &codetoanalyze.java.nullsafe_default.NullFieldAccess_codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &this -> [this] StrictNonnull codetoanalyze.java.nullsafe_default.NullFieldAccess* Executing typecheck_expr: Expr: &bad Result of typecheck_expr: Typ: java.lang.Object*; Nullability: Nullable Setting Nullable to Id _: Sil.Load New state: n$1 -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* _ -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &bad -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &codetoanalyze.java.nullsafe_default.NullFieldAccess_codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &this -> [this] StrictNonnull codetoanalyze.java.nullsafe_default.NullFieldAccess* ----------------------------- Typecking instr: n$3=_fun_String Object.toString()(n$1:java.lang.Object*) virtual [line 45] Executing typecheck_expr: Expr: n$1 Result of typecheck_expr: Typ: java.lang.Object*; Nullability: Nullable Executing convert_complex_exp_to_pvar: Result of convert_complex_exp_to_pvar: Exp: &bad; Typestate: n$1 -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* _ -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &bad -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &codetoanalyze.java.nullsafe_default.NullFieldAccess_codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &this -> [this] StrictNonnull codetoanalyze.java.nullsafe_default.NullFieldAccess* Executing typecheck_expr: Expr: &bad Result of typecheck_expr: Typ: java.lang.Object*; Nullability: Nullable exp_rv_dexp: normal var n$1 find_normal_variable_load defining &bad exp_lv_dexp: program var &bad WARNING: ERADICATE_NULLABLE_DEREFERENCE `bad` is nullable and is not locally checked for null when calling `toString()`: field nullableStatic at line 44. Setting ThirdPartyNonnull to Id n$3: typecheck_sil_call_function New state: n$3 -> [Fun toString()] ThirdPartyNonnull java.lang.String* n$1 -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* _ -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &bad -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &codetoanalyze.java.nullsafe_default.NullFieldAccess_codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &this -> [this] StrictNonnull codetoanalyze.java.nullsafe_default.NullFieldAccess* ----------------------------- Typecking instr: *&$irvar0:java.lang.String*=n$3 [line 45] Executing typecheck_expr: Expr: &$irvar0 Result of typecheck_expr: Typ: void; Nullability: StrictNonnull Executing convert_complex_exp_to_pvar: exp_rv_dexp: program var &$irvar0 exp_lv_dexp: program var &$irvar0 exp_rv_dexp: constant _fun_String Object.toString() exp_rv_dexp: normal var n$1 find_normal_variable_load defining &bad exp_lv_dexp: program var &bad Result of convert_complex_exp_to_pvar: Exp: &java.lang.Object.toString():java.lang.String(bad)V; Typestate: n$3 -> [Fun toString()] ThirdPartyNonnull java.lang.String* n$1 -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* _ -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &bad -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &codetoanalyze.java.nullsafe_default.NullFieldAccess_codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &this -> [this] StrictNonnull codetoanalyze.java.nullsafe_default.NullFieldAccess* Executing typecheck_expr: Expr: n$3 Result of typecheck_expr: Typ: java.lang.String*; Nullability: ThirdPartyNonnull Setting ThirdPartyNonnull to Pvar java.lang.Object.toString():java.lang.String(bad)V: Sil.Store: Exp.Lvar case New state: n$3 -> [Fun toString()] ThirdPartyNonnull java.lang.String* n$1 -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* _ -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &java.lang.Object.toString():java.lang.String(bad)V -> [Fun toString()] ThirdPartyNonnull java.lang.String* &bad -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &codetoanalyze.java.nullsafe_default.NullFieldAccess_codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic -> [Field codetoanalyze.java.nullsafe_default.NullFieldAccess.nullableStatic (object: OptimisticFallback)] Nullable java.lang.Object* &this -> [this] StrictNonnull codetoanalyze.java.nullsafe_default.NullFieldAccess* ----------------------------- Typecking instr: NULLIFY(&bad); [line 45] ``` Reviewed By: artempyanykh Differential Revision: D20304424 fbshipit-source-id: 7fa3f459emaster
parent
16ed8950e9
commit
59e17f59b8
Loading…
Reference in new issue