Alexandru Razvan Caciulescu University POLITEHNICA of Bucharest

Slides:



Advertisements
Similar presentations
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Advertisements

Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
Functional Image Synthesis. Pan An image synthesis “language” Images are functions Continuous and infinite Embedded in a functional host language Reusable.
Chapter 16 Exception Handling. What is Exception Handling? A method of handling errors that informs the user of the problem and prevents the program from.
The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
What's new in Microsoft Visual C Preview
Overloading Operators Overloading operators Unary operators Binary operators Member, non-member operators Friend functions and classes Function templates.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
What’s it all about STL vectors offer amortized constant time insertion, by doubling the capacity whenever it’s full Vectors also offer contiguous memory,
CS-212 Intro to C++. Abstract Data Type Abstraction of a real world object as a mathematical entity Implementation independent model of the entity Emphasis.
1 Implementing a Narrow Waist Abstraction for Sensornets Project Update Arsalan Tavakoli Jay Taneja Fall Semester 2005.
OOP Etgar 2008 – Recitation 71 Object Oriented Programming Etgar 2008 Recitation 7.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
Procedure Optimizations and Interprocedural Analysis Chapter 15, 19 Mooly Sagiv.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
XML I/O in ROOT S. Linev, R. Brun, H.G. Essel CHEP 2004.
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
Chapter 9 Defining New Types. Objectives Explore the use of member functions when creating a struct. Introduce some of the concepts behind object-oriented.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
C ++ Basics by Bindra Shrestha sce.uhcl.edu/shresthab CSCI 3333 Data Structures.
Object Oriented Programming (OOP) Lecture No. 8. Review ► Class  Concept  Definition ► Data members ► Member Functions ► Access specifier.
Boost Candy A quick introduction to some libraries.
Templates & STL Stefan Roiser, Lorenzo Moneta CERN PH/SFT.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
1 Recursion n what is it? n how to build recursive algorithms n recursion analysis n tracing simple recursive functions n hands on attempts at writing.
Concepts in C++. Templates in current C++ C++ template is typeless No language support for constrained generics Accidental errors found in instantiation.
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
C++ Functions A bit of review (things we’ve covered so far)
1 Titanium Review: Language and Compiler Amir Kamil Titanium Language and Compiler Changes Amir Kamil U.C. Berkeley September.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
C++ Features Function Overloading Default Functions arguments Thinking about objects – relationship to classes Types of member functions Constructor and.
HDF/HDF-EOS Meeting Oct th 2008, Aurora CO Proposal for adding Named Dimensions to HDF5 Arrays Daniel Kahn Science Systems and Applications, Inc.
D Language Compiler as a Library
CSE1002 – Problem Solving with Object Oriented Programming
Motivation for Generic Programming in C++
Pointer to an Object Can define a pointer to an object:
Memory Management with Classes
Recursion what is it? how to build recursive algorithms
How to be generic Lecture 10
Templates.
Introduction to C++ Systems Programming.
Motivation and Overview
Chapter 1 C++ Basics Review
Operator overloading Conversions friend inline
Operator overloading Conversions friend inline
Review: Two Programming Paradigms
Chapter7 Structure & C++
Operator overloading Conversions friend inline
CISC/CMPE320 - Prof. McLeod
Generic Lightweight Druntime
Initialization List.
Encapsulation and Constructors
Constructors and Other Tools
Reference Parameters.
Miscellaneous C++ Topics
STL Iterators Separating Container from Data Access.
The Standard Template Library
The Big 5 and Lists.
COP 3330 Object-oriented Programming in C++
The Challenge of Cross - Language Interoperability
Passing Arguments and The Big 5
Overview of C++ Polymorphism
Lesson 25 Miscellaneous Topics
ENERGY 211 / CME 211 Lecture 8 October 8, 2008.
ENERGY 211 / CME 211 Lecture 30 December 5, 2008.
Rethinking the Default Class Hierarchy: an Object’s Tale
Initialization List.
Workshop 1++: A bit of C++
Presentation transcript:

Zero Overhead Interface Between the D Language and the C++ Standard Library Alexandru Razvan Caciulescu University POLITEHNICA of Bucharest alexandru.razvan.c@gmail.com DConf 2017 Berlin, May 4-7, 2017

Motivation D C++ STL Efficient Powerful Widely used Awesome Optimized Well tested

The Idea C++ D import core.stdcpp.stl_vector; int main() { … auto v = vector!int(); … v.push_back(x); } C++ … std::vector<int> v; v.push_back(x); 3

Simple Example extern(C++, std) { int foo(char a, char b); // _ZSt3foocc } 4

Challenges Name mangling Rvalue ref Operator Overloading Value vs ref type C++ ctors Portability Const issue __Exceptions__ 5

void foo(void*(*)(void*),void*(*)(const void*),const void*(*)(void*)) Not so Simple Example void foo(void*(*)(void*),void*(*)(const void*),const void*(*)(void*)) 6

Not so Simple Example _ZN11QMouseEvent24createExtendedMouseEventEN6QEvent4TypeERK7QPointFRK6QPointN2Qt11MouseButtonE6QFlagsIS9_ESA_INS8_16KeyboardModifierEE QMouseEvent::createExtendedMouseEvent(QEvent::Type, QPointF const&, QPoint const&, Qt::MouseButton, QFlags<Qt::MouseButton>, QFlags<Qt::KeyboardModifier>) 7

Name Mangling: Issues Mangling discrepancies discovered Unsupported keywords __decay_and_strip First idea: rewrite the mangler? Non trivial 8

Name Mangling: Grammar 9

Name Mangling: Grammar 10

Name Mangling: Grammar 11

Name Mangling: Ideas Second idea: Hack the mangler Works, efficient, not elegant Better solution? Mangling as library code 12

Name Mangling: Workaround pragma(mangle, “_myFoo”) int foo(char a, char b) mangleof!(int(char,char))(“foo”) 13

Rvalue Ref Hot debate topic It’s just a mangling issue! (in this case) One solution: use UDA (User Defined Attributes) push_back(@rvalue ref int); 14

Operator Overloading Different approach Implement it on the D side 15

Operator Overloading 16

Operator Overloading 17

Pass by Value Implies copy constructors Incompatible between C++ and D 18

Current State std::pair std::allocator std::vector std::string 19

Benchmark 20

Inline Optimization void push_back(const ref T x); void push_back_opt(const ref T x) { if (finish == end_of_storage) push_back(x); else *finish++ = x; } 21

Inline Optimization LDC LTO (Link Time Optimization) 22

Future Work Elegant solution for name mangling Mangling as library code Portability Exceptions 23

Conclusions Have zero overhead between D and STL Took first steps towards full STL support Minor STL subset interfaced Incremental approach Long road ahead 24