Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

dmd.escape

Most of the logic to implement scoped pointers and scoped references is here.
Authors:
Walter Bright
License:
Boost License 1.0

Sourceescape.d

Documentationhttps://dlang.org/phobos/dmd_escape.html

Coveragehttps://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/escape.d

structEscapeState;
Groups global state for escape checking together
static voidreset();
Called byinitDMD /deinitializeDMD to reset global state
boolcheckMutableArguments(ref Scopesc, FuncDeclarationfd, TypeFunctiontf, Expressionethis, Expressions*arguments, boolgag);
Checks memory objects passed to a function. Checks that if a memory object is passed by ref or by pointer, all of the refs or pointers are const, or there is only one mutable ref or pointer to it.

ReferencesDIP 1021

Parameters:
Scopescused to determine current function and module
FuncDeclarationfdfunction being called
TypeFunctiontffd's type
Expressionethisif not null, thethis pointer
Expressions*argumentsactual arguments to function
boolgagdo not print error messages
Returns:
true if error
boolcheckArrayLiteralEscape(ref Scopesc, ArrayLiteralExpae, boolgag);
Array literal is going to be allocated on the GC heap. Check its elements to see if any would escape by going on the heap.
Parameters:
Scopescused to determine current function and module
ArrayLiteralExpaearray literal expression
boolgagdo not print error messages
Returns:
true if any elements escaped
boolcheckAssocArrayLiteralEscape(ref Scopesc, AssocArrayLiteralExpae, boolgag);
Associative array literal is going to be allocated on the GC heap. Check its elements to see if any would escape by going on the heap.
Parameters:
Scopescused to determine current function and module
AssocArrayLiteralExpaeassociative array literal expression
boolgagdo not print error messages
Returns:
true if any elements escaped
boolcheckParamArgumentEscape(ref Scopesc, FuncDeclarationfdc, IdentifierparId, VarDeclarationvPar, STCparStc, Expressionarg, boolassertmsg, boolgag);
Function parameterpar is being initialized toarg, andpar may escape. Detect if scoped values can escape this way. Print error messages when these are detected.
Parameters:
Scopescused to determine current function and module
FuncDeclarationfdcfunction being called,null if called indirectly
IdentifierparIdname of function parameter for error messages
VarDeclarationvParVarDeclaration corresponding topar
STCparStcstorage classes of function parameter (may have addedscope frompure)
Expressionarginitializer for param
boolassertmsgtrue if the parameter is the msg argument to assert(bool, msg).
boolgagdo not print error messages
Returns:
true if pointers to the stack can escape via assignment
boolcheckParamArgumentReturn(ref Scopesc, ExpressionfirstArg, Expressionarg, Parameterparam, boolgag);
Function argument initializes areturn parameter, and that parameter gets assigned tofirstArg. Essentially, treat asfirstArg =arg;
Parameters:
Scopescused to determine current function and module
ExpressionfirstArgref argument through whicharg may be assigned
Expressionarginitializer for parameter
Parameterparamparameter declaration corresponding toarg
boolgagdo not print error messages
Returns:
true if assignment tofirstArg would cause an error
boolcheckConstructorEscape(ref Scopesc, CallExpce, boolgag);
Check struct constructor of the forms.this(args), by checking eachreturn parameter to see if it gets assigned tos.
Parameters:
Scopescused to determine current function and module
CallExpceconstructor call of the forms.this(args)
boolgagdo not print error messages
Returns:
true if construction would cause an escaping reference error
enumReturnParamDest: int;
How areturn parameter escapes its pointer value
returnVal
through return statement:return x
this_
assigned to a struct instance:this.x = x
firstArg
assigned to first argument:firstArg = x
ReturnParamDestreturnParamDest(TypeFunctiontf, Typetthis);
Find out if instead of returning areturn parameter via a return statement, it is returned via assignment to eitherthis or the first parameter.
This works the same as returning the value via a return statement. Although the first argument must beref, it is not regarded as returning byref.
See Also:
Parameters:
TypeFunctiontffunction type
Typetthistype ofthis parameter, ornull if none
Returns:
What areturn parameter should transfer the lifetime of the argument to
boolcheckAssignEscape(ref Scopesc, Expressione, boolgag, boolbyRef);
Given anAssignExp, determine if the lvalue will cause the contents of the rvalue to escape. Print error messages when these are detected. Inferscope attribute for the lvalue where possible, in order to eliminate the error.
Parameters:
Scopescused to determine current function and module
ExpressioneAssignExp orCatAssignExp to check for any pointers to the stack
boolgagdo not print error messages
boolbyRefset totrue ife1 ofe gets assigned a reference toe2
Returns:
true if pointers to the stack can escape via assignment
boolcheckThrowEscape(ref Scopesc, Expressione, boolgag);
Detect cases where pointers to the stack can escape the lifetime of the stack frame when throwinge. Print error messages when these are detected.
Parameters:
Scopescused to determine current function and module
Expressioneexpression to check for any pointers to the stack
boolgagdo not print error messages
Returns:
true if pointers to the stack can escape
boolcheckNewEscape(ref Scopesc, Expressione, boolgag);
Detect cases where pointers to the stack can escape the lifetime of the stack frame by being placed into a GC allocated object. Print error messages when these are detected.
Parameters:
Scopescused to determine current function and module
Expressioneexpression to check for any pointers to the stack
boolgagdo not print error messages
Returns:
true if pointers to the stack can escape
boolcheckReturnEscape(ref Scopesc, Expressione, boolgag);
Detect cases where pointers to the stack can escape the lifetime of the stack frame by returninge by value. Print error messages when these are detected.
Parameters:
Scopescused to determine current function and module
Expressioneexpression to check for any pointers to the stack
boolgagdo not print error messages
Returns:
true if pointers to the stack can escape
boolcheckReturnEscapeRef(ref Scopesc, Expressione, boolgag);
Detect cases where returninge byref can result in a reference to the stack being returned. Print error messages when these are detected.
Parameters:
Scopescused to determine current function and module
Expressioneexpression to check
boolgagdo not print error messages
Returns:
true if references to the stack can escape
voidescapeByValue(Expressione, ref scope EscapeByResultser);
e is an expression to be returned by value, and that value contains pointers. Walk e to determine which variables are possibly being returned by value, such as: int* function(int* p) { return p; } If e is a form of &p, determine which variables have content which is being returned as ref, such as: int* function(int i) { return &i; } Multiple variables can be inserted, because of expressions like this: int function(bool b, int i, int* p) { return b ? &i : p; }
No side effects.
Parameters:
Expressioneexpression to be returned by value
EscapeByResultserwhere to place collected data
structEscapeByResults;
Aggregate the data collected by the escapeBy??() functions.
void delegate(VarDeclaration, bool retRefTransition)byRef;
called on variables being returned by ref / address
void delegate(VarDeclaration)byValue;
called on variables with values containing pointers
void delegate(FuncDeclaration, bool called)byFunc;
called on nested functions that are turned into delegatesWhencalled is true, it means the delegate escapes variablesfrom the closure through a call to it, whilefalse means thedelegate itself escapes.
void delegate(Expression, bool retRefTransition)byExp;
called when expression temporaries are being returned by ref / address
boollive;
if @live semantics apply, i.e. expressionsp,*p,**p, etc., all returnp.
voidfindAllOuterAccessedVariables(FuncDeclarationfd, VarDeclarations*vars);
Find all variables accessed by this delegate that are in functions enclosing it.
Parameters:
FuncDeclarationfdfunction
VarDeclarations*varsarray to append found variables to
voidfinishScopeParamInference(FuncDeclarationfuncdecl, ref TypeFunctionf);
After semantic analysis of the function body, try to inferscope /return on the parameters
Parameters:
FuncDeclarationfuncdeclfunction declaration that was analyzed
TypeFunctionffinal function type.funcdecl.type started as the 'premature type' before attribute inference, then its inferred attributes are copied over to final typef
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Sat Feb 21 04:05:51 2026

[8]ページ先頭

©2009-2026 Movatter.jp