Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit582b967

Browse files
authored
Ref/Span fixes (#5146)
* Added LimitedValFlags for PostInferenceChecks* More work* Renamed IsLimited to IsLimitedSpanLike* Don't use isByRefReturnCall in CheckExprs* Minor cleanup* Changed error message. Fixed safety rule regarding byrefs returning and passing.* Fixed an edge case with returning span. Simplified Expr.App* Cleanup* Fixed a few ref return checks. Partially handling byref of span-like types* Simplifying flags. Added CheckCall* Updated test baseline. Added several CheckCall functions* Updated baseline tests* Handling byref of span likes* Added a little bit better error msg for LByrefGet* Removed commented code* Fixed test* Fixed inability to use byref<Span<>> for delegates and slots* Minor cleanup with some comments* Few more comments* Running neg tests in core/span. Fixed bug in IsByRefLike structs with span fields* Updated baseline* Fixed more issues with slots. Simplified PermitByRefType* Added a little better error messages on spans* Fixed record construction for span likes. Fixed setting fields on mutable structs not having any rules for span likes. Updated a few error msgs. Added lots of tests.* Updated error msg on function call. Added a removed comment from previous commit. Updated baselines* Added internalTestSpanStackReferring test option* Added special handling for receivers* Fixing build* Fixing build* Fixing build* More tests, updated baseline
1 parent4200819 commit582b967

34 files changed

+1156
-292
lines changed

‎src/buildfromsource/FSharp.Compiler.Private/FSComp.fs‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4324,10 +4324,10 @@ type internal SR private() =
43244324
/// A type annotated with IsByRefLike must also be a struct. Consider adding the [<Struct>] attribute to the type.
43254325
/// (Originally from ..\FSComp.txt:1432)
43264326
static membertcByRefLikeNotStruct()=(3227, GetStringFunc("tcByRefLikeNotStruct",",,,"))
4327-
/// The address ofthe variable '%s' or a relatedexpression cannot be used at this point. The address may not be passed to a call that returns an address. This is to ensure the address of the local value does not escape its scope.
4327+
/// The address ofa value returned from theexpression cannot be used at this point. This is to ensure the address of the local value does not escape its scope.
43284328
/// (Originally from ..\FSComp.txt:1433)
4329-
static memberchkNoByrefReturnOfLocal(a0:System.String)=(3228, GetStringFunc("chkNoByrefReturnOfLocal",",,,%s,,,")a0)
4330-
/// The IsByRefLike expression cannot be returned from this function or method, because it is composed using elements that may escape their scope.
4329+
static memberchkNoByrefAddressOfValueFromExpression()=(3228, GetStringFunc("chkNoByrefAddressOfValueFromExpression",",,,"))
4330+
/// TheSpan orIsByRefLike expression cannot be returned from this function or method, because it is composed using elements that may escape their scope.
43314331
/// (Originally from ..\FSComp.txt:1434)
43324332
static memberchkNoReturnOfLimitedSpan()=(3229, GetStringFunc("chkNoReturnOfLimitedSpan",",,,"))
43334333
/// This value can't be assigned because the target '%s' may refer to non-stack-local memory, while the expression being assigned is assessed to potentially refer to stack-local memory. This is to help prevent pointers to stack-bound memory escaping their scope.
@@ -4342,6 +4342,15 @@ type internal SR private() =
43424342
/// Struct members cannot return the address of fields of the struct by reference
43434343
/// (Originally from ..\FSComp.txt:1438)
43444344
static memberchkStructsMayNotReturnAddressesOfContents()=(3234, GetStringFunc("chkStructsMayNotReturnAddressesOfContents",",,,"))
4345+
/// The function or method call cannot be used at this point, because one argument that is a byref of a non-stack-local Span or IsByRefLike type is used with another argument that is a stack-local Span or IsByRefLike type. This is to ensure the address of the local value does not escape its scope.
4346+
/// (Originally from ..\FSComp.txt:1439)
4347+
static memberchkNoByrefLikeFunctionCall()=(3235, GetStringFunc("chkNoByrefLikeFunctionCall",",,,"))
4348+
/// The Span or IsByRefLike variable '%s' cannot be used at this point. This is to ensure the address of the local value does not escape its scope.
4349+
/// (Originally from ..\FSComp.txt:1440)
4350+
static memberchkNoSpanLikeVariable(a0:System.String)=(3236, GetStringFunc("chkNoSpanLikeVariable",",,,%s,,,") a0)
4351+
/// A Span or IsByRefLike value returned from the expression cannot be used at ths point. This is to ensure the address of the local value does not escape its scope.
4352+
/// (Originally from ..\FSComp.txt:1441)
4353+
static memberchkNoSpanLikeValueFromExpression()=(3237, GetStringFunc("chkNoSpanLikeValueFromExpression",",,,"))
43454354

43464355
/// Call this method once to validate that all known resources are valid; throws if not
43474356
static memberRunStartupValidation()=
@@ -5748,10 +5757,13 @@ type internal SR private() =
57485757
ignore(GetString("readOnlyAttributeOnStructWithMutableField"))
57495758
ignore(GetString("tcByrefReturnImplicitlyDereferenced"))
57505759
ignore(GetString("tcByRefLikeNotStruct"))
5751-
ignore(GetString("chkNoByrefReturnOfLocal"))
5760+
ignore(GetString("chkNoByrefAddressOfValueFromExpression"))
57525761
ignore(GetString("chkNoReturnOfLimitedSpan"))
57535762
ignore(GetString("chkNoWriteToLimitedSpan"))
57545763
ignore(GetString("tastValueMustBeLocal"))
57555764
ignore(GetString("tcIsReadOnlyNotStruct"))
57565765
ignore(GetString("chkStructsMayNotReturnAddressesOfContents"))
5766+
ignore(GetString("chkNoByrefLikeFunctionCall"))
5767+
ignore(GetString("chkNoSpanLikeVariable"))
5768+
ignore(GetString("chkNoSpanLikeValueFromExpression"))
57575769
()

‎src/buildfromsource/FSharp.Compiler.Private/FSComp.resx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4327,11 +4327,11 @@
43274327
<dataname="tcByRefLikeNotStruct"xml:space="preserve">
43284328
<value>A type annotated with IsByRefLike must also be a struct. Consider adding the [&lt;Struct&gt;] attribute to the type.</value>
43294329
</data>
4330-
<dataname="chkNoByrefReturnOfLocal"xml:space="preserve">
4331-
<value>The address ofthe variable '{0}' or a relatedexpression cannot be used at this point. The address may not be passed to a call that returns an address. This is to ensure the address of the local value does not escape its scope.</value>
4330+
<dataname="chkNoByrefAddressOfValueFromExpression"xml:space="preserve">
4331+
<value>The address ofa value returned from theexpression cannot be used at this point. This is to ensure the address of the local value does not escape its scope.</value>
43324332
</data>
43334333
<dataname="chkNoReturnOfLimitedSpan"xml:space="preserve">
4334-
<value>The IsByRefLike expression cannot be returned from this function or method, because it is composed using elements that may escape their scope.</value>
4334+
<value>TheSpan orIsByRefLike expression cannot be returned from this function or method, because it is composed using elements that may escape their scope.</value>
43354335
</data>
43364336
<dataname="chkNoWriteToLimitedSpan"xml:space="preserve">
43374337
<value>This value can't be assigned because the target '{0}' may refer to non-stack-local memory, while the expression being assigned is assessed to potentially refer to stack-local memory. This is to help prevent pointers to stack-bound memory escaping their scope.</value>
@@ -4345,4 +4345,13 @@
43454345
<dataname="chkStructsMayNotReturnAddressesOfContents"xml:space="preserve">
43464346
<value>Struct members cannot return the address of fields of the struct by reference</value>
43474347
</data>
4348+
<dataname="chkNoByrefLikeFunctionCall"xml:space="preserve">
4349+
<value>The function or method call cannot be used at this point, because one argument that is a byref of a non-stack-local Span or IsByRefLike type is used with another argument that is a stack-local Span or IsByRefLike type. This is to ensure the address of the local value does not escape its scope.</value>
4350+
</data>
4351+
<dataname="chkNoSpanLikeVariable"xml:space="preserve">
4352+
<value>The Span or IsByRefLike variable '{0}' cannot be used at this point. This is to ensure the address of the local value does not escape its scope.</value>
4353+
</data>
4354+
<dataname="chkNoSpanLikeValueFromExpression"xml:space="preserve">
4355+
<value>A Span or IsByRefLike value returned from the expression cannot be used at ths point. This is to ensure the address of the local value does not escape its scope.</value>
4356+
</data>
43484357
</root>

‎src/fsharp/CompileOps.fs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,7 @@ type TcConfigBuilder =
23472347
/// and from which we can read the metadata. Only used when metadataOnly=true.
23482348
mutable tryGetMetadataSnapshot:ILReaderTryGetMetadataSnapshot
23492349

2350+
mutable internalTestSpanStackReferring:bool
23502351
}
23512352

