Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slight cleanup of dead and repeated code #17412

Merged
merged 5 commits into from
Jul 19, 2024
Merged
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
5 changes: 1 addition & 4 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2822,10 +2822,7 @@ let TcVal checkAttributes (cenv: cenv) env (tpenv: UnscopedTyparEnv) (vref: ValR
let exprForVal = Expr.Val (vref, vrefFlags, m)
let exprForVal = mkTyAppExpr m (exprForVal, vTy) tinst
let isSpecial =
(match vrefFlags with NormalValUse | PossibleConstrainedCall _ -> false | _ -> true) ||
valRefEq g vref g.splice_expr_vref ||
valRefEq g vref g.splice_raw_expr_vref

(match vrefFlags with NormalValUse | PossibleConstrainedCall _ -> false | _ -> true) || g.isSpliceOperator vref
let exprForVal = RecordUseOfRecValue cenv valRecInfo vref exprForVal m

tpsorig, exprForVal, isSpecial, tau, tinst, tpenv
Expand Down
10 changes: 3 additions & 7 deletions src/Compiler/Checking/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,6 @@ let CheckNoReraise cenv freesOpt (body: Expr) =
if fvs.UsesUnboundRethrow then
errorR(Error(FSComp.SR.chkErrorContainsCallToRethrow(), body.Range))

/// Check if a function is a quotation splice operator
let isSpliceOperator g v = valRefEq g v g.splice_expr_vref || valRefEq g v g.splice_raw_expr_vref


/// Examples:
/// I<int> & I<int> => ExactlyEqual.
/// I<int> & I<string> => NotEqual.
Expand Down Expand Up @@ -776,8 +772,8 @@ let rec CheckExprNoByrefs cenv env expr =
and CheckValRef (cenv: cenv) (env: env) v m (ctxt: PermitByRefExpr) =

if cenv.reportErrors then
if isSpliceOperator cenv.g v && not env.quote then errorR(Error(FSComp.SR.chkSplicingOnlyInQuotations(), m))
if isSpliceOperator cenv.g v then errorR(Error(FSComp.SR.chkNoFirstClassSplicing(), m))
if cenv.g.isSpliceOperator v && not env.quote then errorR(Error(FSComp.SR.chkSplicingOnlyInQuotations(), m))
if cenv.g.isSpliceOperator v then errorR(Error(FSComp.SR.chkNoFirstClassSplicing(), m))
if valRefEq cenv.g v cenv.g.addrof_vref then errorR(Error(FSComp.SR.chkNoFirstClassAddressOf(), m))
if valRefEq cenv.g v cenv.g.reraise_vref then errorR(Error(FSComp.SR.chkNoFirstClassRethrow(), m))
if valRefEq cenv.g v cenv.g.nameof_vref then errorR(Error(FSComp.SR.chkNoFirstClassNameOf(), m))
Expand Down Expand Up @@ -1192,7 +1188,7 @@ and CheckExpr (cenv: cenv) (env: env) origExpr (ctxt: PermitByRefExpr) : Limit =
NoLimit

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

// Check an application
Expand Down
6 changes: 2 additions & 4 deletions src/Compiler/Checking/QuotationTranslator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ let (|ObjectInitializationCheck|_|) g expr =
isUnitTy g resultTy -> ValueSome()
| _ -> ValueNone

let isSplice g vref = valRefEq g vref g.splice_expr_vref || valRefEq g vref g.splice_raw_expr_vref

let rec EmitDebugInfoIfNecessary cenv env m astExpr : ExprData =
// do not emit debug info if emitDebugInfoInQuotations = false or it was already written for the given expression
if cenv.emitDebugInfoInQuotations && not (QP.isAttributedExpression astExpr) then
Expand Down Expand Up @@ -298,7 +296,7 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
match expr with
// Detect expression tree exprSplices
| Expr.App (InnerExprPat(Expr.Val (vref, _, _)), _, _, x0 :: rest, m)
when isSplice g vref ->
when g.isSpliceOperator vref ->
let idx = cenv.exprSplices.Count
let ty = tyOfExpr g expr

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

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

let numEnclTypeArgs, _, isNewObj, valUseFlags, isSelfInit, takesInstanceArg, isPropGet, isPropSet =
Expand Down
2 changes: 0 additions & 2 deletions src/Compiler/Checking/QuotationTranslator.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,3 @@ val (|SimpleArrayLoopBody|_|): TcGlobals -> Expr -> (Expr * TType * Expr) voptio

[<return: Struct>]
val (|ObjectInitializationCheck|_|): TcGlobals -> Expr -> unit voption

val isSplice: TcGlobals -> ValRef -> bool
10 changes: 4 additions & 6 deletions src/Compiler/TypedTree/TcGlobals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ open System.Diagnostics
open Internal.Utilities.Library
open Internal.Utilities.Library.Extras
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.AbstractIL.ILX
open FSharp.Compiler.CompilerGlobalState
open FSharp.Compiler.Features
open FSharp.Compiler.IO
Expand All @@ -24,9 +23,7 @@ open FSharp.Compiler.Text.FileIndex
open FSharp.Compiler.Text.Range
open FSharp.Compiler.TypedTree
open FSharp.Compiler.TypedTreeBasics

open Internal.Utilities
open System.Reflection

let internal DummyFileNameForRangesWithoutASpecificLocation = startupFileName
let private envRange = rangeN DummyFileNameForRangesWithoutASpecificLocation 0
Expand Down Expand Up @@ -65,7 +62,6 @@ module FSharpLib =
let LanguagePrimitivesName = Root + ".Core.LanguagePrimitives"
let CompilerServicesName = Root + ".Core.CompilerServices"
let LinqRuntimeHelpersName = Root + ".Linq.RuntimeHelpers"
let RuntimeHelpersName = Root + ".Core.CompilerServices.RuntimeHelpers"
let ExtraTopLevelOperatorsName = Root + ".Core.ExtraTopLevelOperators"
let NativeInteropName = Root + ".NativeInterop"

Expand All @@ -77,7 +73,6 @@ module FSharpLib =
let NativeInteropPath = splitNamespace NativeInteropName |> Array.ofList
let CompilerServicesPath = splitNamespace CompilerServicesName |> Array.ofList
let LinqRuntimeHelpersPath = splitNamespace LinqRuntimeHelpersName |> Array.ofList
let RuntimeHelpersPath = splitNamespace RuntimeHelpersName |> Array.ofList
let QuotationsPath = splitNamespace QuotationsName |> Array.ofList

let RootPathArray = RootPath |> Array.ofList
Expand Down Expand Up @@ -218,7 +213,6 @@ type TcGlobals(
let mk_MFLinq_tcref ccu n = mkNonLocalTyconRef2 ccu LinqPathArray n
let mk_MFCollections_tcref ccu n = mkNonLocalTyconRef2 ccu CollectionsPathArray n
let mk_MFCompilerServices_tcref ccu n = mkNonLocalTyconRef2 ccu CompilerServicesPath n
let mk_MFRuntimeHelpers_tcref ccu n = mkNonLocalTyconRef2 ccu RuntimeHelpersPath n
let mk_MFControl_tcref ccu n = mkNonLocalTyconRef2 ccu ControlPathArray n

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

member g.isSpliceOperator v =
primValRefEq g.compilingFSharpCore g.fslibCcu v g.splice_expr_vref ||
primValRefEq g.compilingFSharpCore g.fslibCcu v g.splice_raw_expr_vref

member _.FindSysTyconRef path nm = findSysTyconRef path nm

member _.TryFindSysTyconRef path nm = tryFindSysTyconRef path nm
Expand Down
Loading