Skip to content

Commit decf64b

Browse files
brettfobaronfel
authored andcommitted
re-add changes/files removed during a hasty cherry-pick
1 parent 5fb4c20 commit decf64b

File tree

86 files changed

+19651
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+19651
-86
lines changed

src/fsharp/TastPickle.fs

Lines changed: 69 additions & 68 deletions
Large diffs are not rendered by default.

src/fsharp/TypeChecker.fs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12337,24 +12337,17 @@ module TcRecdUnionAndEnumDeclarations = begin
1233712337
let attrs = TcAttributes cenv env AttributeTargets.UnionCaseDecl synAttrs // the attributes of a union case decl get attached to the generated "static factory" method
1233812338
let vis, _ = ComputeAccessAndCompPath env None m vis None parent
1233912339
let vis = CombineReprAccess parent vis
12340-
let realUnionCaseName =
12341-
if id.idText = opNameCons then "Cons"
12342-
elif id.idText = opNameNil then "Empty"
12343-
else id.idText
12344-
12345-
if realUnionCaseName = "Tags" then
12346-
errorR(Error(FSComp.SR.tcUnionCaseNameConflictsWithGeneratedType(realUnionCaseName, "Tags"), m))
12347-
12348-
CheckUnionCaseName cenv realUnionCaseName id.idRange
12349-
12340+
12341+
CheckUnionCaseName cenv id
12342+
1235012343
let mkName nFields i = if nFields <= 1 then "Item" else "Item"+string (i+1)
1235112344
let rfields, recordTy =
1235212345
match args with
1235312346
| UnionCaseFields flds ->
1235412347
let nFields = flds.Length
1235512348
let rfields = flds |> List.mapi (fun i fld -> TcAnonFieldDecl cenv env parent tpenv (mkName nFields i) fld)
1235612349
ValidateFieldNames(flds, rfields)
12357-
12350+
1235812351
rfields, thisTy
1235912352
| UnionCaseFullType (ty, arity) ->
1236012353
let ty', _ = TcTypeAndRecover cenv NoNewTypars CheckCxs ItemOccurence.UseInType env tpenv ty
@@ -12370,7 +12363,7 @@ module TcRecdUnionAndEnumDeclarations = begin
1237012363
if not (typeEquiv cenv.g recordTy thisTy) then
1237112364
error(Error(FSComp.SR.tcReturnTypesForUnionMustBeSameAsType(), m))
1237212365
rfields, recordTy
12373-
NewUnionCase id realUnionCaseName rfields recordTy attrs (xmldoc.ToXmlDoc()) vis
12366+
NewUnionCase id rfields recordTy attrs (xmldoc.ToXmlDoc()) vis
1237412367

1237512368

1237612369
let TcUnionCaseDecls cenv env parent (thisTy: TType) tpenv unionCases =
@@ -15621,8 +15614,8 @@ module EstablishTypeDefinitionCores =
1562115614

1562215615
structLayoutAttributeCheck(false)
1562315616
noAllowNullLiteralAttributeCheck()
15624-
TcRecdUnionAndEnumDeclarations.CheckUnionCaseName cenv unionCaseName.idText unionCaseName.idRange
15625-
let unionCase = NewUnionCase unionCaseName unionCaseName.idText [] thisTy [] XmlDoc.Empty tycon.Accessibility
15617+
TcRecdUnionAndEnumDeclarations.CheckUnionCaseName cenv unionCaseName
15618+
let unionCase = NewUnionCase unionCaseName [] thisTy [] XmlDoc.Empty tycon.Accessibility
1562615619
writeFakeUnionCtorsToSink [ unionCase ]
1562715620
MakeUnionRepr [ unionCase ], None, NoSafeInitInfo
1562815621

src/fsharp/tast.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,9 +1598,6 @@ and
15981598
/// Return type constructed by the case. Normally exactly the type of the enclosing type, sometimes an abbreviation of it
15991599
ReturnType: TType
16001600

1601-
/// Name of the case in generated IL code
1602-
CompiledName: string
1603-
16041601
/// Documentation for the case
16051602
XmlDoc: XmlDoc
16061603

@@ -1636,6 +1633,13 @@ and
16361633

16371634
member uc.DisplayName = uc.Id.idText
16381635

1636+
/// Name of the case in generated IL code.
1637+
member uc.CompiledName =
1638+
let idText = uc.Id.idText
1639+
if idText = opNameCons then "Cons"
1640+
elif idText = opNameNil then "Empty"
1641+
else idText
1642+
16391643
member uc.RecdFieldsArray = uc.FieldTable.FieldsByIndex
16401644

