-
Notifications
You must be signed in to change notification settings - Fork 790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unused binding warning isn't reported for recursive binding in a type #13849
Comments
@auduchinok not that I can think of a direct connection - but cannot say for sure since CheckExpressions.fs is a very interconnected thing and everything can happen there. Or maybe @dsyme you have insights on that? Regardless, this is a regression, not good - @vzarytovskii FYI. |
It is likely related to the way we check it (i.e. we don't emit warning if member/binding has fsharp/src/Compiler/Checking/CheckIncrementalClasses.fs Lines 291 to 293 in 638e479
And here: fsharp/src/Compiler/Checking/PostInferenceChecks.fs Lines 308 to 319 in 638e479
Right now, we emit the following IL (roughly): .method assembly hidebysig instance void f<a> (!!a x) cil managed
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (01 00 00 00)
.maxstack 8
IL_0000: ret
} // end of method T::f
.method assembly hidebysig instance void g<a> (!!a x) cil managed
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (01 00 00 00
.maxstack 8
IL_0000: ret
} // end of method T::g We've made some changes to codegen in the following PRs: #13542 and #13494 Update: it seems those only touch fields and properties, but not methods. |
Even just this is a repro:
|
@dsyme Ah, interesting, indeed. In all other tests we have a simple value, not a function, and the only function in these tests happened to be recursive. I should've tried to find a smaller repro (and perhaps we need more tests 🙂). Thanks for pointing it out! |
@vzarytovskii strange, the |
@0101 I think it is these lines: // NOTE: putting isCompilerGenerated=true here is strange. The method is not public, nor is
// it a "member" in the F# sense, but the F# spec says it is generated and it is reasonable to reflect on it.
let memberValScheme = ValScheme(id, prelimTyschemeG, Some valReprInfo, None, Some memberInfo, false, ValInline.Never, NormalVal, None, true (* isCompilerGenerated *), true (* isIncrClass *), false, false) |
I added this comment here, though didn't change the setting at that point: |
Note that in the checking of incremental classes, two Val are in play in IncrementalClasses.fs:
Most checking is done in TcCheck* and is done with respect to the "non-member" values which are not marked compiler-generated, however the "PostInferenceChecks" are done after the representations have been decided and so with respect to the "member" values. This is the underlying problem - the PostInferenceChecks are seeing too much of the internal compilation/representation process. We've talked about moving the IncrementalClasses representation-process into a later compiler phase - after PostInferenceChecks - but this is a larger bit of work. I guess the fact that this is a representation-process is the reason we decided long ago to mark these as compiler-generated. Hwoever I don't know why any of this has changed recently - maybe we added the IsCompilerGenerated filter in PostInferenceChecks? @psfinaki did make a change to make the non-member vals visible to the the language service, but I don't think that should be affecting this. Anyway, marking the "member values" as non-compiler-generated is probably OK in principle. However one problem is that there can be duplicates: type C() =
let f() = 1
let f() = 2 This is allowed in F# - and the member-vals for the two This means a simple fix of "mark the value as non-compiler-generated" will lead to diagnostics like So maybe what we really want is two non-compiler-generated member-vals fsharp/src/Compiler/TypedTree/TypedTree.fs Line 2512 in 638e479
That might work out I think. |
We didn't emit the warning because of one flag
fsharp/src/Compiler/Checking/CheckIncrementalClasses.fs Lines 291 to 292 in 2c3ff6d
After reading some code involving this attribute I think the diff --git a/src/Compiler/Checking/CheckIncrementalClasses.fs b/src/Compiler/Checking/CheckIncrementalClasses.fs
index c58414dfb..c4ae53cca 100644
--- a/src/Compiler/Checking/CheckIncrementalClasses.fs
+++ b/src/Compiler/Checking/CheckIncrementalClasses.fs
@@ -289,7 +289,7 @@ type IncrClassReprInfo =
nm, takenFieldNames.Add nm
let reportIfUnused() =
- if not v.HasBeenReferenced && not v.IsCompiledAsTopLevel && not (v.DisplayName.StartsWithOrdinal("_")) && not v.IsCompilerGenerated then
+ if not v.HasBeenReferenced && not (v.DisplayName.StartsWithOrdinal("_")) && not v.IsCompilerGenerated then
warning (Error(FSComp.SR.chkUnusedValue(v.DisplayName), v.Range))
let repr = What do you guys think? |
It seems that removing |
Another difference is now
|
Where is this FSharpSymbol acquired from? |
From results of |
Consider the following type declaration:
Earlier FCS versions would report
f
as unused with--warnon:1182
flag present, but the currentmain
doesn't report it anymore.@psfinaki Could it be somehow related to #13429?
The text was updated successfully, but these errors were encountered: