Skip to content

Run TransparentCompiler unit tests with local response files. - #16609

Merged
0101 merged 6 commits into
dotnet:mainfrom
nojaf:tc-response-files
Jan 30, 2024
Merged

Run TransparentCompiler unit tests with local response files.#16609
0101 merged 6 commits into
dotnet:mainfrom
nojaf:tc-response-files

Conversation

@nojaf

Copy link
Copy Markdown
Contributor

Description

To experiment with the new Transparent Compiler on local projects, I've implemented infrastructure capable of handling a response file from a local project. This approach mirrors the tests in CompilationFromCmdlineArgsTests, offering valuable insights for local testing.

How to generate a response file?

Poor man's response file

Just run your regular dotnet build -v:n with Verbosity set to normal, wait until you see CoreCompile and grab the compiler arguments.

Via script

The scrape.fsx script does a build of a project and extracts it from the bin log file.

Via Telplin

My Telplin tool has a bit of a hidden feature that it can save the response file without generating any signatures at all.
dotnet tool install -g telplin and then telplin --only-record MyProject.fsproj

Checklist

  • Test cases added

  • Performance benchmarks added in case of performance changes

  • Release notes entry updated:

    Please make sure to add an entry with short succinct description of the change as well as link to this pull request to the respective release notes file, if applicable.

    Release notes files:

    • If anything under src/Compiler has been changed, please make sure to make an entry in docs/release-notes/.FSharp.Compiler.Service/<version>.md, where <version> is usually "highest" one, e.g. 42.8.200
    • If language feature was added (i.e. LanguageFeatures.fsi was changed), please add it to docs/releae-notes/.Language/preview.md
    • If a change to FSharp.Core was made, please make sure to edit docs/release-notes/.FSharp.Core/<version>.md where version is "highest" one, e.g. 8.0.200.

    Information about the release notes entries format can be found in the documentation.
    Example:

    If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

@nojaf
nojaf requested a review from a team as a code ownerJanuary 30, 2024 08:48
@nojaf
nojaf requested a review from 0101January 30, 2024 08:48
@nojaf

Copy link
Copy Markdown
ContributorAuthor

FYI @dawedawe@safesparrow

@github-actions

Copy link
Copy Markdown
Contributor

✅ No release notes required

@01010101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks!

It will probably need a refactoring at some point, since it's not just synthetic projects anymore. Maybe ProjectWorkflowBuilder could just work with FSharpProjectSnapshot eventually...

Comment threadtests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs Outdated
@nojaf

Copy link
Copy Markdown
ContributorAuthor

It will probably need a refactoring at some point, since it's not just synthetic projects anymore. Maybe ProjectWorkflowBuilder could just work with FSharpProjectSnapshot eventually...

Yes, it is indeed becoming a bit of a hybrid between generated files and real files.

Comment threadtests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs Outdated
Comment threadtests/FSharp.Test.Utilities/ProjectGeneration.fs
Comment threadtests/FSharp.Test.Utilities/ProjectGeneration.fs Outdated
@0101
0101 merged commit 33e8be6 into dotnet:mainJan 30, 2024
@nojaf

Copy link
Copy Markdown
ContributorAuthor

If anyone ever wants some inspiration how to apply this in a benchmark:

[<MemoryDiagnoser>][<ThreadingDiagnoser>][<SimpleJob(warmupCount=1,iterationCount=4)>][<BenchmarkCategory(LongCategory)>]typeRspFileTransparentCompilerBenchmark()=let mutablebenchmark:ProjectWorkflowBuilder = Unchecked.defaultof<_>letresponseFile= FileInfo @"C:\Users\nojaf\Projects\g-research-fsharp-analyzers\src\FSharp.Analyzers\FSharp.Analyzers.rsp"letsyntheticProject= mkSyntheticProjectForResponseFile responseFile
[<ParamsAllValues>]member valUseTransparentCompiler=truewith get,set
[<GlobalSetup>]memberthis.Setup()=
benchmark <-
ProjectWorkflowBuilder(
syntheticProject,
isExistingProject =true,
useTransparentCompiler = this.UseTransparentCompiler,
runTimeout =15_000).CreateBenchmarkBuilder()[<Benchmark>]memberthis.TypeCheckLastFile()=use _ = Activity.start "Benchmark"["UseTransparentCompiler", this.UseTransparentCompiler.ToString()]letlastFile=
syntheticProject.SourceFiles
|> List.tryLast
|> Option.map (fun sf -> sf.Id)match lastFile with| None -> failwithf "Last file of project could not be found"| Some lastFile ->
benchmark {
clearCache
checkFile lastFile expectOk
}

I'm not sure this exact thing is useful to contribute but at least there is a trace of it now on the internet.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants

@nojaf@0101@vzarytovskii@psfinaki