dotnet / dotnet/fsharp

Instantiating a generative type provider twice results in invalid IL

Aperta
#37 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Area-TypeProviders Bug Impact-Low
Lingua principale
F#
Stelle
4.3k
Fork
876
Merge medio
5g 11h
PR unite (30g)
153

Descrizione

[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) }
> > ```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia riproducendo il malfunzionamento con il reproSln.zip allegato, usando i due tipi identici forniti, T2 e T. Poi esamina il codice di ricollocazione dei tipi in fsc.fs intorno a ~1531, in particolare il modo in cui le definizioni ricollocate condividono i membri. Il lavoro è completato quando l'istanziazione due volte del generative type provider produce un assembly con IL valido.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
fsharp
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.