Skip to content

Commit

Permalink
Merge pull request #17463 from dotnet/merges/main-to-release/dev17.12
Browse files Browse the repository at this point in the history
Merge main to release/dev17.12
  • Loading branch information
psfinaki authored Jul 30, 2024
2 parents f5111c6 + a7af225 commit 1b491f6
Show file tree
Hide file tree
Showing 26 changed files with 1,624 additions and 1,481 deletions.
2 changes: 1 addition & 1 deletion .fantomasignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ src/Compiler/Checking/AttributeChecking.fs
src/Compiler/Checking/AugmentWithHashCompare.fs
src/Compiler/Checking/CheckBasics.fs
src/Compiler/Checking/CheckDeclarations.fs
src/Compiler/Checking/CheckExpressions.fs
src/Compiler/Checking/Expressions/CheckExpressions.fs
src/Compiler/Checking/CheckFormatStrings.fs
src/Compiler/Checking/CheckIncrementalClasses.fs
src/Compiler/Checking/CheckPatterns.fs
Expand Down
4 changes: 2 additions & 2 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The following are the key data formats and internal data representations of the

* _Typed Abstract Syntax Tree (Typed Tree)_, see [TypedTree.fs](https://github.com/dotnet/fsharp/blob/main/src/Compiler/TypedTree/TypedTree.fs), [TypedTreeBasics.fs](https://github.com/dotnet/fsharp/blob/main/src/Compiler/TypedTree/TypedTreeBasics.fs), [TypedTreeOps.fs](https://github.com/dotnet/fsharp/blob/main/src/Compiler/TypedTree/TypedTreeOps.fs), and related files. The typed, bound syntax tree including both type/module definitions and their backing expressions, resulting from type checking and the subject of successive phases of optimization and representation change.

* _Type checking context/state_, see for example [`TcState` in ParseAndCheckInputs.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Driver/ParseAndCheckInputs.fsi) and its constituent parts, particularly `TcEnv` in [CheckExpressions.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/CheckExpressions.fsi) and `NameResolutionEnv` in [NameResolution.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/NameResolution.fsi). A set of tables representing the available names, assemblies etc. in scope during type checking, plus associated information.
* _Type checking context/state_, see for example [`TcState` in ParseAndCheckInputs.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Driver/ParseAndCheckInputs.fsi) and its constituent parts, particularly `TcEnv` in [CheckExpressions.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/Expressions/CheckExpressions.fsi) and `NameResolutionEnv` in [NameResolution.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/NameResolution.fsi). A set of tables representing the available names, assemblies etc. in scope during type checking, plus associated information.

* _Abstract IL_, the output of code generation, then used for binary generation, and the input format when reading .NET assemblies, see [`ILModuleDef` in il.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/AbstractIL/il.fsi).

Expand Down Expand Up @@ -146,7 +146,7 @@ The following are the key phases and high-level logical operations of the F# com

* _Sequentially type checking files_, see [CheckDeclarations.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/CheckDeclarations.fsi)/[CheckDeclarations.fs](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/CheckDeclarations.fs). Accepts an AST plus a type checking context/state and produces new Typed Tree nodes
incorporated into an updated type checking state, plus additional Typed Tree Expression nodes used during code generation. A key part of this is
checking syntactic types and expressions, see [CheckExpressions.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/CheckDeclarations.fsi)/[CheckExpressions.fs](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/CheckDeclarations.fs) including the state held across the checking of a file (see `TcFileState`) and the
checking syntactic types and expressions, see [CheckExpressions.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/CheckDeclarations.fsi)/[CheckExpressions.fs](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/Expressions/CheckDeclarations.fs) including the state held across the checking of a file (see `TcFileState`) and the
environment active as we traverse declarations and expressions (see `TcEnv`).

* _Pattern match compilation_, see [PatternMatchCompilation.fsi](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/PatternMatchCompilation.fsi)/[PatternMatchCompilation.fs](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/PatternMatchCompilation.fs). Accepts a subset of checked Typed Tree nodes representing F# pattern matching and produces Typed Tree expressions implementing the pattern matching. Called during type checking as each construct involving pattern matching is processed.
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
* Treat `{ new Foo() }` as `SynExpr.ObjExpr` ([PR #17388](https://github.com/dotnet/fsharp/pull/17388))
* Optimize metadata reading for type members and custom attributes. ([PR #17364](https://github.com/dotnet/fsharp/pull/17364))
* Enforce `AttributeTargets` on unions. ([PR #17389](https://github.com/dotnet/fsharp/pull/17389))
* Ensure that isinteractive multi-emit backing fields are not public. ([Issue #17439](https://github.com/dotnet/fsharp/issues/17438)), ([PR #17439](https://github.com/dotnet/fsharp/pull/17439))

### Breaking Changes
10 changes: 7 additions & 3 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ open Internal.Utilities.Collections
open Internal.Utilities.Library
open Internal.Utilities.Library.Extras
open Internal.Utilities.Library.ResultOrException
open FSharp.Compiler
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.AccessibilityLogic
open FSharp.Compiler.AttributeChecking
open FSharp.Compiler.CheckComputationExpressions
open FSharp.Compiler.CheckExpressions
open FSharp.Compiler.CheckSequenceExpressions
open FSharp.Compiler.CheckArrayOrListComputedExpressions
open FSharp.Compiler.CheckBasics
open FSharp.Compiler.CheckExpressionsOps
open FSharp.Compiler.CheckIncrementalClasses
open FSharp.Compiler.CheckPatterns
open FSharp.Compiler.ConstraintSolver
Expand Down Expand Up @@ -413,6 +416,7 @@ let private CheckDuplicatesAbstractMethodParmsSig (typeSpecs: SynTypeDefnSig li
| _ -> ()

module TcRecdUnionAndEnumDeclarations =
open CheckExpressionsOps

let CombineReprAccess parent vis =
match parent with
Expand Down Expand Up @@ -612,7 +616,7 @@ module TcRecdUnionAndEnumDeclarations =
| _ ->
let expr, actualTy, _ = TcExprOfUnknownType cenv env tpenv valueExpr
UnifyTypes cenv env valueRange fieldTy actualTy

match EvalLiteralExprOrAttribArg cenv.g expr with
| Expr.Const (konst, _, _) -> MakeEnumCaseSpec g cenv env parent attrs thisTy caseRange id xmldoc konst
| _ -> error(Error(FSComp.SR.tcInvalidEnumerationLiteral(), valueRange))
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckPatterns.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ open FSharp.Compiler.Text.Range
open FSharp.Compiler.TypedTree
open FSharp.Compiler.TypedTreeBasics
open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.CheckExpressionsOps

type cenv = TcFileState

Expand Down Expand Up @@ -787,4 +788,3 @@ and TcPatLongIdentLiteral warnOnUpper (cenv: cenv) env vFlags patEnv ty (mLongId
and TcPatterns warnOnUpper cenv env vFlags s argTys args =
assert (List.length args = List.length argTys)
List.mapFold (fun s (ty, pat) -> TcPat warnOnUpper cenv env None vFlags s ty pat) s (List.zip argTys args)

Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

/// Sequence expressions checking
module internal FSharp.Compiler.CheckArrayOrListComputedExpressions

open FSharp.Compiler.CheckBasics
open FSharp.Compiler.ConstraintSolver
open FSharp.Compiler.CheckExpressionsOps
open FSharp.Compiler.CheckExpressions
open FSharp.Compiler.NameResolution
open FSharp.Compiler.TypedTreeOps
open FSharp.Compiler.Features
open FSharp.Compiler.DiagnosticsLogger
open FSharp.Compiler.Syntax
open FSharp.Compiler.CheckSequenceExpressions

let TcArrayOrListComputedExpression (cenv: TcFileState) env (overallTy: OverallTy) tpenv (isArray, comp) m =
let g = cenv.g

// The syntax '[ n .. m ]' and '[ n .. step .. m ]' is not really part of array or list syntax.
// It could be in the future, e.g. '[ 1; 2..30; 400 ]'
//
// The elaborated form of '[ n .. m ]' is 'List.ofSeq (seq (op_Range n m))' and this shouldn't change
match RewriteRangeExpr comp with
| Some replacementExpr ->
let genCollElemTy = NewInferenceType g

let genCollTy = (if isArray then mkArrayType else mkListTy) cenv.g genCollElemTy

UnifyTypes cenv env m overallTy.Commit genCollTy

let exprTy = mkSeqTy cenv.g genCollElemTy

let expr, tpenv = TcExpr cenv (MustEqual exprTy) env tpenv replacementExpr

let expr =
if cenv.g.compilingFSharpCore then
expr
else
// We add a call to 'seq ... ' to make sure sequence expression compilation gets applied to the contents of the
// comprehension. But don't do this in FSharp.Core.dll since 'seq' may not yet be defined.
mkCallSeq cenv.g m genCollElemTy expr

let expr = mkCoerceExpr (expr, exprTy, expr.Range, overallTy.Commit)

let expr =
if isArray then
mkCallSeqToArray cenv.g m genCollElemTy expr
else
mkCallSeqToList cenv.g m genCollElemTy expr

expr, tpenv

| None ->

// LanguageFeatures.ImplicitYield do not require this validation
let implicitYieldEnabled =
cenv.g.langVersion.SupportsFeature LanguageFeature.ImplicitYield

let validateExpressionWithIfRequiresParenthesis = not implicitYieldEnabled
let acceptDeprecatedIfThenExpression = not implicitYieldEnabled

match comp with
| SimpleSemicolonSequence cenv acceptDeprecatedIfThenExpression elems ->
match comp with
| SimpleSemicolonSequence cenv false _ -> ()
| _ when validateExpressionWithIfRequiresParenthesis ->
errorR (Deprecated(FSComp.SR.tcExpressionWithIfRequiresParenthesis (), m))
| _ -> ()

let replacementExpr =
if isArray then
// This are to improve parsing/processing speed for parser tables by converting to an array blob ASAP
let nelems = elems.Length

if
nelems > 0
&& List.forall
(function
| SynExpr.Const(SynConst.UInt16 _, _) -> true
| _ -> false)
elems
then
SynExpr.Const(
SynConst.UInt16s(
Array.ofList (
List.map
(function
| SynExpr.Const(SynConst.UInt16 x, _) -> x
| _ -> failwith "unreachable")
elems
)
),
m
)
elif
nelems > 0
&& List.forall
(function
| SynExpr.Const(SynConst.Byte _, _) -> true
| _ -> false)
elems
then
SynExpr.Const(
SynConst.Bytes(
Array.ofList (
List.map
(function
| SynExpr.Const(SynConst.Byte x, _) -> x
| _ -> failwith "unreachable")
elems
),
SynByteStringKind.Regular,
m
),
m
)
else
SynExpr.ArrayOrList(isArray, elems, m)
else if cenv.g.langVersion.SupportsFeature(LanguageFeature.ReallyLongLists) then
SynExpr.ArrayOrList(isArray, elems, m)
else
if elems.Length > 500 then
error (Error(FSComp.SR.tcListLiteralMaxSize (), m))

SynExpr.ArrayOrList(isArray, elems, m)

TcExprUndelayed cenv overallTy env tpenv replacementExpr
| _ ->

let genCollElemTy = NewInferenceType g

let genCollTy = (if isArray then mkArrayType else mkListTy) cenv.g genCollElemTy

// Propagating type directed conversion, e.g. for
// let x : seq<int64> = [ yield 1; if true then yield 2 ]
TcPropagatingExprLeafThenConvert cenv overallTy genCollTy env (* canAdhoc *) m (fun () ->

let exprTy = mkSeqTy cenv.g genCollElemTy

// Check the comprehension
let expr, tpenv = TcSequenceExpression cenv env tpenv comp (MustEqual exprTy) m

let expr = mkCoerceIfNeeded cenv.g exprTy (tyOfExpr cenv.g expr) expr

let expr =
if cenv.g.compilingFSharpCore then
//warning(Error(FSComp.SR.fslibUsingComputedListOrArray(), expr.Range))
expr
else
// We add a call to 'seq ... ' to make sure sequence expression compilation gets applied to the contents of the
// comprehension. But don't do this in FSharp.Core.dll since 'seq' may not yet be defined.
mkCallSeq cenv.g m genCollElemTy expr

let expr = mkCoerceExpr (expr, exprTy, expr.Range, overallTy.Commit)

let expr =
if isArray then
mkCallSeqToArray cenv.g m genCollElemTy expr
else
mkCallSeqToList cenv.g m genCollElemTy expr

expr, tpenv)
Loading

0 comments on commit 1b491f6

Please sign in to comment.