Debugging with Class

Inter­ac­tive visu­al­iza­tion of type class res­o­lu­tion is fea­si­ble and with few inter­ac­tions facil­i­tates local­iza­tion. This chap­ter presents Argus; a tool to facil­i­tate inter­ac­tive explo­ration of trait res­o­lu­tion in Rust. Argus does not pro­vide error diag­nos­tics in the tra­di­tional sense, but fea­tures that sat­isfy our cri­te­ria for a good diag­nos­tic: access to the root cause of a trait error, and its full prove­nance. The inter­ac­tive inter­face facil­i­tates explor­ing an error in the way a sta­tic com­piler diag­nos­tic can­not.

In we estab­lished that sets of traits and imple­men­tors are logic pro­grams. Trait bounds, or oblig­a­tions, are logic queries that eval­u­ate the pro­gram. Debug­ging logic pro­grams is dif­fi­cult, and by equiv­a­lence, so is debug­ging arbi­trary trait errors. Lit­er­a­ture from algo­rith­mic debug­ging and inter­ac­tive fault local­iza­tion pro­vides a basis on which we can build an inter­ac­tive tool to debug trait errors.

Rein­ter­pret­ing diag­nos­tics as an inter­face prob­lem intro­duces the chal­lenges and draw­backs of visu­al­iz­ing large data. Not only does Argus pro­vide an exploratory inter­face of proof trees, but also a set of sim­ple heuris­tics to sug­gest devel­op­ers where to start in the debug­ging process. The Rust com­mu­nity has cre­ated a set of con­fus­ing trait errors, and for 80% of tests devel­op­ers using Argus will encounter the root cause within 20 cog­ni­tive steps. This chap­ter out­lines our design and devel­op­ment of Argus and how a gen­er­al­ized tool of this nature could ben­e­fit all lan­guages with class—type class.