dotnet / dotnet/fsharp

Instantiating a generative type provider twice results in invalid IL

Open
#37 3 comments 0 reactions 0 assignees View on GitHub
Area-TypeProviders Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

[from fsbugs]

If one defines a generative type provider with some fields/properties, then creates 2 identical versions of that provided type:

``` fsharp
type T2 = Samples.ShareInfo.TPTest.TPTestType
type T = Samples.ShareInfo.TPTest.TPTestType
```

the resulting assembly contains invalid IL.

file attachments
- [reproSln.zip](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=visualfsharp&WorkItemId=12&FileAttachmentId=817651)

> comments
> latkin wrote Mar 24, 2014 at 4:22 PM [x]
>
> > [investigation from Vlad]
> > It looks like a bug in type relocation code in fsc.fs around ~1531.
> >
> > Here we have 2 type reference T and T2 that point to one actual type definition so the final copy-and-update expression below will create 2 different ILTypeDefs that originate from the same ILTypeDef => they will share same set of members (up to reference equality) => later it will lead to unexpected consequences in codegen because we'll generate normal type T2 and type T where property definition uses metadata token of getter from the type T2 => invalid IL.
> >
> > ``` fsharp
> > let generatedILTypeDefs =
> > let rec buildRelocatedGeneratedType (ProviderGeneratedType(ilOrigTyRef, ilTgtTyRef, ch)) =
> > let isNested = ilTgtTyRef.Enclosing |> nonNil
> > if allTypeDefsInProviderGeneratedAssemblies.ContainsKey ilOrigTyRef then
> > let ilOrigTypeDef = allTypeDefsInProviderGeneratedAssemblies.[ilOrigTyRef]
> > if debugStaticLinking then printfn "Relocating %s to %s " ilOrigTyRef.QualifiedName ilTgtTyRef.QualifiedName
> > { ilOrigTypeDef with
> > Name = ilTgtTyRef.Name
> > Access = (match ilOrigTypeDef.Access with
> > | ILTypeDefAccess.Public when isNested -> ILTypeDefAccess.Nested ILMemberAccess.Public
> > | ILTypeDefAccess.Private when isNested -> ILTypeDefAccess.Nested ILMemberAccess.Assembly
> > | x -> x)
> > NestedTypes = mkILTypeDefs (List.map buildRelocatedGeneratedType ch) }
> > ```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.