How compiler frontend is different from what IDE needs? Ilya - - PowerPoint PPT Presentation

how compiler frontend is different from what ide needs
SMART_READER_LITE
LIVE PREVIEW

How compiler frontend is different from what IDE needs? Ilya - - PowerPoint PPT Presentation

How compiler frontend is different from what IDE needs? Ilya Biryukov JetBrains ReSharper C++ November 3, 2016 Compilers and IDEs Compilers and IDEs are similar, but have different design goals Compilers and IDEs Compilers and IDEs are


slide-1
SLIDE 1

How compiler frontend is different from what IDE needs?

Ilya Biryukov

JetBrains ReSharper C++

November 3, 2016

slide-2
SLIDE 2

Compilers and IDEs

Compilers and IDEs are similar, but have different design goals

slide-3
SLIDE 3

Compilers and IDEs

Compilers and IDEs are similar, but have different design goals Compilers mostly run on correct code, IDEs often run on broken code

slide-4
SLIDE 4

Compilers and IDEs

Compilers and IDEs are similar, but have different design goals Compilers mostly run on correct code, IDEs often run on broken code Compilers need to store fewer source locations than IDEs

slide-5
SLIDE 5

Compilers and IDEs

Compilers and IDEs are similar, but have different design goals Compilers mostly run on correct code, IDEs often run on broken code Compilers need to store fewer source locations than IDEs Compiler works on a single TU, IDE is aware of the whole project

slide-6
SLIDE 6

Deferred resolve

Compilers resolve names as they are encountered

slide-7
SLIDE 7

Deferred resolve

Compilers resolve names as they are encountered This work is often redundant for an IDE

slide-8
SLIDE 8

Deferred resolve

Compilers resolve names as they are encountered This work is often redundant for an IDE E.g., do we really need to resolve everything inside <iostream>? Example #include <iostream> int main() { std::cout << "Hello, world!\n"; }

slide-9
SLIDE 9

Global includes

A typical C++ file //// 1. Global includes #include <vector> #include <boost/something.hpp> /* ... */ //// 2. Declarations struct my_struct { /* ... */ }; my_struct create_struct(); /* ... */

slide-10
SLIDE 10

Global includes

Most includes are well-formed

slide-11
SLIDE 11

Global includes

Most includes are well-formed

Included in global scope

slide-12
SLIDE 12

Global includes

Most includes are well-formed

Included in global scope Parse into a list of well-formed declarations

slide-13
SLIDE 13

Global includes

Most includes are well-formed

Included in global scope Parse into a list of well-formed declarations

Result of parsing the header may be reused between TUs

Some trickery involved to ensure preprocessor context matches

slide-14
SLIDE 14

Reparse inside function body

How to process a change inside a function body?

slide-15
SLIDE 15

Reparse inside function body

How to process a change inside a function body? Parse only the function body Replace old function body with the new one

slide-16
SLIDE 16

Reparse inside function body

How to process a change inside a function body? Parse only the function body Replace old function body with the new one Very fast

slide-17
SLIDE 17

Global reparse

What if a change is global?

slide-18
SLIDE 18

Global reparse

A typical C++ file //// 1. Global includes #include <vector> #include <boost/something.hpp> /* ... */ //// 2. Declarations struct my_struct { /* ... */ }; my_struct create_struct(); /* ... */

slide-19
SLIDE 19

Global reparse

What if a change is global? Log all modifications after includes

slide-20
SLIDE 20

Global reparse

What if a change is global? Log all modifications after includes When reparse is required

Rollback logged modifications Parse only the rest of the file

slide-21
SLIDE 21

Global reparse

What if a change is global? Log all modifications after includes When reparse is required

Rollback logged modifications Parse only the rest of the file

Much faster than processing the whole file

slide-22
SLIDE 22

Conclusion

ReSharper C++ has its own C++ frontend

slide-23
SLIDE 23

Conclusion

ReSharper C++ has its own C++ frontend With some optimizations on top of it

Deferred resolve Optimized processing of global includes Incremental reparse inside function bodies Incremental reparse after global includes

slide-24
SLIDE 24

Conclusion

ReSharper C++ has its own C++ frontend With some optimizations on top of it

Deferred resolve Optimized processing of global includes Incremental reparse inside function bodies Incremental reparse after global includes

Still not fast enough

Running under managed runtime(.NET) Slow preprocessing