Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ type TcConfigBuilder =
mutable exiter: Exiter

mutable parallelReferenceResolution: ParallelReferenceResolution

mutable captureIdentifiersWhenParsing: bool
}

// Directories to start probing in
Expand Down Expand Up @@ -777,6 +779,7 @@ type TcConfigBuilder =
xmlDocInfoLoader = None
exiter = QuitProcessExiter
parallelReferenceResolution = ParallelReferenceResolution.Off
captureIdentifiersWhenParsing = false
}

member tcConfigB.FxResolver =
Expand Down Expand Up @@ -1322,6 +1325,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
member _.xmlDocInfoLoader = data.xmlDocInfoLoader
member _.exiter = data.exiter
member _.parallelReferenceResolution = data.parallelReferenceResolution
member _.captureIdentifiersWhenParsing = data.captureIdentifiersWhenParsing

static member Create(builder, validate) =
use _ = UseBuildPhase BuildPhase.Parameter
Expand Down
4 changes: 4 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ type TcConfigBuilder =
mutable exiter: Exiter

mutable parallelReferenceResolution: ParallelReferenceResolution

mutable captureIdentifiersWhenParsing: bool
}

static member CreateNew:
Expand Down Expand Up @@ -858,6 +860,8 @@ type TcConfig =

member parallelReferenceResolution: ParallelReferenceResolution

member captureIdentifiersWhenParsing: bool

/// Represents a computation to return a TcConfig. Normally this is just a constant immutable TcConfig,
/// but for F# Interactive it may be based on an underlying mutable TcConfigBuilder.
[<Sealed>]
Expand Down
52 changes: 29 additions & 23 deletions src/Compiler/Driver/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ let ParseInput
lexbuf: UnicodeLexing.Lexbuf,
defaultNamespace,
fileName,
isLastCompiland
isLastCompiland,
identCapture
) =
// The assert below is almost ok, but it fires in two cases:
// - fsi.exe sometimes passes "stdin" as a dummy file name
Expand All @@ -433,25 +434,29 @@ let ParseInput
let input =
let identStore = HashSet<string>()

let identCaptureLexer x =
let token = lexer x

match token with
| Parser.token.PERCENT_OP ident
| Parser.token.FUNKY_OPERATOR_NAME ident
| Parser.token.ADJACENT_PREFIX_OP ident
| Parser.token.PLUS_MINUS_OP ident
| Parser.token.INFIX_AMP_OP ident
| Parser.token.INFIX_STAR_DIV_MOD_OP ident
| Parser.token.PREFIX_OP ident
| Parser.token.INFIX_BAR_OP ident
| Parser.token.INFIX_AT_HAT_OP ident
| Parser.token.INFIX_COMPARE_OP ident
| Parser.token.INFIX_STAR_STAR_OP ident
| Parser.token.IDENT ident -> identStore.Add ident |> ignore
| _ -> ()

token
let lexer =
if identCapture then
(fun x ->
let token = lexer x

match token with
| Parser.token.PERCENT_OP ident
| Parser.token.FUNKY_OPERATOR_NAME ident
| Parser.token.ADJACENT_PREFIX_OP ident
| Parser.token.PLUS_MINUS_OP ident
| Parser.token.INFIX_AMP_OP ident
| Parser.token.INFIX_STAR_DIV_MOD_OP ident
| Parser.token.PREFIX_OP ident
| Parser.token.INFIX_BAR_OP ident
| Parser.token.INFIX_AT_HAT_OP ident
| Parser.token.INFIX_COMPARE_OP ident
| Parser.token.INFIX_STAR_STAR_OP ident
| Parser.token.IDENT ident -> identStore.Add ident |> ignore
| _ -> ()

token)
else
lexer

if FSharpMLCompatFileSuffixes |> List.exists (FileSystemUtils.checkSuffix fileName) then
if lexbuf.SupportsFeature LanguageFeature.MLCompatRevisions then
Expand All @@ -461,14 +466,14 @@ let ParseInput