23522353
static memberInitial=
@@ -2483,6 +2484,7 @@ type TcConfigBuilder =
24832484
copyFSharpCore= CopyFSharpCoreFlag.No
24842485
shadowCopyReferences=false
24852486
tryGetMetadataSnapshot=(fun _-> None)
2487+
internalTestSpanStackReferring=false
24862488
}
24872489

24882490
static memberCreateNew(legacyReferenceResolver,defaultFSharpBinariesDir,reduceMemoryUsage,implicitIncludeDir,
@@ -2943,6 +2945,7 @@ type TcConfig private (data : TcConfigBuilder, validate:bool) =
29432945
memberx.copyFSharpCore= data.copyFSharpCore
29442946
memberx.shadowCopyReferences= data.shadowCopyReferences
29452947
memberx.tryGetMetadataSnapshot= data.tryGetMetadataSnapshot
2948+
memberx.internalTestSpanStackReferring= data.internalTestSpanStackReferring
29462949
static memberCreate(builder,validate)=
29472950
use unwindBuildPhase= PushThreadBuildPhaseUntilUnwind BuildPhase.Parameter
29482951
TcConfig(builder, validate)
@@ -5431,7 +5434,7 @@ let TypeCheckOneInputEventually (checkForErrors, tcConfig:TcConfig, tcImports:Tc
54315434

54325435
// Typecheck the signature file
54335436
let!(tcEnv,sigFileType,createsGeneratedProvidedTypes)=
5434-
TypeCheckOneSigFile(tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors, tcConfig.conditionalCompilationDefines, tcSink) tcState.tcsTcSigEnv file
5437+
TypeCheckOneSigFile(tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors, tcConfig.conditionalCompilationDefines, tcSink, tcConfig.internalTestSpanStackReferring) tcState.tcsTcSigEnv file
54355438

54365439
letrootSigs= Zmap.add qualNameOfFile sigFileType tcState.tcsRootSigs
54375440

@@ -5468,7 +5471,7 @@ let TypeCheckOneInputEventually (checkForErrors, tcConfig:TcConfig, tcImports:Tc
54685471

54695472
// Typecheck the implementation file
54705473
let!topAttrs,implFile,_implFileHiddenType,tcEnvAtEnd,createsGeneratedProvidedTypes=
5471-
TypeCheckOneImplFile(tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors, tcConfig.conditionalCompilationDefines, tcSink) tcImplEnv rootSigOpt file
5474+
TypeCheckOneImplFile(tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors, tcConfig.conditionalCompilationDefines, tcSink, tcConfig.internalTestSpanStackReferring) tcImplEnv rootSigOpt file
54725475

54735476
lethadSig= rootSigOpt.IsSome
54745477
letimplFileSigType= SigTypeOfImplFile implFile

‎src/fsharp/CompileOps.fsi‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ type TcConfigBuilder =
363363
/// A function to call to try to get an object that acts as a snapshot of the metadata section of a .NET binary,
364364
/// and from which we can read the metadata. Only used when metadataOnly=true.
365365
mutable tryGetMetadataSnapshot:ILReaderTryGetMetadataSnapshot
366+
367+
/// if true - 'let mutable x = Span.Empty', the value 'x' is a stack referring span. Used for internal testing purposes only until we get true stack spans.
368+
mutable internalTestSpanStackReferring:bool
366369
}
367370

368371
static memberInitial:TcConfigBuilder

‎src/fsharp/CompileOptions.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ let advancedFlagsFsc tcConfigB =
832832
lettestFlag tcConfigB=
833833
CompilerOption("test", tagString, OptionString(fun s->
834834
match swith
835+
|"StackSpan"-> tcConfigB.internalTestSpanStackReferring<-true
835836
|"ErrorRanges"-> tcConfigB.errorStyle<- ErrorStyle.TestErrors
836837
|"MemberBodyRanges"-> PostTypeCheckSemanticChecks.testFlagMemberBody:=true
837838
|"Tracking"-> Lib.tracking:=true(* general purpose on/off diagnostics flag*)

‎src/fsharp/FSComp.txt‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,9 +1430,12 @@ notAFunctionButMaybeDeclaration,"This value is not a function and cannot be appl
14301430
3225,readOnlyAttributeOnStructWithMutableField,"A ReadOnly attribute has been applied to a struct type with a mutable field."
14311431
3226,tcByrefReturnImplicitlyDereferenced,"A byref pointer returned by a function or method is implicitly dereferenced as of F# 4.5. To acquire the return value as a pointer, use the address-of operator, e.g. '&f(x)' or '&obj.Method(arg1, arg2)'."
14321432
3227,tcByRefLikeNotStruct,"A type annotated with IsByRefLike must also be a struct. Consider adding the [<Struct>] attribute to the type."
1433-
3228,chkNoByrefReturnOfLocal,"The address ofthe variable '%s' or a relatedexpression cannot be used at this point. The address may not be passed to a call that returns an address. This is to ensure the address of the local value does not escape its scope."
1434-
3229,chkNoReturnOfLimitedSpan,"The IsByRefLike expression cannot be returned from this function or method, because it is composed using elements that may escape their scope."
1433+
3228,chkNoByrefAddressOfValueFromExpression,"The address ofa value returned from theexpression cannot be used at this point. This is to ensure the address of the local value does not escape its scope."
1434+
3229,chkNoReturnOfLimitedSpan,"TheSpan orIsByRefLike expression cannot be returned from this function or method, because it is composed using elements that may escape their scope."
14351435
3230,chkNoWriteToLimitedSpan,"This value can't be assigned because the target '%s' may refer to non-stack-local memory, while the expression being assigned is assessed to potentially refer to stack-local memory. This is to help prevent pointers to stack-bound memory escaping their scope."
14361436
3231,tastValueMustBeLocal,"A value defined in a module must be mutable in order to take its address, e.g. 'let mutable x = ...'"
14371437
3232,tcIsReadOnlyNotStruct,"A type annotated with IsReadOnly must also be a struct. Consider adding the [<Struct>] attribute to the type."
14381438
3234,chkStructsMayNotReturnAddressesOfContents,"Struct members cannot return the address of fields of the struct by reference"
1439+
3235,chkNoByrefLikeFunctionCall,"The function or method call cannot be used at this point, because one argument that is a byref of a non-stack-local Span or IsByRefLike type is used with another argument that is a stack-local Span or IsByRefLike type. This is to ensure the address of the local value does not escape its scope."
1440+
3236,chkNoSpanLikeVariable,"The Span or IsByRefLike variable '%s' cannot be used at this point. This is to ensure the address of the local value does not escape its scope."
1441+
3237,chkNoSpanLikeValueFromExpression,"A Span or IsByRefLike value returned from the expression cannot be used at ths point. This is to ensure the address of the local value does not escape its scope."

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp