Skip to content
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
1 change: 0 additions & 1 deletion src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,6 @@ featureRequiredProperties,"support for required properties"
featureMatchNotAllowedForUnionCaseWithNoData,"Pattern match discard is not allowed for union case that takes no data."
featureCSharpExtensionAttributeNotRequired,"Allow implicit Extension attribute on declaring types, modules"
featureErrorForNonVirtualMembersOverrides,"Raises errors for non-virtual members overrides"
featureArithmeticInLiterals,"Arithmetic and logical operations in literals, enum definitions and attributes"
featureErrorReportingOnStaticClasses,"Error reporting on static classes"
featureWarningWhenCopyAndUpdateRecordChangesAllFields,"Raises warnings when an copy-and-update record expression changes all fields of a record."
featureNonInlineLiteralsAsPrintfFormat,"String values marked as literals and IL constants as printf format"
Expand Down
7 changes: 0 additions & 7 deletions src/Compiler/Facilities/DiagnosticsLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -869,13 +869,6 @@ let NormalizeErrorRichText (text: RichText) =

RichText.ofParts (parts.ToArray())

/// Indicates whether a language feature check should be skipped. Typically used in recursive functions
/// where we don't want repeated recursive calls to raise the same diagnostic multiple times.
[<RequireQualifiedAccess>]
type internal SuppressLanguageFeatureCheck =
| Yes
| No

let internal languageFeatureError (langVersion: LanguageVersion) (langFeature: LanguageFeature) (m: range) =
let featureStr = LanguageVersion.GetFeatureString langFeature
let currentVersionStr = langVersion.SpecifiedVersionString
Expand Down
7 changes: 0 additions & 7 deletions src/Compiler/Facilities/DiagnosticsLogger.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,6 @@ val NormalizeErrorString: text: string -> string
/// classification of each part is preserved. Parts left empty by normalization are dropped.
val NormalizeErrorRichText: text: RichText -> RichText

/// Indicates whether a language feature check should be skipped. Typically used in recursive functions
/// where we don't want repeated recursive calls to raise the same diagnostic multiple times.
[<RequireQualifiedAccess>]
type SuppressLanguageFeatureCheck =
| Yes
| No

val languageFeatureError: langVersion: LanguageVersion -> langFeature: LanguageFeature -> m: range -> exn

val checkLanguageFeatureError: langVersion: LanguageVersion -> langFeature: LanguageFeature -> m: range -> unit
Expand Down
3 changes: 0 additions & 3 deletions src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type LanguageFeature =
| MatchNotAllowedForUnionCaseWithNoData
| CSharpExtensionAttributeNotRequired
| ErrorForNonVirtualMembersOverrides
| ArithmeticInLiterals
| ErrorReportingOnStaticClasses
| WarningWhenCopyAndUpdateRecordChangesAllFields
| NonInlineLiteralsAsPrintfFormat
Expand Down Expand Up @@ -155,7 +154,6 @@ type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array)
LanguageFeature.MatchNotAllowedForUnionCaseWithNoData, languageVersion80
LanguageFeature.CSharpExtensionAttributeNotRequired, languageVersion80
LanguageFeature.ErrorForNonVirtualMembersOverrides, languageVersion80
LanguageFeature.ArithmeticInLiterals, languageVersion80
LanguageFeature.ErrorReportingOnStaticClasses, languageVersion80
LanguageFeature.WarningWhenCopyAndUpdateRecordChangesAllFields, languageVersion80
LanguageFeature.NonInlineLiteralsAsPrintfFormat, languageVersion80
Expand Down Expand Up @@ -335,7 +333,6 @@ type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array)
| LanguageFeature.MatchNotAllowedForUnionCaseWithNoData -> FSComp.SR.featureMatchNotAllowedForUnionCaseWithNoData ()
| LanguageFeature.CSharpExtensionAttributeNotRequired -> FSComp.SR.featureCSharpExtensionAttributeNotRequired ()
| LanguageFeature.ErrorForNonVirtualMembersOverrides -> FSComp.SR.featureErrorForNonVirtualMembersOverrides ()
| LanguageFeature.ArithmeticInLiterals -> FSComp.SR.featureArithmeticInLiterals ()
| LanguageFeature.ErrorReportingOnStaticClasses -> FSComp.SR.featureErrorReportingOnStaticClasses ()
| LanguageFeature.WarningWhenCopyAndUpdateRecordChangesAllFields ->
FSComp.SR.featureWarningWhenCopyAndUpdateRecordChangesAllFields ()
Expand Down
1 change: 0 additions & 1 deletion src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type LanguageFeature =
| MatchNotAllowedForUnionCaseWithNoData
| CSharpExtensionAttributeNotRequired
| ErrorForNonVirtualMembersOverrides
| ArithmeticInLiterals
| ErrorReportingOnStaticClasses
| WarningWhenCopyAndUpdateRecordChangesAllFields
| NonInlineLiteralsAsPrintfFormat
Expand Down
109 changes: 30 additions & 79 deletions src/Compiler/TypedTree/TypedTreeOps.Transforms.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2439,14 +2439,10 @@ module internal ConstantEvaluation =
error (Error(FSComp.SR.tastConstantExpressionOverflow (), m))

