SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne
Tour of the DMD D Programming
Language Compiler
by Walter Bright
http://www.walterbright.com
Organization
● One front end to rule them all
– and in the D bind them
– written in D
● Three back ends
– Digital Mars (dmd)
– Gnu compiler collection (gdc)
– LLVM (ldc)
Major Changes in Last Year
● Converted front end from C++ to D
● Switch to using Dwarf exception handling
– opens up more comprehensive C++ interfacing
Source Code
https://github.com/dlang/dmd
Directories
● src/ front end source code
● src/tk generic code for back end
● src/root generic code for front end
● src/backend optimizer and code generator
● src/vcbuild for building compiler with VS
Types of Compiles
● diagnose errors in source code
● generate a debug build
● generate a release build
Memory Allocation
● root/rmem.d
● Allocate, but never free
● Very fast
● No need for ownership tracking
● Puts upper limit on size of compile
Strings
● root/stringtable.d
● const(char)*
● identifier strings stored in single hash table
● address of string becomes its hash
– Identifier.idPool()
● very fast
Array(T)
● root/array.d
● a workalike to D dynamic arrays
● accessible from C++ code
● heavily used
alias Strings = Array!(const(char)*);
alias Statements = Array!Statement;
alias Identifiers = Array!Identifier;
… etc.
RootObject
● root/object.d
● single rooted hierarchy
– much like D's Object, but predates it
– a C++ class, so accessible from glue layer
– Declarations, Statements, Expressions
– heavy use of OOP plus Visitor Pattern
Passes
● read files
● lex
● parse
● create symbol table
● semantic 1
● semantic 2
● semantic 3
● inline
● glue
● optimize
● generate code
● write to object file
Lexing
● lexer.d
● pretty simple
● rarely changes
● mostly concerned with speed
Parsing
● parse.d
● also simple and rarely changes
● lookahead is done by forming a stack of tokens
● code looks a lot like the grammar …
case TOKwhile:
{
nextToken();
check(TOKlparen);
Expression condition = parseExpression();
check(TOKrparen);
Loc endloc;
Statement _body =
parseStatement(PSscope, null, &endloc);
s = new
WhileStatement(loc,condition,_body,endloc);
break;
}
Create Symbol Table
● importAll()
● establishes a Scope for each symbol
Scope
● dscope.d
● link to enclosing Scope
● fields
– module
– function
– storage class in effect
– ...
Semantic
int a;
int b = 3;
int foo() {
return 6;
}
Lowering
● rewriting ASTs to simpler, canonical forms
● reduces number of cases needing to be dealt
with later
● reduces complexity and bugs
● even makes it easier to document
Loops
while (cond) { body }
for (; cond; ) { body }
foreach (i; n .. m) { body }
for (auto i = n; i < m; ++i) { body }
foreach (e; aggr) { body }
for (auto r = aggr[]; !r.empty; r.popFront())
{
auto e = r.front;
body;
}
Exceptions
● rewritten to be try-finally
● scope
● synchronized
● RAII
Error Recovery Models
● Quit on first error
● Guess at user intention, then repair
● Poisoning
Poisoning
● have a special 'error' AST node
● replace erroneous AST node with 'error' node
● replace any node that has an 'error' child with
an 'error' node
● virtually eliminates cascaded errors
– errors displayed are real errors
Spell Checking
● root/speller.d
● for undefined identifiers
Constant Folding
● constfold.d
UnionExp Bool(Type type, Expression e1) {
UnionExp ue;
Loc loc = e1.loc;
emplaceExp!(IntegerExp)(&ue, loc, e1.isBool(true)?1:0, type);
return ue;
}
Compile Time Function Execution
(CTFE)
● just a glorified constant folder
● allocates memory to evaluate an expression
● so it runs out of memory
● and is slow
Templates
● Stored as ASTs as produced by the parser
● To instantiate:
– copy the AST
– set the scope to where the template declaration is
in the symbol table
– create symbols from template arguments
– run semantic() passes
Inlining
● inline.d
● functions that can be represented as an
expression can be inlined
int func(int x) { if (x == 8) return 9; else return 68; }
y = func(z) + 8;
y = ((int x = z),(x == 8 ? 9 : 68)) + 8;
● but that doesn't work with loops
Inlining Statements
x = 3;
func(x);
y = x + 3;
Challenges
● eliminate global variables
– sooner or later always cause trouble with recursive logic like
compiler guts
● get a grip on complexity
– reduce cyclomatic complexity
– code should flow rather than hop around
– change data structures to eliminate special cases
● reduce memory consumption
– localize (i.e. encapsulate) memory management
More Challenges
● improve encapsulation
– containers leak implementation details like being a
linked list or an array
– encapsulation means data structures can be changed
● use const / pure / nothrow / @safe
● better dogfooding
– too many vestiges of the older C++ implementation
hanging around
Conclusion
● I like working on compilers
● It never stops being fun (much more fun than
playing video games!)
● Always learning new ways to make the code
better
● All welcome to fork on Github and join in the
fray!

