Skip to content

Commit

Permalink
changes - works end-to-end for .fs files and the diamond example
Browse files Browse the repository at this point in the history
  • Loading branch information
safesparrow committed Oct 30, 2022
1 parent b2c265b commit ae722fe
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 52 deletions.
27 changes: 20 additions & 7 deletions src/Compiler/Driver/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ let ParseOneInputFile (tcConfig: TcConfig, lexResourceManager, fileName, isLastC
/// NOTE: this needs to be improved to commit diagnotics as soon as possible
///
/// NOTE: If StopProcessing is raised by any piece of work then the overall function raises StopProcessing.
let UseMultipleDiagnosticLoggers (inputs, diagnosticsLogger, eagerFormat) f =
let UseMultipleDiagnosticLoggers ((inputs, diagnosticsLogger, eagerFormat): 'a list * DiagnosticsLogger * (PhasedDiagnostic -> PhasedDiagnostic) option) (f: ('a * CapturingDiagnosticsLogger) list -> 'b): 'b =

// Check input files and create delayed error loggers before we try to parallel parse.
let delayLoggers =
Expand Down Expand Up @@ -1060,11 +1060,18 @@ type TcState =
// a.fsi + b.fsi + c.fsi (after checking implementation file for c.fs)
member x.CcuSig = x.tcsCcuSig

member x.TcsImplicitOpenDeclarations = x.tcsImplicitOpenDeclarations

member x.NextStateAfterIncrementalFragment tcEnvAtEndOfLastInput =
{ x with
tcsTcSigEnv = tcEnvAtEndOfLastInput
tcsTcImplEnv = tcEnvAtEndOfLastInput
}

member x.WithCreatesGeneratedProvidedTypes (y : bool) : TcState =
{ x with
tcsCreatesGeneratedProvidedTypes = y
}

/// Create the initial type checking state for compiling an assembly
let GetInitialTcState (m, ccuName, tcConfig: TcConfig, tcGlobals, tcImports: TcImports, tcEnv0, openDecls0) =
Expand Down Expand Up @@ -1194,6 +1201,14 @@ let AddDummyCheckResultsToTcState

(tcEnvAtEnd, EmptyTopAttrs, Some emptyImplFile, ccuSigForFile), tcState

type PartialResult = TcEnv * TopAttribs * CheckedImplFile option * ModuleOrNamespaceType

type CheckArgs = CompilationThreadToken * (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcState * (PhasedDiagnostic -> PhasedDiagnostic) * ParsedInput list
/// Use parallel checking of implementation files that have signature files
let mutable CheckMultipleInputsInParallel2 : CheckArgs -> (PartialResult list * TcState)
=
fun _ -> failwith "Dummy implementation"

/// Typecheck a single file (or interactive entry into F# Interactive)
let CheckOneInputAux
(
Expand Down Expand Up @@ -1433,9 +1448,6 @@ let CheckMultipleInputsSequential (ctok, checkForErrors, tcConfig, tcImports, tc
(tcState, inputs)
||> List.mapFold (CheckOneInputEntry args)


type PartialResult = TcEnv * TopAttribs * CheckedImplFile option * ModuleOrNamespaceType

/// Use parallel checking of implementation files that have signature files
let CheckMultipleInputsInParallel
((ctok,
Expand Down Expand Up @@ -1558,16 +1570,16 @@ type WorkInput =
}

/// Use parallel checking of implementation files that have signature files
let CheckMultipleInputsInParallel2
((ctok : CancellationToken,
let CheckMultipleInputsInParallel3
((ctok : CompilationThreadToken,
checkForErrors: unit -> bool,
tcConfig: TcConfig,
tcImports: TcImports,
tcGlobals: TcGlobals,
prefixPathOpt,
tcState,
eagerFormat,
inputs): CancellationToken * (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcState * (PhasedDiagnostic -> PhasedDiagnostic) * ParsedInput list)
inputs): CompilationThreadToken * (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcState * (PhasedDiagnostic -> PhasedDiagnostic) * ParsedInput list)
: PartialResult list * TcState =

let _ = ctok // TODO Use
Expand Down Expand Up @@ -1758,6 +1770,7 @@ let CheckMultipleInputsInParallel2
partialResults, tcState
)


let CheckClosedInputSet (ctok, checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, eagerFormat, inputs) =
// tcEnvAtEndOfLastFile is the environment required by fsi.exe when incrementally adding definitions
let results, tcState =
Expand Down
22 changes: 21 additions & 1 deletion src/Compiler/Driver/ParseAndCheckInputs.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ type ModuleNamesDict = Map<string, Map<string, QualifiedNameOfFile>>
/// Checks if a ParsedInput is using a module name that was already given and deduplicates the name if needed.
val DeduplicateParsedInputModuleName: ModuleNamesDict -> ParsedInput -> ParsedInput * ModuleNamesDict

val UseMultipleDiagnosticLoggers<'a, 'b> :
('a list * DiagnosticsLogger * (PhasedDiagnostic -> PhasedDiagnostic) option) ->
(('a * CapturingDiagnosticsLogger) list -> 'b) ->
'b
/// Parse a single input (A signature file or implementation file)
val ParseInput:
lexer: (Lexbuf -> Parser.token) *
Expand Down Expand Up @@ -112,7 +117,6 @@ val GetInitialTcEnv: assemblyName: string * range * TcConfig * TcImports * TcGlo
/// Represents the incremental type checking state for a set of inputs
[<Sealed>]
type TcState =

/// The CcuThunk for the current assembly being checked
member Ccu: CcuThunk

Expand All @@ -129,6 +133,22 @@ type TcState =
member NextStateAfterIncrementalFragment: TcEnv -> TcState

member CreatesGeneratedProvidedTypes: bool

member TcsImplicitOpenDeclarations: OpenDeclaration list

member WithCreatesGeneratedProvidedTypes : bool -> TcState

val AddCheckResultsToTcState :
(TcGlobals * Import.ImportMap * bool * LongIdent option * NameResolution.TcResultsSink * TcEnv * QualifiedNameOfFile * ModuleOrNamespaceType)
-> TcState
-> (ModuleOrNamespaceType * TcState)

type PartialResult = TcEnv * TopAttribs * CheckedImplFile option * ModuleOrNamespaceType

type CheckArgs = CompilationThreadToken * (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcState * (PhasedDiagnostic -> PhasedDiagnostic) * ParsedInput list

/// Use parallel checking of implementation files that have signature files
val mutable CheckMultipleInputsInParallel2 : (CheckArgs -> PartialResult list * TcState)

/// Get the initial type checking state for a set of inputs
val GetInitialTcState: range * string * TcConfig * TcGlobals * TcImports * TcEnv * OpenDeclaration list -> TcState
Expand Down
20 changes: 10 additions & 10 deletions src/Compiler/Utilities/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -924,12 +924,12 @@ module Cancellable =

type CancellableBuilder() =

member inline _.Delay([<InlineIfLambda>] f) =
member _.Delay(f) =
Cancellable(fun ct ->
let (Cancellable g) = f ()
g ct)

member inline _.Bind(comp, [<InlineIfLambda>] k) =
member _.Bind(comp, k) =
Cancellable(fun ct ->
#if !FSHARPCORE_USE_PACKAGE
__debugPoint ""
Expand All @@ -939,7 +939,7 @@ type CancellableBuilder() =
| ValueOrCancelled.Value v1 -> Cancellable.run ct (k v1)
| ValueOrCancelled.Cancelled err1 -> ValueOrCancelled.Cancelled err1)

member inline _.BindReturn(comp, [<InlineIfLambda>] k) =
member _.BindReturn(comp, k) =
Cancellable(fun ct ->
#if !FSHARPCORE_USE_PACKAGE
__debugPoint ""
Expand All @@ -949,7 +949,7 @@ type CancellableBuilder() =
| ValueOrCancelled.Value v1 -> ValueOrCancelled.Value(k v1)
| ValueOrCancelled.Cancelled err1 -> ValueOrCancelled.Cancelled err1)

member inline _.Combine(comp1, comp2) =
member _.Combine(comp1, comp2) =
Cancellable(fun ct ->
#if !FSHARPCORE_USE_PACKAGE
__debugPoint ""
Expand All @@ -959,7 +959,7 @@ type CancellableBuilder() =
| ValueOrCancelled.Value () -> Cancellable.run ct comp2
| ValueOrCancelled.Cancelled err1 -> ValueOrCancelled.Cancelled err1)

member inline _.TryWith(comp, [<InlineIfLambda>] handler) =
member _.TryWith(comp, handler) =
Cancellable(fun ct ->
#if !FSHARPCORE_USE_PACKAGE
__debugPoint ""
Expand All @@ -980,7 +980,7 @@ type CancellableBuilder() =
| Choice2Of2 err -> Cancellable.run ct (handler err)
| ValueOrCancelled.Cancelled err1 -> ValueOrCancelled.Cancelled err1)

member inline _.Using(resource, [<InlineIfLambda>] comp) =
member _.Using(resource, comp) =
Cancellable(fun ct ->
#if !FSHARPCORE_USE_PACKAGE
__debugPoint ""
Expand All @@ -1004,7 +1004,7 @@ type CancellableBuilder() =
| Choice2Of2 err -> raise err
| ValueOrCancelled.Cancelled err1 -> ValueOrCancelled.Cancelled err1)

member inline _.TryFinally(comp, [<InlineIfLambda>] compensation) =
member _.TryFinally(comp, compensation) =
Cancellable(fun ct ->
#if !FSHARPCORE_USE_PACKAGE
__debugPoint ""
Expand All @@ -1027,12 +1027,12 @@ type CancellableBuilder() =
| Choice2Of2 err -> raise err
| ValueOrCancelled.Cancelled err1 -> ValueOrCancelled.Cancelled err1)

member inline _.Return v =
member _.Return v =
Cancellable(fun _ -> ValueOrCancelled.Value v)

member inline _.ReturnFrom(v: Cancellable<'T>) = v
member _.ReturnFrom(v: Cancellable<'T>) = v

member inline _.Zero() =
member _.Zero() =
Cancellable(fun _ -> ValueOrCancelled.Value())

[<AutoOpen>]
Expand Down
24 changes: 12 additions & 12 deletions src/Compiler/Utilities/illib.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -394,28 +394,28 @@ type internal CancellableBuilder =

new: unit -> CancellableBuilder

member inline BindReturn: comp: Cancellable<'T> * [<InlineIfLambda>] k: ('T -> 'U) -> Cancellable<'U>
member BindReturn: comp: Cancellable<'T> * k: ('T -> 'U) -> Cancellable<'U>

member inline Bind: comp: Cancellable<'T> * [<InlineIfLambda>] k: ('T -> Cancellable<'U>) -> Cancellable<'U>
member Bind: comp: Cancellable<'T> * k: ('T -> Cancellable<'U>) -> Cancellable<'U>

member inline Combine: comp1: Cancellable<unit> * comp2: Cancellable<'T> -> Cancellable<'T>
member Combine: comp1: Cancellable<unit> * comp2: Cancellable<'T> -> Cancellable<'T>

member inline Delay: [<InlineIfLambda>] f: (unit -> Cancellable<'T>) -> Cancellable<'T>
member Delay: f: (unit -> Cancellable<'T>) -> Cancellable<'T>

member inline Return: v: 'T -> Cancellable<'T>
member Return: v: 'T -> Cancellable<'T>

member inline ReturnFrom: v: Cancellable<'T> -> Cancellable<'T>
member ReturnFrom: v: Cancellable<'T> -> Cancellable<'T>

member inline TryFinally: comp: Cancellable<'T> * [<InlineIfLambda>] compensation: (unit -> unit) -> Cancellable<'T>
member TryFinally: comp: Cancellable<'T> * compensation: (unit -> unit) -> Cancellable<'T>

member inline TryWith:
comp: Cancellable<'T> * [<InlineIfLambda>] handler: (exn -> Cancellable<'T>) -> Cancellable<'T>
member TryWith:
comp: Cancellable<'T> * handler: (exn -> Cancellable<'T>) -> Cancellable<'T>

member inline Using:
resource: 'Resource * [<InlineIfLambda>] comp: ('Resource -> Cancellable<'T>) -> Cancellable<'T>
member Using:
resource: 'Resource * comp: ('Resource -> Cancellable<'T>) -> Cancellable<'T>
when 'Resource :> IDisposable

member inline Zero: unit -> Cancellable<unit>
member Zero: unit -> Cancellable<unit>

[<AutoOpen>]
module internal CancellableAutoOpens =
Expand Down
2 changes: 1 addition & 1 deletion tests/DiamondTest/B1.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DiamondTest.B1

open DiamondTest
let b1 = A.a + 10
2 changes: 1 addition & 1 deletion tests/DiamondTest/B2.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DiamondTest.B2

open DiamondTest
let b2 = B1.b1 + 100
2 changes: 1 addition & 1 deletion tests/DiamondTest/C1.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DiamondTest.C1

open DiamondTest
let c1 = A.a + 30
2 changes: 1 addition & 1 deletion tests/DiamondTest/C2.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DiamondTest.C2

open DiamondTest
let c2 = C1.c1 + 300
2 changes: 1 addition & 1 deletion tests/DiamondTest/D.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DiamondTest.D

open DiamondTest
let d = C2.c2 + B2.b2
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
<Compile Include="Tests\TestDepResolving.fs" />
<Compile Include="Tests\RunCompiler.fs" />
<Compile Include="Program.fs" />
<Content Include="SimpleArgs.txt" />
<Content Include="DiamondArgs.txt" />
<Content Include="FCSArgs.txt" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit ae722fe

Please sign in to comment.