Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
1fc8949
WIP
ScottCarda-MS Feb 3, 2021
451f28b
Removed type parameters for IEntryPoint interface.
ScottCarda-MS Feb 11, 2021
71abbfe
Allowed Diver to handle multiple entry points.
ScottCarda-MS Feb 15, 2021
7823083
Documentation.
ScottCarda-MS Feb 15, 2021
6cb13cf
Got Entry Point Classes to generate.
ScottCarda-MS Feb 23, 2021
1591e09
generated main class/method for entry point driver
ScottCarda-MS Feb 23, 2021
685f6fd
WIP
ScottCarda-MS Feb 24, 2021
6e09bd2
temp
ScottCarda-MS Feb 24, 2021
0813a2f
Got the simulator option working again
ScottCarda-MS Feb 24, 2021
f26fc22
return
ScottCarda-MS Feb 24, 2021
bd5eab4
Moved Main into separate ns
ScottCarda-MS Feb 24, 2021
dbc18cd
fixed hard-coded simulator name
ScottCarda-MS Feb 24, 2021
1a9090e
Support validators from being elevated to super-command when sub-comm…
ScottCarda-MS Feb 25, 2021
20296b3
cleaned up stuff
ScottCarda-MS Feb 25, 2021
319bc73
further cleanup
ScottCarda-MS Feb 25, 2021
4cd5b01
Moved using statements to be file-wide for the entry point files.
ScottCarda-MS Feb 25, 2021
1f7339b
Merge branch 'main' into sccarda/MultipleEntryPoints
ScottCarda-MS Feb 25, 2021
b7fde3c
fixed
ScottCarda-MS Feb 25, 2021
9379191
Fixed vs solution issue
ScottCarda-MS Feb 25, 2021
f64ceda
Added test for multiple entry points. It is skipped until this is sup…
ScottCarda-MS Feb 25, 2021
2853b56
PR comments and cleanup
ScottCarda-MS Feb 25, 2021
e079d75
Removed precondition for C# generation on only having one entry point.
ScottCarda-MS Feb 25, 2021
d206778
.
ScottCarda-MS Feb 26, 2021
91224ee
Updates version number, will need to be reverted
ScottCarda-MS Feb 26, 2021
df3bfe1
make default ep commands hidden
ScottCarda-MS Feb 27, 2021
969b807
Added custom type for commands with their validators.
ScottCarda-MS Feb 27, 2021
2d772a2
Added more tests for multiple entry points
ScottCarda-MS Feb 27, 2021
250eb65
Revert "Updates version number, will need to be reverted"
ScottCarda-MS Feb 27, 2021
0e5a61e
Merge branch 'main' into sccarda/MultipleEntryPoints
ScottCarda-MS Feb 27, 2021
112aa3b
changed line endings in Simulation.sln
ScottCarda-MS Feb 27, 2021
0405951
Moved the simulator and execution target options to the driver settin…
ScottCarda-MS Mar 1, 2021
faf5cd9
Merge branch 'main' into sccarda/MultipleEntryPoints
ScottCarda-MS Mar 1, 2021
89cffad
updated tests
ScottCarda-MS Mar 1, 2021
b01b82e
Fixed help text
ScottCarda-MS Mar 1, 2021
c6d8b39
Reverted the properties of the AzureSettings to public for compatibil…
ScottCarda-MS Mar 2, 2021
60f756e
updated submit multi-entry point tests
ScottCarda-MS Mar 2, 2021
46f4d80
update version numbers
ScottCarda-MS Mar 2, 2021
09a68c9
Merge branch 'main' into sccarda/MultipleEntryPoints
ScottCarda-MS Mar 2, 2021
9d92371
removed unused parameter
ScottCarda-MS Mar 2, 2021
e857473
Enabled tests, consolidated type casting
ScottCarda-MS Mar 4, 2021
82a8e8c
Changed the endings of generated files to avoid name collisions. Main…
ScottCarda-MS Mar 4, 2021
49f1648
Simplified CommandWithValidators data struct
ScottCarda-MS Mar 4, 2021
26eeee3
generateEntryPointClassName to entryPointClassFullName
ScottCarda-MS Mar 4, 2021
7353e08
Replaced IEnumerable usage.
ScottCarda-MS Mar 4, 2021
6ddcf7d
Revert "update version numbers"
ScottCarda-MS Mar 4, 2021
dad7fdf
Skipping tests while versions number doesn't support it.
ScottCarda-MS Mar 4, 2021
bb3879a
Updated included generated C# files for projects.
ScottCarda-MS Mar 4, 2021
40e7ee2
Enabled tests/updated version numbers
ScottCarda-MS Mar 4, 2021
44a8778
Update version number
ScottCarda-MS Mar 9, 2021
162d386
Using new compilation loader write file function
ScottCarda-MS Mar 9, 2021
2729cfc
added todo
ScottCarda-MS Mar 9, 2021
cf03902
Merge branch 'main' into sccarda/MultipleEntryPoints
ScottCarda-MS Mar 9, 2021
ad93c24
Merged in from main
ScottCarda-MS Mar 16, 2021
7cba363
sync versions with compiler branch
ScottCarda-MS Mar 17, 2021
af938e1
merged in from main
ScottCarda-MS Mar 18, 2021
8acf2f4
Remove dependency on WriteFile from compiler
ScottCarda-MS Mar 19, 2021
eb3d829
Use ImmutableList for validators
ScottCarda-MS Mar 19, 2021
636a36c
Added overwrite protection to generated C# files.
ScottCarda-MS Mar 20, 2021
2418cbd
merged in from main
ScottCarda-MS Mar 25, 2021
20d8e9a
Flatten output folder structure
ScottCarda-MS Mar 25, 2021
1577c6a
Try without GenratedFiles
ScottCarda-MS Mar 30, 2021
640a73f
Merge branch 'main' into sccarda/EnumeratedFileNames
ScottCarda-MS Mar 30, 2021
33d96dd
Removed Azure.Identity
ScottCarda-MS Mar 30, 2021
d8d3e52
Added test for C# gen naming scheme
ScottCarda-MS Apr 1, 2021
5eef446
Merge branch 'main' into sccarda/EnumeratedFileNames
ScottCarda-MS Apr 1, 2021
a739316
Add files via upload
ScottCarda-MS Apr 1, 2021
1f8f0d1
Delete HelloOther.qs
ScottCarda-MS Apr 1, 2021
d304d5c
Delete HelloWorld.qs
ScottCarda-MS Apr 1, 2021
8549b02
Merge branch 'main' into sccarda/EnumeratedFileNames
ScottCarda-MS Apr 1, 2021
3520ecf
Remove files at start of test
ScottCarda-MS Apr 5, 2021
cdeef55
Merge branch 'main' into sccarda/EnumeratedFileNames
ScottCarda-MS Apr 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Tests.SubDirectory
{

operation HelloOther (n : Int) : Int
{
let r = n + 1;

return r;
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Tests.SubDirectory
{

operation HelloWorld (n : Int) : Int
{
let r = n + 1;

return r;
}

}


60 changes: 56 additions & 4 deletions src/Simulation/CSharpGeneration.Tests/SimulationCodeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ namespace N1
|> failwith
let functorGenSuccessful = CodeGeneration.GenerateFunctorSpecializations(compilation, &compilation)
// todo: we might want to raise an error here if the functor generation fails (which will be the case for incorrect code)
compilation.Namespaces
compilation
with | e -> sprintf "compilation threw exception: \n%s" e.Message |> failwith // should never happen (all exceptions are caught by the compiler)

let syntaxTree = parse [ (Path.Combine("Circuits", "Intrinsic.qs")); (Path.Combine("Circuits", "CodegenTests.qs")) ]
let syntaxTree = parse [ (Path.Combine("Circuits", "Intrinsic.qs")); (Path.Combine("Circuits", "CodegenTests.qs")) ] |> (fun compilation -> compilation.Namespaces)

let globalContext = CodegenContext.Create syntaxTree

Expand Down Expand Up @@ -225,9 +225,9 @@ namespace N1
expected
|> (fun s -> s.Replace("%%%", fullPath |> HttpUtility.JavaScriptStringEncode |> escapeCSharpString))
|> (fun s -> s.Replace("%%", fullPath |> escapeCSharpString))
let tree = parse [Path.Combine ("Circuits", "Intrinsic.qs"); fileName]
let compilation = parse [Path.Combine ("Circuits", "Intrinsic.qs"); fileName]
let actual =
CodegenContext.Create (tree, ImmutableDictionary.Empty)
CodegenContext.Create (compilation, ImmutableDictionary.Empty)
|> generate (Path.GetFullPath fileName)
Assert.Equal(expected |> clearFormatting, actual |> clearFormatting)

Expand All @@ -248,6 +248,58 @@ namespace N1
List.zip expected actual
|> List.iter Assert.Equal<'Z>

[<Fact>]
let ``testGeneratedFileNames`` () =

let outputDir = "output" |> Path.GetFullPath
let outputDirSrc = Path.Combine(outputDir, "src")

let intrinsic = Path.Combine(outputDirSrc, "Intrinsic.g.cs")
let helloWorld = Path.Combine(outputDirSrc, "HelloWorld.g.cs")
let helloWorld1 = Path.Combine(outputDirSrc, "HelloWorld.g1.cs")
let helloOther = Path.Combine(outputDirSrc, "HelloOther.g.cs")

let deleteFile filePath =
if File.Exists filePath then
File.Delete filePath

intrinsic |> deleteFile
helloWorld |> deleteFile
helloWorld1 |> deleteFile
helloOther |> deleteFile

let compilation = parse [
Path.Combine("Circuits", "Intrinsic.qs")
Path.Combine("Circuits", "HelloWorld.qs")
Path.Combine("Circuits", "SubDirectory", "HelloWorld.qs")
Path.Combine("Circuits", "SubDirectory", "HelloOther.qs")
]
let transformed = ref { Namespaces = ImmutableArray<QsNamespace>.Empty; EntryPoints = ImmutableArray<QsQualifiedName>.Empty }
let rewriteStep = Emitter() :> IRewriteStep
rewriteStep.AssemblyConstants.Add(AssemblyConstants.OutputPath, outputDir)
rewriteStep.Transformation(compilation, transformed) |> ignore

let mutable allFilesFound = true
let checkAndDeleteFile filePath =
if File.Exists filePath then
File.Delete filePath
else
allFilesFound <- false

intrinsic |> checkAndDeleteFile
helloWorld |> checkAndDeleteFile
helloWorld1 |> checkAndDeleteFile
helloOther |> checkAndDeleteFile

let deleteDir dirPath =
if Directory.Exists dirPath && Directory.EnumerateFileSystemEntries dirPath |> Seq.isEmpty then
Directory.Delete dirPath

outputDirSrc |> deleteDir
outputDir |> deleteDir

Assert.True allFilesFound

[<Fact>]
let ``tupleBaseClassName test`` () =
let testOne (_, udt) expected =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
</PropertyGroup>

<ItemGroup>
<None Include="Circuits\SubDirectory\HelloWorld.qs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Circuits\SubDirectory\HelloOther.qs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Circuits\UnitTests.qs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
47 changes: 40 additions & 7 deletions src/Simulation/CSharpGeneration/RewriteStep.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,31 @@ type Emitter() =

let _AssemblyConstants = new Dictionary<_, _>()

let _FileNamesGenerated = new HashSet<string>();

[<Literal>]
let _EnumerationLimit = 100;

member private this.WriteFile (fileId : string) outputFolder (fileEnding : string) content overwrite =
let mutable fileEnding = fileEnding
let withoutEnding = Path.GetFileNameWithoutExtension(fileId)
let mutable targetFile = Path.GetFullPath(Path.Combine(outputFolder, withoutEnding + fileEnding))

if (not overwrite) && _FileNamesGenerated.Contains(targetFile) then
let mutable enumeration = 1
let pos = fileEnding.LastIndexOf('.')
let (beforeEnumeration, afterEnumeration) =
if pos = -1
then "", fileEnding
else fileEnding.Substring(0, pos), fileEnding.Substring(pos)
while _FileNamesGenerated.Contains(targetFile) && enumeration < _EnumerationLimit do
fileEnding <- beforeEnumeration + enumeration.ToString() + afterEnumeration
targetFile <- Path.GetFullPath(Path.Combine(outputFolder, withoutEnding + fileEnding))
enumeration <- enumeration + 1

_FileNamesGenerated.Add targetFile |> ignore
File.WriteAllText(targetFile, content)

interface IRewriteStep with

member this.Name = "CSharpGeneration"
Expand All @@ -34,19 +59,27 @@ type Emitter() =

member this.Transformation (compilation, transformed) =
let step = this :> IRewriteStep
let dir = step.AssemblyConstants.TryGetValue AssemblyConstants.OutputPath |> function
| true, outputFolder when outputFolder <> null -> Path.Combine(outputFolder, "src")
| _ -> step.Name
let dir =
step.AssemblyConstants.TryGetValue AssemblyConstants.OutputPath
|> function
| true, outputFolder when outputFolder <> null -> Path.Combine(outputFolder, "src")
| _ -> step.Name
|> (fun str -> (str.TrimEnd [| Path.DirectorySeparatorChar; Path.AltDirectorySeparatorChar |]) + Path.DirectorySeparatorChar.ToString() |> Uri)
|> (fun uri -> uri.LocalPath |> Path.GetDirectoryName)

let context = CodegenContext.Create (compilation, step.AssemblyConstants)
let allSources = GetSourceFiles.Apply compilation.Namespaces

if (allSources.Count > 0 || not (compilation.EntryPoints.IsEmpty)) && not (Directory.Exists dir) then
Directory.CreateDirectory dir
|> ignore

for source in allSources |> Seq.filter context.GenerateCodeForSource do
let content = SimulationCode.generate source context
CompilationLoader.GeneratedFile(source, dir, ".g.cs", content) |> ignore
this.WriteFile source dir ".g.cs" content false
for source in allSources |> Seq.filter (not << context.GenerateCodeForSource) do
let content = SimulationCode.loadedViaTestNames source context
if content <> null then CompilationLoader.GeneratedFile(source, dir, ".dll.g.cs", content) |> ignore
this.WriteFile source dir ".dll.g.cs" content false

if not compilation.EntryPoints.IsEmpty then

Expand All @@ -60,11 +93,11 @@ type Emitter() =

let mainSourceFile = (dir, "EntryPoint") |> Path.Combine |> Path.GetFullPath |> Uri |> CompilationUnitManager.GetFileId
let content = EntryPoint.generateMainSource context entryPointCallables
CompilationLoader.GeneratedFile(mainSourceFile, dir, ".g.Main.cs", content) |> ignore
this.WriteFile mainSourceFile dir ".g.Main.cs" content false

for (sourceFile, callables) in entryPointSources do
let content = EntryPoint.generateSource context callables
CompilationLoader.GeneratedFile(sourceFile, dir, ".g.EntryPoint.cs", content) |> ignore
this.WriteFile sourceFile dir ".g.EntryPoint.cs" content false

transformed <- compilation
true