Contenu connexe

Tendances

Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
Moriyoshi Koizumi
 

Tendances (20)

Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
 
Klee and angr
Klee and angrKlee and angr
Klee and angr
 
A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
A look into the sanitizer family (ASAN & UBSAN) by Akul PillaiA look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmers
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / Overview
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
 
Clojure+ClojureScript Webapps
Clojure+ClojureScript WebappsClojure+ClojureScript Webapps
Clojure+ClojureScript Webapps
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 
Boosting Developer Productivity with Clang
Boosting Developer Productivity with ClangBoosting Developer Productivity with Clang
Boosting Developer Productivity with Clang
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON China
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New Rope
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
 
JavaScript for Web Analysts
JavaScript for Web AnalystsJavaScript for Web Analysts
JavaScript for Web Analysts
 
Pwning in c++ (basic)
Pwning in c++ (basic)Pwning in c++ (basic)
Pwning in c++ (basic)
 
Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11
 
C++ Coroutines
C++ CoroutinesC++ Coroutines
C++ Coroutines
 

En vedette

Salina Ocnele Mari
Salina Ocnele MariSalina Ocnele Mari
Salina Ocnele Mari
guest03989ed
 
Reportaje.revista.egirl.videojuego.eyepet.playstation.move
Reportaje.revista.egirl.videojuego.eyepet.playstation.moveReportaje.revista.egirl.videojuego.eyepet.playstation.move
Reportaje.revista.egirl.videojuego.eyepet.playstation.move
MariaVedia
 
6. una página
6.  una página6.  una página
6. una página
Adalberto
 
2016-08-17 Transparencia y recuperación de la capacidad para actuar
2016-08-17 Transparencia y recuperación de la capacidad para actuar2016-08-17 Transparencia y recuperación de la capacidad para actuar
2016-08-17 Transparencia y recuperación de la capacidad para actuar
Emanuel Kramer
 
V R U D D H A T R I H I S A M R U D D H A B E S T S E L L E R F O R S E ...
V R U D D H A  T R I H I  S A M R U D D H A  B E S T S E L L E R  F O R  S E ...V R U D D H A  T R I H I  S A M R U D D H A  B E S T S E L L E R  F O R  S E ...
V R U D D H A T R I H I S A M R U D D H A B E S T S E L L E R F O R S E ...
Monika Gavali
 
Presentacion online
Presentacion onlinePresentacion online
Presentacion online
angie rivera
 
Trabajo de ssmm
Trabajo de ssmmTrabajo de ssmm
Trabajo de ssmm
Chamo SD
 
Gandhi & mandela paper
Gandhi & mandela paperGandhi & mandela paper
Gandhi & mandela paper
mistysims
 

En vedette (20)

Salina Ocnele Mari
Salina Ocnele MariSalina Ocnele Mari
Salina Ocnele Mari
 
15790076
1579007615790076
15790076
 
Reportaje.revista.egirl.videojuego.eyepet.playstation.move
Reportaje.revista.egirl.videojuego.eyepet.playstation.moveReportaje.revista.egirl.videojuego.eyepet.playstation.move
Reportaje.revista.egirl.videojuego.eyepet.playstation.move
 
Mapa conceptual terminado
Mapa conceptual terminadoMapa conceptual terminado
Mapa conceptual terminado
 
6. una página
6.  una página6.  una página
6. una página
 
Reporte planilla20107224549140620131853
Reporte planilla20107224549140620131853Reporte planilla20107224549140620131853
Reporte planilla20107224549140620131853
 
2016-08-17 Transparencia y recuperación de la capacidad para actuar
2016-08-17 Transparencia y recuperación de la capacidad para actuar2016-08-17 Transparencia y recuperación de la capacidad para actuar
2016-08-17 Transparencia y recuperación de la capacidad para actuar
 
