Difference between revisions of "DIP56"

From D Wiki
Jump to: navigation, search
(MediaWiki formatting)
(Clarify behavior.)
Line 33: Line 33:
 
== Description ==
 
== Description ==
 
This adds a pragma 'inline' and two values for it: true and false, which influences the inlining of the
 
This adds a pragma 'inline' and two values for it: true and false, which influences the inlining of the
function they appear in. 'true' means always inline, 'false' means never inline.
+
function they appear in. 'true' means always inline, 'false' means never inline, no argument means default
 +
behavior.
 +
 
 +
If this pragma is outside of a function, it affects the functions in the block it encloses.
 +
 
 +
Nested pragmas override the outer ones.
 +
 
 +
If there are multiple pragmas inside a function, the lexically last one that is semantically analyzed
 +
controls the behavior.
 +
 
 +
If the pragma is versioned out or in a false static if conditional, it is ignored.
  
 
These are not attributes because they should not affect the semantics of the function.
 
These are not attributes because they should not affect the semantics of the function.
Line 40: Line 50:
 
== Usage ==
 
== Usage ==
  
  pragma(inline, true);
+
  pragma(inline, true); // always inline
  pragma(inline, false);
+
  pragma(inline, false); // never inline
 +
pragma(inline);        // revert to default behavior
  
 
== Copyright ==
 
== Copyright ==

Revision as of 20:34, 23 February 2014

Title: Provide pragma to control function inlining
DIP: 56
Version: 0
Status: Draft
Created: 2014-02-23
Last Modified: 2014-02-23
Author: Walter Bright
Links:

Abstract

This proposal uses pragmas to add hints to the compiler.

Rationale

Sometimes generating better code requires runtime profile information. But being a static compiler, not a JIT, the compiler could use such hints from the programmer.

Description

This adds a pragma 'inline' and two values for it: true and false, which influences the inlining of the function they appear in. 'true' means always inline, 'false' means never inline, no argument means default behavior.

If this pragma is outside of a function, it affects the functions in the block it encloses.

Nested pragmas override the outer ones.

If there are multiple pragmas inside a function, the lexically last one that is semantically analyzed controls the behavior.

If the pragma is versioned out or in a false static if conditional, it is ignored.

These are not attributes because they should not affect the semantics of the function. In particular, the function signature must not be affected.

Usage

pragma(inline, true);  // always inline
pragma(inline, false); // never inline
pragma(inline);        // revert to default behavior

Copyright

This document has been placed in the Public Domain.