提交 f6e160a2 编写于 作者: A Alfonso Garcia-Caro 提交者: Kevin Ransom (msft)

Deduplicate module names (#2728)

* Deduplicate module names

* Small refactor of deduplicate module name operation
上级 3066c282
......@@ -1761,6 +1761,38 @@ let main0(ctok, argv, referenceResolver, bannerAlreadyPrinted, exiter:Exiter, er
with e ->
errorRecoveryNoRange e
exiter.Exit 1
let inputs =
// Deduplicate module names
let seen = Dictionary<string,Set<string>>()
let deduplicate (paths: Set<string>) path (qualifiedNameOfFile: QualifiedNameOfFile) =
let count = if paths.Contains path then paths.Count else paths.Count + 1
seen.[qualifiedNameOfFile.Text] <- Set.add path paths
let id = qualifiedNameOfFile.Id
if count = 1 then qualifiedNameOfFile else QualifiedNameOfFile(Ident(id.idText + "___" + count.ToString(),id.idRange))
inputs
|> List.map (fun (input,x) ->
match input with
| ParsedInput.ImplFile (ParsedImplFileInput.ParsedImplFileInput(fileName,isScript,qualifiedNameOfFile,scopedPragmas,hashDirectives,modules,(isLastCompiland,isExe))) ->
let path = Path.GetDirectoryName fileName
match seen.TryGetValue qualifiedNameOfFile.Text with
| true, paths ->
let qualifiedNameOfFile = deduplicate paths path qualifiedNameOfFile
let input = ParsedInput.ImplFile(ParsedImplFileInput.ParsedImplFileInput(fileName,isScript,qualifiedNameOfFile,scopedPragmas,hashDirectives,modules,(isLastCompiland,isExe)))
input,x
| _ ->
seen.Add(qualifiedNameOfFile.Text,Set.singleton path)
input,x
| ParsedInput.SigFile (ParsedSigFileInput.ParsedSigFileInput(fileName,qualifiedNameOfFile,scopedPragmas,hashDirectives,modules)) ->
let path = Path.GetDirectoryName fileName
match seen.TryGetValue qualifiedNameOfFile.Text with
| true, paths ->
let qualifiedNameOfFile = deduplicate paths path qualifiedNameOfFile
let input = ParsedInput.SigFile (ParsedSigFileInput.ParsedSigFileInput(fileName,qualifiedNameOfFile,scopedPragmas,hashDirectives,modules))
input,x
| _ ->
seen.Add(qualifiedNameOfFile.Text,Set.singleton path)
input,x)
if tcConfig.parseOnly then exiter.Exit 0
if not tcConfig.continueAfterParseFailure then
......
namespace tempet
module SayA =
let hello name =
printfn "Hello %s" name
namespace tempet
module SayA =
val hello : string -> unit
namespace tempet
module SayB =
let hello name =
printfn "Hello %s" name
namespace tempet
module SayB =
val hello : string -> unit
namespace tempet
module SayC =
let hello name =
printfn "Hello %s" name
namespace tempet
module SayC =
val hello : string -> unit
namespace tempet
module SayD =
let hello name =
printfn "Hello %s" name
namespace tempet
module SayD =
val hello : string -> unit
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="folder1/a.fsi" />
<Compile Include="folder1/a.fs" />
<Compile Include="folder1/b.fsi" />
<Compile Include="folder1/b.fs" />
<Compile Include="folder2/a.fsi" />
<Compile Include="folder2/a.fs" />
<Compile Include="folder2/b.fsi" />
<Compile Include="folder2/b.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.1.*" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
</ItemGroup>
</Project>
......@@ -774,7 +774,41 @@ module CoreTests =
peverify cfg "test2.exe"
exec cfg ("." ++ "test2.exe") ""
// Repro for https://github.com/Microsoft/visualfsharp/issues/2679
[<Test>]
let ``add files with same name from different folders`` () =
let cfg = testConfig "core/samename"
log "== Compiling F# Code with files with same name in different folders"
fsc cfg "%s -o:test.exe" cfg.fsc_flags ["folder1/a.fs"; "folder1/b.fs"; "folder2/a.fs"; "folder2/b.fs"]
peverify cfg "test.exe"
exec cfg ("." ++ "test.exe") ""
[<Test>]
let ``add files with same name from different folders including signature files`` () =
let cfg = testConfig "core/samename"
log "== Compiling F# Code with files with same name in different folders including signature files"
fsc cfg "%s -o:test.exe" cfg.fsc_flags ["folder1/a.fsi"; "folder1/a.fs"; "folder1/b.fsi"; "folder1/b.fs"; "folder2/a.fsi"; "folder2/a.fs"; "folder2/b.fsi"; "folder2/b.fs"]
peverify cfg "test.exe"
exec cfg ("." ++ "test.exe") ""
[<Test>]
let ``add files with same name from different folders including signature files that are not synced`` () =
let cfg = testConfig "core/samename"
log "== Compiling F# Code with files with same name in different folders including signature files"
fsc cfg "%s -o:test.exe" cfg.fsc_flags ["folder1/a.fsi"; "folder1/a.fs"; "folder1/b.fs"; "folder2/a.fsi"; "folder2/a.fs"; "folder2/b.fsi"; "folder2/b.fs"]
peverify cfg "test.exe"
exec cfg ("." ++ "test.exe") ""
[<Test>]
let ``libtest-FSI_STDIN`` () = singleTestBuildAndRun "core/libtest" FSI_STDIN
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册