// See also PostTypeCheckSemanticChecks.CheckAttribArgExpr, which must match this precisely
let rec EvalAttribArgExpr suppressLangFeatureCheck (g: TcGlobals) (x: Expr) =
let rec EvalAttribArgExpr (g: TcGlobals) (x: Expr) =
let ignore (_x: 'a) = Unchecked.defaultof<'a>
let ignore2 (_x: 'a) (_y: 'a) = Unchecked.defaultof<'a>

let inline checkFeature () =
if suppressLangFeatureCheck = SuppressLanguageFeatureCheck.No then
checkLanguageFeatureAndRecover g.langVersion LanguageFeature.ArithmeticInLiterals x.Range

match x with

// Detect standard constants
Expand Down Expand Up @@ -2476,33 +2472,28 @@ module internal ConstantEvaluation =

| TypeOfExpr g _ -> x
| TypeDefOfExpr g _ -> x
| Expr.Op(TOp.Coerce, _, [ arg ], _) -> EvalAttribArgExpr suppressLangFeatureCheck g arg
| EnumExpr g arg1 -> EvalAttribArgExpr suppressLangFeatureCheck g arg1
| Expr.Op(TOp.Coerce, _, [ arg ], _) -> EvalAttribArgExpr g arg
| EnumExpr g arg1 -> EvalAttribArgExpr g arg1
// Detect bitwise or of attribute flags
| AttribBitwiseOrExpr g (arg1, arg2) ->
let v1 = EvalAttribArgExpr suppressLangFeatureCheck g arg1
let v1 = EvalAttribArgExpr g arg1

match v1 with
| IntegerConstExpr ->
EvalArithBinOp
((|||), (|||), (|||), (|||), (|||), (|||), (|||), (|||), ignore2, ignore2, ignore2)
v1
(EvalAttribArgExpr suppressLangFeatureCheck g arg2)
(EvalAttribArgExpr g arg2)
| _ ->
errorR (Error(FSComp.SR.tastNotAConstantExpression (), x.Range))
x
| SpecificBinopExpr g g.unchecked_addition_vref (arg1, arg2) ->
let v1, v2 =
EvalAttribArgExpr suppressLangFeatureCheck g arg1, EvalAttribArgExpr suppressLangFeatureCheck g arg2
let v1, v2 = EvalAttribArgExpr g arg1, EvalAttribArgExpr g arg2

match v1, v2 with
| Expr.Const(Const.String x1, m, ty), Expr.Const(Const.String x2, _, _) -> Expr.Const(Const.String(x1 + x2), m, ty)
| Expr.Const(Const.Char x1, m, ty), Expr.Const(Const.Char x2, _, _) ->
checkFeature ()
Expr.Const(Const.Char(x1 + x2), m, ty)
| Expr.Const(Const.Char x1, m, ty), Expr.Const(Const.Char x2, _, _) -> Expr.Const(Const.Char(x1 + x2), m, ty)
| _ ->
checkFeature ()

EvalArithBinOp
(Checked.(+),
Checked.(+),
Expand All @@ -2518,10 +2509,7 @@ module internal ConstantEvaluation =
v1
v2
| SpecificBinopExpr g g.unchecked_subtraction_vref (arg1, arg2) ->
checkFeature ()

let v1, v2 =
EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1, EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg2
let v1, v2 = EvalAttribArgExpr g arg1, EvalAttribArgExpr g arg2

match v1, v2 with
| Expr.Const(Const.Char x1, m, ty), Expr.Const(Const.Char x2, _, _) -> Expr.Const(Const.Char(x1 - x2), m, ty)
Expand All @@ -2541,8 +2529,6 @@ module internal ConstantEvaluation =
v1
v2
| SpecificBinopExpr g g.unchecked_multiply_vref (arg1, arg2) ->
checkFeature ()

EvalArithBinOp
(Checked.(*),
Checked.(*),
Expand All @@ -2555,90 +2541,63 @@ module internal ConstantEvaluation =
Checked.(*),
Checked.(*),
Checked.(*))
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1)
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg2)
(EvalAttribArgExpr g arg1)
(EvalAttribArgExpr g arg2)
| SpecificBinopExpr g g.unchecked_division_vref (arg1, arg2) ->
checkFeature ()

