Release: `inline` function taking the address of a module-level `let mutable` emits a field reference to the wrong startup class when inlined into another assembly (TypeLoadException)
Los mantenedores suelen responder en 3 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 28/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- compilers
Línea de trabajo
Reproduce with the two projects in the report: Lib/State.fs defines the inline read that takes &value, and App/Program.fs calls it. Build both in Release, then inspect App.dll for the value@3 MemberRef and compare its parent type with the startup classes in Lib.dll. Done means the Release app prints ok without a TypeLoadException, or the compiler stops inlining such a function across assemblies.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
When an inline function takes the address of a module-level let mutable value (&value, e.g. to call Volatile.Read) and that function is inlined into another assembly, the optimized (Release) build of the calling assembly emits a MemberRef to the backing static field on a type named after the assembly (<StartupCode$Lib>.$Lib) instead of the startup class of the file that defines the value (<StartupCode$Lib>.$State). At run time this fails with TypeLoadException. Debug builds (no cross-assembly inlining) work.
To Reproduce
Lib/Lib.fsproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="State.fs" />
</ItemGroup>
</Project>
Lib/State.fs:
module State
let mutable value : string = "ok"
let inline read () : string = System.Threading.Volatile.Read(&value)
App/App.fsproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lib\Lib.fsproj" />
</ItemGroup>
</Project>
App/Program.fs:
[<EntryPoint>]
let main _ =
printfn "%s" (State.read ())
0
dotnet run --project App -c Debug # prints: ok
dotnet run --project App -c Release # fails:
Unhandled exception. System.TypeLoadException: Could not load type '<StartupCode$Lib>.$Lib' from assembly 'Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at Program.main(String[] _arg1)
Metadata of the Release App.dll versus the types that actually exist in Lib.dll:
App TypeRef: ns=<StartupCode$Lib> name=$Lib
App MemberRef: value@3 on <StartupCode$Lib>.$Lib
Lib types: State
<StartupCode$Lib>.$State
<StartupCode$Lib>.$Lib.AssemblyInfo
Expected behavior
Either the inlined code references the correct, accessible storage for value, or the compiler does not inline such a function across assemblies (the backing field is assembly-internal, so even the correct type name would fail with FieldAccessException). It should not compile into a reference to a non-existent type.
Actual behavior
TypeLoadException at run time in Release only. In a larger project this surfaced as hundreds of failing tests in Release (and in a Microsoft.NET.Sdk.WebAssembly publish) while Debug was fully green. The assembly name does not matter: the same happens for CasAlgebra and Cas.Algebra (<StartupCode$Cas-Algebra>.$Cas.Algebra).
Known workarounds
- Do not take the address of a module-level
let mutablein aninlinefunction that may be inlined into another assembly: plain reads/assignments (optionally withThread.MemoryBarrier()) work. - Not inlining the function (
inlineremoved, or[<MethodImpl(MethodImplOptions.NoInlining)>]) also avoids the problem. --crossoptimize-on the consuming project did not help in our case.
Related information
- .NET SDK 10.0.400, F# 10.0 (
dotnet fsi --version: 15.2.400), FSharp.Core 10.1.400 - Windows 10 x64; also reproduced in a .NET WebAssembly (AOT) host
- Occurs with
Volatile.Read(&x),Volatile.Write(&x, v)on module-levellet mutablevalues used frominlinefunctions
- Lenguaje dominante
- F#
- Estrellas
- 4.3k
- Forks
- 883
- Merge medio
- 3 d 17 h
- PR fusionados (30 d)
- 114
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dotnet/fsharp
-
Needs-Triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
Los mantenedores suelen responder en 3 días
-
Semantic classification cache for opened documents is never populated (written to the unopened-documents cache)Posiblemente ocupada @xperiandri la tomó hace 60 días. AbiertoNeeds-Triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
Los mantenedores suelen responder en 3 días
-
Needs-Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dotnet/fsharp#20265 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
Bug Needs-Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 3 días
-
Dificultad 4/5 1-2 días Aptitud para principiantes 15/100
Los mantenedores suelen responder en 3 días
Todos los issues de dotnet/fsharp
Issues similares
-
0.kind: enhancement 9.needs: package (update)
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
Bug: the Atlas reports the five injected `$` helpers as unknown identifiers, including in the default scaffoldPosiblemente ocupada @ShahadatTest la tomó hoy. Abiertobug Compiler difficulty:easy good first issue help wanted Tooling
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Avenx-JS/avenx-js#1615 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
respond_to? on a poly receiver answers true for a program class's private or protected methodAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
AeneasVerif/aeneas#1534 ·
Los mantenedores suelen responder en 1 día
-
arrays asr pass bug ICE intrinsic medium priority
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día