V R U D D H A T R I H I S A M R U D D H A B E S T S E L L E R F O R S E ...
V R U D D H A  T R I H I  S A M R U D D H A  B E S T S E L L E R  F O R  S E ...V R U D D H A  T R I H I  S A M R U D D H A  B E S T S E L L E R  F O R  S E ...
V R U D D H A T R I H I S A M R U D D H A B E S T S E L L E R F O R S E ...
 
Anuncio
AnuncioAnuncio
Anuncio
 
Anexo 60 b ficha base diseño oh mar e mio
Anexo  60 b  ficha base diseño oh mar e mioAnexo  60 b  ficha base diseño oh mar e mio
Anexo 60 b ficha base diseño oh mar e mio
 
Mi cuento
Mi cuentoMi cuento
Mi cuento
 
Diizcostu
DiizcostuDiizcostu
Diizcostu
 
Nueva informacion de investigacion
Nueva informacion de investigacionNueva informacion de investigacion
Nueva informacion de investigacion
 
Presentacion online
Presentacion onlinePresentacion online
Presentacion online
 
Trabajo de ssmm
Trabajo de ssmmTrabajo de ssmm
Trabajo de ssmm
 
Andrei Alexandrescu keynote at CSDN 2007 in Beijing, China
Andrei Alexandrescu keynote at CSDN 2007 in Beijing, ChinaAndrei Alexandrescu keynote at CSDN 2007 in Beijing, China
Andrei Alexandrescu keynote at CSDN 2007 in Beijing, China
 
El agua y su ciclo en la producción de moda
El agua y su ciclo en la producción de modaEl agua y su ciclo en la producción de moda
El agua y su ciclo en la producción de moda
 
Proteínas sara
Proteínas saraProteínas sara
Proteínas sara
 
Mobio Threat
Mobio ThreatMobio Threat
Mobio Threat
 
Gandhi & mandela paper
Gandhi & mandela paperGandhi & mandela paper
Gandhi & mandela paper
 

Similaire à DConf 2016: Keynote by Walter Bright

Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
guest3eed30
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
Wei Lin
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
Eelco Visser
 
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdfDatabase & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
InSync2011
 

Similaire à DConf 2016: Keynote by Walter Bright (20)

Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
Robust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time ChecksRobust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time Checks
 
Spark 4th Meetup Londond - Building a Product with Spark
Spark 4th Meetup Londond - Building a Product with SparkSpark 4th Meetup Londond - Building a Product with Spark
Spark 4th Meetup Londond - Building a Product with Spark
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
Clang: More than just a C/C++ Compiler
Clang: More than just a C/C++ CompilerClang: More than just a C/C++ Compiler
Clang: More than just a C/C++ Compiler
 
Apache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & InternalsApache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & Internals
 
Apache Spark: What? Why? When?
Apache Spark: What? Why? When?Apache Spark: What? Why? When?
Apache Spark: What? Why? When?
 
Tips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyTips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development Efficiency
 
A fast introduction to PySpark with a quick look at Arrow based UDFs
A fast introduction to PySpark with a quick look at Arrow based UDFsA fast introduction to PySpark with a quick look at Arrow based UDFs
A fast introduction to PySpark with a quick look at Arrow based UDFs
 
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdfDatabase & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
 
Apache Spark™ is a multi-language engine for executing data-S5.ppt
Apache Spark™ is a multi-language engine for executing data-S5.pptApache Spark™ is a multi-language engine for executing data-S5.ppt
Apache Spark™ is a multi-language engine for executing data-S5.ppt
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
 
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
 
Getting started with Perl XS and Inline::C
Getting started with Perl XS and Inline::CGetting started with Perl XS and Inline::C
Getting started with Perl XS and Inline::C
 
Challenges in GPU compilers
Challenges in GPU compilersChallenges in GPU compilers
Challenges in GPU compilers
 

Dernier

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Dernier (20)

WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 

