Skip to content

Commit

Permalink
More ValueOption in compiler: part 3 (and the last)
Browse files Browse the repository at this point in the history
  • Loading branch information
psfinaki committed Mar 6, 2024
1 parent 107ac93 commit 07ba16a
Show file tree
Hide file tree
Showing 18 changed files with 844 additions and 517 deletions.
5 changes: 3 additions & 2 deletions src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,11 @@ module OldStyleMessages =
let mutable showParserStackOnParseError = false
#endif

[<return: Struct>]
let (|InvalidArgument|_|) (exn: exn) =
match exn with
| :? ArgumentException as e -> Some e.Message
| _ -> None
| :? ArgumentException as e -> ValueSome e.Message
| _ -> ValueNone

let OutputNameSuggestions (os: StringBuilder) suggestNames suggestionsF idText =
if suggestNames then
Expand Down
5 changes: 3 additions & 2 deletions src/Compiler/Driver/CreateILModule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ module AttributeHelpers =
| Some(Attrib(_, _, [ AttribBoolArg p ], _, _, _, _)) -> Some p
| _ -> None

[<return: Struct>]
let (|ILVersion|_|) (versionString: string) =
try
Some(parseILVersion versionString)
ValueSome(parseILVersion versionString)
with e ->
None
ValueNone

//----------------------------------------------------------------------------
// ValidateKeySigningAttributes, GetStrongNameSigner
Expand Down
26 changes: 14 additions & 12 deletions src/Compiler/Driver/GraphChecking/FileContentMapping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ let visitNameofResult (nameofResult: NameofResult) : FileContentEntry =
FileContentEntry.PrefixedIdentifier(longIdentToPath false longIdent)

/// Special case of `nameof Module` type of expression
let (|NameofExpr|_|) (e: SynExpr) : NameofResult option =
[<return: Struct>]
let (|NameofExpr|_|) (e: SynExpr) : NameofResult voption =
let rec stripParen (e: SynExpr) =
match e with
| SynExpr.Paren(expr = expr) -> stripParen expr
Expand All @@ -339,15 +340,15 @@ let (|NameofExpr|_|) (e: SynExpr) : NameofResult option =
match e with
| SynExpr.App(flag = ExprAtomicFlag.NonAtomic; isInfix = false; funcExpr = SynExpr.Ident NameofIdent; argExpr = moduleNameExpr) ->
match stripParen moduleNameExpr with
| SynExpr.Ident moduleNameIdent -> Some(NameofResult.SingleIdent moduleNameIdent)
| SynExpr.Ident moduleNameIdent -> ValueSome(NameofResult.SingleIdent moduleNameIdent)
| SynExpr.LongIdent(longDotId = longIdent) ->
match longIdent.LongIdent with
| [] -> None
| [] -> ValueNone
// This is highly unlikely to be produced by the parser
| [ moduleNameIdent ] -> Some(NameofResult.SingleIdent moduleNameIdent)
| lid -> Some(NameofResult.LongIdent(lid))
| _ -> None
| _ -> None
| [ moduleNameIdent ] -> ValueSome(NameofResult.SingleIdent moduleNameIdent)
| lid -> ValueSome(NameofResult.LongIdent(lid))
| _ -> ValueNone
| _ -> ValueNone

let visitSynExpr (e: SynExpr) : FileContentEntry list =
let rec visit (e: SynExpr) (continuation: FileContentEntry list -> FileContentEntry list) : FileContentEntry list =
Expand Down Expand Up @@ -566,6 +567,7 @@ let visitSynExpr (e: SynExpr) : FileContentEntry list =
visit e id

/// Special case of `| nameof Module ->` type of pattern
[<return: Struct>]
let (|NameofPat|_|) (pat: SynPat) =
let rec stripPats p =
match p with
Expand All @@ -582,11 +584,11 @@ let (|NameofPat|_|) (pat: SynPat) =
argPats = SynArgPats.Pats []
accessibility = None) ->
match longIdent with
| [] -> None
| [ moduleNameIdent ] -> Some(NameofResult.SingleIdent moduleNameIdent)
| lid -> Some(NameofResult.LongIdent lid)
| _ -> None
| _ -> None
| [] -> ValueNone
| [ moduleNameIdent ] -> ValueSome(NameofResult.SingleIdent moduleNameIdent)
| lid -> ValueSome(NameofResult.LongIdent lid)
| _ -> ValueNone
| _ -> ValueNone

let visitPat (p: SynPat) : FileContentEntry list =
let rec visit (p: SynPat) (continuation: FileContentEntry list -> FileContentEntry list) : FileContentEntry list =
Expand Down
5 changes: 3 additions & 2 deletions src/Compiler/Facilities/AsyncMemoize.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ module internal Utils =

let replayDiagnostics (logger: DiagnosticsLogger) = Seq.iter ((<|) logger.DiagnosticSink)

[<return: Struct>]
let (|TaskCancelled|_|) (ex: exn) =
match ex with
| :? System.Threading.Tasks.TaskCanceledException as tce -> Some tce
| :? System.Threading.Tasks.TaskCanceledException as tce -> ValueSome tce
//| :? System.AggregateException as ae ->
// if ae.InnerExceptions |> Seq.forall (fun e -> e :? System.Threading.Tasks.TaskCanceledException) then
// ae.InnerExceptions |> Seq.tryHead |> Option.map (fun e -> e :?> System.Threading.Tasks.TaskCanceledException)
// else
// None
| _ -> None
| _ -> ValueNone

type internal StateUpdate<'TValue> =
| CancelRequest
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Facilities/AsyncMemoize.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module internal Utils =
/// Return file name with one directory above it
val shortPath: path: string -> string

val (|TaskCancelled|_|): ex: exn -> TaskCanceledException option
[<return: Struct>]
val (|TaskCancelled|_|): ex: exn -> TaskCanceledException voption

type internal JobEvent =
| Requested
Expand Down
5 changes: 3 additions & 2 deletions src/Compiler/Facilities/DiagnosticsLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ exception StopProcessingExn of exn option with
| StopProcessingExn(Some exn) -> "StopProcessingExn, originally (" + exn.ToString() + ")"
| _ -> "StopProcessingExn"

[<return: Struct>]
let (|StopProcessing|_|) exn =
match exn with
| StopProcessingExn _ -> Some()
| _ -> None
| StopProcessingExn _ -> ValueSome()
| _ -> ValueNone

let StopProcessing<'T> = StopProcessingExn None

Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Facilities/DiagnosticsLogger.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ val NoSuggestions: Suggestions
/// Thrown when we stop processing the F# Interactive entry or #load.
exception StopProcessingExn of exn option

val (|StopProcessing|_|): exn: exn -> unit option
[<return: Struct>]
val (|StopProcessing|_|): exn: exn -> unit voption

val StopProcessing<'T> : exn

Expand Down
Loading

0 comments on commit 07ba16a

Please sign in to comment.