Skip to content

Commit 2818689

Browse files
authored
Slight cleanup of dead and repeated code (#17412)
* Slight cleanup * splitoperator
1 parent b73be15 commit 2818689

File tree

5 files changed

+10
-23
lines changed

5 files changed

+10
-23
lines changed

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,10 +2822,7 @@ let TcVal checkAttributes (cenv: cenv) env (tpenv: UnscopedTyparEnv) (vref: ValR
28222822
let exprForVal = Expr.Val (vref, vrefFlags, m)
28232823
let exprForVal = mkTyAppExpr m (exprForVal, vTy) tinst
28242824
let isSpecial =
2825-
(match vrefFlags with NormalValUse | PossibleConstrainedCall _ -> false | _ -> true) ||
2826-
valRefEq g vref g.splice_expr_vref ||
2827-
valRefEq g vref g.splice_raw_expr_vref
2828-
2825+
(match vrefFlags with NormalValUse | PossibleConstrainedCall _ -> false | _ -> true) || g.isSpliceOperator vref
28292826
let exprForVal = RecordUseOfRecValue cenv valRecInfo vref exprForVal m
28302827

28312828
tpsorig, exprForVal, isSpecial, tau, tinst, tpenv

src/Compiler/Checking/PostInferenceChecks.fs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,6 @@ let CheckNoReraise cenv freesOpt (body: Expr) =
703703
if fvs.UsesUnboundRethrow then
704704
errorR(Error(FSComp.SR.chkErrorContainsCallToRethrow(), body.Range))
705705

706-
/// Check if a function is a quotation splice operator
707-
let isSpliceOperator g v = valRefEq g v g.splice_expr_vref || valRefEq g v g.splice_raw_expr_vref
708-
709-
710706
/// Examples:
711707
/// I<int> & I<int> => ExactlyEqual.
712708
/// I<int> & I<string> => NotEqual.
@@ -776,8 +772,8 @@ let rec CheckExprNoByrefs cenv env expr =
776772
and CheckValRef (cenv: cenv) (env: env) v m (ctxt: PermitByRefExpr) =
777773

778774
if cenv.reportErrors then
779-
if isSpliceOperator cenv.g v && not env.quote then errorR(Error(FSComp.SR.chkSplicingOnlyInQuotations(), m))
780-
if isSpliceOperator cenv.g v then errorR(Error(FSComp.SR.chkNoFirstClassSplicing(), m))
775+
if cenv.g.isSpliceOperator v && not env.quote then errorR(Error(FSComp.SR.chkSplicingOnlyInQuotations(), m))
776+
if cenv.g.isSpliceOperator v then errorR(Error(FSComp.SR.chkNoFirstClassSplicing(), m))
781777
if valRefEq cenv.g v cenv.g.addrof_vref then errorR(Error(FSComp.SR.chkNoFirstClassAddressOf(), m))
782778
if valRefEq cenv.g v cenv.g.reraise_vref then errorR(Error(FSComp.SR.chkNoFirstClassRethrow(), m))
783779
if valRefEq cenv.g v cenv.g.nameof_vref then errorR(Error(FSComp.SR.chkNoFirstClassNameOf(), m))
@@ -1192,7 +1188,7 @@ and CheckExpr (cenv: cenv) (env: env) origExpr (ctxt: PermitByRefExpr) : Limit =
11921188
NoLimit
11931189

11941190
// Allow '%expr' in quotations
1195-
| Expr.App (Expr.Val (vref, _, _), _, tinst, [arg], m) when isSpliceOperator g vref && env.quote ->
1191+
| Expr.App (Expr.Val (vref, _, _), _, tinst, [arg], m) when g.isSpliceOperator vref && env.quote ->
11961192
CheckSpliceApplication cenv env (tinst, arg, m)
11971193

11981194
// Check an application

src/Compiler/Checking/QuotationTranslator.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ let (|ObjectInitializationCheck|_|) g expr =
214214
isUnitTy g resultTy -> ValueSome()
215215
| _ -> ValueNone
216216

217-
let isSplice g vref = valRefEq g vref g.splice_expr_vref || valRefEq g vref g.splice_raw_expr_vref
218-
219217
let rec EmitDebugInfoIfNecessary cenv env m astExpr : ExprData =
220218
// do not emit debug info if emitDebugInfoInQuotations = false or it was already written for the given expression
221219
if cenv.emitDebugInfoInQuotations && not (QP.isAttributedExpression astExpr) then
@@ -298,7 +296,7 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
298296
match expr with
299297
// Detect expression tree exprSplices
300298
| Expr.App (InnerExprPat(Expr.Val (vref, _, _)), _, _, x0 :: rest, m)
301-
when isSplice g vref ->
299+
when g.isSpliceOperator vref ->
302300
let idx = cenv.exprSplices.Count
303301
let ty = tyOfExpr g expr
304302

@@ -311,7 +309,7 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
311309
(hole, rest) ||> List.fold (fun fR arg -> QP.mkApp (fR, ConvExpr cenv env arg))
312310

313311
| ModuleValueOrMemberUse g (vref, vFlags, _f, _fTy, tyargs, curriedArgs)
314-
when not (isSplice g vref) ->
312+
when not (g.isSpliceOperator vref) ->
315313
let m = expr.Range
316314

317315
let numEnclTypeArgs, _, isNewObj, valUseFlags, isSelfInit, takesInstanceArg, isPropGet, isPropSet =

src/Compiler/Checking/QuotationTranslator.fsi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,3 @@ val (|SimpleArrayLoopBody|_|): TcGlobals -> Expr -> (Expr * TType * Expr) voptio
5353

5454
[<return: Struct>]
5555
val (|ObjectInitializationCheck|_|): TcGlobals -> Expr -> unit voption
56-
57-
val isSplice: TcGlobals -> ValRef -> bool

src/Compiler/TypedTree/TcGlobals.fs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ open System.Diagnostics
1515
open Internal.Utilities.Library
1616
open Internal.Utilities.Library.Extras
1717
open FSharp.Compiler.AbstractIL.IL
18-
open FSharp.Compiler.AbstractIL.ILX
1918
open FSharp.Compiler.CompilerGlobalState
2019
open FSharp.Compiler.Features
2120
open FSharp.Compiler.IO
@@ -24,9 +23,7 @@ open FSharp.Compiler.Text.FileIndex
2423
open FSharp.Compiler.Text.Range
2524
open FSharp.Compiler.TypedTree
2625
open FSharp.Compiler.TypedTreeBasics
27-
2826
open Internal.Utilities
29-
open System.Reflection
3027

3128
let internal DummyFileNameForRangesWithoutASpecificLocation = startupFileName
3229
let private envRange = rangeN DummyFileNameForRangesWithoutASpecificLocation 0
@@ -65,7 +62,6 @@ module FSharpLib =
6562
let LanguagePrimitivesName = Root + ".Core.LanguagePrimitives"
6663
let CompilerServicesName = Root + ".Core.CompilerServices"
6764
let LinqRuntimeHelpersName = Root + ".Linq.RuntimeHelpers"
68-
let RuntimeHelpersName = Root + ".Core.CompilerServices.RuntimeHelpers"
6965
let ExtraTopLevelOperatorsName = Root + ".Core.ExtraTopLevelOperators"
7066
let NativeInteropName = Root + ".NativeInterop"
7167

@@ -77,7 +73,6 @@ module FSharpLib =
7773
let NativeInteropPath = splitNamespace NativeInteropName |> Array.ofList
7874
let CompilerServicesPath = splitNamespace CompilerServicesName |> Array.ofList
7975
let LinqRuntimeHelpersPath = splitNamespace LinqRuntimeHelpersName |> Array.ofList
80-
let RuntimeHelpersPath = splitNamespace RuntimeHelpersName |> Array.ofList
8176
let QuotationsPath = splitNamespace QuotationsName |> Array.ofList
8277

8378
let RootPathArray = RootPath |> Array.ofList
@@ -218,7 +213,6 @@ type TcGlobals(
218213
let mk_MFLinq_tcref ccu n = mkNonLocalTyconRef2 ccu LinqPathArray n
219214
let mk_MFCollections_tcref ccu n = mkNonLocalTyconRef2 ccu CollectionsPathArray n
220215
let mk_MFCompilerServices_tcref ccu n = mkNonLocalTyconRef2 ccu CompilerServicesPath n
221-
let mk_MFRuntimeHelpers_tcref ccu n = mkNonLocalTyconRef2 ccu RuntimeHelpersPath n
222216
let mk_MFControl_tcref ccu n = mkNonLocalTyconRef2 ccu ControlPathArray n
223217

224218
let tryFindSysTypeCcu path nm =
@@ -1893,6 +1887,10 @@ type TcGlobals(
18931887
/// Indicates if we can use System.Array.Empty when emitting IL for empty array literals
18941888
member val isArrayEmptyAvailable = v_Array_tcref.ILTyconRawMetadata.Methods.FindByName "Empty" |> List.isEmpty |> not
18951889

1890+
member g.isSpliceOperator v =
1891+
primValRefEq g.compilingFSharpCore g.fslibCcu v g.splice_expr_vref ||
1892+
primValRefEq g.compilingFSharpCore g.fslibCcu v g.splice_raw_expr_vref
1893+
18961894
member _.FindSysTyconRef path nm = findSysTyconRef path nm
18971895

18981896
member _.TryFindSysTyconRef path nm = tryFindSysTyconRef path nm

0 commit comments

Comments
 (0)