DConf 2016: Keynote by Walter Bright

  • 1. Tour of the DMD D Programming Language Compiler by Walter Bright http://www.walterbright.com
  • 2.
  • 3. Organization ● One front end to rule them all – and in the D bind them – written in D ● Three back ends – Digital Mars (dmd) – Gnu compiler collection (gdc) – LLVM (ldc)
  • 4. Major Changes in Last Year ● Converted front end from C++ to D ● Switch to using Dwarf exception handling – opens up more comprehensive C++ interfacing
  • 6.
  • 7. Directories ● src/ front end source code ● src/tk generic code for back end ● src/root generic code for front end ● src/backend optimizer and code generator ● src/vcbuild for building compiler with VS
  • 8.
  • 9. Types of Compiles ● diagnose errors in source code ● generate a debug build ● generate a release build
  • 10. Memory Allocation ● root/rmem.d ● Allocate, but never free ● Very fast ● No need for ownership tracking ● Puts upper limit on size of compile
  • 11. Strings ● root/stringtable.d ● const(char)* ● identifier strings stored in single hash table ● address of string becomes its hash – Identifier.idPool() ● very fast
  • 12. Array(T) ● root/array.d ● a workalike to D dynamic arrays ● accessible from C++ code ● heavily used alias Strings = Array!(const(char)*); alias Statements = Array!Statement; alias Identifiers = Array!Identifier; … etc.
  • 13. RootObject ● root/object.d ● single rooted hierarchy – much like D's Object, but predates it – a C++ class, so accessible from glue layer – Declarations, Statements, Expressions – heavy use of OOP plus Visitor Pattern
  • 14. Passes ● read files ● lex ● parse ● create symbol table ● semantic 1 ● semantic 2 ● semantic 3 ● inline ● glue ● optimize ● generate code ● write to object file
  • 15. Lexing ● lexer.d ● pretty simple ● rarely changes ● mostly concerned with speed
  • 16. Parsing ● parse.d ● also simple and rarely changes ● lookahead is done by forming a stack of tokens ● code looks a lot like the grammar …
  • 17. case TOKwhile: { nextToken(); check(TOKlparen); Expression condition = parseExpression(); check(TOKrparen); Loc endloc; Statement _body = parseStatement(PSscope, null, &endloc); s = new WhileStatement(loc,condition,_body,endloc); break; }
  • 18. Create Symbol Table ● importAll() ● establishes a Scope for each symbol
  • 19. Scope ● dscope.d ● link to enclosing Scope ● fields – module – function – storage class in effect – ...
  • 20. Semantic int a; int b = 3; int foo() { return 6; }
  • 21. Lowering ● rewriting ASTs to simpler, canonical forms ● reduces number of cases needing to be dealt with later ● reduces complexity and bugs ● even makes it easier to document
  • 22. Loops while (cond) { body } for (; cond; ) { body } foreach (i; n .. m) { body } for (auto i = n; i < m; ++i) { body } foreach (e; aggr) { body } for (auto r = aggr[]; !r.empty; r.popFront()) { auto e = r.front; body; }
  • 23. Exceptions ● rewritten to be try-finally ● scope ● synchronized ● RAII
  • 24. Error Recovery Models ● Quit on first error ● Guess at user intention, then repair ● Poisoning
  • 25. Poisoning ● have a special 'error' AST node ● replace erroneous AST node with 'error' node ● replace any node that has an 'error' child with an 'error' node ● virtually eliminates cascaded errors – errors displayed are real errors
  • 26. Spell Checking ● root/speller.d ● for undefined identifiers
  • 27. Constant Folding ● constfold.d UnionExp Bool(Type type, Expression e1) { UnionExp ue; Loc loc = e1.loc; emplaceExp!(IntegerExp)(&ue, loc, e1.isBool(true)?1:0, type); return ue; }
  • 28. Compile Time Function Execution (CTFE) ● just a glorified constant folder ● allocates memory to evaluate an expression ● so it runs out of memory ● and is slow
  • 29. Templates ● Stored as ASTs as produced by the parser ● To instantiate: – copy the AST – set the scope to where the template declaration is in the symbol table – create symbols from template arguments – run semantic() passes
  • 30.
  • 31. Inlining ● inline.d ● functions that can be represented as an expression can be inlined int func(int x) { if (x == 8) return 9; else return 68; } y = func(z) + 8; y = ((int x = z),(x == 8 ? 9 : 68)) + 8; ● but that doesn't work with loops
  • 32. Inlining Statements x = 3; func(x); y = x + 3;
  • 33. Challenges ● eliminate global variables – sooner or later always cause trouble with recursive logic like compiler guts ● get a grip on complexity – reduce cyclomatic complexity – code should flow rather than hop around – change data structures to eliminate special cases ● reduce memory consumption – localize (i.e. encapsulate) memory management
  • 34. More Challenges ● improve encapsulation – containers leak implementation details like being a linked list or an array – encapsulation means data structures can be changed ● use const / pure / nothrow / @safe ● better dogfooding – too many vestiges of the older C++ implementation hanging around
  • 35. Conclusion ● I like working on compilers ● It never stops being fun (much more fun than playing video games!) ● Always learning new ways to make the code better ● All welcome to fork on Github and join in the fray!