16411645
member uc.RecdFields = uc.FieldTable.FieldsByIndex |> Array.toList
@@ -5662,7 +5666,6 @@ let NewRigidTypar nm m = NewTypar (TyparKind.Type, TyparRigidity.Rigid, Typar(mk
56625666

56635667
let NewUnionCase id tys rty attribs docOption access: UnionCase =
56645668
{ Id=id
5665-
CompiledName=nm
56665669
XmlDoc=docOption
56675670
XmlDocSig=""
56685671
Accessibility=access
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#if INTERACTIVE
2+
#r "../../artifacts/bin/fcs/net46/FSharp.Compiler.Service.dll" // note, build FSharp.Compiler.Service.Tests.fsproj to generate this, this DLL has a public API so can be used from F# Interactive
3+
#r "../../artifacts/bin/fcs/net46/nunit.framework.dll"
4+
#load "FsUnit.fs"
5+
#load "Common.fs"
6+
#else
7+
module Tests.Service.AssemblyContentProviderTests
8+
#endif
9+
10+
open System
11+
open System.IO
12+
open System.Text
13+
open NUnit.Framework
14+
open FSharp.Compiler.SourceCodeServices
15+
16+
let private filePath = "C:\\test.fs"
17+
18+
let private projectOptions : FSharpProjectOptions =
19+
{ ProjectFileName = "C:\\test.fsproj"
20+
ProjectId = None
21+
SourceFiles = [| filePath |]
22+
ReferencedProjects = [| |]
23+
OtherOptions = [| |]
24+
IsIncompleteTypeCheckEnvironment = true
25+
UseScriptResolutionRules = false
26+
LoadTime = DateTime.MaxValue
27+
OriginalLoadReferences = []
28+
UnresolvedReferences = None
29+
ExtraProjectInfo = None
30+
Stamp = None }
31+
32+
let private checker = FSharpChecker.Create()
33+
34+
let (=>) (source: string) (expected: string list) =
35+
let lines =
36+
use reader = new StringReader(source)
37+
[| let line = ref (reader.ReadLine())
38+
while not (isNull !line) do
39+
yield !line
40+
line := reader.ReadLine()
41+
if source.EndsWith "\n" then
42+
// last trailing space not returned
43+
// http://stackoverflow.com/questions/19365404/stringreader-omits-trailing-linebreak
44+
yield "" |]
45+
46+
let _, checkFileAnswer = checker.ParseAndCheckFileInProject(filePath, 0, source, projectOptions) |> Async.RunSynchronously
47+
48+
let checkFileResults =
49+
match checkFileAnswer with
50+
| FSharpCheckFileAnswer.Aborted -> failwithf "ParseAndCheckFileInProject aborted"
51+
| FSharpCheckFileAnswer.Succeeded(checkFileResults) -> checkFileResults
52+
53+
let actual =
54+
AssemblyContentProvider.getAssemblySignatureContent AssemblyContentType.Full checkFileResults.PartialAssemblySignature
55+
|> List.map (fun x -> x.CleanedIdents |> String.concat ".")
56+
|> List.sort
57+
58+
let expected = List.sort expected
59+
60+
if actual <> expected then failwithf "\n\nExpected\n\n%A\n\nbut was\n\n%A" expected actual
61+
62+
[<Test>]
63+
let ``implicitly added Module suffix is removed``() =
64+
"""
65+
type MyType = { F: int }
66+
67+
module MyType =
68+
let func123 x = x
69+
"""
70+
=> ["Test"
71+
"Test.MyType"
72+
"Test.MyType"
73+
"Test.MyType.func123"]
74+
75+
[<Test>]
76+
let ``Module suffix added by an xplicitly applied MuduleSuffix attribute is removed``() =
77+
"""
78+
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
79+
module MyType =
80+
let func123 x = x
81+
"""
82+
=> [ "Test"
83+
"Test.MyType"
84+
"Test.MyType.func123" ]
85+
86+

tests/service/AssemblyReaderShim.fs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#if INTERACTIVE
2+
#r "../../artifacts/bin/fcs/net46/FSharp.Compiler.Service.dll" // note, build FSharp.Compiler.Service.Tests.fsproj to generate this, this DLL has a public API so can be used from F# Interactive
3+
#r "../../artifacts/bin/fcs/net46/nunit.framework.dll"
4+
#load "FsUnit.fs"
5+
#load "Common.fs"
6+
#else
7+
module FSharp.Compiler.Service.Tests.AssemblyReaderShim
8+
#endif
9+
10+
open FSharp.Compiler.Service.Tests.Common
11+
open FsUnit
12+
open FSharp.Compiler.AbstractIL.ILBinaryReader
13+
open NUnit.Framework
14+
15+
[<Test>]
16+
let ``Assembly reader shim gets requests`` () =
17+
let defaultReader = Shim.AssemblyReader
18+
let mutable gotRequest = false
19+
let reader =
20+
{ new IAssemblyReader with
21+
member x.GetILModuleReader(path, opts) =
22+
gotRequest <- true
23+
defaultReader.GetILModuleReader(path, opts)
24+
}
25+
Shim.AssemblyReader <- reader
26+
let source = """
27+
module M
28+
let x = 123
29+
"""
30+
31+
let fileName, options = Common.mkTestFileAndOptions source [| |]
32+
Common.checker.ParseAndCheckFileInProject(fileName, 0, source, options) |> Async.RunSynchronously |> ignore
33+
gotRequest |> should be True

0 commit comments

Comments
 (0)