EvalArithBinOp
((/), (/), (/), (/), (/), (/), (/), (/), (/), (/), (/))
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1)
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg2)
EvalArithBinOp ((/), (/), (/), (/), (/), (/), (/), (/), (/), (/), (/)) (EvalAttribArgExpr g arg1) (EvalAttribArgExpr g arg2)
| SpecificBinopExpr g g.unchecked_modulus_vref (arg1, arg2) ->
checkFeature ()

EvalArithBinOp
((%), (%), (%), (%), (%), (%), (%), (%), (%), (%), (%))
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1)
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg2)
EvalArithBinOp ((%), (%), (%), (%), (%), (%), (%), (%), (%), (%), (%)) (EvalAttribArgExpr g arg1) (EvalAttribArgExpr g arg2)
| SpecificBinopExpr g g.bitwise_shift_left_vref (arg1, arg2) ->
checkFeature ()

EvalArithShiftOp
((<<<), (<<<), (<<<), (<<<), (<<<), (<<<), (<<<), (<<<))
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1)
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg2)
EvalArithShiftOp ((<<<), (<<<), (<<<), (<<<), (<<<), (<<<), (<<<), (<<<)) (EvalAttribArgExpr g arg1) (EvalAttribArgExpr g arg2)
| SpecificBinopExpr g g.bitwise_shift_right_vref (arg1, arg2) ->
checkFeature ()

EvalArithShiftOp
((>>>), (>>>), (>>>), (>>>), (>>>), (>>>), (>>>), (>>>))
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1)
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg2)
EvalArithShiftOp ((>>>), (>>>), (>>>), (>>>), (>>>), (>>>), (>>>), (>>>)) (EvalAttribArgExpr g arg1) (EvalAttribArgExpr g arg2)
| SpecificBinopExpr g g.bitwise_and_vref (arg1, arg2) ->
checkFeature ()
let v1 = EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1
let v1 = EvalAttribArgExpr g arg1

match v1 with
| IntegerConstExpr ->
EvalArithBinOp
((&&&), (&&&), (&&&), (&&&), (&&&), (&&&), (&&&), (&&&), ignore2, ignore2, ignore2)
v1
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg2)
(EvalAttribArgExpr g arg2)
| _ ->
errorR (Error(FSComp.SR.tastNotAConstantExpression (), x.Range))
x
| SpecificBinopExpr g g.bitwise_xor_vref (arg1, arg2) ->
checkFeature ()
let v1 = EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1
let v1 = EvalAttribArgExpr g arg1

match v1 with
| IntegerConstExpr ->
EvalArithBinOp
((^^^), (^^^), (^^^), (^^^), (^^^), (^^^), (^^^), (^^^), ignore2, ignore2, ignore2)
v1
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg2)
(EvalAttribArgExpr g arg2)
| _ ->
errorR (Error(FSComp.SR.tastNotAConstantExpression (), x.Range))
x
| SpecificBinopExpr g g.exponentiation_vref (arg1, arg2) ->
checkFeature ()
let v1 = EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1
let v1 = EvalAttribArgExpr g arg1

