Skip to content

Commit

Permalink
Merge pull request #3616 from KevinRansom/vs2017-rtm
Browse files Browse the repository at this point in the history
merge master into vs2017-rtm
  • Loading branch information
KevinRansom committed Sep 20, 2017
2 parents 8615245 + 2b13f5d commit d26de72
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ if "%OSARCH%"=="AMD64" set SYSWOW64=SysWoW64

if not "%OSARCH%"=="x86" set REGEXE32BIT=%WINDIR%\syswow64\reg.exe

echo SDK environment vars from Registry
echo SDK environment vars from Registry (note: ignore "ERROR: The system was unable to find ....")
echo ==================================
FOR /F "tokens=2* delims= " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\WOW6432Node\Microsoft\Microsoft SDKs\NETFXSDK\4.6.2\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
if "%WINSDKNETFXTOOLS%"=="" FOR /F "tokens=2* delims= " %%A IN ('%REGEXE32BIT% QUERY "HKLM\Software\WOW6432Node\Microsoft\Microsoft SDKs\NETFXSDK\4.6.1\WinSDK-NetFx40Tools" /v InstallationFolder') DO SET WINSDKNETFXTOOLS=%%B
Expand Down
64 changes: 37 additions & 27 deletions src/fsharp/FSharp.Build/FSharpEmbedResourceText.fs
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,21 @@ open Printf

let generateResxAndSource (filename:string) =
try
let printMessage message = printfn "FSharpEmbedResourceText: %s" message
let justfilename = Path.GetFileNameWithoutExtension(filename) // .txt
if justfilename |> Seq.exists (System.Char.IsLetterOrDigit >> not) then
Err(filename, 0, sprintf "The filename '%s' is not allowed; only letters and digits can be used, as the filename also becomes the namespace for the SR class" justfilename)
let outFilename = Path.Combine(_outputPath, justfilename + ".fs")
let outXmlFilename = Path.Combine(_outputPath, justfilename + ".resx")
let printMessage message = printfn "FSharpEmbedResourceText: %s" message
let justfilename = Path.GetFileNameWithoutExtension(filename) // .txt
if justfilename |> Seq.exists (System.Char.IsLetterOrDigit >> not) then
Err(filename, 0, sprintf "The filename '%s' is not allowed; only letters and digits can be used, as the filename also becomes the namespace for the SR class" justfilename)
let outFilename = Path.Combine(_outputPath, justfilename + ".fs")
let outXmlFilename = Path.Combine(_outputPath, justfilename + ".resx")

if File.Exists(outFilename) &&
File.Exists(outXmlFilename) &&
File.Exists(filename) &&
File.GetLastWriteTime(filename) <= File.GetLastWriteTime(outFilename) &&
File.GetLastWriteTime(filename) <= File.GetLastWriteTime(outXmlFilename) then
printMessage (sprintf "Skipping generation of %s and %s since up-to-date" outFilename outXmlFilename)
Some (outFilename, outXmlFilename)
else

printMessage (sprintf "Reading %s" filename)
let lines = File.ReadAllLines(filename)
Expand Down Expand Up @@ -472,27 +481,28 @@ open Printf
with get() = _hostObject
and set(value) = _hostObject <- value
member this.Execute() =
let sourceItem (source:string) (originalItem:string) =
let item = TaskItem(source)
item.SetMetadata("AutoGen", "true")
item.SetMetadata("DesignTime", "true")
item.SetMetadata("DependentUpon", originalItem)
item :> ITaskItem
let resxItem (resx:string) =
let item = TaskItem(resx)
item.SetMetadata("ManifestResourceName", Path.GetFileNameWithoutExtension(resx))
item :> ITaskItem
let generatedFiles, generatedResult =

let generatedFiles =
this.EmbeddedText
|> Array.fold (fun (resultList, aggregateResult) item ->
match generateResxAndSource item.ItemSpec with
| Some (source, resx) -> (((source, resx) :: resultList), aggregateResult)
| None -> (resultList, false)
) ([], true)
|> Array.choose (fun item -> generateResxAndSource item.ItemSpec)