// Call the appropriate parser - for signature files or implementation files
if FSharpImplFileSuffixes |> List.exists (FileSystemUtils.checkSuffix fileName) then
let impl = Parser.implementationFile identCaptureLexer lexbuf
let impl = Parser.implementationFile lexer lexbuf

let tripleSlashComments =
LexbufLocalXmlDocStore.ReportInvalidXmlDocPositions(lexbuf)

PostParseModuleImpls(defaultNamespace, fileName, isLastCompiland, impl, lexbuf, tripleSlashComments, Set identStore)
elif FSharpSigFileSuffixes |> List.exists (FileSystemUtils.checkSuffix fileName) then
let intfs = Parser.signatureFile identCaptureLexer lexbuf
let intfs = Parser.signatureFile lexer lexbuf

let tripleSlashComments =
LexbufLocalXmlDocStore.ReportInvalidXmlDocPositions(lexbuf)
Expand Down Expand Up @@ -640,7 +645,8 @@ let ParseOneInputLexbuf (tcConfig: TcConfig, lexResourceManager, lexbuf, fileNam
lexbuf,
None,
fileName,
isLastCompiland
isLastCompiland,
tcConfig.captureIdentifiersWhenParsing
)

// Report the statistics for testing purposes
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Driver/ParseAndCheckInputs.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ val ParseInput:
lexbuf: Lexbuf *
defaultNamespace: string option *
fileName: string *
isLastCompiland: (bool * bool) ->
isLastCompiland: (bool * bool) *
identCapture: bool ->
ParsedInput

/// A general routine to process hash directives
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSharp.Compiler.Service.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@
<Compile Include="Service\QuickParse.fs" />
<Compile Include="Service\FSharpCheckerResults.fsi" />
<Compile Include="Service\FSharpCheckerResults.fs" />
<Compile Include="Service\FindAllIndentifiers.fs" />
<Compile Include="Service\service.fsi" />
<Compile Include="Service\service.fs" />
<Compile Include="Service\ServiceInterfaceStubGenerator.fsi" />
Expand Down
7 changes: 4 additions & 3 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ module internal ParseAndCheckFile =

matchingBraces.ToArray()

let parseFile (sourceText: ISourceText, fileName, options: FSharpParsingOptions, userOpName: string, suggestNamesForErrors: bool) =
let parseFile (sourceText: ISourceText, fileName, options: FSharpParsingOptions, userOpName: string, suggestNamesForErrors: bool, identCapture: bool) =
Trace.TraceInformation("FCS: {0}.{1} ({2})", userOpName, "parseFile", fileName)

use act =
Expand Down Expand Up @@ -2377,7 +2377,8 @@ module internal ParseAndCheckFile =
lexbuf,
None,
fileName,
(isLastCompiland, isExe)
(isLastCompiland, isExe),
identCapture
)
with e ->
errHandler.DiagnosticsLogger.StopProcessingRecovery e range0 // don't re-raise any exceptions, we must return None.
Expand Down Expand Up @@ -3180,7 +3181,7 @@ type FsiInteractiveChecker(legacyReferenceResolver, tcConfig: TcConfig, tcGlobal
FSharpParsingOptions.FromTcConfig(tcConfig, [| fileName |], true)

let parseErrors, parsedInput, anyErrors =
ParseAndCheckFile.parseFile (sourceText, fileName, parsingOptions, userOpName, suggestNamesForErrors)
ParseAndCheckFile.parseFile (sourceText, fileName, parsingOptions, userOpName, suggestNamesForErrors, tcConfig.captureIdentifiersWhenParsing)

let dependencyFiles = [||] // interactions have no dependencies

Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Service/FSharpCheckerResults.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ module internal ParseAndCheckFile =
fileName: string *
options: FSharpParsingOptions *
userOpName: string *
suggestNamesForErrors: bool ->
suggestNamesForErrors: bool *
identCapture: bool ->
FSharpDiagnostic[] * ParsedInput * bool

val matchBraces:
Expand Down
Loading