Rotor: First Steps Towards a Refactoring Tool for OCaml Reuben N. S. Rowe r.n.s.rowe @ kent.ac.uk Simon Thompson s.j.thompson @ kent.ac.uk University of Kent, Canterbury OCaml Users and Developers Workshop, Oxford, UK Friday 8 th September 2017
What is Rotor? R eliable O Caml-based T ool for O Caml R efactoring 1/9
What is Rotor? R eliable O Caml-based T ool for O Caml R efactoring 1/9
What is Rotor? R eliable O Caml-based T ool for O Caml R efactoring 1/9
What is Rotor? R eliable O Caml-based T ool for O Caml R efactoring 1/9
What is Rotor? R eliable O Caml-based T ool for O Caml R efactoring 1/9
What is Rotor? R eliable O Caml-based T ool for O Caml R efactoring 1/9
What is Rotor? • Written in OCaml itself • allows re-use of the existing compiler infrastructure • Provide evidence that the result is correct (Future work) • A prototype refactoring tool for OCaml (4.04.x) programs • currently implements renaming for value bindings • Designed with extensibility in mind • write new refactorings and ‘plug them in’ easily 1/9
What is Rotor? • Written in OCaml itself • allows re-use of the existing compiler infrastructure • Provide evidence that the result is correct (Future work) • A prototype refactoring tool for OCaml (4.04.x) programs • currently implements renaming for value bindings • Designed with extensibility in mind • write new refactorings and ‘plug them in’ easily 1/9
What is Rotor? • Written in OCaml itself • allows re-use of the existing compiler infrastructure • Provide evidence that the result is correct (Future work) • A prototype refactoring tool for OCaml (4.04.x) programs • currently implements renaming for value bindings • Designed with extensibility in mind • write new refactorings and ‘plug them in’ easily 1/9
What is Rotor? • Written in OCaml itself • allows re-use of the existing compiler infrastructure • Provide evidence that the result is correct (Future work) • A prototype refactoring tool for OCaml (4.04.x) programs • currently implements renaming for value bindings • Designed with extensibility in mind • write new refactorings and ‘plug them in’ easily 1/9
What is Rotor? • Written in OCaml itself • allows re-use of the existing compiler infrastructure • Provide evidence that the result is correct (Future work) • A prototype refactoring tool for OCaml (4.04.x) programs • currently implements renaming for value bindings • Designed with extensibility in mind • write new refactorings and ‘plug them in’ easily 1/9
What is Rotor? • Written in OCaml itself • allows re-use of the existing compiler infrastructure • Provide evidence that the result is correct (Future work) • A prototype refactoring tool for OCaml (4.04.x) programs • currently implements renaming for value bindings • Designed with extensibility in mind • write new refactorings and ‘plug them in’ easily 1/9
What is Rotor? • Written in OCaml itself • allows re-use of the existing compiler infrastructure • Provide evidence that the result is correct (Future work) • A prototype refactoring tool for OCaml (4.04.x) programs • currently implements renaming for value bindings • Designed with extensibility in mind • write new refactorings and ‘plug them in’ easily 1/9
Renaming Value Bindings: Rebinding src/foo.ml: . . . open Foo src/bar.ml: . . . . . . 2/9 Foo.f �→ g let f = . . . let f = . . . . . . f . . . . . . f . . .
Renaming Value Bindings: Rebinding src/foo.ml: . . . open Foo src/bar.ml: . . . . . . 2/9 Foo.f �→ g let f = . . . let g = . . . . . . g . . . . . . g . . .
Renaming Value Bindings: Rebinding src/foo.ml: . . . open Foo src/bar.ml: 2/9 . . . Foo.f �→ g let g = . . . let f = . . . let f = . . . . . . . . . . . . f . . . g . . .
Renaming Value Bindings: Rebinding src/foo.ml: . . . open Foo src/bar.ml: . . . 2/9 Foo.f �→ g let g = . . . let f = . . . let g = . . . . . . g . . . . . . g . . . g . . .
Renaming Value Bindings: Punning src/bar.ml: map ~ ['a';'b';'c'] . . . let map ~f xs = open Foo 3/9 src/foo.ml: . . . Foo.f �→ g type t = { f : . . . ; . . . } let f = . . . . . . { f; . . . } : t . . .
Renaming Value Bindings: Punning src/foo.ml: . . . open Foo src/bar.ml: 3/9 . . . Foo.f �→ g type t = { f : . . . ; . . . } let f = . . . . . . { f; . . . } : t . . . let map ~f xs = . . . . . . map ~f ['a';'b';'c'] . . .
Renaming Value Bindings: Punning src/foo.ml: . . . open Foo src/bar.ml: 3/9 . . . Foo.f �→ g type t = { f : . . . ; . . . } let g = . . . . . . { f=g; . . . } : t . . . let map ~f xs = . . . . . . map ~f:g ['a';'b';'c'] . . .
Renaming Value Bindings: include include Foo . . . src/baz.ml: . . . g src/foo.ml: Bar.f src/bar.ml: . . . 4/9 Foo.f �→ g let f = . . . . . . f . . . . . . Bar.f . . .
Renaming Value Bindings: include include Foo . . . src/baz.ml: . . . g src/foo.ml: Bar.f src/bar.ml: . . . 4/9 Foo.f �→ g let g = . . . . . . g . . . . . . Bar.g . . .
Renaming Value Bindings: include src/foo.ml: . . . src/baz.ml: . . . include Foo src/bar.ml: . . . 4/9 Foo.f �→ g let g = . . . . . . g . . . Bar.f �→ g . . . Bar.g . . .
Renaming Value Bindings: Module Signatures Sig.S.f end module M : Sig.S = struct let f = src/baz.ml: end module type S = sig val f : g src/sig.ml: src/foo.ml: include Sig.S src/bar.mli: include Foo src/bar.ml: 5/9 Foo.f �→ g let f = . . . Bar.f �→ g
Renaming Value Bindings: Module Signatures src/sig.ml: end module M : Sig.S = struct let f = src/baz.ml: g Sig.S.f include Sig.S src/foo.ml: src/bar.mli: include Foo src/bar.ml: 5/9 Foo.f �→ g let f = . . . Bar.f �→ g module type S = sig val f : . . . end
Renaming Value Bindings: Module Signatures src/foo.ml: src/bar.ml: include Foo src/bar.mli: include Sig.S src/sig.ml: src/baz.ml: module M : Sig.S = struct let f = end 5/9 Foo.f �→ g let f = . . . Bar.f �→ g Sig.S.f �→ g module type S = sig val f : . . . end
Renaming Value Bindings: Module Signatures src/foo.ml: src/bar.ml: include Foo src/bar.mli: include Sig.S src/sig.ml: src/baz.ml: 5/9 Foo.f �→ g let f = . . . Bar.f �→ g Sig.S.f �→ g module type S = sig val f : . . . end module M : Sig.S = struct let f = . . . end
Renaming Value Bindings: Module Signatures src/foo.ml: src/bar.ml: include Foo src/bar.mli: include Sig.S src/sig.ml: src/baz.ml: 5/9 Foo.f �→ g let g = . . . Bar.f �→ g Sig.S.f �→ g module type S = sig val g : . . . end module M : Sig.S = struct let g = . . . end
Renaming Value Bindings: Module Signatures src/foo.ml: src/bar.ml: include Foo src/bar.mli: include Sig.S src/sig.ml: src/baz.ml: 5/9 Foo.f �→ g let g = . . . Bar.f �→ g Sig.S.f �→ g module type S = sig val g : . . . end module M : Sig.S = struct let g = . . . end
Rotor: Architectural Overview 6/9
Rotor: Architectural Overview Visitors Path_visitors Longident_visitors . . . Types_visitors Parsetree_visitors Typedtree_visitors 6/9
Rotor: Architectural Overview Path_visitors Typedtree_visitors Parsetree_visitors Types_visitors . . . Longident_visitors Visitors Compiler-libs Typedtree Parsetree Types . . . Longident Path 6/9
Rotor: Architectural Overview Path_visitors Typedtree_visitors Parsetree_visitors Types_visitors . . . Longident_visitors Visitors Compiler-libs Typedtree Parsetree Types . . . Longident Path 6/9
Rotor: Architectural Overview . Deps View Identifier Elements Language Typedtree_visitors Parsetree_visitors Types_visitors . . Longident_visitors Compiler-libs Path_visitors Visitors Typedtree Parsetree Types . . . Longident Path 6/9
Rotor: Architectural Overview Types_visitors Buildenv Codebase Sourcefile Fileinfos Infrastructure Deps View Identifier Elements Language Typedtree_visitors Parsetree_visitors . Compiler-libs . . Longident_visitors Path_visitors Visitors Typedtree Parsetree Types . . . Longident Path 6/9
Rotor: Architectural Overview Codebase Identifier View Deps Infrastructure Fileinfos Sourcefile Buildenv Language Refactoring Replacement Refactoring Refactoring_lib Refactoring_utils Refactoring_visitors Elements Typedtree_visitors Compiler-libs Parsetree Path Longident . . . Types Typedtree Parsetree_visitors Visitors Path_visitors Longident_visitors . . . Types_visitors 6/9
Recommend
More recommend