let generatedSource, generatedResx =
generatedFiles
|> List.map (fun (source, resx) -> (sourceItem source resx, resxItem resx))
|> List.fold (fun (sources, resxs) (source, resx) -> (source :: sources, resx:: resxs)) ([], [])
_generatedSource <- generatedSource |> List.rev |> List.toArray
_generatedResx <- generatedResx |> List.rev |> List.toArray
[| for (source, resx) in generatedFiles do
let sourceItem =
let item = TaskItem(source)
item.SetMetadata("AutoGen", "true")
item.SetMetadata("DesignTime", "true")
item.SetMetadata("DependentUpon", resx)
item :> ITaskItem
let resxItem =
let item = TaskItem(resx)
item.SetMetadata("ManifestResourceName", Path.GetFileNameWithoutExtension(resx))
item :> ITaskItem
yield (sourceItem, resxItem) |]
|> Array.unzip

let generatedResult = (generatedFiles.Length = this.EmbeddedText.Length)

_generatedSource <- generatedSource
_generatedResx <- generatedResx
generatedResult
13 changes: 8 additions & 5 deletions src/fsharp/FSharp.Build/Fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ type [<Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:Iden
let mutable subsystemVersion : string = null
let mutable tailcalls : bool = true
let mutable targetProfile : string = null
let mutable targetType : string = null
let mutable targetType : string = null
let mutable toolExe : string = "fsc.exe"
let mutable toolPath : string =
let locationOfThisDll =
Expand Down Expand Up @@ -277,7 +277,7 @@ type [<Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:Iden
| "WINEXE" -> "winexe"
| "MODULE" -> "module"
| _ -> null)

// NoWarn
match disabledWarnings with
| null -> ()
Expand Down Expand Up @@ -418,7 +418,7 @@ type [<Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:Iden
// --noframework
member fsc.NoFramework
with get() = noFramework
and set(b) = noFramework <- b
and set(b) = noFramework <- b

// --optimize
member fsc.Optimize
Expand Down Expand Up @@ -543,7 +543,7 @@ type [<Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:Iden
member fsc.Win32ManifestFile
with get() = win32manifest
and set(m) = win32manifest <- m

// For specifying the warning level (0-4)
member fsc.WarningLevel
with get() = warningLevel
Expand All @@ -552,7 +552,7 @@ type [<Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:Iden
member fsc.WarningsAsErrors
with get() = warningsAsErrors
and set(s) = warningsAsErrors <- s

member fsc.VisualStudioStyleErrors
with get() = vserrors
and set(p) = vserrors <- p
Expand Down Expand Up @@ -581,6 +581,9 @@ type [<Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:Iden
override fsc.GenerateFullPathToTool() =
if toolPath = "" then raise (new System.InvalidOperationException(FSBuild.SR.toolpathUnknown()))
System.IO.Path.Combine(toolPath, fsc.ToolExe)
override fsc.LogToolCommand (message:string) =
fsc.Log.LogMessageFromText(message, MessageImportance.Normal) |>ignore

member internal fsc.InternalGenerateFullPathToTool() = fsc.GenerateFullPathToTool() // expose for unit testing
member internal fsc.BaseExecuteTool(pathToTool, responseFileCommands, commandLineCommands) = // F# does not allow protected members to be captured by lambdas, this is the standard workaround
base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands)
Expand Down
4 changes: 4 additions & 0 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5310,6 +5310,8 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p
checkNoArgsForLiteral()
UnifyTypes cenv env m ty (finfo.FieldType(cenv.amap, m))
let c' = TcFieldInit m lit
let item = Item.ILField(finfo)
CallNameResolutionSink cenv.tcSink (m, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Pattern, env.DisplayEnv, env.AccessRights)
(fun _ -> TPat_const (c', m)), (tpenv, names, takenNames)

| Item.RecdField rfinfo ->
Expand Down Expand Up @@ -5337,6 +5339,8 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p
CheckFSharpAttributes cenv.g vref.Attribs m |> CommitOperationResult
checkNoArgsForLiteral()
UnifyTypes cenv env m ty vexpty
let item = Item.Value(vref)
CallNameResolutionSink cenv.tcSink (m, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Pattern, env.DisplayEnv, env.AccessRights)
(fun _ -> TPat_const (lit, m)), (tpenv, names, takenNames)

| _ -> error (Error(FSComp.SR.tcRequireVarConstRecogOrLiteral(), m))
Expand Down
96 changes: 96 additions & 0 deletions tests/service/EditorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,103 @@ let test3 = System.Text.RegularExpressions.RegexOptions.Compiled
]
|]

[<Test>]
let ``IL enum fields should be reported`` () =
let input =
"""
open System
let _ =
match ConsoleKey.Tab with
| ConsoleKey.OemClear -> ConsoleKey.A
| _ -> ConsoleKey.B
"""

let file = "/home/user/Test.fsx"
let _, typeCheckResults = parseAndCheckScript(file, input)
typeCheckResults.GetAllUsesOfAllSymbolsInFile()
|> Async.RunSynchronously
|> Array.map (fun su ->
let r = su.RangeAlternate
su.Symbol.ToString(), (r.StartLine, r.StartColumn, r.EndLine, r.EndColumn))
|> shouldEqual
[|("ConsoleKey", (5, 10, 5, 20))
("field Tab", (5, 10, 5, 24))
("ConsoleKey", (6, 6, 6, 16))
("field OemClear", (6, 6, 6, 25))
("ConsoleKey", (6, 29, 6, 39))
("field A", (6, 29, 6, 41))
("ConsoleKey", (7, 11, 7, 21))
("field B", (7, 11, 7, 23))
("Test", (1, 0, 1, 0))|]

[<Test>]
let ``Literal values should be reported`` () =
let input =
"""
module Module1 =
let [<Literal>] ModuleValue = 1
let _ =
match ModuleValue + 1 with
| ModuleValue -> ModuleValue + 2
| _ -> 0
type Class1() =
let [<Literal>] ClassValue = 1
static let [<Literal>] StaticClassValue = 2
let _ = ClassValue
let _ = StaticClassValue
let _ =
match ClassValue + StaticClassValue with
| ClassValue -> ClassValue + 1
| StaticClassValue -> StaticClassValue + 2
| _ -> 3
"""

let file = "/home/user/Test.fsx"
let _, typeCheckResults = parseAndCheckScript(file, input)
typeCheckResults.GetAllUsesOfAllSymbolsInFile()
|> Async.RunSynchronously
|> Array.map (fun su ->
let r = su.RangeAlternate
su.Symbol.ToString(), (r.StartLine, r.StartColumn, r.EndLine, r.EndColumn))
|> shouldEqual
[|("LiteralAttribute", (3, 10, 3, 17))
("LiteralAttribute", (3, 10, 3, 17))
("member .ctor", (3, 10, 3, 17))
("val ModuleValue", (3, 20, 3, 31))
("val op_Addition", (6, 26, 6, 27))
("val ModuleValue", (6, 14, 6, 25))
("val ModuleValue", (7, 10, 7, 21))
("val op_Addition", (7, 37, 7, 38))
("val ModuleValue", (7, 25, 7, 36))
("Module1", (2, 7, 2, 14))
("Class1", (10, 5, 10, 11))
("member .ctor", (10, 5, 10, 11))
("LiteralAttribute", (11, 10, 11, 17))
("LiteralAttribute", (11, 10, 11, 17))
("member .ctor", (11, 10, 11, 17))
("val ClassValue", (11, 20, 11, 30))
("LiteralAttribute", (12, 17, 12, 24))
("LiteralAttribute", (12, 17, 12, 24))
("member .ctor", (12, 17, 12, 24))
("val StaticClassValue", (12, 27, 12, 43))
("val ClassValue", (14, 12, 14, 22))
("val StaticClassValue", (15, 12, 15, 28))
("val op_Addition", (18, 25, 18, 26))
("val ClassValue", (18, 14, 18, 24))
("val StaticClassValue", (18, 27, 18, 43))
("val ClassValue", (19, 10, 19, 20))
("val op_Addition", (19, 35, 19, 36))
("val ClassValue", (19, 24, 19, 34))
("val StaticClassValue", (20, 10, 20, 26))
("val op_Addition", (20, 47, 20, 48))
("val StaticClassValue", (20, 30, 20, 46))
("member .cctor", (10, 5, 10, 11))
("Test", (1, 0, 1, 0))|]

//-------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private void BuildStartedHandler(object sender, BuildStartedEventArgs buildEvent
try
{
this.haveCachedRegistry = false;
if (LogAtImportance(MessageImportance.Low))
if (LogAtImportance(MessageImportance.Normal))
{
LogEvent(sender, buildEvent);
}
Expand All @@ -385,7 +385,7 @@ private void BuildFinishedHandler(object sender, BuildFinishedEventArgs buildEve
{
try
{
if (LogAtImportance(buildEvent.Succeeded ? MessageImportance.Low :
if (LogAtImportance(buildEvent.Succeeded ? MessageImportance.Normal :
MessageImportance.High))
{
if (this.outputWindowPane != null)
Expand All @@ -408,7 +408,7 @@ private void ProjectStartedHandler(object sender, ProjectStartedEventArgs buildE
{
try
{
if (LogAtImportance(MessageImportance.Low))
if (LogAtImportance(MessageImportance.Normal))
{
LogEvent(sender, buildEvent);
}
Expand All @@ -427,7 +427,7 @@ private void ProjectFinishedHandler(object sender, ProjectFinishedEventArgs buil
{
try
{
if (LogAtImportance(buildEvent.Succeeded ? MessageImportance.Low
if (LogAtImportance(buildEvent.Succeeded ? MessageImportance.Normal
: MessageImportance.High))
{
LogEvent(sender, buildEvent);
Expand Down Expand Up @@ -473,7 +473,7 @@ private void TargetFinishedHandler(object sender, TargetFinishedEventArgs buildE
{
--this.currentIndent;
if ((isLogTaskDone) &&
LogAtImportance(buildEvent.Succeeded ? MessageImportance.Low
LogAtImportance(buildEvent.Succeeded ? MessageImportance.Normal
: MessageImportance.High))
{
LogEvent(sender, buildEvent);
Expand Down Expand Up @@ -556,36 +556,37 @@ private void CustomHandler(object sender, CustomBuildEventArgs buildEvent)
/// This method takes a MessageImportance and returns true if messages
/// at importance i should be loggeed. Otherwise return false.
/// </summary>
private bool LogAtImportance(MessageImportance importance)
{
// If importance is too low for current settings, ignore the event
bool logIt = false;

this.SetVerbosity();

switch (this.Verbosity)
{
case LoggerVerbosity.Quiet:
logIt = false;
break;
case LoggerVerbosity.Minimal:
logIt = (importance == MessageImportance.High);
break;
case LoggerVerbosity.Normal:
// Falling through...
case LoggerVerbosity.Detailed:
logIt = (importance != MessageImportance.Low);
break;
case LoggerVerbosity.Diagnostic:
logIt = true;
break;
default:
Debug.Fail("Unknown Verbosity level. Ignoring will cause everything to be logged");
break;
}

return logIt;
}
private bool LogAtImportance(MessageImportance importance)
{
// If importance is too low for current settings, ignore the event
bool logIt = false;

this.SetVerbosity();

switch (this.Verbosity)
{
case LoggerVerbosity.Quiet:
logIt = false;
break;
case LoggerVerbosity.Minimal:
logIt = (importance == MessageImportance.High);
break;
case LoggerVerbosity.Normal:
logIt = (importance == MessageImportance.Normal) || (importance == MessageImportance.High);
break;
case LoggerVerbosity.Detailed:
logIt = (importance == MessageImportance.Low) || (importance == MessageImportance.Normal) || (importance == MessageImportance.High);
break;
case LoggerVerbosity.Diagnostic:
logIt = true;
break;
default:
Debug.Fail("Unknown Verbosity level. Ignoring will cause everything to be logged");
break;
}

return logIt;
}

/// <summary>
/// This is the method that does the main work of logging an event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PropertyGroup>
<Win32Resource>$(IntermediateOutputPath)\ProjectResources.rc.res</Win32Resource>
</PropertyGroup>
<Target Name="BeforeBuild">
<Target Name="BeforeBuild" Condition="!Exists('$(IntermediateOutputPath)$(RCResourceFile).res')">
<Exec Command="&quot;$(ProgramFiles)\Windows Kits\8.1\bin\x86\rc.exe&quot; /fo $(IntermediateOutputPath)$(RCResourceFile).res $(RCResourceFile)" Condition="Exists('$(ProgramFiles)\Windows Kits\8.1\bin\x86\rc.exe')" />
<Exec Command="&quot;$(ProgramFiles)\Windows Kits\10\bin\x86\rc.exe&quot; /fo $(IntermediateOutputPath)$(RCResourceFile).res $(RCResourceFile)" Condition="Exists('$(ProgramFiles)\Windows Kits\10\bin\x86\rc.exe')" />
<Exec Command="&quot;$(ProgramFiles)\Windows Kits\10\bin\10.0.15063.0\x86\rc.exe&quot; /fo $(IntermediateOutputPath)$(RCResourceFile).res $(RCResourceFile)" Condition="Exists('$(ProgramFiles)\Windows Kits\10\bin\10.0.15063.0\x86\rc.exe')" />
Expand Down

0 comments on commit d26de72

Please sign in to comment.