match v1 with
| FloatConstExpr ->
EvalArithBinOp
(ignore2, ignore2, ignore2, ignore2, ignore2, ignore2, ignore2, ignore2, ( ** ), ( ** ), ignore2)
v1
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg2)
(EvalAttribArgExpr g arg2)
| _ ->
errorR (Error(FSComp.SR.tastNotAConstantExpression (), x.Range))
x
| SpecificUnopExpr g g.bitwise_unary_not_vref arg1 ->
checkFeature ()
let v1 = EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1
let v1 = EvalAttribArgExpr g arg1

match v1 with
| IntegerConstExpr ->
EvalArithUnOp
((~~~), (~~~), (~~~), (~~~), (~~~), (~~~), (~~~), (~~~), ignore, ignore)
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1)
EvalArithUnOp ((~~~), (~~~), (~~~), (~~~), (~~~), (~~~), (~~~), (~~~), ignore, ignore) (EvalAttribArgExpr g arg1)
| _ ->
errorR (Error(FSComp.SR.tastNotAConstantExpression (), x.Range))
x
| SpecificUnopExpr g g.unchecked_unary_minus_vref arg1 ->
checkFeature ()
let v1 = EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1
let v1 = EvalAttribArgExpr g arg1

match v1 with
| SignedConstExpr ->
Expand All @@ -2649,15 +2608,9 @@ module internal ConstantEvaluation =
errorR (Error(FSComp.SR.tastNotAConstantExpression (), v1.Range))
x
| SpecificUnopExpr g g.unchecked_unary_plus_vref arg1 ->
checkFeature ()

EvalArithUnOp
((~+), (~+), (~+), (~+), (~+), (~+), (~+), (~+), (~+), (~+))
(EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1)
EvalArithUnOp ((~+), (~+), (~+), (~+), (~+), (~+), (~+), (~+), (~+), (~+)) (EvalAttribArgExpr g arg1)
| SpecificUnopExpr g g.unchecked_unary_not_vref arg1 ->
checkFeature ()

match EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g arg1 with
match EvalAttribArgExpr g arg1 with
| Expr.Const(Const.Bool value, m, ty) -> Expr.Const(Const.Bool(not value), m, ty)
| expr ->
errorR (Error(FSComp.SR.tastNotAConstantExpression (), expr.Range))
Expand All @@ -2666,16 +2619,14 @@ module internal ConstantEvaluation =
| Expr.Match(
decision = TDSwitch(input = input; cases = [ TCase(DecisionTreeTest.Const(Const.Bool test), TDSuccess([], targetNum)) ])
targets = [| TTarget(_, t0, _); TTarget(_, t1, _) |]) ->
checkFeature ()

match EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g (stripDebugPoints input) with
match EvalAttribArgExpr g (stripDebugPoints input) with
| Expr.Const(Const.Bool value, _, _) ->
let pass, fail = if targetNum = 0 then t0, t1 else t1, t0

if value = test then
EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g (stripDebugPoints pass)
EvalAttribArgExpr g (stripDebugPoints pass)
else
EvalAttribArgExpr SuppressLanguageFeatureCheck.Yes g (stripDebugPoints fail)
EvalAttribArgExpr g (stripDebugPoints fail)
| _ ->
errorR (Error(FSComp.SR.tastNotAConstantExpression (), x.Range))
x
Expand Down Expand Up @@ -2713,9 +2664,9 @@ module internal ConstantEvaluation =
match x with
| Expr.Op(TOp.Coerce, _, [ Expr.Op(TOp.Array, [ elemTy ], args, m) ], _)
| Expr.Op(TOp.Array, [ elemTy ], args, m) ->
let args = args |> List.map (EvalAttribArgExpr SuppressLanguageFeatureCheck.No g)
let args = args |> List.map (EvalAttribArgExpr g)
Expr.Op(TOp.Array, [ elemTy ], args, m)
| _ -> EvalAttribArgExpr SuppressLanguageFeatureCheck.No g x
| _ -> EvalAttribArgExpr g x

/// Match an Int32 constant expression
[<return: Struct>]
Expand Down
5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading